This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Using R for hypothesis testing 1. Categorical data A) One sample proportion test (Chapter 9): This test compares the proportion of some event in our sample to an established, or null, value. R does this test as a Chi Square instead of a z test, but the result is the same. The default test has a two-sided alternative hypothesis. To do this in R, you need to know: k = # of times the event of interest happens in the sample, n = total # of subjects in the sample, and p = the null value from your hypotheses. Then all you do is type the following into R: &gt;prop.test(k, n, p0) Note that the output includes a 95% confidence interval for the population proportion, as well as the point estimate!! 1. What to do if you want a one-sided test: for Ha: p &lt; p 0 &gt;prop.test(k, n, p0, alternative= "less") for Ha: p &gt; p 0 &gt;prop.test(k, n, p0, alternative = "greater") 2. What to do if you want a different level of confidence for CI (use two-sided default): for 98% &gt;prop.test(k, n, p0, conf.level = 0.98) for y% &gt;prop.test(k, n, p0, conf.level = 0.y) 3. Example: The M&amp;M's data from class notes: &gt; prop.test(54, 565, 0.10, alternative=&quot;less&quot;) 1-sample proportions test with continuity correction data: 54 out of 565, null probability 0.1 X-squared = 0.0787, df = 1, p-value = 0.3896 alternative hypothesis: true p is less than 0.1 95 percent confidence interval: 0.0000000 0.1188543 sample estimates: p 0.09557522 4. Note: the test gives you the p-value, you have to interpret! B) Two sample proportion test (Chapter 10): This test two different groups to see if some event happens at the same proportion in the two groups, or not. Again, the alternative hypothesis is that the two proportions are not equal. The command is the same as in part A, but in a different format. First, we need to know: k 1 = # of times the event of interest happens in the first group, n 1 = total # of subjects in the first group, k 2 = # of times the event of interest happens in the second group, and n 2 = total # of subjects in the second group, Then all you do is type the following into R: &gt;prop.test(c(k 1, k 2 ), c(n 1, n 2 )) Note that the output includes a 95% confidence interval for the difference, as well as the point estimate for the difference. Example: In the chapter 10 notes, there was a survey to determine if 12 th grade boys were more likely to be offered drugs at school than 9 th grade boys. Note that, since the 12 th grade boys are listed first here, then their data needs to be listed first in each pair: &gt; prop.test(c(42, 42), c(183, 235), alternative = &quot;greater&quot;) 2-sample test for equality of proportions with...
View Full Document
This note was uploaded on 02/28/2012 for the course ECON 111 taught by Professor Aaa during the Summer '11 term at UIBE.
- Summer '11