In: Math
Use R to complete the following questions. You should include your R code, output and plots in your answer.
1. Two methods of generating a standard normal random variable are:
a. Take the sum of 5 uniform (0,1) random numbers and scale to have mean 0 and standard deviation 1. (Use the properties of the uniform distribution to determine the required transformation).
b. Generate a standard uniform and then apply inverse cdf function to obtain a normal random variate (Hint: use qnorm).
For each method generate 10,000 random numbers and check the distribution using
a. Normal probability plot
b. Mean and standard deviation
c. The proportion of the data lying within the theoretical 2.5 and 97.5 percentiles and the 0.5 and 99.5 percentiles. (Hint: The ifelse function will be useful)
r code :- random number generate and output
> ##### uniform random number (sample size n=5 )
> u=runif(n=5,0,1)
> u
[1] 0.01102249 0.39552950 0.78375498 0.02191521 0.75244598
> sum(u)
[1] 1.964668
> a=mean(u);a
[1] 0.3929336
> b=var(u);b
[1] 0.141377
> sd=sqrt(b);sd
[1] 0.3760013
> ####inverse method use genrate random number n=5
> u=runif(5)
> u
[1] 0.13909559 0.09987109 0.11123441 0.01423793 0.86949264
> a=qnorm(u);a
[1] -1.084392 -1.282286 -1.219990 -2.190668 1.123996
> b=mean(u);b
[1] 0.2467863
> c=var(u);c
[1] 0.1233494
> sd=sqrt(c);sd
[1] 0.3512113
> ##### uniform random number n=5
> u=runif(n=5,0,1)
> u
[1] 0.01102249 0.39552950 0.78375498 0.02191521 0.75244598
> sum(u)
[1] 1.964668
> a=mean(u);a
[1] 0.3929336
> b=var(u);b
[1] 0.141377
> sd=sqrt(b);sd
[1] 0.3760013
> ####inverse method use genrate random number n=5
> u=runif(5)
> u
[1] 0.13909559 0.09987109 0.11123441 0.01423793 0.86949264
> a=qnorm(u);a
[1] -1.084392 -1.282286 -1.219990 -2.190668 1.123996
> b=mean(u);b
[1] 0.2467863
> c=var(u);c
[1] 0.1233494
> sd=sqrt(c);sd
[1] 0.3512113
>
> ##### uniform random number n=5
> u=runif(n=5,0,1)
> u
[1] 0.01102249 0.39552950 0.78375498 0.02191521 0.75244598
> sum(u)
[1] 1.964668
> a=mean(u);a
[1] 0.3929336
> b=var(u);b
[1] 0.141377
> sd=sqrt(b);sd
[1] 0.3760013
> ####inverse method use genrate random number n=5
> u=runif(5)
> u
[1] 0.13909559 0.09987109 0.11123441 0.01423793 0.86949264
> a=qnorm(u);a
[1] -1.084392 -1.282286 -1.219990 -2.190668 1.123996
> b=mean(u);b
[1] 0.2467863
> c=var(u);c
[1] 0.1233494
> sd=sqrt(c);sd
[1] 0.3512113
> > ##### uniform random number n=5
> u=runif(n=5,0,1)
> u
[1] 0.01102249 0.39552950 0.78375498 0.02191521 0.75244598
> sum(u)
[1] 1.964668
> a=mean(u);a
[1] 0.3929336
> b=var(u);b
[1] 0.141377
> sd=sqrt(b);sd
[1] 0.3760013
> ####inverse method use genrate random number n=5
> u=runif(5)
> u
[1] 0.13909559 0.09987109 0.11123441 0.01423793 0.86949264
> a=qnorm(u);a
[1] -1.084392 -1.282286 -1.219990 -2.190668 1.123996
> b=mean(u);b
[1] 0.2467863
> c=var(u);c
[1] 0.1233494
> sd=sqrt(c);sd
[1] 0.3512113
> ############random rumber n=10000
> sum(u)
[1] 4987.53
> a=mean(u);a
[1] 0.498753
> b=var(u);b
[1] 0.08299141
> sd=sqrt(b);sd
[1] 0.2880823
> boxplot(u)
> hist(u)
> qqline(u)
Please hit like button