prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, correct = TRUE)
x, n |
numeric vectors, a table, or a matrix that specifies
the counts of successes and trials respectively.
|
p |
vector of probabilities of success specified by the null hypothesis.
length(p) must equal length(x) and length(n),
and all elements must be greater than zero and less than one.
|
alternative |
a character string that specifies the alternative hypothesis.
Possible values are: "two.sided", "greater", "less".
Note: You need to enter only enough of the character string to create
a unique match for the value.
alternative is usually automatically set to two.sided in most cases. The values greater and less are meaningful in two special cases.
|
conf.level |
a numeric vector in the range [0, 1] that specifies the confidence level for the returned confidence interval.
conf.level is meaningful only when there is one group, or when p=NULL and there are two groups. (See the description of the alternative argument for more information.) In all other cases, conf.level is ignored. |
correct |
a logical value. If TRUE (the default), Yates' continuity
correction is applied, but only under certain conditions:
|
To test the null hypothesis that the true probabilities of success equal those specified in input argument p (or 0.5 if p=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.
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=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.
statistic | the X-squared statistic. |
parameters | the degrees of freedom of the asymptotic chi-square distribution associated with the X-squared statistic. |
p.value | the asymptotic p-value for the test. |
conf.int |
In the following two cases, the confidence level is recorded in the attribute conf.level.
|
estimate | a numeric vector that returns the sample proportions as calculated by x / n, which estimate the true probabilities of success in the corresponding groups. When there is only one group the names attribute is p and when there are two or more groups the names attribute is prop 1, prop 2, .... |
null.value | when the null hypothesis is that the true probabilities of success equal specified values (usually input argument p), the component null.value records these specified values, and returns them along with a names attribute as described under component estimate. In all other cases, null.value is not returned. |
alternative |
a character string that returns the alternative hypothesis
(two.sided, greater, or less)
as specified in the alternative argument. If there is only one group, or when there are two groups and the argument p=NULL, alternative returns the actual value specified for the alternative argument. In all other cases, alternative returns two.sided. |
method | a character string that returns the name of the method used, including whether Yates' continuity correction was applied. |
data.name | a character string that contains the actual names of the input vectors x, n, and of p, if given. |
In the special case of one group, the null hypothesis is that the true probability of success is the specified value of p or 0.5 if p is not specified. 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.
The number of groups, insofar as it influences the nature of the test, is determined by length(x) before removal of NAs and other special values. However, the returned component method reflects the actual number of groups containing valid data used in computations.
# (a) Testing Whether Probabilities of Success Equal Those Specified in 'p'.# 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. heads <- 5; tosses <- 10 prop.test(heads, tosses, 0.6)
# 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(heads, tosses)
# 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. successes <- c(19, 20, 18); trial.counts <- c(21, 25, 23) prop.test(successes, trial.counts, rep(0.9, times=length(successes)))
# (b) Testing Whether All Probabilities of Success are the Same.
# 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. incidence.counts <- c(12, 15); group.sizes <- c(20, 20) prop.test(incidence.counts, group.sizes, alternative="greater" )
# 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. smokers <- c(83, 90, 129, 70) patients <- c(86, 93, 136, 82) prop.test(smokers, patients)
# Matrix format, the result is the same as above prop.test(cbind(smokers, patients-smokers))