Proportions Tests

DESCRIPTION:
Compares proportions against hypothesized values. Alternately, tests whether underlying proportions are equal.


USAGE:
prop.test(x, n, p=<<see below>>, alternative="two.sided",
          conf.level=.95, correct=T)

REQUIRED ARGUMENTS:
x,n:
vectors of counts of successes and trials respectively. The elements of n must be positive; those of x must be nonnegative and no greater than the corresponding values in n. Both vectors must have the same length. NAs and Infs are allowed, but pairs (x[i],n[i]) containing these will be removed. The elements of x and n should be whole numbers, as these proportions tests are based on counts; however, the storage mode of x and n will be coerced to "double".

OPTIONAL ARGUMENTS:
p:
vector of probabilities of success specified by the null hypothesis. Vector p must have the same length as x and n, and have all elements greater than zero and less than one. NAs and Infs are not allowed. If p is NULL (the default) and there is only one group (length(x) == 1), the null hypothesis tested is that the true probability of success is 0.5; if p is NULL and there is more than one group, the null hypothesis tested is that the true probability of success is the same in all groups. If p is not NULL, the null hypothesis tested is that the vector of true probabilities of success is equal to p, regardless of the number of groups.
alternative:
character string, one of "greater", "less" or "two.sided", or just the initial letter of each, indicating the specification of the alternative hypothesis. The values "greater" and "less" have meaning only in two special cases. When there is one group, alternative pertains to the true probability of success in relation to its value specified under the null hypothesis (see argument p). When there are two groups and p is NULL, so that the null hypothesis tested is that the true probability of success is the same in both groups, then alternative pertains to the true probability of success in the first group in relation to that in the second. In all other cases, alternative is automatically set to "two.sided".
conf.level:
confidence level for the returned confidence interval, restricted to lie between zero and one. This has meaning only when there is one group, or when there are two groups and p is NULL; see argument alternative. In all other cases, conf.level is ignored.
correct:
logical flag: if TRUE, Yates' continuity correction will be applied, but only under certain conditions. When there is only one group, the continuity correction may not exceed in magnitude the difference between the sample proportion x/n and the hypothesized true probability of success. When there are two groups, and p is NULL, then the continuity correction may not exceed in magnitude the difference between the sample proportions. When there are more than two groups, the continuity correction is never used. See Section DETAILS for an algebraic definition of the continuity correction.

VALUE:
A list of class "htest", containing the following components:

statistic:
Pearson's X-squared statistic with names attribute "X-squared".
parameters:
the degrees of freedom of the asymptotic chi-square distribution associated with statistic. parameters has names attribute "df".
p.value:
the asymptotic p-value for the test.
conf.int:
when there is one group, a confidence interval for the true probability of success. When there are two groups and input argument p is NULL, conf.int contains a confidence interval for the difference in probabilities of success between the first and second groups. In these two cases, the confidence level is recorded in the attribute conf.level. In all other cases, conf.int is not returned.
estimate:
vector giving the sample proportions x/n; these estimate the true probabilities of success in the corresponding groups. The names attribute of component estimate will be based on the names attribute of the first object p, x or n which has a names attribute, or on the vector c("Group 1", "Group 2",...) if none of those has names.
null.value:
when the null hypothesis is that the true probabilities of success equal specified values (usually input argument p), component null.value records these specified values, and is given a names attribute as described under component estimate. Otherwise null.value is not returned.
alternative:
when there is only one group, or when there are two groups and argument p is NULL, component alternative records the value of the input argument alternative: one of "greater", "less" or "two.sided". In all other cases, alternative is "two.sided".
method:
character string giving the name of the method used, including whether Yates' continuity correction was applied.
data.name:
a character string containing the actual names of the input vectors x and n, and of p if given.


NULL:
Two types of null hypothesis can be tested. If input argument p is not NULL, the null hypothesis states that the true probability of success in group i is p[i], for each value of i. The alternative hypothesis when there are at least two groups is that there is some group for which this relation does not hold; thus alternative is "two.sided".

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.


TEST:
It is assumed that each of the length(x) samples is independent of the others, and that each sample consists of a predetermined number n[i] of independent trials, for which the true probability of success is constant. Furthermore, the p-value is based on an approximation which works best when none of the probabilities of success is close to zero or one, and when the numbers of trials n[i] are not too small. At the very minimum, all (estimated) expected counts of successes or failures should be at least five. See section DETAILS for details on the approximation and the definition of expected counts.

DETAILS:
Suppose that all elements of x and n are valid numbers (not NA, etc.), so that the number of groups used in the test is given by length(x). Conceptually, the data may be arranged in a length(x) by 2 table, where rows correspond to groups (samples), and columns to "success" or "failure" respectively. Thus the entry in the i-th row and j-th column is x[i] if j == 1 or n[i] - x[i] if j == 2.

(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.


REFERENCES:

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.


SEE ALSO:
binom.test , chisq.test , fisher.test , Binomial .

EXAMPLES:

(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.