In: Statistics and Probability
R Simulation:
For n = 1000, simulate a random sample of size n from N(0,1). Use the generated data to give an approximation to the critical values when α = 0.01,0.05,0.1, and compare them with the theoretical values zα/2. Repeat with n = 10,000 to get a better approximation.
Please use Commands quantile( ) or qnorm( ) or both.
code
x<- rnorm(1000)
z0.01 <- quantile(x,0.995)
z0.05 <- quantile(x,0.975)
z0.1 <- quantile(x,0.95)
c0.01 <- qnorm(0.995)
c0.05 <- qnorm(0.975)
c0.1 <- qnorm(0.95)
z0.01
c0.01
z0.05
c0.05
z0.1
c0.1
y <- rnorm(10000)
z0.01 <- quantile(y,0.995)
z0.05 <- quantile(y,0.975)
z0.1 <- quantile(y,0.95)
c0.01 <- qnorm(0.995)
c0.05 <- qnorm(0.975)
c0.1 <- qnorm(0.95)
z0.01
c0.01
z0.05
c0.05
z0.1
c0.1
#running the code
> x<- rnorm(1000) > z0.01 <- quantile(x,0.995) > z0.05 <- quantile(x,0.975) > z0.1 <- quantile(x,0.95) > > c0.01 <- qnorm(0.995) > c0.05 <- qnorm(0.975) > c0.1 <- qnorm(0.95) > > > z0.01 99.5% 2.614842 > c0.01 [1] 2.575829 > > z0.05 97.5% 1.818711 > c0.05 [1] 1.959964 > > z0.1 95% 1.567166 > c0.1 [1] 1.644854 > > > y <- rnorm(10000) > z0.01 <- quantile(y,0.995) > z0.05 <- quantile(y,0.975) > z0.1 <- quantile(y,0.95) > > c0.01 <- qnorm(0.995) > c0.05 <- qnorm(0.975) > c0.1 <- qnorm(0.95) > > > z0.01 99.5% 2.561284 > c0.01 [1] 2.575829 > > z0.05 97.5% 1.942748 > c0.05 [1] 1.959964 > > z0.1 95% 1.649045 > c0.1 [1] 1.644854
we see that when n = 10000
both are close to each other