In: Statistics and Probability
Dr. Lee now wants to generate a random sample of size 10,000 from the F distribution with df1 = 1 and df2 = 4 degrees of freedom. But he doesn’t remember the probability density function (pdf) of the F distribution at all. Fortunately, he knows the relationship between t distribution and F distribution. He knows that if X follows the t distribution with ν = 4 degrees of freedom, then X2 follows the F distribution with df1 = 1 and df2 = 4 degrees of freedom. 1. First use the Metropolis algorithm to generate a random sample of size 10,000 from the t distribution with ν = 4 degrees of freedom and then use the generated sample together with Dr. Lee’s knowledge to obtain the random sample following F distribution (df1 = 1, df2 = 4). 1 2. To verify Dr. Lee’s knowledge, compute the sample percentiles and compare with the F distribution (df1 = 1, df2 = 4) percentiles. (Hint: Use qf(p, df1, df2) to find F distribution percentiles.)
Here
it is given that X^2 follows F distribution with df1=1 and df2=n if
X follows t distribution with df=n. So first we are generating
samples from the t distribution using Metropolis-algorithm from t
distribution with df=4. The following is the R code to generate
these samples:
target = function(t){
return((3/8)*((1+((t^2)/4))^(-5/2)));
}
x = rep(0,10000)
x[1] = 0 #this is just a starting value,
which I've set arbitrarily to 0, the mean of t distribution
for(i in 2:10000){
currentx = x[i-1]
proposedx = currentx + rnorm(1,mean=0,sd=1)
A = target(proposedx)/target(currentx)
if(runif(1)<A){
x[i] =
proposedx # accept move with
probabily min(1,A)
} else {
x[i] =
currentx # otherwise
"reject" move, and stay where we are
}
}
#x; # the samples generated from the t distribution
xf <- x^2; #the samples generated for f distribution with df1=1, df2=4.
quantile(xf, 0.5) # sample 50th percentile
qf(0.5, 1, 4) # Percentile from f distribuiton
#Output
> #x; # the samples generated from the t distribution
>
> xf <- x^2; #the samples generated for f distribution with
df1=1, df2=4.
>
> quantile(xf, 0.5) # sample 50th percentile
50%
0.5638703
>
> qf(0.5, 1, 4) # Percentile from f distribuiton
[1] 0.5486322