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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> R <strong>for</strong> introductory statistics 168* In Windows you may need to call flush, console() () to get the output. See the FAQ <strong>for</strong> details.6.5 Investigating distributions■ Example 6.1: The sample medianThe sample median, M, is a measurement of central tendency like the sample mean. Doesit, too, have an approximately normal distribution? How does the sampling distribution ofM reflect the parent distribution of the sample? Will M converge to some parameter ofthe parent distribution as converges to µ?Figure 6.4 Density estimates <strong>for</strong>simulations of the sample medianfrom exponential data. As nincreases, the sampling distributionappears to become normallydistributed and concentrates on themedian of the parent population.To investigate these questions, we will per<strong>for</strong>m a simulation. Assume we have a randomsample X 1 , X 2 , …, X n taken from the Exponential(1) distribution. This distribution hasmean 1 and median log(2) = .6931. We per<strong>for</strong>m a simulation <strong>for</strong> n = 25, 100, and 400.First we define a function to find the median from the sample:> f = function(n) median(rexp(n))Now we generate samples <strong>for</strong> different sizes of n.> m = 500> res.25 = c(); res.100 = c(); res.400 = c()> <strong>for</strong>d in 1:m) res.25[i] = f(25)> <strong>for</strong>(i in 1:m) res.100[i] = f(100)> <strong>for</strong>(i in 1:m) res.400[i] = f(400)

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

Saved successfully!

Ooh no, something went wrong!