Learn R Programming

mosaic (version 0.2-3)

binom.test: Exact and Approximate Tests for Proportions

Description

These are wrapper functions around the functions of the same name in stats. They provide an extended interface (including formulas). binom.test performs an exact test of a simple null hypothesis about the probability of success in a Bernoulli experiment from summarized data or from raw data. 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

binom.test(x, n, p=0.5, 
	alternative = c("two.sided", "less", "greater"), 
	conf.level = 0.95, ...)

## S3 method for class 'default': binom.test(x, n, p = 0.5, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, ...)

## S3 method for class 'numeric': binom.test(x, n, p = 0.5, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'character': binom.test(x, n, p = 0.5, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'factor': binom.test(x, n, p = 0.5, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'formula': binom.test(x, n , p = 0.5, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, data, ...)

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

## S3 method for class 'default': prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, ...)

## S3 method for class 'numeric': prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'character': prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'factor': prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, ...)

## S3 method for class 'formula': prop.test(x, n , p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, success, data.name, data, ...)

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
probability for null hypothesis
alternative
type of alternative hypothesis
conf.level
confidence level for confidence interval
success
level of variable to be considered success. All other levels are considered failure.
data.name
name for data. If missing, this is inferred from variable names.
data
a data frame (if missing, n may be a data frame)
...
additional arguments (often ignored)

Value

  • an htest object

Details

This is a wrapper around binom.test to simplify its use when the raw data are available.

See Also

binom.test, prop.test

Examples

Run this code
# Several ways to get a confidence interval for the proportion of Old Faithful
# eruptions lasting more than 3 minutes.
binom.test( faithful$eruptions > 3 )
binom.test(97,272)
binom.test(c(97,272-97))
faithful$long <- faithful$eruptions > 3
binom.test( faithful$long )
binom.test( ~long , faithful )

Run the code above in your browser using DataLab