mosaic (version 1.1.1)

prop.test: Exact and Approximate Tests for Proportions

Description

The mosaic prop.test provides wrapper functions around the function of the same name in stats. These wrappers provide an extended interface (including formulas). prop.test performs an approximate test of a simple null hypothesis about the probability of success in a Bernoulli or multinomial experiment from summarized data or from raw data.

Usage

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

Arguments

x

count of successes, length 2 vector of success and failure counts, a formula, or a character, numeric, or factor vector containing raw data.

n

sample size (successes + failures) or a data frame (for the formula interface)

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

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.

data

a data frame (if missing, n may be a data frame)

success

level of variable to be considered success. All other levels are considered failure.

...

additional arguments (often ignored). When x is a formula, groups can be used to compare groups: x = ~ var, groups=g is equivalent to x = var ~ g. See the examples.

Value

an htest object

Details

conf.level = 0.95, ...)

This is a wrapper around prop.test() to simplify its use when the raw data are available, in which case an extended syntax for prop.test is provided.

See Also

mosaic::binom.test(), stats::prop.test()

Examples

Run this code
# NOT RUN {
# Several ways to get a confidence interval for the proportion of Old Faithful
# eruptions lasting more than 3 minutes.
prop.test( faithful$eruptions > 3 )
prop.test(97,272)
faithful$long <- faithful$eruptions > 3
prop.test( faithful$long )
prop.test( ~long , data = faithful )
prop.test( homeless ~ sex, data = HELPrct )
prop.test( ~ homeless | sex, data = HELPrct )
prop.test( ~ homeless, groups = sex, data = HELPrct )

# }

Run the code above in your browser using DataCamp Workspace