10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Using</strong> R <strong>for</strong> introductory statistics 1646.3 Simulations related to the central limit theoremWe use a <strong>for</strong> loop to investigate the normality of <strong>for</strong> different parent populations anddifferent sample sizes. For example, if the X i are Uni<strong>for</strong>m(0, 1) we can simulate <strong>for</strong>n=2, 10, 25, and 100 with these commands:## set up plot window> plot(0,0,type="n",xlim=c(0,1),ylim=c(0,13.5),+ xlab="Density estimate",ylab="f(x)")> m = 500;a=0;b=1> n = 2> <strong>for</strong> (i in 1:m) res[i]=mean(runif(n,a,b))> lines(density(res),lwd=2)## repeat last 3 lines with n=10, 25, and 100Figure 6.3 Density estimates <strong>for</strong> <strong>for</strong>n=2, 10, 25, and 100 with Uni<strong>for</strong>m(0,1) dataIn Figure 6.3 a density estimate is plotted <strong>for</strong> each simulation. Observe how the densitiessqueeze in and become approximately bell shaped, as expected, even <strong>for</strong> n=10. As thestandard deviation of is if n goes up four times (from 25 to 100, <strong>for</strong> example),the standard deviation gets cut in half. Comparing the density estimate <strong>for</strong> n=25 andn=100, we can see that the n=100 graph has about half the spread.In this example the <strong>for</strong> loop takes the shortened <strong>for</strong>m<strong>for</strong>(i in values) a_single_commandIf there is just a single command, then no braces are necessary. This is convenient whenwe use the up arrow to edit previous command lines.In the problems, you are asked to simulate <strong>for</strong> a variety of parent populations toverify that the more skewed the data is, the larger n must be <strong>for</strong> the normal distribution toapproximate the sampling distribution of

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!