Question: Use R code!!!!!!! We wish to generate realizations from the following pdf using the Accept - Reject method: ( | ) = K ( -
Use R code!!!!!!!
We wish to generate realizations from the following pdf using the AcceptReject method:
;
is the normalizing constant so that it is a proper pdf The value of is not difficult to find and is
Also note that for or
The mean of the above distribution is clearly equal to as it is symmetric about So the first step is
to find the variance of the above distribution,
Recall that in the AR method, a candidate generating distribution is needed along with a
constant such that for all
The candidate generating distribution that I want you to use is the Normal distribution where
is the variance calculated above. The value of will not be provided by the user, so you have
two choices to determine its value automatically:
You can determine its value by maximizing mathematically ie taking derivative,
setting equal to etc. to find and letting
You can determine its value by maximizing empirically by searching for the value of
numerically. I would suggest a simple grid search, but if your background includes
knowledge of numerical optimization, then feel free to utilize it
With the preliminaries out of the way, on to the task at hand. Write a function called "myrdist" to
generate realizations from above using the AcceptReject method.
The function's name must be "myrdist".
It must take the following arguments named as such:
The sample size; ie the number of realizations to generate.
Include error checking to be sure that is a numeric scalar and greater than or
equal to
If it is not an integer, then coerce into the nearest integer less than the value
given.
No default value.
beta This is the value of
Include error checking to be sure that beta is a numeric scalar and greater than
The default value is
It must return a list with the following components:
The vector of realizations, named "realizations".
The value of used, named
The average number of iterations required per realization ie the number of candidate
s generated divided by named "avg,iterations".
We wish to generate realizations from the following pdf using the AcceptReject method:
;
is the normalizing constant so that it is a proper pdf The value of is not difficult to find and is
Also note that for or
The mean of the above distribution is clearly equal to as it is symmetric about So the first step is
to find the variance of the above distribution,
Recall that in the AR method, a candidate generating distribution is needed along with a
constant such that for all
The candidate generating distribution that I want you to use is the Normal distribution where
is the variance calculated above. The value of will not be provided by the user, so you have
two choices to determine its value automatically:
You can determine its value by maximizing mathematically ie taking derivative,
setting equal to etc. to find and letting
Instructions i should be able to copy and paste the R code and execute without having to track down aby bugs Dont use global variables
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
