In: Math
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
Suppose, we have two independent random samples from standard normal distribution.
Then,
Using this idea we will first generate a set of 2 standard normal random numbers and another set of 5 standard normal random numbers which are independent from the first set of random numbers.
Then we will square the numbers and add then to get the chi-square distribution with degrees of freedom 2 and 5 respectively. Then finally using the relation of F and Chi-square density we generate the random numbers from F(2,5) distribution. We use for loop and iterate for 1000 times to generate 1000 F(2,5) random numbers.
The R-code is given below:
f_random_number = vector()
for (i in 1:1000){
a = rnorm(2,0,1) # generate 2 standard normal random numbers
b = rnorm(5,0,1) # generate 5 standard normal random numbers
chi1 = sum(a^2) # chi1 follows chi-square distribution with 2
degrees of freedom
chi2 = sum(b^2) # chi1 follows chi-square distribution with 5
degrees of freedom
f = (chi1/2)/(chi2/5) # f is random number from F(2,5)
f_random_number[i]=f
}