proportions.fisher: Power Analysis for Fisher's Exact Test (Independent...

power.exact.fisherR Documentation

Power Analysis for Fisher's Exact Test (Independent Proportions)

Description

Calculates power or sample size for Fisher's exact test on independent binary outcomes. Approximate and exact methods are available.

Validated via PASS and G*Power.

Usage

power.exact.fisher(prob1, prob2, n2 = NULL, n.ratio = 1,
                   alpha = 0.05, power = NULL,
                   alternative = c("two.sided", "one.sided"),
                   method = c("exact", "approximate"),
                   ceiling = TRUE, verbose = TRUE, pretty = FALSE)

Arguments

prob1

probability of success in the first group.

prob2

probability of success in the second group.

n2

integer; sample size for the second group.

n.ratio

n1 / n2 ratio.

power

statistical power, defined as the probability of correctly rejecting a false null hypothesis, denoted as 1 - \beta.

alpha

type 1 error rate, defined as the probability of incorrectly rejecting a true null hypothesis, denoted as \alpha.

alternative

character; direction or type of the hypothesis test: "two.sided" or "one.sided".

method

character; method used for power calculation. "exact" specifies Fisher's exact test, while "approximate" refers to the Z-Test based on the normal approximation.

ceiling

logical; if TRUE rounds up sample size in each group.

verbose

logical; if FALSE no output is printed on the console.

pretty

logical; whether the output should show Unicode characters (if encoding allows for it). FALSE by default.

Value

parms

list of parameters used in calculation.

test

type of the test, which is "exact" or "z".

odds.ratio

odds ratio.

mean

mean of the alternative distribution.

sd

standard deviation of the alternative distribution.

null.mean

mean of the null distribution.

null.sd

standard deviation of the null distribution.

z.alpha

critical value(s).

power

statistical power (1-\beta).

n

sample sizes for the first and second groups, specified as c(n1, n2).

n.total

total sample size, which is sum of cell frequencies in 2 x 2 table (f11 + f10 + f01 + f00), or number of rows in a data frame with group variable stacked.

References

Bennett, B. M., & Hsu, P. (1960). On the power function of the exact test for the 2 x 2 contingency table. Biometrika, 47(3/4), 393-398. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2333309")}

Fisher, R. A. (1935). The logic of inductive inference. Journal of the Royal Statistical Society, 98(1), 39-82. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2342435")}

Examples

# example data for a randomized controlled trial
# subject  group    success
# <int>    <dbl>      <dbl>
#   1        1          1
#   2        0          1
#   3        1          0
#   4        0          1
#   5        1          1
#   ...     ...        ...
#   100      0          0

# prob1 = mean(success | group = 1)
# prob2 = mean(success | group = 0)

# post-hoc exact power
power.exact.fisher(prob1 = 0.60, prob2 = 0.40, n2 = 50)

# we may have 2 x 2 joint probs such as
# -------------------------------------
#             | group (1) | group (0) |
# -------------------------------------
# success (1) |  0.24    |   0.36     |
# -------------------------------------
# success (0) |  0.16    |   0.24     |
# -------------------------------------

# convert joint probs to marginal probs
marginal.probs.2x2(prob11 = 0.24, prob10 = 0.36,
                   prob01 = 0.16, prob00 = 0.24)

pwrss documentation built on Sept. 16, 2025, 9:11 a.m.