prop.test(x, n, p=<<see below>>, alternative="two.sided", conf.level=.95, correct=T)
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.
NA
s and
Inf
s 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"
.
p
must have the same length as
x
and
n
, and
have all elements greater than zero and
less than one.
NA
s and
Inf
s 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.
"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"
.
p
is
NULL
; see argument
alternative
. In all other
cases,
conf.level
is ignored.
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.
"htest"
, containing the following components:
names
attribute
"X-squared"
.
statistic
.
parameters
has
names
attribute
"df"
.
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.
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
.
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.
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"
.
x
and
n
, and of
p
if given.
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
NA
s etc.
However, the returned component
method
will reflect the actual number of groups containing valid data
used in computations.
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.
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 If 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 If 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'. heads <- 5; tosses <- 10 prop.test(heads, tosses, 0.6) # 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) # 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. successes <- c(19, 20, 18); trial.counts <- c(21, 25, 23) 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. incidence.counts <- c(12, 15); group.sizes <- c(20, 20) 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.