# prop.test

##### Test of Equal or Given Proportions

`prop.test`

can be used for testing the null that the
proportions (probabilities of success) in several groups are the
same, or that they equal certain given values.

- Keywords
- htest

##### Usage

```
prop.test(x, n, p = NULL,
alternative = c("two.sided", "less", "greater"),
conf.level = 0.95, correct = TRUE)
```

##### Arguments

- x
a vector of counts of successes, a one-dimensional table with two entries, or a two-dimensional table (or matrix) with 2 columns, giving the counts of successes and failures, respectively.

- n
a vector of counts of trials; ignored if

`x`

is a matrix or a table.- p
a vector of probabilities of success. The length of

`p`

must be the same as the number of groups specified by`x`

, and its elements must be greater than 0 and less than 1.- alternative
a character string specifying the alternative hypothesis, must be one of

`"two.sided"`

(default),`"greater"`

or`"less"`

. You can specify just the initial letter. Only used for testing the null that a single proportion equals a given value, or that two proportions are equal; ignored otherwise.- conf.level
confidence level of the returned confidence interval. Must be a single number between 0 and 1. Only used when testing the null that a single proportion equals a given value, or that two proportions are equal; ignored otherwise.

- correct
a logical indicating whether Yates' continuity correction should be applied where possible.

##### Details

Only groups with finite numbers of successes and failures are used. Counts of successes and failures must be nonnegative and hence not greater than the corresponding numbers of trials which must be positive. All finite counts should be integers.

If `p`

is `NULL`

and there is more than one group, the null
tested is that the proportions in each group are the same. If there
are two groups, the alternatives are that the probability of success
in the first group is less than, not equal to, or greater than the
probability of success in the second group, as specified by
`alternative`

. A confidence interval for the difference of
proportions with confidence level as specified by `conf.level`

and clipped to \([-1,1]\) is returned. Continuity correction is
used only if it does not exceed the difference of the sample
proportions in absolute value. Otherwise, if there are more than 2
groups, the alternative is always `"two.sided"`

, the returned
confidence interval is `NULL`

, and continuity correction is never
used.

If there is only one group, then the null tested is that the
underlying probability of success is `p`

, or .5 if `p`

is
not given. The alternative is that the probability of success is less
than, not equal to, or greater than `p`

or 0.5, respectively, as
specified by `alternative`

. A confidence interval for the
underlying proportion with confidence level as specified by
`conf.level`

and clipped to \([0,1]\) is returned. Continuity
correction is used only if it does not exceed the difference between
sample and null proportions in absolute value. The confidence interval
is computed by inverting the score test.

Finally, if `p`

is given and there are more than 2 groups, the
null tested is that the underlying probabilities of success are those
given by `p`

. The alternative is always `"two.sided"`

, the
returned confidence interval is `NULL`

, and continuity correction
is never used.

##### Value

A list with class `"htest"`

containing the following
components:

the value of Pearson's chi-squared test statistic.

the degrees of freedom of the approximate chi-squared distribution of the test statistic.

the p-value of the test.

a vector with the sample proportions `x/n`

.

a confidence interval for the true proportion if
there is one group, or for the difference in proportions if
there are 2 groups and `p`

is not given, or `NULL`

otherwise. In the cases where it is not `NULL`

, the
returned confidence interval has an asymptotic confidence level
as specified by `conf.level`

, and is appropriate to the
specified alternative hypothesis.

the value of `p`

if specified by the null, or
`NULL`

otherwise.

a character string describing the alternative.

a character string indicating the method used, and whether Yates' continuity correction was applied.

a character string giving the names of the data.

##### References

Wilson, E.B. (1927).
Probable inference, the law of succession, and statistical inference.
*Journal of the American Statistical Association*, **22**,
209--212.
10.2307/2276774.

Newcombe R.G. (1998).
Two-Sided Confidence Intervals for the Single Proportion: Comparison
of Seven Methods.
*Statistics in Medicine*, **17**, 857--872.
10.1002/(SICI)1097-0258(19980430)17:8<857::AID-SIM777>3.0.CO;2-E.

Newcombe R.G. (1998).
Interval Estimation for the Difference Between Independent
Proportions: Comparison of Eleven Methods.
*Statistics in Medicine*, **17**, 873--890.
10.1002/(SICI)1097-0258(19980430)17:8<873::AID-SIM779>3.0.CO;2-I.

##### See Also

`binom.test`

for an *exact* test of a binomial
hypothesis.

##### Examples

`library(stats)`

```
# NOT RUN {
heads <- rbinom(1, size = 100, prob = .5)
prop.test(heads, 100) # continuity correction TRUE by default
prop.test(heads, 100, correct = FALSE)
## Data from Fleiss (1981), p. 139.
## H0: The null hypothesis is that the four populations from which
## the patients were drawn have the same true proportion of smokers.
## A: 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)
# }
```

*Documentation reproduced from package stats, version 3.5.0, License: Part of R 3.5.0*