| Title: | Statistical Power and Sample Size Calculation Tools |
|---|---|
| Description: | The 'pwrss' R package provides flexible and comprehensive functions for statistical power and minimum required sample size calculations across a wide range of commonly used hypothesis tests in psychological, biomedical, and social sciences. |
| Authors: | Metin Bulus [aut, cre, cph], Sebastian Jentschke [aut, cph] |
| Maintainer: | Metin Bulus <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.2.0 |
| Built: | 2026-05-30 22:07:13 UTC |
| Source: | https://github.com/metinbulus/pwrss |
Conversion from a correlation to a z-value (Fisher's z-transformation)
cor.to.z(rho, verbose = 1)cor.to.z(rho, verbose = 1)
rho |
correlation |
verbose |
|
z |
z-value |
rho |
correlation |
cor.to.z(rho = 0.1) cor.to.z(rho = 0.5) cor.to.z(rho = 0.9) cor.to.z(rho = 0.99)cor.to.z(rho = 0.1) cor.to.z(rho = 0.5) cor.to.z(rho = 0.9) cor.to.z(rho = 0.99)
Conversion from a correlation Difference to Cohen's q
cors.to.q(rho1, rho2, verbose = 1)cors.to.q(rho1, rho2, verbose = 1)
rho1 |
first correlation. |
rho2 |
second correlation. |
verbose |
|
q |
Cohen's q effect size. |
delta |
correlation difference: rho1 - rho2. |
rho1 |
first correlation. |
rho2 |
second correlation. |
cors.to.q(rho2 = 0.5712027, rho1 = 0.50) cors.to.q(rho2 = 0.6907068, rho1 = 0.50) cors.to.q(rho2 = 0.7815365, rho1 = 0.50)cors.to.q(rho2 = 0.5712027, rho1 = 0.50) cors.to.q(rho2 = 0.6907068, rho1 = 0.50) cors.to.q(rho2 = 0.7815365, rho1 = 0.50)
Helper function to convert Cohen's d to common language effect size (or vice versa). The result is the probability of superiority for independent samples. It can be interpreted as the probability that a randomly selected observation from Group 1 exceeds a randomly selected observation from Group 2. The rationale is the same for paired-samples and one-sample designs, but the interpretation differs: For paired samples, it can be interpreted as the probability that the difference score (i.e., the score under Condition 1 minus the score under Condition 2) is greater than zero for a randomly selected individual. For a one-sample design, it can be interpreted as the probability that a randomly selected observation is greater than the reference value (e.g., 0).
d.to.cles(d, design = c("independent", "paired", "one.sample"), verbose = 1)d.to.cles(d, design = c("independent", "paired", "one.sample"), verbose = 1)
d |
Cohen's d |
design |
character; one of the "independent", "paired", or "one.sample". The default is "independent". |
verbose |
|
cles |
common language effect size. |
d |
Cohen's d |
cles |
common language effect size. |
d.to.cles(0.20) # small d.to.cles(0.50) # medium d.to.cles(0.80) # large cles.to.d(0.5562315) cles.to.d(0.6381632) cles.to.d(0.7141962)d.to.cles(0.20) # small d.to.cles(0.50) # medium d.to.cles(0.80) # large cles.to.d(0.5562315) cles.to.d(0.6381632) cles.to.d(0.7141962)
Conversion from Eta-squared to Cohen's f
etasq.to.f(eta.squared, verbose = 1)etasq.to.f(eta.squared, verbose = 1)
eta.squared |
(Partial) Eta-squared. |
verbose |
|
f |
Cohen's f. |
f.squared |
Cohen's f². |
eta.squared |
(Partial) Eta-squared. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
etasq.to.f(eta.squared = 0.01) # small etasq.to.f(eta.squared = 0.06) # medium etasq.to.f(eta.squared = 0.14) # largeetasq.to.f(eta.squared = 0.01) # small etasq.to.f(eta.squared = 0.06) # medium etasq.to.f(eta.squared = 0.14) # large
Conversion between Cohen's f and Eta-squared
f.to.etasq(f, verbose = 1)f.to.etasq(f, verbose = 1)
f |
Cohen's f. |
verbose |
|
eta.squared |
(Partial) Eta-squared. |
f.squared |
Cohen's f². |
f |
Cohen's f. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
f.to.etasq(f = 0.10) # small f.to.etasq(f = 0.25) # medium f.to.etasq(f = 0.40) # largef.to.etasq(f = 0.10) # small f.to.etasq(f = 0.25) # medium f.to.etasq(f = 0.40) # large
Helper function to convert between Cohen's f and R-squared.
f.to.rsq(f, r.squared.full = NULL, verbose = 0)f.to.rsq(f, r.squared.full = NULL, verbose = 0)
f |
Cohen's f. |
r.squared.full |
R-squared for the full model. |
verbose |
|
f |
Cohen's f. |
f.squared |
Cohen's f-squared. |
r.squared.full |
R-squared for the full model. |
r.squared.reduced |
R-squared for the reduced model. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
Selya, A. S., Rose, J. S., Dierker, L. C., Hedeker, D., & Mermelstein, R. J. (2012). A practical guide to calculating Cohen's f2, a measure of local effect size, from PROC MIXED. Frontiers in Psychology, 3, Article 111. https://doi.org/10.3389/fpsyg.2012.00111
f.to.rsq(f = 0.14) # small f.to.rsq(f = 0.39) # medium f.to.rsq(f = 0.59) # largef.to.rsq(f = 0.14) # small f.to.rsq(f = 0.39) # medium f.to.rsq(f = 0.59) # large
Helper function to construct the default contrast coefficients for various coding schemes.
Validated using lm() and aov() functions.
factorial.contrasts( factor.levels = c(3, 2), coding.scheme = rep("deviation", length(factor.levels)), base = factor.levels, intercept = FALSE, verbose = 1 )factorial.contrasts( factor.levels = c(3, 2), coding.scheme = rep("deviation", length(factor.levels)), base = factor.levels, intercept = FALSE, verbose = 1 )
factor.levels |
integer; Number of levels or groups in each factor. For example, for two factors each having two levels or groups use e.g. c(2, 2), for three factors each having two levels or groups use e.g. c(2, 2, 2). |
coding.scheme |
character vector; Coding scheme for each factor. "sum" for deviation or effect coding, "treatment" for dummy coding, "helmert" for Helmert type of coding, and "poly" for polynomial coding. Each factor can have their own coding scheme. If a single character value is provided, it will be copied to other factors. |
base |
integer vector; Specifies which group is considered the baseline group. Ignored for coding schemes other than "treatment". |
intercept |
logical; |
verbose |
|
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as factor instead of
factor.levels, or such as cod or coding instead of
coding.scheme.
factor.levels |
Number of levels (or groups) in each factor |
factor.data |
Unique combination of factor levels |
model.matrix |
Model (design) matrix based on unique combination of factor levels |
contrast.matrix |
Contrast matrix |
################################################### ############### dummy coding scheme ############### #################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ####################################################### ############### deviation coding scheme ############## ####################################################### # especially useful for factorial designs # two factors w/ 2 and 3 levels, respectively contrast.object <- factorial.contrasts(factor.levels = c(2, 3), coding = "sum") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ###################################################### ############### Helmert coding scheme ############### ###################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "helmert") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ######################################################### ############### polynomial coding scheme ############### ######################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "poly") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix################################################### ############### dummy coding scheme ############### #################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ####################################################### ############### deviation coding scheme ############## ####################################################### # especially useful for factorial designs # two factors w/ 2 and 3 levels, respectively contrast.object <- factorial.contrasts(factor.levels = c(2, 3), coding = "sum") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ###################################################### ############### Helmert coding scheme ############### ###################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "helmert") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix ######################################################### ############### polynomial coding scheme ############### ######################################################### # one factor w/ 3 levels contrast.object <- factorial.contrasts(factor.levels = 3, coding = "poly") # model matrix contrast.object$model.matrix # contrast matrix contrast.object$contrast.matrix
Inflate Sample Size for Attrition
inflate.sample(n, rate = 0.05, ceil.n = TRUE, verbose = 1)inflate.sample(n, rate = 0.05, ceil.n = TRUE, verbose = 1)
n |
sample size. |
rate |
attrition rate. |
ceil.n |
rounds-up the inflated sample size. |
verbose |
|
inflated sample size.
inflate.sample(n = 100, rate = 0.05)inflate.sample(n = 100, rate = 0.05)
Helper function to converts joint probabilities to marginal probabilities for the McNemar test applied to paired binary data.
joint.probs.2x2(prob1, prob2, rho = 0.5, verbose = 1)joint.probs.2x2(prob1, prob2, rho = 0.5, verbose = 1)
prob1 |
(marginal) probability of success in case group (or after). |
prob2 |
(marginal) probability of success in matched-control group (or before). |
rho |
the correlation between case and matched-control, or after and before (phi coefficient). |
verbose |
|
parms |
list of parameters used in calculation. |
prob11 |
(joint) probability of success in both groups. 'prob11' and 'prob00' are known as concordant probs. |
prob10 |
(joint) probability of success in case (or after) but failure in matched control (or before). 'prob10' and 'prob01' are known as discordant probs. |
prob01 |
(joint) probability of failure in case (or after) but success in matched control (or before). prob10' and 'prob01' are known as discordant probs. |
prob00 |
(joint) probability of failure in both groups. 'prob11' and 'prob00' are known as concordant probs. |
Zhang, S., Cao, J., and Ahn, C. (2017). Inference and sample size calculation for clinical trials with incomplete observations of paired binary outcomes. Statistics in Medicine, 36(4), 581-591. https://doi.org/10.1002/sim.7168
# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(case) which is 0.55 # prob2 = mean(control) which is 0.45 # rho = cor(case, control) which is 0.4141414 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(after) which is 0.55 # prob2 = mean(before) which is 0.45 # rho = cor(after, before) which is 0.4141414 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # we may not have 2 x 2 joint probs # convert marginal probs to joint probs using summary stats jp <- joint.probs.2x2(prob1 = 0.55, # mean of case (or after) prob2 = 0.45, # mean of matched control (or before) # correlation b/w matched case-control / before-after rho = 0.4141414) # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob01 = jp$prob01, prob10 = jp$prob10, power = 0.80, alpha = 0.05, method = "exact") # convert joint probs to marginal probs and calc phi coefficient (rho) # these values can be used in other procedures marginal.probs.2x2(prob11 = 0.35, # mean of case (or after) prob10 = 0.20, # mean of matched control (or before) prob01 = 0.10, prob00 = 0.35)# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(case) which is 0.55 # prob2 = mean(control) which is 0.45 # rho = cor(case, control) which is 0.4141414 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(after) which is 0.55 # prob2 = mean(before) which is 0.45 # rho = cor(after, before) which is 0.4141414 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # we may not have 2 x 2 joint probs # convert marginal probs to joint probs using summary stats jp <- joint.probs.2x2(prob1 = 0.55, # mean of case (or after) prob2 = 0.45, # mean of matched control (or before) # correlation b/w matched case-control / before-after rho = 0.4141414) # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob01 = jp$prob01, prob10 = jp$prob10, power = 0.80, alpha = 0.05, method = "exact") # convert joint probs to marginal probs and calc phi coefficient (rho) # these values can be used in other procedures marginal.probs.2x2(prob11 = 0.35, # mean of case (or after) prob10 = 0.20, # mean of matched control (or before) prob01 = 0.10, prob00 = 0.35)
Helper function to converts marginal probabilities to joint probabilities for the McNemar test applied to paired binary data.
marginal.probs.2x2(prob11, prob10, prob01, prob00, verbose = 1)marginal.probs.2x2(prob11, prob10, prob01, prob00, verbose = 1)
prob11 |
(joint) probability of success in both groups. 'prob11' and 'prob00' are known as concordant probs. |
prob10 |
(joint) probability of success in case (or after) but failure in matched control (or before). 'prob10' and 'prob01' are known as discordant probs. |
prob01 |
(joint) probability of failure in case (or after) but success in matched control (or before). prob10' and 'prob01' are known as discordant probs. |
prob00 |
(joint) probability of failure in both groups. 'prob11' and 'prob00' are known as concordant probs. |
verbose |
|
parms |
list of parameters used in calculation. |
prob1 |
(marginal) probability of success in case group (or after). |
prob2 |
(marginal) probability of success in matched-control group (or before). |
rho |
the correlation between case and matched-control, or after and before (phi coefficient). |
Zhang, S., Cao, J., and Ahn, C. (2017). Inference and sample size calculation for clinical trials with incomplete observations of paired binary outcomes. Statistics in Medicine, 36(4), 581-591. https://doi.org/10.1002/sim.7168
# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(case) which is 0.55 # prob2 = mean(control) which is 0.45 # rho = cor(case, control) which is 0.4141414 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(after) which is 0.55 # prob2 = mean(before) which is 0.45 # rho = cor(after, before) which is 0.4141414 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # we may not have 2 x 2 joint probs # convert marginal probs to joint probs using summary stats jp <- joint.probs.2x2(prob1 = 0.55, # mean of case (or after) prob2 = 0.45, # mean of matched control (or before) # correlation b/w matched case-control / before-after rho = 0.4141414) # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob01 = jp$prob01, prob10 = jp$prob10, power = 0.80, alpha = 0.05, method = "exact") # convert joint probs to marginal probs and calc phi coefficient (rho) # these values can be used in other procedures marginal.probs.2x2(prob11 = 0.35, # mean of case (or after) prob10 = 0.20, # mean of matched control (or before) prob01 = 0.10, prob00 = 0.35)# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(case) which is 0.55 # prob2 = mean(control) which is 0.45 # rho = cor(case, control) which is 0.4141414 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example summary stats # prob1 = mean(after) which is 0.55 # prob2 = mean(before) which is 0.45 # rho = cor(after, before) which is 0.4141414 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # we may not have 2 x 2 joint probs # convert marginal probs to joint probs using summary stats jp <- joint.probs.2x2(prob1 = 0.55, # mean of case (or after) prob2 = 0.45, # mean of matched control (or before) # correlation b/w matched case-control / before-after rho = 0.4141414) # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob01 = jp$prob01, prob10 = jp$prob10, power = 0.80, alpha = 0.05, method = "exact") # convert joint probs to marginal probs and calc phi coefficient (rho) # these values can be used in other procedures marginal.probs.2x2(prob11 = 0.35, # mean of case (or after) prob10 = 0.20, # mean of matched control (or before) prob01 = 0.10, prob00 = 0.35)
Helper function to convert means and standard deviations to Cohen's d.
means.to.d( mu1, mu2 = 0, sd1 = 1, sd2 = 1, n.ratio = 1, n2 = 10000000000, paired = FALSE, rho.paired = 0.5, verbose = 1 )means.to.d( mu1, mu2 = 0, sd1 = 1, sd2 = 1, n.ratio = 1, n2 = 10000000000, paired = FALSE, rho.paired = 0.5, verbose = 1 )
mu1 |
mean of the first group. |
mu2 |
mean of the second group. |
sd1 |
standard deviation of the first group. |
sd2 |
standard deviation of the second group. |
n.ratio |
|
n2 |
integer; sample size in the second group (or for the single group in paired samples). |
paired |
if |
rho.paired |
correlation between repeated measures for paired samples (e.g., pretest and post-test). |
verbose |
|
parms |
list of parameters used in calculation. |
d |
Cohen's d |
pooled.sd |
Pooled standard deviation |
var.ratio |
Ratio of the variance in the two groups (applies to independent samples only) |
n1 |
Sample size group 1 (applies to independent samples only) |
n2 |
Sample size group 2 |
# means and standard deviations from independent samples means.to.d(mu1 = 20, mu2 = 17.5, sd1 = 5, sd2 = 15, n2 = 30, n.ratio = 1) # means and standard deviations from paired samples means.to.d(mu1 = 20, mu2 = 17.5, sd1 = 5, sd2 = 15, n2 = 30, n.ratio = 1, paired = TRUE, rho.paired = 0.50)# means and standard deviations from independent samples means.to.d(mu1 = 20, mu2 = 17.5, sd1 = 5, sd2 = 15, n2 = 30, n.ratio = 1) # means and standard deviations from paired samples means.to.d(mu1 = 20, mu2 = 17.5, sd1 = 5, sd2 = 15, n2 = 30, n.ratio = 1, paired = TRUE, rho.paired = 0.50)
Calculates Cohen's f or Eta-squared for one-way ANOVA/ANCOVA. Set k.cov =
0 for one-way ANOVA (without any pretest or covariate adjustment). Set
k.cov > 0 in combination with r.squared > 0 for one-way ANCOVA (with
pretest or covariate adjustment).
means.to.etasq( mu.vector, sd.vector, n.vector, k.covariates = 0, r.squared = 0, factor.levels = NULL, verbose = 1 )means.to.etasq( mu.vector, sd.vector, n.vector, k.covariates = 0, r.squared = 0, factor.levels = NULL, verbose = 1 )
mu.vector |
vector of adjusted means (or estimated marginal means) for each level of a factor. |
sd.vector |
vector of unadjusted standard deviations for each level of a factor. |
n.vector |
vector of sample sizes for each level of a factor. |
k.covariates |
integer; number of covariates in the ANCOVA model. The
default is |
r.squared |
explanatory power of covariates (R-squared) in the
ANCOVA model. The default is |
factor.levels |
integer; number of levels or groups in each factor. For example, for two factors each having two levels or groups use e.g. c(2, 2), for three factors each having two levels or groups use e.g. c(2, 2, 2) |
verbose |
|
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.cov instead of
k.covariates.
f |
Cohen's f |
eta.squared |
(partial) eta-squared. |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter under alternative. |
Keppel, G., & Wickens, T. D. (2004). Design and analysis: A researcher's handbook (4th ed.). Pearson.
means.to.etasq(mu.vector = c(0.50, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviation n.vector = c(33, 33), # sample size (will be calculated) k.cov = 1, # number of covariates r.squared = 0.50)means.to.etasq(mu.vector = c(0.50, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviation n.vector = c(33, 33), # sample size (will be calculated) k.cov = 1, # number of covariates r.squared = 0.50)
Calculates power or find Probability (Non-Centrality) for the generic binomial test with (optional) Type 1 and Type 2 error plots.
power.binom.test( power = NULL, size = NULL, prob = NULL, null.prob = 0.5, req.sign = "+", alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )power.binom.test( power = NULL, size = NULL, prob = NULL, null.prob = 0.5, req.sign = "+", alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
size |
number of trials (zero or more); either |
prob |
probability of success on each trial under alternative;
either |
null.prob |
probability of success on each trial under null. |
req.sign |
whether 'prob' is expected to be greater '+1', less than '-1', or within '0' the null.prob' bounds. |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". For non-inferiority or superiority tests, add or subtract the margin from the null hypothesis value and use alternative = "one.sided". |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
power |
statistical power |
size |
number of trials (zero or more). |
prob |
probability of success on each trial under alternative. |
null.prob |
probability of success on each trial under null. |
alpha |
type 1 error rate. |
alternative |
direction or type of the hypothesis test. |
binom.alpha |
critical value(s). |
# one-sided power.binom.test(size = 200, prob = 0.6, null.prob = 0.5, alpha = 0.05, alternative = "one.sided") power.binom.test(power = 0.80, size = 200, req.sign = "+", null.prob = 0.5, alpha = 0.05, alternative = "one.sided") # two-sided power.binom.test(size = 200, prob = 0.4, null.prob = 0.5, alpha = 0.05, alternative = "two.sided") power.binom.test(power = 0.80, size = 200, req.sign = "+", null.prob = 0.5, alpha = 0.05, alternative = "two.sided") # equivalence power.binom.test(size = 200, prob = 0.5, null.prob = c(0.4, 0.6), alpha = 0.05, alternative = "two.one.sided") power.binom.test(power = 0.80, size = 200, req.sign = "0", null.prob = c(0.4, 0.6), alpha = 0.05, alternative = "two.one.sided")# one-sided power.binom.test(size = 200, prob = 0.6, null.prob = 0.5, alpha = 0.05, alternative = "one.sided") power.binom.test(power = 0.80, size = 200, req.sign = "+", null.prob = 0.5, alpha = 0.05, alternative = "one.sided") # two-sided power.binom.test(size = 200, prob = 0.4, null.prob = 0.5, alpha = 0.05, alternative = "two.sided") power.binom.test(power = 0.80, size = 200, req.sign = "+", null.prob = 0.5, alpha = 0.05, alternative = "two.sided") # equivalence power.binom.test(size = 200, prob = 0.5, null.prob = c(0.4, 0.6), alpha = 0.05, alternative = "two.one.sided") power.binom.test(power = 0.80, size = 200, req.sign = "0", null.prob = c(0.4, 0.6), alpha = 0.05, alternative = "two.one.sided")
Calculates power, sample size or effect size (only one can be NULL at a time) for Chi-square goodness-of-fit or independence tests.
power.chisq.gof( w = NULL, null.w = 0, df, n = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )power.chisq.gof( w = NULL, null.w = 0, df, n = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )
w |
Cohen's w effect size under alternative. It can be any of
Cohen's W, Phi coefficient, or Cramer's V but degrees of
freedom should be specified accordingly. Phi coefficient is
defined as |
null.w |
Cohen's w effect size under null. |
df |
integer; degrees of freedom. Defined as (n.cells - 1) if
|
n |
integer; total sample size. |
power |
statistical power, defined as the probability of correctly
rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of incorrectly
rejecting a true null hypothesis, denoted as |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode characters
(if encoding allows for it). |
NB: The pwrss.chisq.gofit() function is deprecated. However, it
will remain available as a wrapper for the power.chisq.gof()
function during a transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Chi-square Test). |
df |
degrees of freedom. |
ncp |
non-centrality parameter under alternative. |
null.ncp |
non-centrality parameter under null. |
chisq.alpha |
critical value. |
w |
Cohen's w effect size under alternative. |
power |
statistical power |
n |
total sample size. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
# ---------------------------------------------------------# # Example 1: Cohen's W # # goodness-of-fit test for 1 x k or k x 1 table # # How many subjects are needed to claim that # # girls choose STEM related majors less than males? # # ---------------------------------------------------------# ## Option 1: Use cell probabilities ## from https://www.aauw.org/resources/research/the-stem-gap/ ## 28 percent of the workforce in STEM field is women prob.vector <- c(0.28, 0.72) null.prob.vector <- c(0.50, 0.50) probs.to.w(prob.vector, null.prob.vector) power.chisq.gof(w = 0.44, df = 1, power = 0.80, alpha = 0.05) # ---------------------------------------------------------# # Example 2: Phi Coefficient (or Cramer's V or Cohen's W) # # test of independence for 2 x 2 contingency tables # # How many subjects are needed to claim that # # girls are underdiagnosed with ADHD? # # ---------------------------------------------------------# ## from http://archive.today/E2hqM ## 5.6 percent of girls and 13.2 percent of boys are diagnosed with ADHD prob.matrix <- rbind(c(0.056, 0.132), c(0.944, 0.868)) colnames(prob.matrix) <- c("Girl", "Boy") rownames(prob.matrix) <- c("ADHD", "No ADHD") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.1302134, df = 1, power = 0.80, alpha = 0.05) # --------------------------------------------------------# # Example 3: Cramer's V (or Cohen's W) # # test of independence for j x k contingency tables # # How many subjects are needed to detect the relationship # # between depression severity and gender? # # --------------------------------------------------------# ## from https://doi.org/10.1016/j.jad.2019.11.121 prob.matrix <- cbind(c(0.6759, 0.1559, 0.1281, 0.0323, 0.0078), c(0.6771, 0.1519, 0.1368, 0.0241, 0.0101)) rownames(prob.matrix) <- c("Normal", "Mild", "Moderate", "Severe", "Extremely Severe") colnames(prob.matrix) <- c("Female", "Male") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.03022008, df = 4, power = 0.80, alpha = 0.05)# ---------------------------------------------------------# # Example 1: Cohen's W # # goodness-of-fit test for 1 x k or k x 1 table # # How many subjects are needed to claim that # # girls choose STEM related majors less than males? # # ---------------------------------------------------------# ## Option 1: Use cell probabilities ## from https://www.aauw.org/resources/research/the-stem-gap/ ## 28 percent of the workforce in STEM field is women prob.vector <- c(0.28, 0.72) null.prob.vector <- c(0.50, 0.50) probs.to.w(prob.vector, null.prob.vector) power.chisq.gof(w = 0.44, df = 1, power = 0.80, alpha = 0.05) # ---------------------------------------------------------# # Example 2: Phi Coefficient (or Cramer's V or Cohen's W) # # test of independence for 2 x 2 contingency tables # # How many subjects are needed to claim that # # girls are underdiagnosed with ADHD? # # ---------------------------------------------------------# ## from http://archive.today/E2hqM ## 5.6 percent of girls and 13.2 percent of boys are diagnosed with ADHD prob.matrix <- rbind(c(0.056, 0.132), c(0.944, 0.868)) colnames(prob.matrix) <- c("Girl", "Boy") rownames(prob.matrix) <- c("ADHD", "No ADHD") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.1302134, df = 1, power = 0.80, alpha = 0.05) # --------------------------------------------------------# # Example 3: Cramer's V (or Cohen's W) # # test of independence for j x k contingency tables # # How many subjects are needed to detect the relationship # # between depression severity and gender? # # --------------------------------------------------------# ## from https://doi.org/10.1016/j.jad.2019.11.121 prob.matrix <- cbind(c(0.6759, 0.1559, 0.1281, 0.0323, 0.0078), c(0.6771, 0.1519, 0.1368, 0.0241, 0.0101)) rownames(prob.matrix) <- c("Normal", "Mild", "Moderate", "Severe", "Extremely Severe") colnames(prob.matrix) <- c("Female", "Male") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.03022008, df = 4, power = 0.80, alpha = 0.05)
Determines power, the non-centrality parameter (NCP) for the generic chi-square test with (optional) Type 1 and Type 2 error plots.
power.chisq.test( power = NULL, ncp = NULL, null.ncp = 0, df = NULL, alpha = 0.05, plot = TRUE, verbose = 1, utf = FALSE )power.chisq.test( power = NULL, ncp = NULL, null.ncp = 0, df = NULL, alpha = 0.05, plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
ncp |
non-centrality parameter for the alternative; either
|
null.ncp |
non-centrality parameter for the null. |
df |
integer; degrees of freedom, e.g., for the test of
independence df = (nrow - 1) * (ncol - 1); either |
alpha |
type 1 error rate, defined as the probability of incorrectly
rejecting a true null hypothesis, denoted as |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode characters
(if encoding allows for it). |
power |
statistical power |
ncp |
non-centrality parameter under alternative. |
null.ncp |
non-centrality parameter under null. |
df |
degrees of freedom. |
alpha |
type 1 error rate (user-specified). |
chisq.alpha |
critical value. |
# power is defined as the probability of observing a test statistics greater # than the critical value power.chisq.test(ncp = 20, df = 100, alpha = 0.05) power.chisq.test(power = 0.80, df = 100, alpha = 0.05) power.chisq.test(power = 0.80, ncp = 20, alpha = 0.05)# power is defined as the probability of observing a test statistics greater # than the critical value power.chisq.test(ncp = 20, df = 100, alpha = 0.05) power.chisq.test(power = 0.80, df = 100, alpha = 0.05) power.chisq.test(power = 0.80, ncp = 20, alpha = 0.05)
Calculates power or sample size for Fisher's exact test on independent binary outcomes. Approximate and exact methods are available.
Validated using the PASS documentation and G*Power.
power.exact.fisher( prob1 = NULL, prob2 = NULL, req.sign = "+", n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.exact.fisher( prob1 = NULL, prob2 = NULL, req.sign = "+", n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )
prob1 |
probability of success in the first group. |
prob2 |
probability of success in the second group. |
req.sign |
whether estimated prob is smaller or larger than the other (when minimum detectable prob is of interest). |
n.ratio |
n1 / n2 ratio. |
n2 |
integer; sample size for the second group. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the 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. |
ceil.n |
logical; if |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
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 |
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 the 2 x 2 table (f11 + f10 + f01 + f00), or number of rows in a data frame with group variable stacked. |
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. https://doi.org/10.2307/2333309
Fisher, R. A. (1935). The logic of inductive inference. Journal of the Royal Statistical Society, 98(1), 39-82. https://doi.org/10.2307/2342435
# 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)# 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)
Calculates power or sample size for McNemar's test on paired binary outcomes. Approximate and exact methods are available (check references for details).
Validated using the PASS documentation and G*Power.
power.exact.mcnemar( prob10 = NULL, prob01 = NULL, req.sign = "+", n.paired = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.exact.mcnemar( prob10 = NULL, prob01 = NULL, req.sign = "+", n.paired = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )
prob10 |
(joint) probability of success in case (or after) but failure in matched control (or before). 'prob10' and 'prob01' are known as discordant probs. |
prob01 |
(joint) probability of failure in case (or after) but success in matched control (or before). prob10' and 'prob01' are known as discordant probs. |
req.sign |
whether estimated prob is smaller or larger than the other (when minimum detectable prob is of interest). |
n.paired |
number of pairs, which is sum of cell frequencies in the 2 x 2 table (f11 + f10 + f01 + f00), or number of rows in a data frame with matched variables 'case' and 'control' or 'after' and 'before'. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
method |
character; the method used for power calculation. "exact" specifies Fisher's exact test, while "approximate" refers to the z-test based on the normal approximation. |
ceil.n |
logical; if |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
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 |
n.paired |
paired sample size, which is sum of cell frequencies in the 2 x 2 table (f11 + f10 + f01 + f00), or number of rows in a data frame with variables 'case' and 'control' or 'after' and 'before'. |
Bennett, B. M., & Underwood, R. E. (1970). 283. Note: On McNemar's Test for the 2 * 2 Table and Its Power Function. Biometrics, 26(2), 339-343. https://doi.org/10.2307/2529083
Connor, R. J. (1987). Sample size for testing differences in proportions for the paired-sample design. Biometrics, 43(1), 207-211. https://doi.org/10.2307/2531961
Duffy, S. W. (1984). Asymptotic and exact power for the McNemar test and its analogue with R controls per case. Biometrics, 40(4) 1005-1015. https://doi.org/10.2307/2531151
McNemar, Q. (1947). Note on the sampling error of the difference between correlated proportions or percentages. Psychometrika, 12(2), 153-157. https://doi.org/10.1007/BF02295996
Miettinen, O. S. (1968). The matched pairs design in the case of all-or-none responses. Biometrics, 24(2), 339-352. https://doi.org/10.2307/2528039
# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # post-hoc exact power power.exact.mcnemar(prob10 = 0.20, prob01 = 0.10, n.paired = 100, alpha = 0.05, alternative = "two.sided", method = "exact") # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob10 = 0.20, prob01 = 0.10, power = 0.80, alpha = 0.05, alternative = "two.sided", method = "exact") # we may not have 2 x 2 joint probs # convert marginal probs to joint probs joint.probs.2x2(prob1 = 0.55, # mean of case group (or after) prob2 = 0.45, # mean of matched control group (or before) # correlation between matched case-control or before-after rho = 0.4141414 )# example data for a matched case-control design # subject case control # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # example data for a before-after design # subject before after # <int> <dbl> <dbl> # 1 1 1 # 2 0 1 # 3 1 0 # 4 0 1 # 5 1 1 # ... ... ... # 100 0 0 # convert to a 2 x 2 frequency table freqs <- matrix(c(30, 10, 20, 40), nrow = 2, ncol = 2) colnames(freqs) <- c("control_1", "control_0") rownames(freqs) <- c("case_1", "case_0") freqs # convert to a 2 x 2 proportion table props <- freqs / sum(freqs) props # discordant pairs (0 and 1, or 1 and 0) in 'props' matrix # are the sample estimates of prob01 and prob10 # post-hoc exact power power.exact.mcnemar(prob10 = 0.20, prob01 = 0.10, n.paired = 100, alpha = 0.05, alternative = "two.sided", method = "exact") # required sample size for exact test # assuming prob01 and prob10 are population parameters power.exact.mcnemar(prob10 = 0.20, prob01 = 0.10, power = 0.80, alpha = 0.05, alternative = "two.sided", method = "exact") # we may not have 2 x 2 joint probs # convert marginal probs to joint probs joint.probs.2x2(prob1 = 0.55, # mean of case group (or after) prob2 = 0.45, # mean of matched control group (or before) # correlation between matched case-control or before-after rho = 0.4141414 )
Calculates power, sample size, or minimum detectable correlation (only one can be NULL at a time) to test a (Pearson) correlation against a constant using exact method described in Barabesi and Greco (2002).
Formulas are validated using G*Power.
power.exact.onecor( rho = NULL, req.sign = "+", null.rho = 0, n = NULL, n.max = 10000, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), verbose = 1, utf = FALSE )power.exact.onecor( rho = NULL, req.sign = "+", null.rho = 0, n = NULL, n.max = 10000, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), verbose = 1, utf = FALSE )
rho |
correlation. |
req.sign |
whether estimated rho is smaller or larger than the null.rho (when minimum detectable rho is of interest). |
null.rho |
correlation when null is true. Only 0 is allowed for now. |
n |
sample size. |
n.max |
max. number of observations in the sample (default: 500). |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test) |
rho.alpha |
critical value(s). |
es |
minimum detectable correlation. |
power |
statistical power |
n |
sample size. |
Barabesi, L., & Greco, L. (2002). A Note on the Exact Computation of the Student t, Snedecor F and Sample Correlation Coefficient Distribution Functions. Journal of the Royal Statistical Society. Series D (The Statistician), 51(1), 105–110. https://www.jstor.org/stable/3650394
# expected correlation is 0.20 and it is different from 0 # it could be 0.20 as well as -0.20 power.exact.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "two.sided") # expected correlation is 0.20 and it is greater than 0 power.exact.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "one.sided")# expected correlation is 0.20 and it is different from 0 # it could be 0.20 as well as -0.20 power.exact.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "two.sided") # expected correlation is 0.20 and it is greater than 0 power.exact.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "one.sided")
Calculates power, sample size or effect size (only one can be NULL at a time) for test of a proportion against a constant using the exact method.
Formulas are validated using PASS documentation.
power.exact.oneprop( prob = NULL, req.sign = "+", null.prob = 0.5, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), verbose = 1, utf = FALSE )power.exact.oneprop( prob = NULL, req.sign = "+", null.prob = 0.5, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), verbose = 1, utf = FALSE )
prob |
probability of success under alternative. |
req.sign |
whether |
null.prob |
probability of success under null. |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test:
"two.sided", "one.sided", or "two.one.sided". For
non-inferiority or superiority tests, add margin to the
null hypothesis value and use
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test ("exact"). |
delta |
difference between |
odds.ratio |
Odds-ratio |
prob |
probability of success under alternative. |
null.prob |
probability of success under null. |
binom.alpha |
critical value(s). |
power |
statistical power |
n |
sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
# power' power.exact.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, n = 500, alternative = "one.sided") # sample size power.exact.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, power = 0.80, alternative = "one.sided")# power' power.exact.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, n = 500, alternative = "one.sided") # sample size power.exact.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, power = 0.80, alternative = "one.sided")
Calculates power or sample size (only one can be NULL at a time) for two
proportions using the exact method. The function is a wrapper for
power.exact.mcnemar (if paired == TRUE), or power.exact.fisher (if
paired == FALSE)
Validated via G*Power and PASS documentation.
power.exact.twoprops( prob1 = NULL, prob2 = NULL, req.sign = "+", n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), paired = FALSE, rho.paired = 0.5, method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.exact.twoprops( prob1 = NULL, prob2 = NULL, req.sign = "+", n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), paired = FALSE, rho.paired = 0.5, method = c("exact", "approximate"), ceil.n = TRUE, verbose = 1, utf = FALSE )
prob1 |
probability of success in the first group. |
prob2 |
probability of success in the second group. |
req.sign |
whether estimated prob is smaller or larger than the other (when minimum detectable prob is of interest). |
n.ratio |
sample size ratio (n1 / n2). |
n2 |
integer; sample size for the second group. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
paired |
logical; if |
rho.paired |
correlation between paired observations. |
method |
character; whether to use "approximate" or "exact"
method. Default is |
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the test, which is "z" or "exact". |
delta |
difference between |
odds.ratio |
Odds-ratio |
size |
... (applies to paired proportions). |
prob |
... (applies to paired proportions). |
null.prob |
... (applies to paired proportions). |
binom.alpha |
critical value(s) (applies to paired proportions). |
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. |
alternative |
standard deviation of the null distribution. |
z.alpha |
critical value(s). |
power |
statistical power |
n |
sample size in the form of c(n1, n2) (applies to independent proportions). |
n.total |
total sample size (applies to independent proportions). |
n.paired |
paired sample size (applies to paired proportions). |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
# power power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided") power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided", paired = TRUE) # sample size power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided") power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided", paired = TRUE)# power power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided") power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided", paired = TRUE) # sample size power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided") power.exact.twoprops(prob1 = 0.70, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided", paired = TRUE)
Calculates power, sample size or effect size for one-way, two-way, or
three-way ANOVA/ANCOVA. Set k.covariates = 0 for ANOVA, and
k.covariates > 0 for ANCOVA. Note that in the latter, the effect
size (eta.squared should be obtained from the relevant ANCOVA model,
which is already adjusted for the explanatory power of covariates (thus,
an additional R-squared argument is not required as an input).
Formulas are validated using G*Power and tables in the PASS documentation.
power.f.ancova( eta.squared = NULL, null.eta.squared = 0, factor.levels = 2, target.effect = NULL, k.covariates = 0, n.total = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )power.f.ancova( eta.squared = NULL, null.eta.squared = 0, factor.levels = 2, target.effect = NULL, k.covariates = 0, n.total = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )
eta.squared |
(partial) eta-squared for the alternative. |
null.eta.squared |
(partial) eta-squared for the null. |
factor.levels |
integer; number of levels or groups in each factor. For example, for two factors each having two levels or groups use e.g. c(2, 2), for three factors each having two levels (groups) use e.g. c(2, 2, 2). |
target.effect |
character; determine the main effect or interaction that is of interest, e.g., in a three-way-design, it is possible to define "A" (main effect of the first factor), "B:C" (interaction of factor two and three) or "A:B:C" (the three-way interaction of all factors); if target is not used, the three-way interaction is the default. |
k.covariates |
integer; number of covariates in an ANCOVA model |
n.total |
integer; total sample size |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis,
denoted as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
ceil.n |
logical; if |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.covariates instead of
k.covariates.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (F-Test). |
eta.squared |
(partial) eta-squared for the alternative. |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
f.alpha |
critical value. |
power |
statistical power |
n.total |
total sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
############################################# # one-way ANOVA # ############################################# # Cohen's d = 0.50 between treatment and control # translating into eta-squared = 0.059 # estimate sample size using ANOVA approach power.f.ancova(eta.squared = 0.059, factor.levels = 2, power = .80, alpha = 0.05) # estimate sample size using regression approach(F-Test) power.f.regression(r.squared = 0.059, k.total = 1, power = 0.80, alpha = 0.05) # estimate sample size using regression approach (t-Test) p <- 0.50 # proportion of sample in treatment (allocation rate) power.t.regression(beta = 0.50, r.squared = 0, k.total = 1, sd.predictor = sqrt(p * (1 - p)), power = 0.80, alpha = 0.05) # estimate sample size using t test approach power.t.student(d = 0.50, power = 0.80, alpha = 0.05) ############################################# # two-way ANOVA # ############################################# # a researcher is expecting a partial eta-squared = 0.03 # for interaction of treatment (Factor A) with # gender consisting of two levels (Factor B) power.f.ancova(eta.squared = 0.03, factor.levels = c(2,2), power = 0.80, alpha = 0.05) # estimate sample size using regression approach (F test) # one dummy for treatment, one dummy for gender, and their interaction (k = 3) # partial eta-squared is equivalent to the increase in R-squared by adding # only the interaction term (m = 1) power.f.regression(r.squared = 0.03, k.total = 3, k.test = 1, power = 0.80, alpha = 0.05) ############################################# # one-way ANCOVA # ############################################# # a researcher is expecting an adjusted difference of # Cohen's d = 0.45 between treatment and control after # controllling for the pretest (k.covariates = 1) # translating into eta-squared = 0.048 power.f.ancova(eta.squared = 0.048, factor.levels = 2, k.covariates = 1, power = .80, alpha = 0.05) ############################################# # two-way ANCOVA # ############################################# # a researcher is expecting an adjusted partial eta-squared = 0.02 # for interaction of treatment (Factor A) with # gender consisting of two levels (Factor B) power.f.ancova(eta.squared = 0.02, factor.levels = c(2,2), k.covariates = 1, power = .80, alpha = 0.05)############################################# # one-way ANOVA # ############################################# # Cohen's d = 0.50 between treatment and control # translating into eta-squared = 0.059 # estimate sample size using ANOVA approach power.f.ancova(eta.squared = 0.059, factor.levels = 2, power = .80, alpha = 0.05) # estimate sample size using regression approach(F-Test) power.f.regression(r.squared = 0.059, k.total = 1, power = 0.80, alpha = 0.05) # estimate sample size using regression approach (t-Test) p <- 0.50 # proportion of sample in treatment (allocation rate) power.t.regression(beta = 0.50, r.squared = 0, k.total = 1, sd.predictor = sqrt(p * (1 - p)), power = 0.80, alpha = 0.05) # estimate sample size using t test approach power.t.student(d = 0.50, power = 0.80, alpha = 0.05) ############################################# # two-way ANOVA # ############################################# # a researcher is expecting a partial eta-squared = 0.03 # for interaction of treatment (Factor A) with # gender consisting of two levels (Factor B) power.f.ancova(eta.squared = 0.03, factor.levels = c(2,2), power = 0.80, alpha = 0.05) # estimate sample size using regression approach (F test) # one dummy for treatment, one dummy for gender, and their interaction (k = 3) # partial eta-squared is equivalent to the increase in R-squared by adding # only the interaction term (m = 1) power.f.regression(r.squared = 0.03, k.total = 3, k.test = 1, power = 0.80, alpha = 0.05) ############################################# # one-way ANCOVA # ############################################# # a researcher is expecting an adjusted difference of # Cohen's d = 0.45 between treatment and control after # controllling for the pretest (k.covariates = 1) # translating into eta-squared = 0.048 power.f.ancova(eta.squared = 0.048, factor.levels = 2, k.covariates = 1, power = .80, alpha = 0.05) ############################################# # two-way ANCOVA # ############################################# # a researcher is expecting an adjusted partial eta-squared = 0.02 # for interaction of treatment (Factor A) with # gender consisting of two levels (Factor B) power.f.ancova(eta.squared = 0.02, factor.levels = c(2,2), k.covariates = 1, power = .80, alpha = 0.05)
Calculates power, sample size or effect size for one-way ANOVA/ANCOVA. Set
k.covariates = 0 for one-way ANOVA (without any pretest or covariate
adjustment). Set k.covariates > 0 in combination with
r.squared > 0 for one-way ANCOVA (with pretest or covariate
adjustment).
Formulas are validated using the PASS documentation.
power.f.ancova.keppel( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, factor.levels = NULL, r.squared = 0, k.covariates = 0, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )power.f.ancova.keppel( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, factor.levels = NULL, r.squared = 0, k.covariates = 0, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )
mu.vector |
vector of adjusted means (or estimated marginal means) for each level of a factor. |
sd.vector |
vector of unadjusted standard deviations for each level of a factor. |
n.vector |
vector of sample sizes for each level of a factor. |
p.vector |
vector of proportion of total sample size in each level of a factor. These proportions should sum to one. |
factor.levels |
integer; number of levels or groups in each factor. For example, for two factors each having two levels or groups use e.g. c(2, 2), for three factors each having two levels or groups use e.g. c(2, 2, 2) |
r.squared |
explanatory power of covariates (R-squared) in the
ANCOVA model. The default is |
k.covariates |
integer; number of covariates in the ANCOVA model. The
default is |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted
as |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.cov instead of
k.covariates.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (F-Test). |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter under alternative. |
null.ncp |
non-centrality parameter under null. |
power |
statistical power |
n.total |
total sample size. |
Keppel, G., & Wickens, T. D. (2004). Design and analysis: A researcher's handbook (4th ed.). Pearson.
# required sample size to detect a mean difference of # Cohen's d = 0.50 for a one-way two-group design power.f.ancova.keppel(mu.vector = c(0.50, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations n.vector = NULL, # sample size (will be calculated) p.vector = c(0.50, 0.50), # balanced allocation k.covariates = 1, # number of covariates r.squared = 0.50, # explanatory power of covariates alpha = 0.05, # Type 1 error rate power = .80) # effect size approach power.f.ancova(eta.squared = 0.111, # effect size that is already adjusted for covariates factor.levels = 2, # one-way ANCOVA with two levels (groups) k.covariates = 1, # number of covariates alpha = 0.05, # Type 1 error rate power = .80) # regression approach p <- 0.50 power.t.regression(beta = 0.50, sd.predictor = sqrt(p * (1 - p)), sd.outcome = 1, k.total = 1, r.squared = 0.50, n = NULL, power = 0.80)# required sample size to detect a mean difference of # Cohen's d = 0.50 for a one-way two-group design power.f.ancova.keppel(mu.vector = c(0.50, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations n.vector = NULL, # sample size (will be calculated) p.vector = c(0.50, 0.50), # balanced allocation k.covariates = 1, # number of covariates r.squared = 0.50, # explanatory power of covariates alpha = 0.05, # Type 1 error rate power = .80) # effect size approach power.f.ancova(eta.squared = 0.111, # effect size that is already adjusted for covariates factor.levels = 2, # one-way ANCOVA with two levels (groups) k.covariates = 1, # number of covariates alpha = 0.05, # Type 1 error rate power = .80) # regression approach p <- 0.50 power.t.regression(beta = 0.50, sd.predictor = sqrt(p * (1 - p)), sd.outcome = 1, k.total = 1, r.squared = 0.50, n = NULL, power = 0.80)
Calculates power, sample size or effect size for one-, two-, three-way
ANCOVA. For factorial designs, use the argument factor.levels but
note that unique combination of levels (cells in this case) should follow a
specific order for the test of interaction. The order of marginal means and
standard deviations is printed as a warning message.
Formulas are validated using examples and tables in Shieh (2020).
power.f.ancova.shieh( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, factor.levels = NULL, r.squared = 0, k.covariates = 1, contrast.matrix = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )power.f.ancova.shieh( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, factor.levels = NULL, r.squared = 0, k.covariates = 1, contrast.matrix = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )
mu.vector |
vector; adjusted means (or estimated marginal means) for each level of a factor. |
sd.vector |
vector; unadjusted standard deviations for each level of a factor. If a pooled standard deviation is provided, repeat its value to match the number of group means. A warning will be issued if group standard deviations differ substantially beyond what is expected due to sampling error. |
n.vector |
vector; sample sizes for each level of a factor. |
p.vector |
vector; proportion of total sample size in each level of a factor. These proportions should sum to one. |
factor.levels |
integer; number of levels or groups in each factor. For example, for two factors each having two levels or groups use e.g. c(2, 2), for three factors each having two levels or groups use e.g. c(2, 2, 2). |
r.squared |
explanatory power of covariates (R-squared) in the ANCOVA model. |
k.covariates |
integer; number of covariates in the ANCOVA model. |
contrast.matrix |
vector or matrix; contrasts should not be confused with the model (design) matrix. Rows of contrast matrix indicate independent vector of contrasts summing to zero. The default contrast matrix is constructed using deviation coding scheme (a.k.a. effect coding). Columns in the contrast matrix indicate number of levels or groups (or cells in factorial designs). |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted
as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted
as |
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.cov instead of
k.covariates.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (F-Test) |
eta.squared |
(partial) eta-squared. |
f |
Cohen's f statistic. |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
power |
statistical power |
n.total |
total sample size. |
Shieh, G. (2020). Power analysis and sample size planning in ANCOVA designs. Psychometrika, 85(1), 101-120. https://doi.org/10.1007/s11336-019-09692-3
################################################################### ########################## main effect ########################## ################################################################### # power for one-way ANCOVA (two levels or groups) power.f.ancova.shieh(mu.vector = c(0.20, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations n.vector = c(150, 150), # sample sizes r.squared = 0.50, # proportion of variance explained by covariates k.covariates = 1, # number of covariates alpha = 0.05) # sample size for one-way ANCOVA (two levels or groups) power.f.ancova.shieh(mu.vector = c(0.20, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations p.vector = c(0.50, 0.50), # allocation, should sum to 1 r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) ################################################################### ####################### interaction effect ###################### ################################################################### # sample size for two-way ANCOVA (2 x 2) power.f.ancova.shieh(mu.vector = c(0.20, 0.25, 0.15, 0.05), # marginal means sd.vector = c(1, 1, 1, 1), # unadjusted standard deviations p.vector = c(0.25, 0.25, 0.25, 0.25), # allocation, should sum to 1 factor.levels = c(2, 2), # 2 by 2 factorial design r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # Elements of `mu.vector`, `sd.vector`, `n.vector` or `p.vector` should follow this specific order: # A1:B1 A1:B2 A2:B1 A2:B2 ################################################################### ####################### planned contrasts ####################### ################################################################### ######################### ## dummy coding scheme ## ######################### contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 3 levels coding = "treatment") # use dummy coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of planned contrasts, adjusted for alpha level power.t.contrasts(ancova.design, adjust.alpha = "fdr") ########################### ## Helmert coding scheme ## ########################### contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels coding = "helmert") # use helmert coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of planned contrasts power.t.contrasts(ancova.design) ############################## ## polynomial coding scheme ## ############################## contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels coding = "poly") # use polynomial coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of the planned contrasts power.t.contrasts(ancova.design) ###################### ## custom contrasts ## ###################### # custom contrasts contrast.matrix <- rbind( cbind(A1 = 1, A2 = -0.50, A3 = -0.50), cbind(A1 = 0.50, A2 = 0.50, A3 = -1) ) # labels are not required for custom contrasts, # but they make it easier to understand power.t.contrasts() output # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of the planned contrasts power.t.contrasts(ancova.design)################################################################### ########################## main effect ########################## ################################################################### # power for one-way ANCOVA (two levels or groups) power.f.ancova.shieh(mu.vector = c(0.20, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations n.vector = c(150, 150), # sample sizes r.squared = 0.50, # proportion of variance explained by covariates k.covariates = 1, # number of covariates alpha = 0.05) # sample size for one-way ANCOVA (two levels or groups) power.f.ancova.shieh(mu.vector = c(0.20, 0), # marginal means sd.vector = c(1, 1), # unadjusted standard deviations p.vector = c(0.50, 0.50), # allocation, should sum to 1 r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) ################################################################### ####################### interaction effect ###################### ################################################################### # sample size for two-way ANCOVA (2 x 2) power.f.ancova.shieh(mu.vector = c(0.20, 0.25, 0.15, 0.05), # marginal means sd.vector = c(1, 1, 1, 1), # unadjusted standard deviations p.vector = c(0.25, 0.25, 0.25, 0.25), # allocation, should sum to 1 factor.levels = c(2, 2), # 2 by 2 factorial design r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # Elements of `mu.vector`, `sd.vector`, `n.vector` or `p.vector` should follow this specific order: # A1:B1 A1:B2 A2:B1 A2:B2 ################################################################### ####################### planned contrasts ####################### ################################################################### ######################### ## dummy coding scheme ## ######################### contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 3 levels coding = "treatment") # use dummy coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of planned contrasts, adjusted for alpha level power.t.contrasts(ancova.design, adjust.alpha = "fdr") ########################### ## Helmert coding scheme ## ########################### contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels coding = "helmert") # use helmert coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of planned contrasts power.t.contrasts(ancova.design) ############################## ## polynomial coding scheme ## ############################## contrast.object <- factorial.contrasts(factor.levels = 3, # one factor w/ 4 levels coding = "poly") # use polynomial coding scheme # get contrast matrix from the contrast object contrast.matrix <- contrast.object$contrast.matrix # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of the planned contrasts power.t.contrasts(ancova.design) ###################### ## custom contrasts ## ###################### # custom contrasts contrast.matrix <- rbind( cbind(A1 = 1, A2 = -0.50, A3 = -0.50), cbind(A1 = 0.50, A2 = 0.50, A3 = -1) ) # labels are not required for custom contrasts, # but they make it easier to understand power.t.contrasts() output # calculate sample size given design characteristics ancova.design <- power.f.ancova.shieh(mu.vector = c(0.15, 0.30, 0.20), # marginal means sd.vector = c(1, 1, 1), # unadjusted standard deviations p.vector = c(1/3, 1/3, 1/3), # allocation, should sum to 1 contrast.matrix = contrast.matrix, r.squared = 0.50, k.covariates = 1, alpha = 0.05, power = 0.80) # power of the planned contrasts power.t.contrasts(ancova.design)
Calculates power, sample size or effect size for mixed-effects ANOVA design with two factors (between and within). When there is only one group observed over time, this design is often referred to as repeated-measures ANOVA.
Formulas are validated using G*Power and tables in the PASS documentation.
power.f.mixed.anova( eta.squared = NULL, null.eta.squared = 0, factor.levels = c(2, 2), factor.type = c("between", "within"), rho.within = 0.5, epsilon = 1, n.total = NULL, power = NULL, alpha = 0.05, effect = c("between", "within", "interaction"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.f.mixed.anova( eta.squared = NULL, null.eta.squared = 0, factor.levels = c(2, 2), factor.type = c("between", "within"), rho.within = 0.5, epsilon = 1, n.total = NULL, power = NULL, alpha = 0.05, effect = c("between", "within", "interaction"), ceil.n = TRUE, verbose = 1, utf = FALSE )
eta.squared |
(partial) eta-squared for the alternative. |
null.eta.squared |
(partial) eta-squared for the null. |
factor.levels |
vector; integer; length of two representing the number of levels for groups and measures. For example, in randomized controlled trials with two arms (treatment and control) where pre-test, post-test, and follow-up test are administered, this would be represented as c(2, 3). |
factor.type |
vector; character; length of two indicating the order of between-subject and within-subject factors. By default, the first value represents the between-subject factor and the second value represents the within-subject factor. This argument is rarely needed, except when unsure which element in 'factor.levels' represent between-subject or within-subject factors. Therefore, specify the 'factor.levels' accordingly. |
rho.within |
Correlation between repeated measures. For example,
for pretest/post-test designs, this is the
correlation between pretest and post-test scores
regardless of group membership. The default is 0.50.
If |
epsilon |
non-sphericity correction factor, default is 1
(means no violation of sphericity). Lower bound for
this argument is
|
n.total |
integer; total sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted
as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
effect |
character; the effect of interest: "between", "within", or "interaction". |
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it).
|
NB: The pwrss.f.rmanova() function is deprecated and will no longer
be supported, but it will remain available as a wrapper for the
power.f.mixed.anova() function during a transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (F-Test). |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter under alternative. |
null.ncp |
non-centrality parameter under null. |
power |
statistical power |
n.total |
total sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
###################################################### # pretest-post-test design with treatment group only # ###################################################### # a researcher is expecting a difference of Cohen's d = 0.30 # between post-test and pretest score translating into # Eta-squared = 0.022 # adjust effect size for correlation with 'rho.within' power.f.mixed.anova(eta.squared = 0.022, factor.levels = c(1, 2), # 1 between 2 within rho.within = 0.50, effect = "within", power = 0.80, alpha = 0.05) # if effect size is already adjusted for correlation # use 'rho.within = NA' power.f.mixed.anova(eta.squared = 0.08255, factor.levels = c(1, 2), # 1 between 2 within rho.within = NA, effect = "within", power = 0.80, alpha = 0.05) ########################################################## # post-test only design with treatment and control groups # ########################################################## # a researcher is expecting a difference of Cohen's d = 0.50 # on the post-test score between treatment and control groups # translating into Eta-squared = 0.059 power.f.mixed.anova(eta.squared = 0.059, factor.levels = c(2, 1), # 2 between 1 within effect = "between", power = 0.80, alpha = 0.05) ############################################################# # pretest-post-test design with treatment and control groups # ############################################################# # a researcher is expecting a difference of Cohen's d = 0.40 # on the post-test score between treatment and control groups # after controlling for the pretest translating into # partial Eta-squared = 0.038 power.f.mixed.anova(eta.squared = 0.038, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "between", power = 0.80, alpha = 0.05) # a researcher is expecting an interaction effect # (between groups and time) of Eta-squared = 0.01 power.f.mixed.anova(eta.squared = 0.01, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "interaction", power = 0.80, alpha = 0.05) # a researcher is expecting an interaction effect # (between groups and time) of Eta-squared = 0.01 power.f.mixed.anova(eta.squared = 0.01, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "within", power = 0.80, alpha = 0.05)###################################################### # pretest-post-test design with treatment group only # ###################################################### # a researcher is expecting a difference of Cohen's d = 0.30 # between post-test and pretest score translating into # Eta-squared = 0.022 # adjust effect size for correlation with 'rho.within' power.f.mixed.anova(eta.squared = 0.022, factor.levels = c(1, 2), # 1 between 2 within rho.within = 0.50, effect = "within", power = 0.80, alpha = 0.05) # if effect size is already adjusted for correlation # use 'rho.within = NA' power.f.mixed.anova(eta.squared = 0.08255, factor.levels = c(1, 2), # 1 between 2 within rho.within = NA, effect = "within", power = 0.80, alpha = 0.05) ########################################################## # post-test only design with treatment and control groups # ########################################################## # a researcher is expecting a difference of Cohen's d = 0.50 # on the post-test score between treatment and control groups # translating into Eta-squared = 0.059 power.f.mixed.anova(eta.squared = 0.059, factor.levels = c(2, 1), # 2 between 1 within effect = "between", power = 0.80, alpha = 0.05) ############################################################# # pretest-post-test design with treatment and control groups # ############################################################# # a researcher is expecting a difference of Cohen's d = 0.40 # on the post-test score between treatment and control groups # after controlling for the pretest translating into # partial Eta-squared = 0.038 power.f.mixed.anova(eta.squared = 0.038, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "between", power = 0.80, alpha = 0.05) # a researcher is expecting an interaction effect # (between groups and time) of Eta-squared = 0.01 power.f.mixed.anova(eta.squared = 0.01, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "interaction", power = 0.80, alpha = 0.05) # a researcher is expecting an interaction effect # (between groups and time) of Eta-squared = 0.01 power.f.mixed.anova(eta.squared = 0.01, factor.levels = c(2, 2), # 2 between 2 within rho.within = 0.50, effect = "within", power = 0.80, alpha = 0.05)
Calculates power or sample size (only one can be NULL at a time) to test R-squared deviation from 0 (zero) in linear regression or to test R-squared change between two linear regression models. The test of R-squared change is often used to evaluate incremental contribution of a set of predictors in hierarchical linear regression.
Formulas are validated using Monte Carlo simulation, G*Power, and tables in the PASS documentation.
power.f.regression( r.squared.change = NULL, margin = 0, k.total, k.tested = k.total, n = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )power.f.regression( r.squared.change = NULL, margin = 0, k.total, k.tested = k.total, n = NULL, power = NULL, alpha = 0.05, ceil.n = TRUE, verbose = 1, utf = FALSE )
r.squared.change |
R-squared (or R-squared change). |
margin |
margin - ignorable R-squared (or R-squared change). |
k.total |
integer; total number of predictors. |
k.tested |
integer; number of predictors in the subset of
interest. By default |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted
as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it).
|
NB: The pwrss.f.regression function and its alias
pwrss.f.reg() are deprecated, but they will remain available as a
wrapper for the power.f.regression() function during a transition
period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (F-Test). |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
f.alpha |
critical value. |
power |
statistical power |
n |
sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
# in the outcome (R-squared = 0.15). power.f.regression(r.squared = 0.15, k.total = 3, # total number of predictors power = 0.80) # adding two more variables will increase R-squared # from 0.15 (with 3 predictors) to 0.25 (with 3 + 2 predictors) power.f.regression(r.squared.change = 0.10, # R-squared change k.total = 5, # total number of predictors k.tested = 2, # predictors to be tested power = 0.80)# in the outcome (R-squared = 0.15). power.f.regression(r.squared = 0.15, k.total = 3, # total number of predictors power = 0.80) # adding two more variables will increase R-squared # from 0.15 (with 3 predictors) to 0.25 (with 3 + 2 predictors) power.f.regression(r.squared.change = 0.10, # R-squared change k.total = 5, # total number of predictors k.tested = 2, # predictors to be tested power = 0.80)
Determines the power or the non-centrality parameter for the generic F-Test with (optional) Type 1 and Type 2 error plots.
power.f.test( power = NULL, ncp = NULL, null.ncp = 0, df1, df2, alpha = 0.05, plot = TRUE, verbose = 1, utf = FALSE )power.f.test( power = NULL, ncp = NULL, null.ncp = 0, df1, df2, alpha = 0.05, plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
ncp |
non-centrality parameter for the alternative; either |
null.ncp |
non-centrality parameter for the null. |
df1 |
integer; numerator degrees of freedom. |
df2 |
integer; denominator degrees of freedom. |
alpha |
type 1 error rate, defined as the probability of incorrectly
rejecting a true null hypothesis, denoted as |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode characters
(if encoding allows for it). |
power |
statistical power |
ncp |
non-centrality parameter under alternative. |
ncp.null |
non-centrality parameter under null. |
df1 |
numerator degrees of freedom. |
df2 |
denominator degrees of freedom. |
f.alpha |
critical value(s). |
# power is defined as the probability of observing a test statistics greater # than the critical value power.f.test(ncp = 1, df1 = 4, df2 = 100, alpha = 0.05) power.f.test(power = 0.80, df1 = 4, df2 = 100, alpha = 0.05)# power is defined as the probability of observing a test statistics greater # than the critical value power.f.test(ncp = 1, df1 = 4, df2 = 100, alpha = 0.05) power.f.test(power = 0.80, df1 = 4, df2 = 100, alpha = 0.05)
Determines the power, the non-centrality parameter, or the degrees of freedom for the lambda-prime distribution with (optional) Type 1 and Type 2 error plots.
power.lp.test( power = NULL, ncp = NULL, req.sign = "+", null.ncp = 0, df = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )power.lp.test( power = NULL, ncp = NULL, req.sign = "+", null.ncp = 0, df = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
ncp |
non-centrality parameter for the alternative; either
|
req.sign |
whether |
null.ncp |
non-centrality parameter for the null. When alternative =
"two.one.sided", the function expects two values in the
form |
df |
degrees of freedom; either |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". "two.one.sided" is used for equivalence and minimal effect testing. |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
power |
statistical power |
ncp |
non-centrality parameter under alternative. |
ncp.null |
non-centrality parameter under null. |
df |
degrees of freedom. |
alpha |
type 1 error rate (user-specified). |
alternative |
the direction or type of the hypothesis test. |
t.alpha |
critical value(s). |
beta |
type 2 error rate. |
type.s |
type S error rate (only for two-tailed test). |
type.m |
type M error rate (only for two-tailed test). |
# two-sided # power defined as the probability of observing test statistics greater # than the positive critical value OR less than the negative critical value power.lp.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "two.sided") power.lp.test(power = 0.80, df = 100, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.lp.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "one.sided") power.lp.test(power = 0.80, df = 100, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.lp.test(ncp = 0, null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") power.lp.test(power = 0.80, req.sign = "0", null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.lp.test(ncp = 2, null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided") power.lp.test(power = 0.80, req.sign = "+", null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided")# two-sided # power defined as the probability of observing test statistics greater # than the positive critical value OR less than the negative critical value power.lp.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "two.sided") power.lp.test(power = 0.80, df = 100, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.lp.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "one.sided") power.lp.test(power = 0.80, df = 100, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.lp.test(ncp = 0, null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") power.lp.test(power = 0.80, req.sign = "0", null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.lp.test(ncp = 2, null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided") power.lp.test(power = 0.80, req.sign = "+", null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided")
Calculates power, sample size or effect size (only one can be NULL at a time) for non-parametric rank-based tests. The following tests and designs are available:
Wilcoxon Signed-Rank Test (One Sample)
Wilcoxon Rank-Sum or Mann-Whitney U Test (Independent Samples)
Wilcoxon Matched-Pairs Signed-Rank Test (Paired Samples)
Formulas are validated using GPower and tables in the PASS documentation. However, we adopt the rounding convention used by GPower.
power.np.wilcoxon( d = NULL, null.d = 0, margin = 0, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), design = c("independent", "paired", "one.sample"), distribution = c("normal", "uniform", "double.exponential", "laplace", "logistic"), method = c("guenther", "noether"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.np.wilcoxon( d = NULL, null.d = 0, margin = 0, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), design = c("independent", "paired", "one.sample"), distribution = c("normal", "uniform", "double.exponential", "laplace", "logistic"), method = c("guenther", "noether"), ceil.n = TRUE, verbose = 1, utf = FALSE )
d |
Cohen's d or Hedges' g. |
null.d |
Cohen's d or Hedges' g under null, typically 0 (zero). |
margin |
margin - ignorable |
n.ratio |
|
n2 |
integer; sample size in the second group (or for the single group in paired samples or one-sample) |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". |
design |
character; "independent" (default), "one.sample", or "paired". |
distribution |
character; parent distribution: "normal", "uniform", "double.exponential", "laplace", or "logistic". |
method |
character; non-parametric approach: "guenther" (default) or "noether" |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Use means.to.d() to convert raw means and standard deviations to
Cohen's d, and d.to.cles() to convert Cohen's d to the probability
of superiority. Note that this interpretation is appropriate only when the
underlying distribution is approximately normal and the two groups have
similar population variances.
NB: pwrss.np.2means() function is depreciated and no longer
supported. pwrss.np.2groups() will remain available for some time.
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as alt instead of
alternative, or dist instead of distribution.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z- or T-Test). |
df |
degrees of freedom (applies when method = 'guenther'). |
ncp |
non-centrality parameter for the alternative (applies when method = 'guenther'). |
null.ncp |
non-centrality parameter for the null (applies when method = 'guenther'). |
t.alpha |
critical value(s) (applies when method = 'guenther'). |
mean |
mean of the alternative (applies when method = 'noether'). |
null.mean |
mean of the null (applies when method = 'noether'). |
sd |
standard deviation of the alternative (applies when method = 'noether'). |
null.sd |
standard deviation of the null (applies when method = 'noether'). |
z.alpha |
critical value(s) (applies when method = 'noether'). |
power |
statistical power |
n |
sample size ( |
Al-Sunduqchi, M. S. (1990). Determining the appropriate sample size for inferences based on the Wilcoxon statistics [Unpublished doctoral dissertation]. University of Wyoming - Laramie
Chow, S. C., Shao, J., Wang, H., and Lokhnygina, Y. (2018). Sample size calculations in clinical research (3rd ed.). Taylor & Francis/CRC.
Lehmann, E. (1975). Nonparameterics: Statistical methods based on ranks. McGraw-Hill.
Noether, G. E. (1987). Sample size determination for some common nonparametric tests. Journal of the American Statistical Association, 82(1), 645-647.
Ruscio, J. (2008). A probability-based measure of effect size: Robustness to base rates and other factors. Psychological Methods, 13(1), 19-30.
Ruscio, J., & Mullen, T. (2012). Confidence intervals for the probability of superiority effect size measure and the area under a receiver operating characteristic curve. Multivariate Behavioral Research, 47(2), 201-223.
Zhao, Y.D., Rahardja, D., & Qu, Y. (2008). Sample size calculation for the Wilcoxon-Mann-Whitney test adjusting for ties. Statistics in Medicine, 27(3), 462-468.
# see `?pwrss::power.t.student` for further examples # Mann-Whitney U or Wilcoxon rank-sum test # (a.k.a Wilcoxon-Mann-Whitney test) for independent samples ## difference between group 1 and group 2 is not equal to zero ## estimated difference is Cohen'd = 0.25 power.np.wilcoxon(d = 0.25, power = 0.80) ## difference between group 1 and group 2 is greater than zero ## estimated difference is Cohen'd = 0.25 power.np.wilcoxon(d = 0.25, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically not smaller than mean of group 2 ## estimated difference is Cohen'd = 0.10 and can be as small as -0.05 power.np.wilcoxon(d = 0.10, margin = -0.05, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically greater than mean of group 2 ## estimated difference is Cohen'd = 0.10 and can be as small as 0.05 power.np.wilcoxon(d = 0.10, margin = 0.05, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically same as mean of group 2 ## estimated difference is Cohen'd = 0 ## and can be as small as -0.05 and as high as 0.05 power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided") # Wilcoxon signed-rank test for matched pairs (dependent samples) ## difference between time 1 and time 2 is not equal to zero ## estimated difference between time 1 and time 2 is Cohen'd = -0.25 power.np.wilcoxon(d = -0.25, power = 0.80, design = "paired") ## difference between time 1 and time 2 is greater than zero ## estimated difference between time 1 and time 2 is Cohen'd = -0.25 power.np.wilcoxon(d = -0.25, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically not smaller than mean of time 2 ## estimated difference is Cohen'd = -0.10 and can be as small as 0.05 power.np.wilcoxon(d = -0.10, margin = 0.05, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically greater than mean of time 2 ## estimated difference is Cohen'd = -0.10 and can be as small as -0.05 power.np.wilcoxon(d = -0.10, margin = -0.05, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically same as mean of time 2 ## estimated difference is Cohen'd = 0 ## and can be as small as -0.05 and as high as 0.05 power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, design = "paired", alternative = "two.one.sided")# see `?pwrss::power.t.student` for further examples # Mann-Whitney U or Wilcoxon rank-sum test # (a.k.a Wilcoxon-Mann-Whitney test) for independent samples ## difference between group 1 and group 2 is not equal to zero ## estimated difference is Cohen'd = 0.25 power.np.wilcoxon(d = 0.25, power = 0.80) ## difference between group 1 and group 2 is greater than zero ## estimated difference is Cohen'd = 0.25 power.np.wilcoxon(d = 0.25, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically not smaller than mean of group 2 ## estimated difference is Cohen'd = 0.10 and can be as small as -0.05 power.np.wilcoxon(d = 0.10, margin = -0.05, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically greater than mean of group 2 ## estimated difference is Cohen'd = 0.10 and can be as small as 0.05 power.np.wilcoxon(d = 0.10, margin = 0.05, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically same as mean of group 2 ## estimated difference is Cohen'd = 0 ## and can be as small as -0.05 and as high as 0.05 power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided") # Wilcoxon signed-rank test for matched pairs (dependent samples) ## difference between time 1 and time 2 is not equal to zero ## estimated difference between time 1 and time 2 is Cohen'd = -0.25 power.np.wilcoxon(d = -0.25, power = 0.80, design = "paired") ## difference between time 1 and time 2 is greater than zero ## estimated difference between time 1 and time 2 is Cohen'd = -0.25 power.np.wilcoxon(d = -0.25, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically not smaller than mean of time 2 ## estimated difference is Cohen'd = -0.10 and can be as small as 0.05 power.np.wilcoxon(d = -0.10, margin = 0.05, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically greater than mean of time 2 ## estimated difference is Cohen'd = -0.10 and can be as small as -0.05 power.np.wilcoxon(d = -0.10, margin = -0.05, power = 0.80, design = "paired", alternative = "one.sided") ## mean of time 1 is practically same as mean of time 2 ## estimated difference is Cohen'd = 0 ## and can be as small as -0.05 and as high as 0.05 power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, design = "paired", alternative = "two.one.sided")
Calculates power or sample size for a single one-, two-, three-Way ANCOVA contrast.
Formulas are validated using examples and tables in Shieh (2017).
power.t.contrast( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, contrast.vector, r.squared = 0, k.covariates = 1, power = NULL, alpha = 0.05, tukey.kramer = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )power.t.contrast( mu.vector, sd.vector, n.vector = NULL, p.vector = NULL, contrast.vector, r.squared = 0, k.covariates = 1, power = NULL, alpha = 0.05, tukey.kramer = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )
mu.vector |
vector; adjusted means (or estimated marginal means) for each level of a factor. |
sd.vector |
vector; unadjusted standard deviations for each level of a factor. |
n.vector |
vector; sample sizes for each level of a factor. |
p.vector |
vector; proportion of total sample size in each level of a factor. These proportions should sum to one. |
contrast.vector |
vector; a single contrast in the form of a vector with as many elements as number of levels or groups (or cells in factorial designs). Ignored when 'x' is specified. |
r.squared |
explanatory power of covariates (R-squared) in the ANCOVA model. |
k.covariates |
Number of covariates in the ANCOVA model. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted
as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted
as |
tukey.kramer |
logical; |
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.cov instead of
k.covariates.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
psi |
contrast-weighted mean difference. |
d |
contrast-weighted standardized mean difference. |
df |
degrees of freedom. |
t.alpha |
critical values. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
power |
statistical power |
n.vector |
sample sizes for each level of a factor. |
n.total |
total sample size. |
Shieh, G. (2017). Power and sample size calculations for contrast analysis in ANCOVA. Multivariate Behavioral Research, 52(1), 1-11. https://doi.org/10.1080/00273171.2016.1219841
# dummy coding example (uses the first contrast from a three-level- / two-contrasts-design) contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment", verbose = 0) contrast.vector <- contrast.object[["contrast.matrix"]][1, ] power.t.contrast(mu.vector = c(0.15, 0.30, 0.20), sd.vector = c(1, 1, 1), p.vector = c(1/3, 1/3, 1/3), r.squared = 0.50, k.covariates = 1, contrast.vector = contrast.vector, power = 0.80, alpha = 0.05)# dummy coding example (uses the first contrast from a three-level- / two-contrasts-design) contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment", verbose = 0) contrast.vector <- contrast.object[["contrast.matrix"]][1, ] power.t.contrast(mu.vector = c(0.15, 0.30, 0.20), sd.vector = c(1, 1, 1), p.vector = c(1/3, 1/3, 1/3), r.squared = 0.50, k.covariates = 1, contrast.vector = contrast.vector, power = 0.80, alpha = 0.05)
Calculates power or sample size for one-, two-, three-Way ANCOVA contrasts
and multiple comparisons. The power.t.contrasts() function permits
to test multiple contrasts (multiple comparisons) and also allows adjustment
to alpha due to multiple testing. Furthermore, power.t.contrasts()
accepts an object returned from the power.f.ancova.shieh() function
for convenience. Beware that, in this case, all other arguments are ignored
except alpha and adjust.alpha.
Formulas are validated using examples and tables in Shieh (2017).
power.t.contrasts( x = NULL, mu.vector = NULL, sd.vector = NULL, n.vector = NULL, p.vector = NULL, r.squared = 0, k.covariates = 1, contrast.matrix = NULL, power = NULL, alpha = 0.05, adjust.alpha = c("none", "tukey", "bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.t.contrasts( x = NULL, mu.vector = NULL, sd.vector = NULL, n.vector = NULL, p.vector = NULL, r.squared = 0, k.covariates = 1, contrast.matrix = NULL, power = NULL, alpha = 0.05, adjust.alpha = c("none", "tukey", "bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr"), ceil.n = TRUE, verbose = 1, utf = FALSE )
x |
object; an object returned from the
|
mu.vector |
vector; adjusted means (or estimated marginal means) for each level of a factor. Ignored when 'x' is specified. |
sd.vector |
vector; unadjusted standard deviations for each level of a factor. Ignored when 'x' is specified. |
n.vector |
vector; sample sizes for each level of a factor. Ignored when 'x' is specified. |
p.vector |
vector; proportion of total sample size in each level of a factor. These proportions should sum to one. Ignored when 'x' is specified. |
r.squared |
explanatory power of covariates (R-squared) in the ANCOVA model. Ignored when 'x' is specified. |
k.covariates |
Number of covariates in the ANCOVA model. Ignored when 'x' is specified. |
contrast.matrix |
vector or matrix; contrasts should not be confused with the model (design) matrix. Rows of contrast matrix indicate independent vector of contrasts summing to zero. The default contrast matrix is constructed using deviation coding scheme (a.k.a. effect coding). Columns in the contrast matrix indicate number of levels or groups (or cells in factorial designs). Ignored when 'x' is specified. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted
as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted
as |
adjust.alpha |
character; one of the methods in c("none", "tukey",
"bonferroni", "holm", "hochberg", "hommel", "BH",
"BY", "fdr") to control Type 1 error. See
|
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Note that R has a partial matching feature which allows you to specify
shortened versions of arguments, such as mu or mu.vec instead
of mu.vector, or such as k or k.cov instead of
k.covariates.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
contrast |
contrast number (one contrast per line). |
comparison |
which factor levels are compared (one contrast per line). |
psi |
contrast-weighted mean difference (one contrast per line). |
d |
contrast-weighted standardized mean difference (one contrast per line). |
ncp |
non-centrality parameter for the alternative (one contrast per line). |
df |
degrees of freedom (one contrast per line). |
t.alpha |
critical values (one contrast per line). |
n.total |
total sample size (one contrast per line). |
power |
statistical power |
Shieh, G. (2017). Power and sample size calculations for contrast analysis in ANCOVA. Multivariate Behavioral Research, 52(1), 1-11. https://doi.org/10.1080/00273171.2016.1219841
# see `?pwrss::power.f.ancova.shieh` for further examples # dummy coding example contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment", verbose = 0) contrast.matrix <- contrast.object[["contrast.matrix"]] power.t.contrasts(mu.vector = c(0.15, 0.30, 0.20), sd.vector = c(1, 1, 1), p.vector = c(1/3, 1/3, 1/3), r.squared = 0.50, k.covariates = 1, contrast.matrix = contrast.matrix, power = 0.80, alpha = 0.05, adjust.alpha = "holm")# see `?pwrss::power.f.ancova.shieh` for further examples # dummy coding example contrast.object <- factorial.contrasts(factor.levels = 3, coding = "treatment", verbose = 0) contrast.matrix <- contrast.object[["contrast.matrix"]] power.t.contrasts(mu.vector = c(0.15, 0.30, 0.20), sd.vector = c(1, 1, 1), p.vector = c(1/3, 1/3, 1/3), r.squared = 0.50, k.covariates = 1, contrast.matrix = contrast.matrix, power = 0.80, alpha = 0.05, adjust.alpha = "holm")
Calculates power, sample size or effect size (only one can be NULL at a
time) to test a single coefficient in multiple linear regression. By
default, the predictor is assumed to be continuous. However, one can
calculate power, sample size or effect size for a binary predictor (such
as treatment and control groups in an experimental design) by specifying
sd.predictor = sqrt(p * (1 - p)) where p is the proportion
of subjects in one of the groups. The sample size in each group would be
n * p and n * (1 - p).
Minimal effect and equivalence tests are implemented in line with Hodges and Lehmann (1954), Kim and Robinson (2019), Phillips (1990), and Dupont and Plummer (1998).
Formulas are validated using Monte Carlo simulation, G*Power, tables in the PASS documentation, and tables in Bulus (2021).
power.t.regression( beta = NULL, null.beta = 0, margin = 0, sd.predictor = 1, sd.outcome = 1, r.squared = NULL, k.total = 1, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.t.regression( beta = NULL, null.beta = 0, margin = 0, sd.predictor = 1, sd.outcome = 1, r.squared = NULL, k.total = 1, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )
beta |
regression coefficient. One can use standardized
regression coefficient, but should keep
|
null.beta |
regression coefficient under null hypothesis (typically
zero). One can use standardized regression coefficient,
but should keep |
margin |
margin - ignorable |
sd.predictor |
standard deviation of the predictor. For a binary
predictor, |
sd.outcome |
standard deviation of the outcome. |
r.squared |
model R-squared. Please see also Details below. |
k.total |
integer; total number of predictors, including the predictor of interest. |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
When it is requested to calculate the effect size (by giving both their
parameters n and power), r.squared must be empty and beta can be
empty (NULL). By default, a linear regression with one predictor is
assumed. If beta, sd.predictor and sd.outcome are given (i.e., in
cases where it is not requested to calculate the effect size), r.squared
is calculated as follows:
r.squared = (beta * sd.predictor / sd.outcome) ^ 2. If the given
beta results in an r.squared below this value, a warning will be
issued. To calculate beta from r.squared, the following formula can be
used: beta = (sqrt(r.squared) * sd.outcome / sd.predictor).
To consider other covariates in the model provide a value greater than the
default value for r.squared (see above) along with the argument
k.total > 1. However, in such case, the above formula for
calculating beta can not be used.
power.t.regression(), pwrss.t.regression(),
power.t.reg() and pwrss.t.reg() are the same functions.
NB: The pwrss.z.regression() function and its alias
pwrss.z.reg() are deprecated, but they will remain available as a
wrapper for the power.t.regression() function during a transition
period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
df |
degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
t.alpha |
critical value(s). |
r.squared |
model R-squared. |
power |
statistical power |
n |
sample size. |
Bulus, M. (2021). Sample size determination and optimal design of randomized / non-equivalent pretest-post-test control-group designs. Adiyaman University Journal of Educational Sciences, 11(1), 48-69. https://doi.org/10.17984/adyuebd.941434
Hodges Jr, J. L., & Lehmann, E. L. (1954). Testing the approximate validity of statistical hypotheses. Journal of the Royal Statistical Society Series B: Statistical Methodology, 16(2), 261-268. https://doi.org/10.1111/j.2517-6161.1954.tb00169.x
Kim, J. H., & Robinson, A. P. (2019). Interval-based hypothesis testing and its applications to economics and finance. Econometrics, 7(2), 21. https://doi.org/10.1111/10.3390/econometrics7020021
Phillips, K. F. (1990). Power of the two one-sided tests procedure in bioequivalence. Journal of Pharmacokinetics and Biopharmaceutics, 18(2), 137-144. https://doi.org/10.1007/bf01063556
Dupont, W. D., and Plummer, W. D. (1998). Power and sample size calculations for studies involving linear regression. Controlled Clinical Trials, 19(6), 589-601. https://doi.org/10.1007/10.1016/s0197-2456(98)00037-3
# continuous predictor x (and 4 covariates) power.t.regression(beta = 0.20, k.total = 5, r.squared = 0.30, power = 0.80) # binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80) # non-inferiority test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, # Cohen's d margin = -0.05, # non-inferiority margin in Cohen's d unit alternative = "one.sided", sd.predictor = sqrt(p*(1-p)), k.total = 5, r.squared = 0.30, power = 0.80) # superiority test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, # Cohen's d margin = 0.05, # superiority margin in Cohen's d unit alternative = "one.sided", sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80) # equivalence test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0, # Cohen's d margin = c(-0.05, 0.05), # equivalence bounds in Cohen's d unit alternative = "two.one.sided", sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80)# continuous predictor x (and 4 covariates) power.t.regression(beta = 0.20, k.total = 5, r.squared = 0.30, power = 0.80) # binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80) # non-inferiority test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, # Cohen's d margin = -0.05, # non-inferiority margin in Cohen's d unit alternative = "one.sided", sd.predictor = sqrt(p*(1-p)), k.total = 5, r.squared = 0.30, power = 0.80) # superiority test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0.20, # Cohen's d margin = 0.05, # superiority margin in Cohen's d unit alternative = "one.sided", sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80) # equivalence test with binary predictor x (and 4 covariates) p <- 0.50 # proportion of subjects in one group power.t.regression(beta = 0, # Cohen's d margin = c(-0.05, 0.05), # equivalence bounds in Cohen's d unit alternative = "two.one.sided", sd.predictor = sqrt(p * (1 - p)), k.total = 5, r.squared = 0.30, power = 0.80)
Calculates power, sample size or effect size (only one can be NULL at a time) for Student's t-Test.
In contrast to previous versions, users can now specify whether their claims will be based on raw score mean difference with P-values or standardized mean difference with confidence intervals. While results typically differ by only a few units, these distinctions can be particularly consequential in studies with small sample sizes or high-risk interventions.
Formulas are validated using Monte Carlo simulations (see Bulus, 2024),
G*Power, and tables in the PASS documentation. One key difference between
PASS and pwrss lies in how they handle non-inferiority and
superiority tests-that is, one-sided tests defined by a negligible effect
margin (implemented as of this version). PASS shifts the test statistic so
that the null hypothesis assumes a zero effect, treating the negligible
margin as part of the alternative hypothesis. As a result, the test
statistic is evaluated against a central distribution. In contrast,
pwrss treats the negligible effect as the true null value, and the
test statistic is evaluated under a non-central distribution. This leads to
slight differences up to third decimal place. To get the same results,
reflect the margin in null.d and specify margin = 0.
Equivalence tests are implemented in line with Bulus and Polat (2023), Chow et al. (2018) and Lakens (2017).
power.t.student( d = NULL, null.d = 0, margin = 0, n2 = NULL, n.ratio = 1, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), design = c("independent", "paired", "one.sample"), claim.basis = c("md.pval", "smd.ci"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.t.student( d = NULL, null.d = 0, margin = 0, n2 = NULL, n.ratio = 1, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), design = c("independent", "paired", "one.sample"), claim.basis = c("md.pval", "smd.ci"), ceil.n = TRUE, verbose = 1, utf = FALSE )
d |
Cohen's d or Hedges' g. |
null.d |
Cohen's d or Hedges' g under null, typically 0(zero). |
margin |
margin - ignorable |
n2 |
integer; sample size in the second group (or for the single group in paired samples or one-sample). |
n.ratio |
|
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test:
"two.sided", "one.sided", or "two.one.sided". For
non-inferiority or superiority tests, add or subtract the
margin from the null hypothesis value and use
|
design |
character; "independent", "paired" or "one.sample". |
claim.basis |
character; "md.pval" when claims are based on raw mean differences and p-values, "smd.ci" when claims are based on standardized mean differences and confidence intervals. |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Use means.to.d() to convert raw means and standard deviations to
Cohen's d, and d.to.cles() to convert Cohen's d to the probability
of superiority. Note that this interpretation is appropriate only when the
underlying distribution is approximately normal and the two groups have
similar population variances.
NB: The functions pwrss.z.mean() and pwrss.z.2means() are no
longer supported. The pwrss.t.mean() and pwrss.t.2means()
functions are deprecated, but they will remain available as wrappers for
power.t.student() or power.t.welch() functions during a
transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
df |
degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
t.alpha |
critical value(s). |
power |
statistical power |
n |
sample size ( |
Bulus, M. (2024). Robust standard errors and confidence intervals for standardized mean differences. https://doi.org/10.31219/osf.io/k6mbs
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Chow, S. C., Shao, J., Wang, H., & Lokhnygina, Y. (2018). Sample size calculations in clinical research (3rd ed.). Taylor & Francis/CRC.
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
Lakens, D. (2017). Equivalence tests: A practical primer for t tests, correlations, and meta-analyses. Social psychological and personality science, 8(4), 355-362. https://doi.org/10.1177/1948550617697177
####################### # Independent Samples # ####################### ## difference between group 1 and group 2 is not equal to zero ## targeting minimal difference of Cohen'd = 0.20 ## non-parametric power.np.wilcoxon(d = 0.20, power = 0.80, alternative = "two.sided", design = "independent") ## parametric power.t.student(d = 0.20, power = 0.80, alternative = "two.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "two.sided") ## difference between group 1 and group 2 is greater than zero ## targeting minimal difference of Cohen'd = 0.20 ## non-parametric power.np.wilcoxon(d = 0.20, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically not smaller than mean of group 2 ## targeting minimal difference of Cohen'd = 0.20 and can be as small as -0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, margin = -0.05, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically greater than mean of group 2 ## targeting minimal difference of Cohen'd = 0.20 and can be as small as 0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, margin = 0.05, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically same as mean of group 2 ## targeting minimal difference of Cohen'd = 0 ## and can be as small as -0.05 or as high as 0.05 ## non-parametric power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "independent") ## parametric power.t.student(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0, margin = c(-0.05, 0.05), n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "two.one.sided") ################## # Paired Samples # ################## ## difference between time 1 and time 2 is not equal to zero ## targeting minimal difference of Cohen'd = -0.20 ## non-parametric power.np.wilcoxon(d = -0.20, power = 0.80, alternative = "two.sided", design = "paired") ## parametric power.t.student(d = -0.20, power = 0.80, alternative = "two.sided", design = "paired") ## difference between time 1 and time 2 is less than zero ## targeting minimal difference of Cohen'd = -0.20 ## non-parametric power.np.wilcoxon(d = -0.20, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = -0.20, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically not greater than mean of time 2 ## targeting minimal difference of Cohen'd = -0.20 and can be as small as 0.05 ## non-parametric ## non-parametric power.np.wilcoxon(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically greater than mean of time 2 ## targeting minimal difference of Cohen'd = -0.20 and can be as small as -0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically same as mean of time 2 ## targeting minimal difference of Cohen'd = 0 ## and can be as small as -0.05 or as high as 0.05 ## non-parametric ## non-parametric power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "paired") ## parametric power.t.student(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "paired")####################### # Independent Samples # ####################### ## difference between group 1 and group 2 is not equal to zero ## targeting minimal difference of Cohen'd = 0.20 ## non-parametric power.np.wilcoxon(d = 0.20, power = 0.80, alternative = "two.sided", design = "independent") ## parametric power.t.student(d = 0.20, power = 0.80, alternative = "two.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "two.sided") ## difference between group 1 and group 2 is greater than zero ## targeting minimal difference of Cohen'd = 0.20 ## non-parametric power.np.wilcoxon(d = 0.20, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically not smaller than mean of group 2 ## targeting minimal difference of Cohen'd = 0.20 and can be as small as -0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, margin = -0.05, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically greater than mean of group 2 ## targeting minimal difference of Cohen'd = 0.20 and can be as small as 0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "independent") ## parametric power.t.student(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0.20, margin = 0.05, n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "one.sided") ## mean of group 1 is practically same as mean of group 2 ## targeting minimal difference of Cohen'd = 0 ## and can be as small as -0.05 or as high as 0.05 ## non-parametric power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "independent") ## parametric power.t.student(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "independent") ## when sample size ratio and group variances differ power.t.welch(d = 0, margin = c(-0.05, 0.05), n.ratio = 2, var.ratio = 2, power = 0.80, alternative = "two.one.sided") ################## # Paired Samples # ################## ## difference between time 1 and time 2 is not equal to zero ## targeting minimal difference of Cohen'd = -0.20 ## non-parametric power.np.wilcoxon(d = -0.20, power = 0.80, alternative = "two.sided", design = "paired") ## parametric power.t.student(d = -0.20, power = 0.80, alternative = "two.sided", design = "paired") ## difference between time 1 and time 2 is less than zero ## targeting minimal difference of Cohen'd = -0.20 ## non-parametric power.np.wilcoxon(d = -0.20, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = -0.20, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically not greater than mean of time 2 ## targeting minimal difference of Cohen'd = -0.20 and can be as small as 0.05 ## non-parametric ## non-parametric power.np.wilcoxon(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = 0.20, margin = 0.05, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically greater than mean of time 2 ## targeting minimal difference of Cohen'd = -0.20 and can be as small as -0.05 ## non-parametric power.np.wilcoxon(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "paired") ## parametric power.t.student(d = 0.20, margin = -0.05, power = 0.80, alternative = "one.sided", design = "paired") ## mean of time 1 is practically same as mean of time 2 ## targeting minimal difference of Cohen'd = 0 ## and can be as small as -0.05 or as high as 0.05 ## non-parametric ## non-parametric power.np.wilcoxon(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "paired") ## parametric power.t.student(d = 0, margin = c(-0.05, 0.05), power = 0.80, alternative = "two.one.sided", design = "paired")
Determines the power, the non-centrality parameter, or the degrees of freedom for the generic t-Test with (optional) Type 1 and Type 2 error plots.
power.t.test( power = NULL, ncp = NULL, req.sign = "+", null.ncp = 0, df = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )power.t.test( power = NULL, ncp = NULL, req.sign = "+", null.ncp = 0, df = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
ncp |
non-centrality parameter for the alternative; ; either
|
req.sign |
whether |
null.ncp |
non-centrality parameter for the null. When alternative =
"two.one.sided", the function expects two values in the
form |
df |
degrees of freedom; either |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". "two.one.sided" is used for equivalence and minimal effect testing. |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
power |
statistical power |
ncp |
non-centrality parameter under alternative. |
ncp.null |
non-centrality parameter under null. |
df |
degrees of freedom. |
alpha |
type 1 error rate (user-specified). |
t.alpha |
critical value(s). |
beta |
type 2 error rate. |
type.s |
type S error rate (only for two-tailed test). |
type.m |
type M error rate (only for two-tailed test). |
# two-sided # power defined as the probability of observing test statistics greater # than the positive critical value OR less than the negative critical value power.t.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "two.sided") power.t.test(power = 0.80, df = 100, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.t.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "one.sided") power.t.test(power = 0.80, df = 100, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.t.test(ncp = 0, null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") power.t.test(power = 0.80, req.sign = "0", null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.t.test(ncp = 2, null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided") power.t.test(power = 0.80, req.sign = "+", null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided")# two-sided # power defined as the probability of observing test statistics greater # than the positive critical value OR less than the negative critical value power.t.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "two.sided") power.t.test(power = 0.80, df = 100, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.t.test(ncp = 1.96, df = 100, alpha = 0.05, alternative = "one.sided") power.t.test(power = 0.80, df = 100, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.t.test(ncp = 0, null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") power.t.test(power = 0.80, req.sign = "0", null.ncp = c(-2, 2), df = 100, alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.t.test(ncp = 2, null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided") power.t.test(power = 0.80, req.sign = "+", null.ncp = c(-1, 1), df = 100, alpha = 0.05, alternative = "two.one.sided")
Calculates power, sample size or effect size (only one can be NULL at a time) for Welch's t-Tests. Welch's T-Test implementation relies on formulas proposed by Bulus (2024).
In contrast to previous versions, users can now specify whether their claims will be based on raw score mean difference with p-values or standardized mean difference with confidence intervals. While results typically differ by only a few units, these distinctions can be particularly consequential in studies with small sample sizes or high-risk interventions.
Formulas are validated using Monte Carlo simulations (see Bulus, 2024),
G*Power, and tables in the PASS documentation. One key difference between
PASS and pwrss lies in how they handle non-inferiority and
superiority tests-that is, one-sided tests defined by a negligible effect
margin (implemented as of this version). PASS shifts the test statistic so
that the null hypothesis assumes a zero effect, treating the negligible
margin as part of the alternative hypothesis. As a result, the test
statistic is evaluated against a central distribution. In contrast,
pwrss treats the negligible effect as the true null value, and the
test statistic is evaluated under a non-central distribution. This leads to
slight differences up to third decimal place. To get the same results,
reflect the margin in null.d and specify margin = 0.
Equivalence tests are implemented in line with Bulus and Polat (2023), Chow et al. (2018) and Lakens (2017).
power.t.welch( d = NULL, null.d = 0, margin = 0, var.ratio = 1, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), claim.basis = c("md.pval", "smd.ci"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.t.welch( d = NULL, null.d = 0, margin = 0, var.ratio = 1, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), claim.basis = c("md.pval", "smd.ci"), ceil.n = TRUE, verbose = 1, utf = FALSE )
d |
Cohen's d or Hedges' g. |
null.d |
Cohen's d or Hedges' g under null, typically 0(zero). |
margin |
margin - ignorable |
var.ratio |
variance ratio in the form of sd1 ^ 2 / sd2 ^ 2. |
n.ratio |
|
n2 |
integer; sample size in the second group (or for the single group in paired samples or one-sample). |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test:
"two.sided", "one.sided", or "two.one.sided". For
non-inferiority or superiority tests, add or subtract the
margin from the null hypothesis value and use
|
claim.basis |
character; "md.pval" when claims are based on raw mean differences and p-values, "smd.ci" when claims are based on standardized mean differences and confidence intervals. |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
Use means.to.d() to convert raw means and standard deviations to
Cohen's d, and d.to.cles() to convert Cohen's d to the probability
of superiority. Note that this interpretation is appropriate only when the
underlying distribution is approximately normal and the two groups have
similar population variances.
NB: The functions pwrss.z.mean() and pwrss.z.2means() are no
longer supported. The pwrss.t.mean() and pwrss.t.2means()
functions are deprecated, but they will remain available as wrappers for
power.t.student() or power.t.welch() during a transition
period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (T-Test). |
df |
degrees of freedom. |
ncp |
non-centrality parameter for the alternative. |
null.ncp |
non-centrality parameter for the null. |
t.alpha |
critical value(s). |
power |
statistical power |
n |
sample size ( |
Bulus, M. (2024). Robust standard errors and confidence intervals for standardized mean differences. https://doi.org/10.31219/osf.io/k6mbs
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Chow, S. C., Shao, J., Wang, H., & Lokhnygina, Y. (2018). Sample size calculations in clinical research (3rd ed.). Taylor & Francis/CRC.
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
Lakens, D. (2017). Equivalence tests: A practical primer for t tests, correlations, and meta-analyses. Social psychological and personality science, 8(4), 355-362. https://doi.org/10.1177/1948550617697177
# see `?pwrss::power.t.student` for examples# see `?pwrss::power.t.student` for examples
Calculates power or sample size (only one can be NULL at a time) to test a
single coefficient in logistic regression. power.z.logistic() and
power.z.logreg() are the same functions, as well as
pwrss.z.logistic() and pwrss.z.logreg().
The distribution of the predictor variable can be one of the following:
c("normal", "poisson", "uniform", "exponential", "binomial",
"bernouilli", "lognormal") for Demidenko (2007) procedure but only
c("normal", "binomial", "bernouilli") for Hsieh et al. (1998)
procedure. The default parameters for these distributions are:
distribution = list(dist = "normal", mean = 0, sd = 1) distribution = list(dist = "poisson", lambda = 1) distribution = list(dist = "uniform", min = 0, max = 1) distribution = list(dist = "exponential", rate = 1) distribution = list(dist = "binomial", size = 1, prob = 0.50) distribution = list(dist = "bernoulli", prob = 0.50) distribution = list(dist = "lognormal", meanlog = 0, sdlog = 1)
Parameters defined in list() form can be modified, but element names
should be kept the same. It is sufficient to use distribution's name for
default parameters (e.g. dist = "normal").
Formulas are validated using G*Power and tables in the PASS documentation.
power.z.logistic( prob = NULL, base.prob = NULL, odds.ratio = NULL, beta0 = NULL, beta1 = NULL, req.sign = "+", n = NULL, power = NULL, r.squared.predictor = 0, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("demidenko(vc)", "demidenko", "hsieh"), distribution = "normal", ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.logistic( prob = NULL, base.prob = NULL, odds.ratio = NULL, beta0 = NULL, beta1 = NULL, req.sign = "+", n = NULL, power = NULL, r.squared.predictor = 0, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("demidenko(vc)", "demidenko", "hsieh"), distribution = "normal", ceil.n = TRUE, verbose = 1, utf = FALSE )
prob |
probability under alternative hypothesis (probability that an event occurs when the value of the predictor is increased from 0 to 1). Warning: This is base probability + incremental increase. |
base.prob |
base probability under null hypothesis (probability that an event occurs without the influence of the predictor - or when the value of the predictor is zero). |
odds.ratio |
odds ratio defined as
|
beta0 |
regression coefficient defined as
|
beta1 |
regression coefficient for the predictor X defined as
|
req.sign |
sign of the beta1 coefficient (when minimum detectable effect or beta1 is of interest). |
n |
integer; sample size |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis,
denoted as |
r.squared.predictor |
proportion of variance in the predictor accounted for by other covariates. This is not a pseudo R-squared. To compute it, regress the predictor on the covariates and extract the adjusted R-squared from that model. |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
method |
character; analytic method.
|
distribution |
character; distribution family. Can be one of the
|
ceil.n |
logical; whether sample size should be rounded
up. |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it).
|
NB: The pwrss.z.logistic() and its alias pwrss.z.logreg()
are deprecated. However, they will remain available as wrappers for the
power.z.logistic() function during a transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test). |
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 |
n |
sample size. |
Demidenko, E. (2007). Sample size determination for logistic regression revisited. Statistics in Medicine, 26(18), 3385-3397. https://doi.org/10.1002/sim.2771
Hsieh, F. Y., Bloch, D. A., & Larsen, M. D. (1998). A simple method of sample size calculation for linear and logistic regression. Statistics in Medicine, 17(4), 1623-1634.
########################################### # predictor X follows normal distribution # ########################################### ## probability specification power.z.logistic(base.prob = 0.15, prob = 0.20, alpha = 0.05, power = 0.80, dist = "normal") ## odds ratio specification power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = "normal") ## regression coefficient specification power.z.logistic(beta0 = -1.734601, beta1 = 0.3483067, alpha = 0.05, power = 0.80, dist = "normal") ## change parameters associated with predictor X pred.dist <- list(dist = "normal", mean = 10, sd = 2) power.z.logistic(base.prob = 0.15, beta1 = 0.3483067, alpha = 0.05, power = 0.80, dist = pred.dist) ############################################## # predictor X follows Bernoulli distribution # # (such as treatment/control groups) # ############################################## ## odds ratio specification power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = "bernoulli") ## change parameters associated with predictor X pred.dist <- list(dist = "bernoulli", prob = 0.30) power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = pred.dist) #################################### # predictor X is an ordinal factor # #################################### ## generating an ordinal predictor x.ord <- sample( x = c(1, 2, 3, 4), # levels size = 1e5, # sample size large enough to get stable estimates prob = c(0.25, 0.25, 0.25, 0.25), # category probabilities replace = TRUE ) ## dummy coding the ordinal predictor x.ord <- factor(x.ord, ordered = TRUE) contrasts(x.ord) <- contr.treatment(4, base = 4) x.dummy <- model.matrix( ~ x.ord)[,-1] x.data <- as.data.frame(x.dummy) ## fit linear regression to get multiple r-squared x.fit <- lm(x.ord1 ~ x.ord2 + x.ord3, data = x.data) ## extract parameters bern.prob <- mean(x.data$x.ord1) r.squared.pred <- summary(x.fit)$adj.r.squared ## change parameters associated with predictor X pred.dist <- list(dist = "bernoulli", prob = bern.prob) power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, r.squared.pred = r.squared.pred, dist = pred.dist)########################################### # predictor X follows normal distribution # ########################################### ## probability specification power.z.logistic(base.prob = 0.15, prob = 0.20, alpha = 0.05, power = 0.80, dist = "normal") ## odds ratio specification power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = "normal") ## regression coefficient specification power.z.logistic(beta0 = -1.734601, beta1 = 0.3483067, alpha = 0.05, power = 0.80, dist = "normal") ## change parameters associated with predictor X pred.dist <- list(dist = "normal", mean = 10, sd = 2) power.z.logistic(base.prob = 0.15, beta1 = 0.3483067, alpha = 0.05, power = 0.80, dist = pred.dist) ############################################## # predictor X follows Bernoulli distribution # # (such as treatment/control groups) # ############################################## ## odds ratio specification power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = "bernoulli") ## change parameters associated with predictor X pred.dist <- list(dist = "bernoulli", prob = 0.30) power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, dist = pred.dist) #################################### # predictor X is an ordinal factor # #################################### ## generating an ordinal predictor x.ord <- sample( x = c(1, 2, 3, 4), # levels size = 1e5, # sample size large enough to get stable estimates prob = c(0.25, 0.25, 0.25, 0.25), # category probabilities replace = TRUE ) ## dummy coding the ordinal predictor x.ord <- factor(x.ord, ordered = TRUE) contrasts(x.ord) <- contr.treatment(4, base = 4) x.dummy <- model.matrix( ~ x.ord)[,-1] x.data <- as.data.frame(x.dummy) ## fit linear regression to get multiple r-squared x.fit <- lm(x.ord1 ~ x.ord2 + x.ord3, data = x.data) ## extract parameters bern.prob <- mean(x.data$x.ord1) r.squared.pred <- summary(x.fit)$adj.r.squared ## change parameters associated with predictor X pred.dist <- list(dist = "bernoulli", prob = bern.prob) power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667, alpha = 0.05, power = 0.80, r.squared.pred = r.squared.pred, dist = pred.dist)
Calculates power or sample size (only one can be NULL at a time) to test
indirect effects in a mediation model (Z-Test, Joint Test, and Monte Carlo
Interval Test). One can consider explanatory power of the covariates in the
mediator and outcome model via specifying R-squared values accordingly.
power.z.mediation() and power.z.med() are the same functions.
Formulas are validated using Monte Carlo simulations.
power.z.mediation( beta.a = NULL, beta.b = NULL, ab.ratio = 1, req.sign = "+", beta.cp = 0, sd.predictor = 1, sd.mediator = 1, sd.outcome = 1, r.squared.mediator = NULL, r.squared.outcome = NULL, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("sobel", "aroian", "goodman", "joint", "monte.carlo"), n.simulation = 1000, n.draws = 1000, ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.mediation( beta.a = NULL, beta.b = NULL, ab.ratio = 1, req.sign = "+", beta.cp = 0, sd.predictor = 1, sd.mediator = 1, sd.outcome = 1, r.squared.mediator = NULL, r.squared.outcome = NULL, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("sobel", "aroian", "goodman", "joint", "monte.carlo"), n.simulation = 1000, n.draws = 1000, ceil.n = TRUE, verbose = 1, utf = FALSE )
beta.a |
regression coefficient for X -> M path. One can
use standardized regression coefficient, but
should keep |
beta.b |
regression coefficient for M -> Y path. One can
use standardized regression coefficient, but
should keep |
ab.ratio |
'beta.a' / 'beta.b' ratio (can be negative) when minimum detectable effect is of interest (either beta.a or beta.b, or both). |
req.sign |
Sign of the indirect effect (beta.a * beta.b product), when minimum detectable effect is of interest (either beta.a or beta.b, or both)). |
beta.cp |
regression coefficient for X -> Y path (the
direct path). One can use standardized regression
coefficient, but should keep
|
sd.predictor |
standard deviation of the predictor (X). For a
binary predictor,
|
sd.mediator |
standard deviation of the mediator (M). |
sd.outcome |
standard deviation of the outcome (Y). |
r.squared.mediator |
R-squared value for the mediator model (M ~ X).
The default is |
r.squared.outcome |
R-squared value for the outcome model
(Y ~ M + X). The default is
|
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis,
denoted as |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
method |
character; "sobel", "aroian", "goodman", "joint" or "monte.carlo". "joint" and "monte.carlo" methods can not be used for sample size calculation. |
n.simulation |
integer; number of replications (applies when method = "monte.carlo"). |
n.draws |
integer; number of draws from the distribution of the path coefficients for each replication (applies when method = "monte.carlo"). |
ceil.n |
logical; whether sample size should be rounded
up. |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it).
|
NOTE: The function pwrss.z.mediation() (or its alias
pwrss.z.med()) are no longer supported. However, they will remain
available as wrappers for the power.z.mediation function.
parms |
list of parameters used in calculation. |
test |
type of the statistical test ("Z-Test", "Joint Test", or "Monte Carlo Interval Test"). |
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 |
n |
sample size. |
Aroian, L. A. (1947). The probability function of the product of two normally distributed variables. Annals of Mathematical Statistics, 18(2), 265-271.
Goodman, L. A. (1960). On the exact variance of products. Journal of the American Statistical Association, 55(292), 708-713.
MacKinnon, D. P., & Dwyer, J. H. (1993). Estimating mediated effects in prevention studies. Evaluation Review, 17(2), 144-158.
MacKinnon, D. P., Warsi, G., & Dwyer, J. H. (1995). A simulation study of mediated effect measures. Multivariate Behavioral Research, 30(1), 41-62.
Preacher, K. J., & Hayes, A. F. (2004). SPSS and SAS procedures for estimating indirect effects in simple mediation models. Behavior Research Methods, Instruments, & Computers, 36, 717-731.
Preacher, K. J., & Hayes, A. F. (2008). Asymptotic and resampling strategies for assessing and comparing indirect effects in multiple mediator models. Behavior Research Methods, 40, 879-891.
Sobel, M. E. (1982). Asymptotic intervals for indirect effects in structural equations models. In S. Leinhart (Ed.), Sociological methodology 1982 (pp. 290-312). Jossey-Bass.
# with standardized coefficients ## statistical power power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, n = 200) ## minimum required sample size power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, power = 0.80) ## adjust for covariates in the outcome model power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, r.squared.outcome = 0.50, power = 0.80) # with binary predictor X such as treatment/control variable # in this case standardized coefficients for path a and cp would be Cohen's d values ## statistical power p <- 0.50 # proportion of subjects in one group power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, sd.predictor = sqrt(p*(1-p)), n = 200) ## minimum required sample size power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, sd.predictor = sqrt(p*(1-p)), power = 0.80) ## adjust for covariates in the outcome model power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, r.squared.outcome = 0.50, sd.predictor = sqrt(p*(1-p)), power = 0.80)# with standardized coefficients ## statistical power power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, n = 200) ## minimum required sample size power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, power = 0.80) ## adjust for covariates in the outcome model power.z.mediation(beta.a = 0.25, beta.b = 0.25, beta.cp = 0.10, r.squared.outcome = 0.50, power = 0.80) # with binary predictor X such as treatment/control variable # in this case standardized coefficients for path a and cp would be Cohen's d values ## statistical power p <- 0.50 # proportion of subjects in one group power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, sd.predictor = sqrt(p*(1-p)), n = 200) ## minimum required sample size power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, sd.predictor = sqrt(p*(1-p)), power = 0.80) ## adjust for covariates in the outcome model power.z.mediation(beta.a = 0.40, beta.b = 0.25, beta.cp = 0.10, r.squared.outcome = 0.50, sd.predictor = sqrt(p*(1-p)), power = 0.80)
Calculates power or sample size (only one can be NULL at a time) to test a (Pearson) correlation against a constant using Fisher's z transformation.
Formulas are validated using PASS and G*Power.
power.z.onecor( rho = NULL, req.sign = "+", null.rho = 0, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.onecor( rho = NULL, req.sign = "+", null.rho = 0, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )
rho |
correlation. |
req.sign |
whether estimated rho is smaller or larger than the null.rho (when minimum detectable rho is of interest). |
null.rho |
correlation when null is true. |
n |
sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test) |
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 |
n |
sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Chow, S. C., Shao, J., Wang, H., & Lokhnygina, Y. (2018). Sample size calculations in clinical research (3rd ed.). Taylor & Francis/CRC.
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
# expected correlation is 0.20 and it is different from 0 # it could be 0.20 as well as -0.20 power.z.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "two.sided") # expected correlation is 0.20 and it is greater than 0.10 power.z.onecor(rho = 0.20, null.rho = 0.10, power = 0.80, alpha = 0.05, alternative = "one.sided")# expected correlation is 0.20 and it is different from 0 # it could be 0.20 as well as -0.20 power.z.onecor(rho = 0.20, power = 0.80, alpha = 0.05, alternative = "two.sided") # expected correlation is 0.20 and it is greater than 0.10 power.z.onecor(rho = 0.20, null.rho = 0.10, power = 0.80, alpha = 0.05, alternative = "one.sided")
Calculates power or sample size (only one can be NULL at a time) for test of a proportion against a constant using the normal approximation method.
Formulas are validated using the PASS documentation and G*Power.
power.z.oneprop( prob = NULL, req.sign = "+", null.prob = 0.5, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), std.error = c("null", "alternative"), arcsine = FALSE, correct = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.oneprop( prob = NULL, req.sign = "+", null.prob = 0.5, n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), std.error = c("null", "alternative"), arcsine = FALSE, correct = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )
prob |
probability of success under alternative. |
req.sign |
whether |
null.prob |
probability of success under null. |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test:
"two.sided", "one.sided", or "two.one.sided". For
non-inferiority or superiority tests, add margin to the
null hypothesis value and use
|
std.error |
character; whether to calculate standard error using "null" or "alternative" value. "null" by default. |
arcsine |
logical; whether arcsine transformation should be
applied. |
correct |
logical; whether Yate's continuity correction should be applied. |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
NB: The pwrss.z.prop() function is deprecated, but it will remain
available as a wrapper for the power.z.oneprop() function during a
transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test ("exact"). |
delta |
difference between |
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 |
n |
sample size. |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
# power power.z.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, n = 500, alternative = "one.sided") # sample size power.z.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, power = 0.80, alternative = "one.sided") # effect size power.z.oneprop(req.sign = "+", null.prob = 0.50, alpha = 0.05, n = 500, power = 0.80, alternative = "one.sided")# power power.z.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, n = 500, alternative = "one.sided") # sample size power.z.oneprop(prob = 0.45, null.prob = 0.50, alpha = 0.05, power = 0.80, alternative = "one.sided") # effect size power.z.oneprop(req.sign = "+", null.prob = 0.50, alpha = 0.05, n = 500, power = 0.80, alternative = "one.sided")
Calculates power or sample size (only one can be NULL at a time) to test a
single coefficient in poisson regression. power.z.poisson() and
power.z.poisreg() are the same functions, as well as
pwrss.z.poisson() and pwrss.z.poisreg(). The distribution of
the predictor variable can be one of the following: c("normal",
"poisson", "uniform", "exponential", "binomial", "bernouilli",
"lognormal"). The default parameters for these distributions are
distribution = list(dist = "normal", mean = 0, sd = 1) distribution = list(dist = "poisson", lambda = 1) distribution = list(dist = "uniform", min = 0, max = 1) distribution = list(dist = "exponential", rate = 1) distribution = list(dist = "binomial", size = 1, prob = 0.50) distribution = list(dist = "bernoulli", prob = 0.50) distribution = list(dist = "lognormal", meanlog = 0, sdlog = 1)
Parameters defined in list() form can be modified, but the names
should be kept the same. It is sufficient to use distribution's name for
default parameters (e.g. dist = "normal").
Formulas are validated using Monte Carlo simulation, G*Power, and tables in the PASS documentation.
power.z.poisson( base.rate = NULL, rate.ratio = NULL, beta0 = NULL, beta1 = NULL, req.sign = "+", n = NULL, power = NULL, r.squared.predictor = 0, mean.exposure = 1, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("demidenko(vc)", "demidenko", "signorini"), distribution = "normal", ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.poisson( base.rate = NULL, rate.ratio = NULL, beta0 = NULL, beta1 = NULL, req.sign = "+", n = NULL, power = NULL, r.squared.predictor = 0, mean.exposure = 1, alpha = 0.05, alternative = c("two.sided", "one.sided"), method = c("demidenko(vc)", "demidenko", "signorini"), distribution = "normal", ceil.n = TRUE, verbose = 1, utf = FALSE )
base.rate |
the base mean event rate. |
rate.ratio |
event rate ratio. The relative increase in the mean event rate for one unit increase in the predictor (similar to odds ratio in logistic regression). |
beta0 |
the natural logarithm of the base mean event rate. |
beta1 |
the natural logarithm of the relative increase in the mean event rate for one unit increase in the predictor. |
req.sign |
sign of the beta1 coefficient (when minimum detectable effect or beta1 is of interest). |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis,
denoted as |
r.squared.predictor |
proportion of variance in the predictor accounted for by other covariates. This is not a pseudo R-squared. To compute it, regress the predictor on the covariates and extract the adjusted R-squared from that model. |
mean.exposure |
the mean exposure time (should be > 0), usually it is 1. |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis,
denoted as |
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
method |
character; calculation method:
|
distribution |
character; distribution family. Can be one of the
|
ceil.n |
logical; whether sample size should be rounded
up. |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it).
|
NB: The pwrss.z.poisson() and its alias pwrss.z.poisreg()
are deprecated. However, they will remain available as wrappers for the
power.z.logistic() function during a transition period.
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test). |
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 |
n |
sample size. |
Demidenko, E. (2007). Sample size determination for logistic regression revisited. Statistics in Medicine, 26(18), 3385-3397. https://doi.org/10.1002/sim.2771
Signorini, D. F. (1991). Sample size for Poisson regression. Biometrika, 78(2), 446-450.
# predictor X follows normal distribution ## regression coefficient specification power.z.poisson(beta0 = 0.50, beta1 = -0.10, alpha = 0.05, power = 0.80, dist = "normal") ## rate ratio specification power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = "normal") ## change parameters associated with predictor X dist.x <- list(dist = "normal", mean = 10, sd = 2) power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = dist.x) # predictor X follows Bernoulli distribution (such as treatment/control groups) ## regression coefficient specification power.z.poisson(beta0 = 0.50, beta1 = -0.10, alpha = 0.05, power = 0.80, dist = "bernoulli") ## rate ratio specification power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = "bernoulli") ## change parameters associatied with predictor X dist.x <- list(dist = "bernoulli", prob = 0.30) power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = dist.x)# predictor X follows normal distribution ## regression coefficient specification power.z.poisson(beta0 = 0.50, beta1 = -0.10, alpha = 0.05, power = 0.80, dist = "normal") ## rate ratio specification power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = "normal") ## change parameters associated with predictor X dist.x <- list(dist = "normal", mean = 10, sd = 2) power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = dist.x) # predictor X follows Bernoulli distribution (such as treatment/control groups) ## regression coefficient specification power.z.poisson(beta0 = 0.50, beta1 = -0.10, alpha = 0.05, power = 0.80, dist = "bernoulli") ## rate ratio specification power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = "bernoulli") ## change parameters associatied with predictor X dist.x <- list(dist = "bernoulli", prob = 0.30) power.z.poisson(base.rate = exp(0.50), rate.ratio = exp(-0.10), alpha = 0.05, power = 0.80, dist = dist.x)
Determines the power or the non-centrality parameter (mean) for the generic z-Test with (optional) Type 1 and Type 2 error plots.
power.z.test( power = NULL, mean = NULL, sd = 1, null.mean = 0, null.sd = 1, req.sign = "+", alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )power.z.test( power = NULL, mean = NULL, sd = 1, null.mean = 0, null.sd = 1, req.sign = "+", alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), plot = TRUE, verbose = 1, utf = FALSE )
power |
statistical power |
mean |
mean of the alternative; either |
sd |
standard deviation of the alternative. Do not change this value except when some sort of variance correction is applied (e.g. as in logistic and Poisson regressions). |
null.mean |
mean of the null. When alternative = "two.one.sided", the
function expects two values in the form |
null.sd |
standard deviation of the null. Do not change this value except when some sort of correction is applied. |
req.sign |
whether |
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". "two.one.sided" is used for equivalence and minimal effect testing. |
plot |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
power |
statistical power |
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. |
alpha |
type 1 error rate (user-specified). |
z.alpha |
critical value(s). |
beta |
type 2 error rate. |
type.s |
type S error rate (only for two-tailed test). |
type.m |
type M error rate (only for two-tailed test). |
# two-sided # power defined as the probability of observing test statistics greater than # the positive critical value OR less than the negative critical value power.z.test(mean = 1.96, alpha = 0.05, alternative = "two.sided") power.z.test(power = 0.80, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.z.test(mean = 1.96, alpha = 0.05, alternative = "one.sided") power.z.test(power = 0.80, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.z.test(mean = 0, null.mean = c(-2, 2), alpha = 0.05, alternative = "two.one.sided") power.z.test(power = 0.80, req.sign = "0", null.mean = c(-2, 2), alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.z.test(mean = 2, null.mean = c(-1, 1), alpha = 0.05, alternative = "two.one.sided") power.z.test(power = 0.80, req.sign = "+", null.mean = c(-1, 1), alpha = 0.05, alternative = "two.one.sided")# two-sided # power defined as the probability of observing test statistics greater than # the positive critical value OR less than the negative critical value power.z.test(mean = 1.96, alpha = 0.05, alternative = "two.sided") power.z.test(power = 0.80, alpha = 0.05, alternative = "two.sided") # one-sided # power is defined as the probability of observing a test statistic greater # than the critical value power.z.test(mean = 1.96, alpha = 0.05, alternative = "one.sided") power.z.test(power = 0.80, alpha = 0.05, alternative = "one.sided") # equivalence # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the lower bound) AND less than the # lower critical value (for the upper bound) power.z.test(mean = 0, null.mean = c(-2, 2), alpha = 0.05, alternative = "two.one.sided") power.z.test(power = 0.80, req.sign = "0", null.mean = c(-2, 2), alpha = 0.05, alternative = "two.one.sided") # minimal effect testing # power is defined as the probability of observing a test statistic greater # than the upper critical value (for the upper bound) OR less than the lower # critical value (for the lower bound). power.z.test(mean = 2, null.mean = c(-1, 1), alpha = 0.05, alternative = "two.one.sided") power.z.test(power = 0.80, req.sign = "+", null.mean = c(-1, 1), alpha = 0.05, alternative = "two.one.sided")
Calculates power or sample size (only one can be NULL at a time) to test difference between two independent (Pearson) correlations using Fisher's z transformation.
Formulas are validated using PASS and G*Power.
power.z.twocors( rho1 = NULL, rho2 = NULL, req.sign = "+", n2 = NULL, n.ratio = 1, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.twocors( rho1 = NULL, rho2 = NULL, req.sign = "+", n2 = NULL, n.ratio = 1, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), ceil.n = TRUE, verbose = 1, utf = FALSE )
rho1 |
correlation in the first group. |
rho2 |
correlation in the second group. |
req.sign |
whether estimated rho is smaller or larger than the other (when minimum detectable rho is of interest). |
n2 |
sample size in the second group. Sample size in the first
group can be calculated as |
n.ratio |
|
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
ceil.n |
logical; whether sample size should be rounded up.
|
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test) |
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 |
n |
sample size for the first and second groups, in the form of c(n1, n2). |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
Chow, S. C., Shao, J., Wang, H., & Lokhnygina, Y. (2018). Sample size calculations in clinical research (3rd ed.). Taylor & Francis / CRC.
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
# difference between r1 and r2 is different from zero # it could be -0.10 as well as 0.10 power.z.twocors(rho1 = 0.20, rho2 = 0.30, power = 0.80, alpha = 0.05, alternative = "two.sided") # difference between r1 and r2 is greater than zero power.z.twocors(rho1 = 0.30, rho2 = 0.20, power = 0.80, alpha = 0.05, alternative = "one.sided")# difference between r1 and r2 is different from zero # it could be -0.10 as well as 0.10 power.z.twocors(rho1 = 0.20, rho2 = 0.30, power = 0.80, alpha = 0.05, alternative = "two.sided") # difference between r1 and r2 is greater than zero power.z.twocors(rho1 = 0.30, rho2 = 0.20, power = 0.80, alpha = 0.05, alternative = "one.sided")
Calculates power or sample size (only one can be NULL at a time) to test difference between paired correlations (Pearson) using Fisher's Z-transformation.
Validated via PASS and G*Power.
power.z.twocors.steiger( rho12 = NULL, rho13 = NULL, rho23 = NULL, rho14 = NULL, rho24 = NULL, rho34 = NULL, req.sign = "+", n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), pooled = TRUE, common.index = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.twocors.steiger( rho12 = NULL, rho13 = NULL, rho23 = NULL, rho14 = NULL, rho24 = NULL, rho34 = NULL, req.sign = "+", n = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided"), pooled = TRUE, common.index = FALSE, ceil.n = TRUE, verbose = 1, utf = FALSE )
rho12 |
correlation between variable V1 and V2 (one common index and no common index). Check examples below. |
rho13 |
correlation between variable V1 and V3 (one common index and no common index). Check examples below. |
rho23 |
correlation between variable V2 and V3 (one common index and no common index). Check examples below. |
rho14 |
correlation between variable V1 and V4 (no common index only). Check examples below. |
rho24 |
correlation between variable V2 and V4 (no common index only). Check examples below. |
rho34 |
correlation between variable V3 and V4 (no common index only). Check examples below. |
req.sign |
whether estimated rho is smaller or larger than the other (when minimum detectable rho is of interest). Sign comparison is between rho12 and rho13 with common index and between rho12 and rho34 with no common index. Note that sign comparison is relative to the known correlation. |
n |
integer; sample size. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided" or "one.sided". |
pooled |
logical; whether standard error should be pooled.
|
common.index |
logical; whether calculations pertain to one common
index. |
ceil.n |
logical; if |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
parms |
list of parameters used in calculation. |
test |
type of the statistical test (Z-Test) |
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 |
n |
sample size for the first and second groups, in the form of c(n1, n2). |
Steiger, J. H. (1980). Tests for comparing elements of a correlation matrix. Psychological Bulletin, 87(2), 245-251. https://doi.org/10.1037/0033-2909.87.2.245
# example data for one common index # compare cor(V1, V2) to cor(V1, V3) # subject V1 V2 V3 # <int> <dbl> <dbl> <dbl> # 1 1.2 2.3 0.8 # 2 -0.0 1.1 0.7 # 3 1.9 -0.4 -2.3 # 4 0.7 1.3 0.4 # 5 2.1 -0.1 0.8 # ... ... ... ... # 1000 -0.5 2.7 -1.7 # V1: socio-economic status (common) # V2: pretest # V3: post-test power.z.twocors.steiger(rho12 = 0.35, rho13 = 0.45, rho23 = 0.05, n = 1000, power = NULL, alpha = 0.05, alternative = "two.sided", common.index = TRUE) # example data for no common index # compare cor(V1, V2) to cor(V3, V4) # subject V1 V2 V3 V4 # <int> <dbl> <dbl> <dbl> <dbl> # 1 1.2 2.3 0.8 1.2 # 2 -0.0 1.1 0.7 0.9 # 3 1.9 -0.4 -2.3 -0.1 # 4 0.7 1.3 0.4 -0.3 # 5 2.1 -0.1 0.8 2.7 # ... ... ... ... ... # 1000 -0.5 2.7 -1.7 0.8 # V1: pretest reading # V2: pretest math # V3: post-test reading # V4: post-test math power.z.twocors.steiger(rho12 = 0.45, rho13 = 0.45, rho23 = 0.50, rho14 = 0.50, rho24 = 0.80, rho34 = 0.55, n = 1000, power = NULL, alpha = 0.05, alternative = "two.sided", common.index = FALSE)# example data for one common index # compare cor(V1, V2) to cor(V1, V3) # subject V1 V2 V3 # <int> <dbl> <dbl> <dbl> # 1 1.2 2.3 0.8 # 2 -0.0 1.1 0.7 # 3 1.9 -0.4 -2.3 # 4 0.7 1.3 0.4 # 5 2.1 -0.1 0.8 # ... ... ... ... # 1000 -0.5 2.7 -1.7 # V1: socio-economic status (common) # V2: pretest # V3: post-test power.z.twocors.steiger(rho12 = 0.35, rho13 = 0.45, rho23 = 0.05, n = 1000, power = NULL, alpha = 0.05, alternative = "two.sided", common.index = TRUE) # example data for no common index # compare cor(V1, V2) to cor(V3, V4) # subject V1 V2 V3 V4 # <int> <dbl> <dbl> <dbl> <dbl> # 1 1.2 2.3 0.8 1.2 # 2 -0.0 1.1 0.7 0.9 # 3 1.9 -0.4 -2.3 -0.1 # 4 0.7 1.3 0.4 -0.3 # 5 2.1 -0.1 0.8 2.7 # ... ... ... ... ... # 1000 -0.5 2.7 -1.7 0.8 # V1: pretest reading # V2: pretest math # V3: post-test reading # V4: post-test math power.z.twocors.steiger(rho12 = 0.45, rho13 = 0.45, rho23 = 0.50, rho14 = 0.50, rho24 = 0.80, rho34 = 0.55, n = 1000, power = NULL, alpha = 0.05, alternative = "two.sided", common.index = FALSE)
Calculates power or sample size (only one can be NULL at a time) for two proportions using the normal approximation method.
Validated via G*Power and PASS documentation.
power.z.twoprops( prob1 = NULL, prob2 = NULL, req.sign = "+", margin = 0, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), arcsine = FALSE, correct = FALSE, paired = FALSE, rho.paired = 0.5, std.error = c("pooled", "unpooled"), ceil.n = TRUE, verbose = 1, utf = FALSE )power.z.twoprops( prob1 = NULL, prob2 = NULL, req.sign = "+", margin = 0, n.ratio = 1, n2 = NULL, power = NULL, alpha = 0.05, alternative = c("two.sided", "one.sided", "two.one.sided"), arcsine = FALSE, correct = FALSE, paired = FALSE, rho.paired = 0.5, std.error = c("pooled", "unpooled"), ceil.n = TRUE, verbose = 1, utf = FALSE )
prob1 |
probability of success in the first group. |
prob2 |
probability of success in the second group. |
req.sign |
whether estimated prob is smaller or larger than the other (when minimum detectable prob is of interest). |
margin |
ignorable |
n.ratio |
sample size ratio (n1 / n2). |
n2 |
integer; sample size for the second group. |
power |
statistical power, defined as the probability of
correctly rejecting a false null hypothesis, denoted as
|
alpha |
type 1 error rate, defined as the probability of
incorrectly rejecting a true null hypothesis, denoted as
|
alternative |
character; the direction or type of the hypothesis test: "two.sided", "one.sided", or "two.one.sided". |
arcsine |
logical; whether arcsine transformation should be applied. Note that this only applies to independent proportions without continuity correction. |
correct |
logical; whether Yates' continuity correction should be applied to the test statistic. Ignored for the paired test. |
paired |
logical; if |
rho.paired |
correlation between paired observations. |
std.error |
character; whether to calculate standard error using "pooled" or "unpooled" standard deviation. Ignored for the paired test. |
ceil.n |
logical; |
verbose |
|
utf |
logical; whether the output should show Unicode
characters (if encoding allows for it). |
NB: The pwrss.z.2props() function is deprecated, but it will remain
available as a wrapper for the power.z.twoprops() function during
a transition period.
parms |
list of parameters used in calculation. |
test |
type of the test, which is "z" or "exact". |
power |
statistical power |
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). |
n |
sample size in the form of c(n1, n2) (applies to independent proportions). |
n.total |
total sample size (applies to independent proportions). |
n.paired |
paired sample size (applies to paired proportions). |
Bulus, M., & Polat, C. (2023). pwrss R paketi ile istatistiksel guc analizi [Statistical power analysis with pwrss R package]. Ahi Evran Universitesi Kirsehir Egitim Fakultesi Dergisi, 24(3), 2207-2328. https://doi.org/10.29299/kefad.1209913
# power power.z.twoprops(prob1 = 0.65, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided") # sample size power.z.twoprops(prob1 = 0.65, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided")# power power.z.twoprops(prob1 = 0.65, prob2 = 0.60, alpha = 0.05, n2 = 500, alternative = "one.sided") # sample size power.z.twoprops(prob1 = 0.65, prob2 = 0.60, alpha = 0.05, power = 0.80, alternative = "one.sided")
Helper function to convert probability difference to Cohen's h (and vice versa).
probs.to.h(prob1, prob2 = 0.5, verbose = 1)probs.to.h(prob1, prob2 = 0.5, verbose = 1)
prob1 |
Probability of success in the first group, or under the alternative hypothesis in the one-sample case). |
prob2 |
Probability of success in the second group, or under the null hypothesis in the one-sample case). |
verbose |
|
h |
Cohen's h effect size. |
h |
Cohen's h effect size. |
prob1 |
probability of success in the first group, or under the alternative hypothesis in the one-sample case). |
prob2 |
probability of success in the second group, or under the null hypothesis in the one-sample case). |
probs.to.h(prob1 = 0.56, prob2 = 0.50)probs.to.h(prob1 = 0.56, prob2 = 0.50)
Helper function to convert (multinomial or product-multinomial) probabilities to Cohen's w.
probs.to.w(prob.matrix, null.prob.matrix = NULL, verbose = 1)probs.to.w(prob.matrix, null.prob.matrix = NULL, verbose = 1)
prob.matrix |
a vector or matrix of cell probabilities under the alternative hypothesis |
null.prob.matrix |
a vector or matrix of cell probabilities under the
null hypothesis. Calculated automatically when
|
verbose |
|
w |
Cohen's w effect size. It can be any of Cohen's W, Phi
coefficient, Cramer's V. Phi coefficient is defined as
|
df |
degrees of freedom. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
# ---------------------------------------------------------# # Example 1: Cohen's W # # goodness-of-fit test for 1 x k or k x 1 table # # How many subjects are needed to claim that # # girls choose STEM related majors less than males? # # ---------------------------------------------------------# ## from https://www.aauw.org/resources/research/the-stem-gap/ ## 28 percent of the workforce in STEM field is women prob.vector <- c(0.28, 0.72) null.prob.vector <- c(0.50, 0.50) probs.to.w(prob.vector, null.prob.vector) power.chisq.gof(w = 0.44, df = 1, alpha = 0.05, power = 0.80) # ---------------------------------------------------------# # Example 2: Phi Coefficient (or Cramer's V or Cohen's W) # # test of independence for 2 x 2 contingency tables # # How many subjects are needed to claim that # # girls are underdiagnosed with ADHD? # # ---------------------------------------------------------# ## from https://archive.today/E2hqM ## 5.6 percent of girls and 13.2 percent of boys are diagnosed with ADHD prob.matrix <- rbind(c(0.056, 0.132), c(0.944, 0.868)) colnames(prob.matrix) <- c("Girl", "Boy") rownames(prob.matrix) <- c("ADHD", "No ADHD") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.1302134, df = 1, alpha = 0.05, power = 0.80) # --------------------------------------------------------# # Example 3: Cramer's V (or Cohen's W) # # test of independence for j x k contingency tables # # How many subjects are needed to detect the relationship # # between depression severity and gender? # # --------------------------------------------------------# ## from https://doi.org/10.1016/j.jad.2019.11.121 prob.matrix <- cbind(c(0.6759, 0.1559, 0.1281, 0.0323, 0.0078), c(0.6771, 0.1519, 0.1368, 0.0241, 0.0101)) rownames(prob.matrix) <- c("Normal", "Mild", "Moderate", "Severe", "Extremely Severe") colnames(prob.matrix) <- c("Female", "Male") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.03022008, df = 4, alpha = 0.05, power = 0.80)# ---------------------------------------------------------# # Example 1: Cohen's W # # goodness-of-fit test for 1 x k or k x 1 table # # How many subjects are needed to claim that # # girls choose STEM related majors less than males? # # ---------------------------------------------------------# ## from https://www.aauw.org/resources/research/the-stem-gap/ ## 28 percent of the workforce in STEM field is women prob.vector <- c(0.28, 0.72) null.prob.vector <- c(0.50, 0.50) probs.to.w(prob.vector, null.prob.vector) power.chisq.gof(w = 0.44, df = 1, alpha = 0.05, power = 0.80) # ---------------------------------------------------------# # Example 2: Phi Coefficient (or Cramer's V or Cohen's W) # # test of independence for 2 x 2 contingency tables # # How many subjects are needed to claim that # # girls are underdiagnosed with ADHD? # # ---------------------------------------------------------# ## from https://archive.today/E2hqM ## 5.6 percent of girls and 13.2 percent of boys are diagnosed with ADHD prob.matrix <- rbind(c(0.056, 0.132), c(0.944, 0.868)) colnames(prob.matrix) <- c("Girl", "Boy") rownames(prob.matrix) <- c("ADHD", "No ADHD") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.1302134, df = 1, alpha = 0.05, power = 0.80) # --------------------------------------------------------# # Example 3: Cramer's V (or Cohen's W) # # test of independence for j x k contingency tables # # How many subjects are needed to detect the relationship # # between depression severity and gender? # # --------------------------------------------------------# ## from https://doi.org/10.1016/j.jad.2019.11.121 prob.matrix <- cbind(c(0.6759, 0.1559, 0.1281, 0.0323, 0.0078), c(0.6771, 0.1519, 0.1368, 0.0241, 0.0101)) rownames(prob.matrix) <- c("Normal", "Mild", "Moderate", "Severe", "Extremely Severe") colnames(prob.matrix) <- c("Female", "Male") prob.matrix probs.to.w(prob.matrix) power.chisq.gof(w = 0.03022008, df = 4, alpha = 0.05, power = 0.80)
Conversion from a Cohen's q to a correlation difference
q.to.cors(q, rho1 = NULL, rho2 = NULL, verbose = 1)q.to.cors(q, rho1 = NULL, rho2 = NULL, verbose = 1)
q |
Cohen's q effect size. |
rho1 |
first correlation (either rho1 or rho2 needs to be given) |
rho2 |
second correlation (either rho1 or rho2 needs to be given) |
verbose |
|
q |
Cohen's q effect size. |
delta |
correlation difference: rho1 - rho2. |
rho1 |
first correlation. |
rho2 |
second correlation. |
q.to.cors(q = 0.10, rho1 = 0.50) q.to.cors(q = 0.30, rho1 = 0.50) q.to.cors(q = 0.50, rho1 = 0.50)q.to.cors(q = 0.10, rho1 = 0.50) q.to.cors(q = 0.30, rho1 = 0.50) q.to.cors(q = 0.50, rho1 = 0.50)
Helper function to convert between Cohen's f and R-squared.
rsq.to.f(r.squared.full, r.squared.reduced = 0, verbose = 0)rsq.to.f(r.squared.full, r.squared.reduced = 0, verbose = 0)
r.squared.full |
R-squared for the full model. |
r.squared.reduced |
R-squared for the reduced model. |
verbose |
|
f.squared |
Cohen's f-squared. |
f |
Cohen's f. |
r.squared.full |
R-squared for the full model. |
r.squared.reduced |
R-squared for the reduced model. |
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
Selya, A. S., Rose, J. S., Dierker, L. C., Hedeker, D., & Mermelstein, R. J. (2012). A practical guide to calculating Cohen's f2, a measure of local effect size, from PROC MIXED. Frontiers in Psychology, 3, Article 111. https://doi.org/10.3389/fpsyg.2012.00111
rsq.to.f(r.squared.full = 0.02) # small rsq.to.f(r.squared.full = 0.13) # medium rsq.to.f(r.squared.full = 0.26) # largersq.to.f(r.squared.full = 0.02) # small rsq.to.f(r.squared.full = 0.13) # medium rsq.to.f(r.squared.full = 0.26) # large
Conversion from a z-value to a correlation (inverse Fisher's z-transformation)
z.to.cor(z, verbose = 1)z.to.cor(z, verbose = 1)
z |
z-value |
verbose |
|
rho |
correlation |
z |
z-value |
z.to.cor(z = 0.1003353) z.to.cor(z = 0.5493061) z.to.cor(z = 1.4722193) z.to.cor(z = 2.6466524)z.to.cor(z = 0.1003353) z.to.cor(z = 0.5493061) z.to.cor(z = 1.4722193) z.to.cor(z = 2.6466524)