prop.test(x, n, p=<<see below>>, alternative="two.sided", conf.level=.95, correct=T)
In the special case of one group, the null hypothesis is that the true probability of success is p if p is not NULL, or 0.5 if it is. The alternative hypothesis is that the probability of success is greater than, less than, or simply not equal to p (or 0.5), depending on the input argument alternative.
If input argument p is NULL and there are at least two groups, the null hypothesis states that the true probability of success is the same in every group. When there are two groups, the alternative hypothesis asserts that the probability of success in the first group is greater than, less than, or simply not equal to that in the second group, depending on the value of input argument alternative. When there are more than two groups, the alternative hypothesis is that there is at least one group whose probability of success is different from the others; thus alternative is "two.sided".
The number of groups, insofar as it influences the nature of the test, is determined by length(x) before removal of NAs etc. However, the returned component method will reflect the actual number of groups containing valid data used in computations.
(a) Testing Whether Probabilities of Success Equal Those Specified in p.
To test the null hypothesis that the true probabilities of success equal those specified in input argument p (or 0.5 if p is NULL in the case of only one group), Pearson's X-squared statistic is computed for the above table, with expected counts of successes given by n*p and expected counts of failures by n*(1 - p). Under the null hypothesis, the X-squared statistic has an asymptotic chi-square distribution with length(x) degrees of freedom.
When there is only one group, X-squared coincides with the square of the Z statistic used to compare a proportion with a specified value. See the hardcopy help-file for formulas giving expressions for Z and the related confidence intervals.
(b) Testing Whether All Probabilities of Success are the Same.
To test the hypothesis that the true probability of success is the same in each of the length(x) > 1 groups (the default when p is NULL), Pearson's X-squared statistic is again used with the above table, this time with expected counts of successes estimated by n*(sum(x)/sum(n)) and expected counts of failures by n*(1 - sum(x)/sum(n)). This estimates the (common) probability of success as the total number of observed successes divided by the total number of trials. Under the null hypothesis, X-squared has an asymptotic chi-square distribution with length(x) - 1 degrees of freedom. It can be shown that X-squared computed this way is algebraically equivalent to X-squared for the hypothesis of independence between the row and column attributes of the table. Furthermore, when there are just two groups, the statistic coincides with the square of the Z statistic used to compare two proportions. See the hardcopy help-file for formulas giving expressions for Z and the related confidence intervals.
Fienberg, S. E. (1983). The Analysis of Cross-Classified Categorical Data, 2nd ed. The MIT Press, Cambridge, Mass.
Fleiss, J. L. (1981). Statistical Methods for Rates and Proportions, 2nd ed. Wiley, New York.
Snedecor, G. W. and Cochran, W. G. (1980). Statistical Methods, 7th ed. Iowa State University Press, Ames, Iowa.
(a) Testing Whether Probabilities of Success Equal Those Specified in p.
prop.test( heads, tosses, 0.6 ) # length( heads ) == 1 # The null hypothesis is that the probability of heads for # this coin is 0.6. The alternative is two-sided. A # confidence interval for the true probability of heads # will be computed. prop.test( heads, tosses ) # length( heads ) == 1 # Same as above, but now the null probability is 0.5, the # default for p when there is only one group. This is # a test that the coin is unbiased. prop.test( successes, trial.counts, rep(0.9, times=length(successes))) # The null hypothesis is that all probabilities of success # are equal to 0.9. The alternative is that at least one of # them isn't.
(b) Testing Whether All Probabilities of Success are the Same.
length( incidence.counts ) [1] 2 prop.test( incidence.counts, group.sizes, alternative="greater" ) # The null hypothesis is that the incidence probabilities # in the two groups are the same. The alternative is that # the probability in Group 1 exceeds that in Group 2. # A confidence interval for the difference in the true # probabilities (Group 1 minus Group 2) will be computed. smokers <- c( 83, 90, 129, 70 ) patients <- c( 86, 93, 136, 82 ) prop.test( smokers, patients ) # Data from Fleiss (1981), p. 139. The null hypothesis is # that the four populations from which the patients were # drawn have the same true proportion of smokers. The # alternative is that this proportion is different in at # least one of the populations.