Learn R Programming

mosaic (version 0.4-1)

compareProportion: Compare proportions between 2 groups

Description

A function to facilitate 2 group permutation tests for a categorical outcome variable

Usage

compareProportion(formula, data = NULL, ...)

Arguments

formula
a formula
data
a data frame in which x is evaluated if x is a formula.
...
other arguments

Value

  • the difference in proportions between the second and first group

See Also

do, compareMean and shuffle

Examples

Run this code
data(HELPrct)
# calculate the observed difference
mean(homeless=="housed" ~ sex, data=HELPrct)
obs <- compareProportion(homeless=="housed" ~ sex, data=HELPrct); obs
# calculate the permutation distribution
nulldist <- do(100) * compareProportion(homeless=="housed" ~ shuffle(sex), data=HELPrct)
xhistogram(~ result, groups=(result >= obs), nulldist,
  xlab="difference in proportions")

Run the code above in your browser using DataLab