two_proportion_test: Simulation-based hypothesis test for a difference in...

View source: R/s216-applets.R

two_proportion_testR Documentation

Simulation-based hypothesis test for a difference in proportions

Description

This function will run a simulation-based hypothesis test for a difference in proportion of successes between two independent groups.

Usage

two_proportion_test(
  formula,
  data,
  first_in_subtraction,
  response_value_numerator,
  as_extreme_as,
  direction = c("greater", "less", "two-sided"),
  number_repetitions = 1,
  add_normal = FALSE
)

Arguments

formula

Formula of the form response ~ predictor, where predictor defines the two groups of the explanatory variable and response is binary or a two-level categorical variable.

data

Data frame with columns for response and predictor variables.

first_in_subtraction

Value of predictor variable that should be first in order of subtraction for computing difference in proportions.

response_value_numerator

Value of response that corresponds to "success" when computing proportions.

as_extreme_as

Value of observed difference in proportions.

direction

Direction of alternative hypothesis. Allowed values are "greater", "less", or "two-sided".

number_repetitions

Number of simulated samples.

add_normal

Logical value indicating whether to superimpose a normal curve on the histogram. Defaults to FALSE.

Value

Returns plot of distribution of simulated statistics, with values as or more extreme than specified value highlighted, and reports proportion of simulations as or more extreme than specified as subtitle on plot.

Examples

data(pt)
pt$twoSeconds <- ifelse(pt$responses >= 2, "Yes", "No")
two_proportion_test(twoSeconds ~ brand,
  data = pt,
  first_in_subtraction = "B1",
  response_value_numerator = "Yes",
  as_extreme_as = -.4,
  direction = "two-sided",
  number_repetitions = 1000
)

greenwood-stat/catstats documentation built on Aug. 1, 2022, 2:04 p.m.