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 252worse same bettercelexa 2 3 7placebo 2 8 2> chisq.test(x)Pearson’s Chi-squared testdata: xX-squared = 5.05, df = 2, p-value = 0.08004Warning message:Chi-squared approximation may be incorrect in:chisq.test(x)The warning notes that one or more of the expected cell counts is less than five,indicating a possible discrepancy with the asymptotic distribution used to find the p-value. We can use a simulation to find the p-value, instead of using the chi-squareddistribution approximation, as follows:> chisq.test(x, simulate.p.value=TRUE)Pearson’s Chi-squared test with simulated p-value(basedon 2000 replicates)data: xX-squared = 5.05, df = NA, p-value = 0.1025In both cases, the p-value is small but not tiny.9.2.2 Problems9.11 A number of drivers were surveyed to see whether they had been in an accidentduring the previous year, and, if so, whether it was a minor or major accident. The resultsare tabulated by age group in Table 9.9. Do a chi-squared hypothesis test of independence<strong>for</strong> the two variables.Table 9.9 Type of accident by ageAccident typeAge none minor majorunder 18 67 10 518–25 42 6 526–40 75 8 440–65 56 4 6over 65 57 15 19.12 Table 9.10 contains data on the severity of injuries sustained during car crashes. Thedata is tabulated by whether or not the passenger wore a seat belt. Are the two variablesindependent?

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

Saved successfully!

Ooh no, something went wrong!