Lab Assignment # 2: the Central Limit Theorem and Simulations in R

Lab Assignment # 2: the Central Limit Theorem and Simulations in R

STAT 305 { Solution: Introduction to Statistical Inference Winter 2007 Lab Assignment # 2: The Central Limit Theorem and Simulations in R Question 1. a) X is a discreet random variable and hence the mean for X X6 X6 1 1 X6 ¹ = x p = (i)( ) = ( ) (i) = 3:5 i i 6 6 i=1 i=1 i=1 and the variance X6 1 X6 σ2 = (x ¡ ¹)2p = (i ¡ 3:5)2 = 3:5 i i 6 i=1 i=1 By the central limit theorem, for large n X¹ » N(¹; σ2=n). Hence, X¹ » N(3:5; 0:117) p The standard deviation is sd = 0:117 = 0:34 We can plot this in R > x=seq(2.5,4.5,0.001) >plot(x,dnorm(x,mean=3.5,sd=0.34),type='l',main='The distribution of the sample mean using CLT') The plot is given in the ¯gure 1. b) and c) We need to get samples for X¹. One sample from X¹ means sampling from X 30 times and computing the mean. We choose to get 1000 samples for X¹. The code in R is given in the following: >barX=rep(0,1000) >for (i in 1:1000){barX[i]=mean(sample(1:6,30,replace=T))} >mean(barX) >var(barX) >hist(barX,freq=NULL) 1 Density of normal, mean=3.5,sd=0.34 0.0 0.2 0.4 0.6 0.8 1.0 1.2 2.0 2.5 3.0 3.5 4.0 4.5 5.0 x Figure 1: The distribution of the sample mean using CLT. Histogram of barX Density 0.0 0.2 0.4 0.6 0.8 1.0 1.2 2.5 3.0 3.5 4.0 4.5 barX Figure 2: The distribution of X¹ using CLT and the histogram using simu- lations 2 We get mean=3.501 and var=0.103 using R. The plot obtained in (a) and the histogram obtained in (b) using simulations is given in the ¯gure 2. Question 2. a) We want to ¯nd the probability using di®erent number of iterations. Lets change the number from 1 to 10000. We can change this if necessary af- ter observing the results. We create a vector p to record the computed probability for each iteration. Hence, p should have a length of 10000. If 1 · i · 10000 is the number of iterations, we compute the probability by sampling from the uniform distribution for both X and Y , i times. Then, we count how many times X + Y exceeds 2. The probability will be the number of counts divided by i, the number of iterations. >p=seq(1,10000) >for (i in 1:10000){X=runif(i,0,1) Y=runif(i,0,1) p[i]=sum(X+Y>2)/i } >plot(1:10000,p) b) >p=seq(1,10000) >for (i in 1:10000){X=runif(i,0,1) Y=runif(i,0,1) p[i]=sum(X+Y-5*X*sqrt(Y)>0)/i } >plot(1:10000,p) > mean(p[9900:10000]) [1] 0.25 Based on the ¯gure, we observe after 9000 iterations, the estimated prob- ability is almost ¯xed and hence we take the mean of p between 9900 and 10000 iterations as our ¯nal answer. 3 probability −1.0 −0.5 0.0 0.5 1.0 0 2000 4000 6000 8000 10000 iterations Figure 3: The probability computed using di®erent number of iterations for part a) probability 0.0 0.1 0.2 0.3 0.4 0 2000 4000 6000 8000 10000 iterations Figure 4: The probability computed using di®erent number of iterations for part b) 4.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us