test_binomial: Power and Sample Size Analysis for a Binomial Test

Description Usage Arguments Details Author(s) References Examples

View source: R/test_binomial.R

Description

Determines the sample size, power, null proportion, alternative proportion, or significance level for a binomial test. The results also return the actual power and significance.

Usage

1
2
3
test_binomial(n = NULL, p0 = NULL, p1 = NULL, power = NULL,
  alpha = 0.05, alternative = "two.tailed", conservative = FALSE,
  n_limits = c(2L, 200L))

Arguments

n

The sample size, or number of trials

p0

The value of the probability of a success under the null hypothesis

p1

The value of the probability of a success under the alternative hypothesis

power

The power of the test

alpha

Significance level for the test

alternative

A character vector giving the alternative to the test. Multiple values may be given, but the values must be "two.tailed", "left.tailed", or "right.tailed".

conservative

A logical vector. This determines if the sample size selected is conservative (larger). This decision is required because the power as a function of sample size is non-montonic in the binomial distribution. In practice, it is usually better to look at both and select the sample size where alpha_actual is closest to alpha.

n_limits

The limits of the search for when n=NULL. The sample size is determined in a manner similar to uniroot, but uniroot doesn't handle discrete values.

Details

Exactly one of the parameters n, p0, p1, alpha, and power must be passed as NULL. The only exception is that delta may be passed as a second NULL when mu0 and mu1 are specified.

The parameters are combined via expand.grid, so all combinations of the inputs are evaluated.

Author(s)

Benjamin Nutter

References

O'Brien R, Castelloe J, "Sample-Size Analysis in Study Planning," American Statistical Association Continuing Education Program: Section on Teaching Statistics in the Health Sciences, Joint Statistical Meetings, San Francisco, CA; 5 August 2003 (Short Course Manual)

Some design choices were obtained from the r-help question at: http://r.789695.n4.nabble.com/Sample-size-calculations-for-one-sided-binomial-exact-test-td3964313.html

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#* Julia Chill's Frozen Sensations Example from O'Brien and Castelloe
test_binomial(n=c(20, 40), p0=.5, p1=.8, alpha=c(.01, .05),
              alternative='right.tailed')

#* Plot the sample size for a range of n
library(ggplot2)
Chill <- test_binomial(n=20:40, p0=.5, p1=.8, alpha=c(.01, .05),
              alternative='right.tailed')

ggplot(Chill, aes(x=n, y=power, colour=factor(alpha))) + geom_line()

nutterb/StudyPlanning documentation built on May 24, 2019, 10:51 a.m.