prop_test: Test of Equal or Given Proportions

View source: R/prop_test.R

prop_testR Documentation

Test of Equal or Given Proportions

Description

prop_test is used to test the null hypothesis that the proportions (probabilities of success) in several groups are the same, or that they equal certain values.

Usage

prop_test(
  x,
  n,
  p = NULL,
  alternative = c("two.sided", "less", "greater"),
  conf.level = 0.95,
  correct = FALSE
)

Arguments

x

A number (or vector) of successes (observed counts).

n

A number (or vector) of sample sizes or counts of trials.

p

The null hypothesis value of the proportion (or difference in proportions)

alternative

A character string (in quotes) specifying the alternative hypothesis. Must be one of "two.sided" (the default), "greater", or "less". To compute a confidence interval, set this as "two.sided".

conf.level

The confidence level of the returned confidence interval. Must be a single number between 0 and 1.

correct

A logical (TRUE or FALSE) indicating whether to apply Yates' continuity correction when possible (leave set to FALSE for STATS 250).

Details

Note that this is different from prop.test, which will return confidence intervals created through a method we do not discuss in STATS 250.

Value

A list with class "htest".

Examples

# Computing a confidence interval for one proportion
# We have 1054 successes out of 1553 "trials", and will compute a 95% confidence interval
prop_test(x = 1054, n = 1553, conf.level = 0.95)

# Performing a hypothesis test for one proportion
# We have 1054 successes out of 1553 "trials". Do we have evidence to say the
# population proportion is greater than 55.3%?
prop_test(x = 1054, n = 1553, p = 0.553, alternative = "greater")

# Computing a confidence interval for a difference in two proportions
# We have 22 successes out of 32 in Group A, and 97 successes out of 168 in
# Group B. Let's make a 99% confidence interval for the difference in these
# two proportions.
prop_test(x = c(22, 97), n = c(32, 168), conf.level = 0.99)

# Performing a hypothesis test for a difference in two proportions
# We have 22 successes out of 32 in Group A, and 97 successes out of 168 in
# Group B. Do we have evidence to say that the proportion of successes in
# Group A is less than the proportion of successes in Group B?
prop_test(x = c(22, 97), n = c(32, 168), alternative = "less")

STATS250SBI/stats250sbi documentation built on March 18, 2022, 1:14 p.m.