RHypothesis test

RHypothesis test - Using R for hypothesis testing 1....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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: >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 < p 0 >prop.test(k, n, p0, alternative= "less") for Ha: p > p 0 >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% >prop.test(k, n, p0, conf.level = 0.98) for y% >prop.test(k, n, p0, conf.level = 0.y) 3. Example: The M&M's data from class notes: > prop.test(54, 565, 0.10, alternative="less") 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: >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: > prop.test(c(42, 42), c(183, 235), alternative = "greater") 2-sample test for equality of proportions with...
View Full Document

Page1 / 7

RHypothesis test - Using R for hypothesis testing 1....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online