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.

Confidence intervals 179Figure 7.1 Various estimates <strong>for</strong> theage of universe, some historic, somemodern. Ranges are represented bydotted lines. When the estimate is alower bound, only a bottom bar isdrawn. The current best estimate of13.7 billion years old is drawn with ahorizontal line. This estimate has amargin of error of 1%.wish to know the true proportion of the population that is <strong>for</strong> the proposition. We can’taf<strong>for</strong>d to ask all 10,000 people, but we can survey 100 at random. If our sampleproportion is called and the true proportion is p, what can we infer about the unknownp based onSometimes it helps to change the question to one involving simple objects. In thiscase, imagine we have 10,000 balls inside a box with a certain proportion, p, labeled witha “1,” and the remaining labeled with a “0.” We then select 100 of the balls at randomand count the 1’s.In order to gain some insight, we will do a simulation <strong>for</strong> which we know the answer(the true value of p). Suppose the true proportion <strong>for</strong> the population is p=0.56. That is5,600 are <strong>for</strong> the proposition and 4,400 are against. To sample without replacement weuse the sample() command. A single sample is found as follows:> pop = rep(0:1,c(10000–5600, 5600))> phat = mean(sample(pop,100))> phat[1] 0.59In this example, using the mean() function is equivalent to finding the proportion. If wesimulate this sampling 1,000 times we can get a good understanding of the samplingdistribution of from the repeated values of phat. The following will do so and store theresults in a data vector called res.

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

Saved successfully!

Ooh no, something went wrong!