| Type: | Package |
| Title: | Sample Size Planning with Methods Text and References |
| Version: | 0.1.0 |
| Date: | 2026-11-08 |
| Description: | Sample size calculations for the study designs most used in health and social research: estimating a proportion or mean (with finite-population correction and design effect), comparing two groups (proportions, means, paired data), case-control and cohort studies, diagnostic accuracy, Buderer (1996) <doi:10.1111/j.1553-2712.1996.tb03538.x>, correlation and regression, one-way and repeated-measures analysis of variance, logistic regression, Hsieh, Bloch and Larsen (1998) <doi:10.1002/(SICI)1097-0258(19980730)17:14%3C1623::AID-SIM871%3E3.0.CO;2-S>, survival, Schoenfeld (1983) <doi:10.2307/2531021>, incidence rates, non-inferiority and equivalence trials, longitudinal designs, Diggle, Heagerty, Liang and Zeger (2002, ISBN:9780198524847), and cluster-randomised trials with unequal cluster sizes, Eldridge, Ashby and Kerry (2006) <doi:10.1093/ije/dyl129>, with adjustment for several primary outcomes and for nonresponse. Each result can be turned into a ready-to-use methods paragraph that states every assumption, the target before and after nonresponse and the adjustments made, with the formula and references. The same calculations power the sample size calculator at https://researchite.com/sample-size. |
| License: | GPL (≥ 3) |
| URL: | https://researchite.com/sample-size |
| BugReports: | https://researchite.com/contact |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.5.0) |
| Imports: | stats, utils |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-08 14:14:13 UTC; Tesfahun1 |
| Author: | Tesfahun Mulatu [aut, cre, cph] |
| Maintainer: | Tesfahun Mulatu <tesfahunmulatu@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-29 11:10:14 UTC |
researchite: sample size planning with methods text and references
Description
Sample size calculations for the common designs of health and social research, each of which can be written up as a methods paragraph with its assumptions, formula and references.
Details
Start with the function for your design:
Estimating: [ss_proportion()], [ss_mean()], [ss_sensitivity()], [ss_specificity()].
Comparing groups: [ss_two_proportions()], [ss_two_means()], [ss_paired()], [ss_one_proportion()], [ss_one_mean()], [ss_mcnemar()], [ss_anova()].
Epidemiological studies: [ss_case_control()], [ss_cohort()], [ss_incidence_rates()], [ss_logistic()], [ss_logrank()], [ss_correlation()].
Trials: [ss_noninferiority_means()], [ss_noninferiority_proportions()].
Measured over time: [ss_repeated_within()], [ss_repeated_groups()], [ss_ancova()].
Clusters: [design_effect()], [ss_cluster_means()], [ss_cluster_proportions()].
Then [methods_text()] writes the paragraph, and [references()] and [formula_text()] give the sources and the formula.
Proportions are given between 0 and 1 (0.3 for 30%).
Author(s)
Maintainer: Tesfahun Mulatu tesfahunmulatu@gmail.com [copyright holder]
See Also
Useful links:
Design effect for a cluster sample or cluster-randomised trial
Description
DE = 1 + ((CV^2+1)m - 1)\rho, for clusters of average size m
whose sizes vary with coefficient of variation CV; with equal clusters
(CV = 0) this is Kish's 1+(m-1)\rho (Eldridge, Ashby & Kerry 2006).
Usage
design_effect(cluster_size, icc, cv = 0)
Arguments
cluster_size |
Average number of people per cluster. |
icc |
Intracluster correlation coefficient. |
cv |
Coefficient of variation of cluster sizes (0 for equal sizes). |
Value
The design effect, a single number.
References
Kish L (1965). Survey Sampling. New York: Wiley.
Eldridge SM, Ashby D, Kerry S (2006). Sample size for cluster randomized trials: effect of coefficient of variation of cluster size and analysis method. International Journal of Epidemiology 35(5):1292-1300.
Examples
design_effect(cluster_size = 20, icc = 0.05)
ss_proportion(p = 0.3, precision = 0.05, deff = design_effect(20, 0.05))
The formula used for a sample size calculation
Description
The formula used for a sample size calculation
Usage
formula_text(x)
Arguments
x |
An object of class 'studysize'. |
Value
A single string.
Examples
formula_text(ss_two_means(delta = 5, sd = 10))
A methods paragraph for a sample size calculation
Description
Writes the sample size paragraph for a protocol, thesis or paper: what the calculation was for, every assumption, the result before and after nonresponse, and the adjustments made, followed (optionally) by the formula and the references. The wording is rule-based, so the same calculation always gives the same text, and every number comes from the calculation itself. Edit it to fit your study; the assumptions still need justifying from earlier studies or pilot data.
Usage
methods_text(x, formula = FALSE, references = TRUE, software = TRUE)
Arguments
x |
An object of class 'studysize', from one of the 'ss_*()' functions. |
formula |
Add the formula used. |
references |
Add the references. |
software |
Mention this package (and cite it in the references). |
Value
A single string, with paragraphs separated by blank lines. Print it with [cat()] or [writeLines()].
Examples
x <- ss_proportion(p = 0.5, precision = 0.05, deff = 1.5, nonresponse = 0.1)
cat(methods_text(x))
cat(methods_text(ss_case_control(p0 = 0.2, or = 2, ratio = 2, nonresponse = 0.05)))
References for a sample size calculation
Description
The methodological sources for the calculation and for each adjustment it uses (design effect, nonresponse, finite population, several outcomes).
Usage
references(x, software = TRUE)
Arguments
x |
An object of class 'studysize'. |
software |
Add the citation for this package. |
Value
A character vector of references.
Examples
references(ss_proportion(p = 0.3, precision = 0.05, deff = 2))
Sample size for a baseline-adjusted comparison (ANCOVA)
Description
Analysis of covariance of the mean of m follow-up measurements,
adjusted for one baseline measurement, with correlation \rho between
all measurements (Frison & Pocock 1992):
n_1 = (z_{\alpha/2}+z_\beta)^2\sigma^2(1+1/r)[(1+(m-1)\rho)/m-\rho^2]/\Delta^2.
With one follow-up this is the familiar factor 1-\rho^2 (Borm et al. 2007).
Usage
ss_ancova(
delta,
sd,
rho,
followups = 1,
ratio = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
method = c("z", "t"),
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Difference between groups at follow-up to detect. |
sd |
Standard deviation of one measurement. |
rho |
Correlation between baseline and follow-up (and between follow-ups). |
followups |
Number of follow-up measurements (1 to 50). |
ratio |
Allocation ratio, group 2 : group 1. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
method |
'"z"', or '"t"' (exact t-test power; 'summary = "mean"' only). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Frison L, Pocock SJ (1992). Repeated measures in clinical trials: analysis using mean summary statistics and its implications for design. Statistics in Medicine 11(13):1685-1704.
Borm GF, Fransen J, Lemmens WAJG (2007). A simple sample size formula for analysis of covariance in randomized clinical trials. Journal of Clinical Epidemiology 60(12):1234-1238.
Examples
ss_ancova(delta = 5, sd = 10, rho = 0.6)
Sample size for a one-way ANOVA
Description
The smallest equal group size whose power, from the noncentral F
distribution with noncentrality \lambda = f^2 N, reaches the target
(Cohen 1988); f is Cohen's effect size.
Usage
ss_anova(
f,
groups,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
f |
Cohen's f. |
groups |
Number of groups (2 or more). |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Cohen J (1988). Statistical Power Analysis for the Behavioral Sciences, 2nd ed. Hillsdale: Lawrence Erlbaum.
Examples
ss_anova(f = 0.25, groups = 3)
Sample size for an unmatched case-control study
Description
The exposure among cases implied by the odds ratio,
p_1 = OR\,p_0/(1-p_0+OR\,p_0), compared with the exposure among
controls p_0 by the two-proportions formula of
[ss_two_proportions()] (Kelsey et al. 1996).
Usage
ss_case_control(
p0,
or,
ratio = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p0 |
Expected proportion exposed among controls. |
or |
Odds ratio to detect. |
ratio |
Controls per case. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Kelsey JL, Whittemore AS, Evans AS, Thompson WD (1996). Methods in Observational Epidemiology, 2nd ed. New York: Oxford University Press.
Schlesselman JJ (1982). Case-Control Studies: Design, Conduct, Analysis. New York: Oxford University Press.
Examples
ss_case_control(p0 = 0.2, or = 2, ratio = 2)
Sample size for a cluster-randomised trial
Description
Clusters per arm k = n \cdot DE / m, with n the individually
randomised size per arm and DE from [design_effect()]. The critical
values use Student's t on 2(k-1) degrees of freedom: k is the smallest
number of clusters whose own t values need no more, as recommended when clusters are few (Hayes & Moulton
2017).
Usage
ss_cluster_means(
delta,
sd,
cluster_size,
icc,
cv = 0,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
ss_cluster_proportions(
p1,
p2,
cluster_size,
icc,
cv = 0,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Difference in means between arms to detect. |
sd |
Standard deviation of the outcome (individual level). |
cluster_size |
Average number of people per cluster. |
icc |
Intracluster correlation coefficient. |
cv |
Coefficient of variation of cluster sizes (0 for equal sizes). |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion lost within each cluster. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
p1, p2 |
Expected proportions in the intervention and control arms. |
Value
An object of class 'studysize'; 'extra$clusters' holds the clusters per arm, and 'extra$deff' the design effect.
References
Hayes RJ, Moulton LH (2017). Cluster Randomised Trials, 2nd ed. Boca Raton: Chapman & Hall/CRC.
Eldridge SM, Ashby D, Kerry S (2006). Sample size for cluster randomized trials: effect of coefficient of variation of cluster size and analysis method. International Journal of Epidemiology 35(5):1292-1300.
Donner A, Klar N (2000). Design and Analysis of Cluster Randomization Trials in Health Research. London: Arnold.
Examples
ss_cluster_means(delta = 0.3, sd = 1, cluster_size = 20, icc = 0.05)
ss_cluster_proportions(p1 = 0.4, p2 = 0.25, cluster_size = 30, icc = 0.02, cv = 0.4)
Sample size for a cohort study comparing two risks
Description
The two-proportions formula of [ss_two_proportions()] applied to the risk in the exposed (group 1) and unexposed (group 2) groups.
Usage
ss_cohort(
p1,
p2,
ratio = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p1 |
Expected risk among the exposed. |
p2 |
Expected risk among the unexposed. |
ratio |
Unexposed per exposed participant. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Kelsey JL, Whittemore AS, Evans AS, Thompson WD (1996). Methods in Observational Epidemiology, 2nd ed. New York: Oxford University Press.
Examples
ss_cohort(p1 = 0.15, p2 = 0.08, ratio = 2)
Sample size to detect a correlation, or one predictor in a regression
Description
Fisher's z approximation, n = 3 + k + [(z_{\alpha/2}+z_\beta)/\mathrm{atanh}(r)]^2,
where k is the number of other predictors controlled for (k = 0
for a plain Pearson correlation; Cohen 1988).
Usage
ss_correlation(
r,
covariates = 0,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
r |
Expected correlation (or partial correlation when 'covariates > 0'), between -1 and 1 and not 0. |
covariates |
Number of other predictors controlled for. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Cohen J (1988). Statistical Power Analysis for the Behavioral Sciences, 2nd ed. Hillsdale: Lawrence Erlbaum.
Examples
ss_correlation(r = 0.3)
ss_correlation(r = 0.2, covariates = 4)
Sample size for comparing two incidence rates
Description
The person-time needed to compare two Poisson rates (Breslow & Day 1987),
T_1 = [z_{\alpha/2}\sqrt{(1+1/r)\bar\lambda} + z_\beta\sqrt{\lambda_1+\lambda_2/r}]^2/(\lambda_1-\lambda_2)^2,
converted to participants by the average follow-up.
Usage
ss_incidence_rates(
rate1,
rate2,
followup,
ratio = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
rate1, rate2 |
Incidence rates (events per unit of person-time). |
followup |
Average follow-up per participant, in the same time unit. |
ratio |
Person-time ratio, group 2 : group 1. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Breslow NE, Day NE (1987). Statistical Methods in Cancer Research, Vol. II: The Design and Analysis of Cohort Studies. Lyon: IARC.
Examples
ss_incidence_rates(rate1 = 0.05, rate2 = 0.03, followup = 2)
Sample size for a binary predictor in a logistic regression
Description
The outcome probability at the predictor's other level implied by the
odds ratio, compared by the two-proportions formula and inflated by the
variance-inflation factor 1/(1-R^2) for the other covariates
(Hsieh, Bloch & Larsen 1998).
Usage
ss_logistic(
p0,
or,
ratio = 1,
r2 = 0,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p0 |
Outcome probability at the reference level of the predictor. |
or |
Odds ratio to detect. |
ratio |
Allocation, predictor = 1 : predictor = 0. |
r2 |
Proportion of the predictor's variance explained by the other covariates (0 when there are none). |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Hsieh FY, Bloch DA, Larsen MD (1998). A simple method of sample size calculation for linear and logistic regression. Statistics in Medicine 17(14):1623-1634.
Examples
ss_logistic(p0 = 0.2, or = 1.8, r2 = 0.1)
Sample size for comparing survival (log-rank test)
Description
Schoenfeld's (1983) number of events,
E = (z_{\alpha/2}+z_\beta)^2/[\phi(1-\phi)(\ln HR)^2] with
\phi = 1/(1+r), converted to participants with the expected
probability of an event in each group by the end of the study.
Usage
ss_logrank(
hr,
p1,
p2,
ratio = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
hr |
Hazard ratio to detect. |
p1, p2 |
Expected probability of an event by the end of the study in group 1 and group 2. |
ratio |
Allocation ratio, group 2 : group 1. |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'; 'extra$events' holds the events needed.
References
Schoenfeld DA (1983). Sample-size formula for the proportional-hazards regression model. Biometrics 39(2):499-503.
Examples
ss_logrank(hr = 0.7, p1 = 0.3, p2 = 0.4)
Sample size for paired proportions (McNemar's test)
Description
Connor's (1987) formula for the number of matched pairs:
N = [z_{\alpha/2}\sqrt{p_d} + z_\beta\sqrt{p_d-\delta^2}]^2/\delta^2,
with p_d = p_{01}+p_{10} and \delta = |p_{10}-p_{01}|.
Usage
ss_mcnemar(
p01,
p10,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p01, p10 |
Expected proportions of the two kinds of discordant pairs (changing from 0 to 1, and from 1 to 0). |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'; the unit is pairs.
References
Connor RJ (1987). Sample size for testing differences in proportions for the paired-sample design. Biometrics 43(1):207-211.
Examples
ss_mcnemar(p01 = 0.25, p10 = 0.10)
Sample size to estimate a mean
Description
The number of participants needed to estimate a mean to within a given
precision: n_0 = (z \sigma / d)^2, with optional finite-population
correction and design effect, then inflated for nonresponse. 'method = "t"'
gives the smallest n for which Student's t on
n-1 degrees of freedom reaches the precision.
Usage
ss_mean(
sd,
precision,
conf.level = 0.95,
population = NULL,
deff = 1,
nonresponse = 0,
method = c("z", "t")
)
Arguments
sd |
Expected standard deviation. |
precision |
Precision |
conf.level |
Confidence level (two-sided). |
population |
Size of the population sampled, for the finite-population correction; 'NULL' (the default) for no correction. |
deff |
Design effect (1 for simple random sampling; often 1.5 to 2 for multistage cluster samples). |
nonresponse |
Expected proportion of nonresponse or loss, from 0 up to 1. |
method |
‘"z"' (normal) or '"t"' (Student’s t). |
Value
An object of class 'studysize'.
References
Cochran WG (1977). Sampling Techniques, 3rd ed. New York: Wiley.
Examples
ss_mean(sd = 12, precision = 2)
ss_mean(sd = 12, precision = 4, method = "t")
Sample size for non-inferiority or equivalence trials
Description
Means: n_1 = (z_\alpha+z_\beta)^2\sigma^2(1+1/r)/\Delta^2, assuming no
true difference. Proportions: n_1 = (z_\alpha+z_\beta)^2[p_1(1-p_1)+p_2(1-p_2)/r]/\delta^2,
with \delta = (p_1-p_2)+\Delta for non-inferiority or
\Delta-|p_1-p_2| for equivalence. z_\alpha is one-sided; for
equivalence (two one-sided tests) z_\beta becomes z_{\beta/2}
(Julious 2004; Chow, Shao & Wang 2008).
Usage
ss_noninferiority_means(
margin,
sd,
ratio = 1,
sig.level = 0.025,
power = 0.8,
deff = 1,
nonresponse = 0,
type = c("noninferiority", "equivalence")
)
ss_noninferiority_proportions(
p1,
p2,
margin,
ratio = 1,
sig.level = 0.025,
power = 0.8,
deff = 1,
nonresponse = 0,
type = c("noninferiority", "equivalence")
)
Arguments
margin |
The non-inferiority or equivalence margin (for proportions, between 0 and 1). |
sd |
Common standard deviation. |
ratio |
Allocation ratio, group 2 : group 1. |
sig.level |
One-sided significance level (0.025 corresponds to a two-sided 95% confidence interval). |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
type |
'"noninferiority"' or '"equivalence"'. |
p1, p2 |
Expected proportions with the new (test) and reference treatment. |
Value
An object of class 'studysize'.
References
Julious SA (2004). Sample sizes for clinical trials with Normal data. Statistics in Medicine 23(12):1921-1986.
Chow SC, Shao J, Wang H (2008). Sample Size Calculations in Clinical Research, 2nd ed. Boca Raton: Chapman & Hall/CRC.
Examples
ss_noninferiority_means(margin = 3, sd = 10)
ss_noninferiority_proportions(p1 = 0.85, p2 = 0.85, margin = 0.1)
Sample size to test one mean against a reference value
Description
n = (z_{\alpha/2}+z_\beta)^2\sigma^2/\Delta^2, with \Delta the
difference from the reference value to detect. 'method = "t"' solves the exact
one-sample t-test power (noncentral t) for n, as [stats::power.t.test()].
Usage
ss_one_mean(
delta,
sd,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
method = c("z", "t"),
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Difference from the reference value to detect. |
sd |
Common standard deviation. |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
method |
'"z"' (normal approximation) or '"t"' (exact t-test power). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Chow SC, Shao J, Wang H (2008). Sample Size Calculations in Clinical Research, 2nd ed. Boca Raton: Chapman & Hall/CRC.
Examples
ss_one_mean(delta = 4, sd = 10)
Sample size to test one proportion against a reference value
Description
n = [z_{\alpha/2}\sqrt{p_0(1-p_0)} + z_\beta\sqrt{p(1-p)}]^2/(p-p_0)^2
(Fleiss, Levin & Paik 2003).
Usage
ss_one_proportion(
p,
p0,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p |
Expected (true) proportion. |
p0 |
Reference value. |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Fleiss JL, Levin B, Paik MC (2003). Statistical Methods for Rates and Proportions, 3rd ed. Hoboken: Wiley.
Examples
ss_one_proportion(p = 0.65, p0 = 0.5)
Sample size for paired measurements (before-after, matched pairs)
Description
n = (z_{\alpha/2}+z_\beta)^2\sigma_d^2/\Delta^2, with \sigma_d the
standard deviation of the within-pair differences. 'method = "t"' solves the exact
one-sample t-test power (noncentral t) for n, as [stats::power.t.test()].
Usage
ss_paired(
delta,
sd_diff,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
method = c("z", "t"),
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Mean difference to detect. |
sd_diff |
Standard deviation of the within-pair differences (not of either measurement). |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
method |
'"z"' (normal approximation) or '"t"' (exact t-test power). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Julious SA (2004). Sample sizes for clinical trials with Normal data. Statistics in Medicine 23(12):1921-1986.
Examples
ss_paired(delta = 3, sd_diff = 8)
Sample size to estimate a proportion (prevalence)
Description
The number of participants needed to estimate a proportion with a given absolute precision (half-width of the confidence interval), with optional finite-population correction, design effect and allowance for nonresponse.
Usage
ss_proportion(
p,
precision,
conf.level = 0.95,
population = NULL,
deff = 1,
nonresponse = 0,
method = c("wald", "wilson")
)
Arguments
p |
Expected proportion, between 0 and 1 (use 0.5 when nothing is known). |
precision |
Absolute precision |
conf.level |
Confidence level (two-sided). |
population |
Size of the population sampled, for the finite-population correction; 'NULL' (the default) for no correction. |
deff |
Design effect (1 for simple random sampling; often 1.5 to 2 for multistage cluster samples). |
nonresponse |
Expected proportion of nonresponse or loss, from 0 up to 1. |
method |
'"wald"' (normal approximation) or '"wilson"' (Wilson score). |
Details
The normal-approximation (Wald) size is n_0 = z^2 p(1-p)/d^2
(Cochran 1977; Lwanga & Lemeshow 1991). 'method = "wilson"' instead solves
the Wilson score interval for n, which behaves better for proportions
near 0 or 1. With a population of size N, n = n_0/[1+(n_0-1)/N].
The result is multiplied by the design effect, rounded up, and then
inflated for nonresponse.
Value
An object of class 'studysize': see [studysize-class]. Use [methods_text()] for a ready-to-use methods paragraph with references.
References
Cochran WG (1977). Sampling Techniques, 3rd ed. New York: Wiley.
Lwanga SK, Lemeshow S (1991). Sample Size Determination in Health Studies: A Practical Manual. Geneva: World Health Organization.
Wilson EB (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association 22(158):209-212.
Examples
# Prevalence about 50\%, +/- 5 percentage points, design effect 1.5, 10\% nonresponse
x <- ss_proportion(p = 0.5, precision = 0.05, deff = 1.5, nonresponse = 0.1)
x
methods_text(x)
Sample size to compare two groups measured repeatedly
Description
With ‘summary = "mean"', the groups are compared on each person’s average
over m measurements with exchangeable correlation \rho:
n_1 = (z_{\alpha/2}+z_\beta)^2\sigma^2(1+1/r)[1+(m-1)\rho]/(m\Delta^2).
With 'summary = "slope"', on the rate of change over m equally spaced
measurements across 'duration': n_1 = (z_{\alpha/2}+z_\beta)^2\sigma^2(1-\rho)(1+1/r)/(\sum(t_j-\bar t)^2\Delta^2)
(Diggle et al. 2002).
Usage
ss_repeated_groups(
delta,
sd,
times,
rho,
ratio = 1,
summary = c("mean", "slope"),
duration = NULL,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
method = c("z", "t"),
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Difference between groups to detect: in the mean over time, or ('summary = "slope"') in the change per time unit. |
sd |
Standard deviation of one measurement. |
times |
Number of measurements per person (2 to 50). |
rho |
Correlation between a person's measurements. |
ratio |
Allocation ratio, group 2 : group 1. |
summary |
'"mean"' (average over time) or '"slope"' (rate of change). |
duration |
Follow-up time from the first to the last measurement ('summary = "slope"' only). |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
method |
'"z"', or '"t"' (exact t-test power; 'summary = "mean"' only). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Diggle PJ, Heagerty P, Liang KY, Zeger SL (2002). Analysis of Longitudinal Data, 2nd ed. Oxford: Oxford University Press.
Examples
ss_repeated_groups(delta = 3, sd = 10, times = 4, rho = 0.5)
ss_repeated_groups(delta = 1, sd = 10, times = 5, rho = 0.6, summary = "slope", duration = 12)
Sample size for repeated measures in one group (repeated-measures ANOVA)
Description
The smallest number of participants, each measured 'times' times, whose
power for the within-subject effect reaches the target. Noncentral F with
\lambda = f^2 N m \varepsilon/(1-\rho), df_1 = (m-1)\varepsilon
and df_2 = (N-1)(m-1)\varepsilon, as in G*Power (Faul et al. 2007).
Usage
ss_repeated_within(
f,
times,
rho,
eps = 1,
sig.level = 0.05,
power = 0.8,
nonresponse = 0,
outcomes = 1,
rule = c("any", "all")
)
Arguments
f |
Cohen's f for the change in means across the measurements. |
times |
Number of measurements per person (2 to 50). |
rho |
Correlation between a person's measurements. |
eps |
Nonsphericity correction |
sig.level |
Two-sided significance level. |
power |
Power. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Faul F, Erdfelder E, Lang AG, Buchner A (2007). G*Power 3: a flexible statistical power analysis program for the social, behavioral, and biomedical sciences. Behavior Research Methods 39(2):175-191.
Examples
ss_repeated_within(f = 0.25, times = 3, rho = 0.5)
Sample size to estimate diagnostic sensitivity or specificity
Description
Buderer's (1996) method: the number of participants with the condition
(for sensitivity) or without it (for specificity) needed to estimate the
accuracy with a given precision, z^2 A(1-A)/d^2, divided by the
expected prevalence (or 1 minus it) to give the total to enrol.
Usage
ss_sensitivity(se, prevalence, precision, conf.level = 0.95, nonresponse = 0)
ss_specificity(sp, prevalence, precision, conf.level = 0.95, nonresponse = 0)
Arguments
se, sp |
Expected sensitivity or specificity, between 0 and 1. |
prevalence |
Expected prevalence of the condition among those enrolled. |
precision |
Absolute precision, between 0 and 1. |
conf.level |
Confidence level (two-sided). |
nonresponse |
Expected proportion of nonresponse or loss, from 0 up to 1. |
Value
An object of class 'studysize'.
References
Buderer NM (1996). Statistical methodology: I. Incorporating the prevalence of disease into the sample size calculation for sensitivity and specificity. Academic Emergency Medicine 3(9):895-900.
Examples
ss_sensitivity(se = 0.9, prevalence = 0.2, precision = 0.05)
ss_specificity(sp = 0.85, prevalence = 0.2, precision = 0.05)
Sample size to compare two independent means
Description
n_1 = (z_{\alpha/2}+z_\beta)^2\sigma^2(1+1/r)/\Delta^2, n_2 = r n_1
(Julious 2004). 'method = "t"' solves the exact power of the
two-sample t-test (noncentral t, both tails) for the group size, as
[stats::power.t.test()] with 'strict = TRUE' does for equal groups, before
the design effect is applied.
Usage
ss_two_means(
delta,
sd,
ratio = 1,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
method = c("z", "t"),
outcomes = 1,
rule = c("any", "all")
)
Arguments
delta |
Difference in means to detect. |
sd |
Common standard deviation. |
ratio |
Allocation ratio, group 2 : group 1. |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
method |
'"z"' (normal approximation) or '"t"' (exact t-test power). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Julious SA (2004). Sample sizes for clinical trials with Normal data. Statistics in Medicine 23(12):1921-1986.
Examples
ss_two_means(delta = 5, sd = 10)
ss_two_means(delta = 5, sd = 10, method = "t")
Sample size to compare two independent proportions
Description
The normal-approximation sample size for a two-sided test of two
proportions with allocation ratio r = group 2 : group 1 (Fleiss,
Levin & Paik 2003): n_1 = [z_{\alpha/2}\sqrt{(1+1/r)\bar p(1-\bar p)} +
z_\beta\sqrt{p_1(1-p_1)+p_2(1-p_2)/r}]^2/(p_1-p_2)^2, n_2 = r n_1.
Usage
ss_two_proportions(
p1,
p2,
ratio = 1,
sig.level = 0.05,
power = 0.8,
deff = 1,
nonresponse = 0,
continuity = FALSE,
outcomes = 1,
rule = c("any", "all")
)
Arguments
p1, p2 |
Expected proportions in group 1 and group 2. |
ratio |
Allocation ratio, group 2 : group 1. |
sig.level |
Two-sided significance level. |
power |
Power. |
deff |
Design effect. |
nonresponse |
Expected proportion of nonresponse or loss to follow-up. |
continuity |
Apply Yates' continuity correction (equal groups only). |
outcomes |
Number of primary outcomes (1 to 10). With more than one, 'rule' says what counts as success. |
rule |
'"any"': success if any one outcome is significant (each tested at 'sig.level / outcomes', Bonferroni); '"all"': co-primary outcomes that must all succeed (each planned with power 'power^(1/outcomes)'). |
Value
An object of class 'studysize'.
References
Fleiss JL, Levin B, Paik MC (2003). Statistical Methods for Rates and Proportions, 3rd ed. Hoboken: Wiley.
Examples
ss_two_proportions(p1 = 0.30, p2 = 0.15)
ss_two_proportions(p1 = 0.30, p2 = 0.15, ratio = 2, nonresponse = 0.1)
Sample size results
Description
Every 'ss_*()' function returns a list of class 'studysize' with:
- method
The calculation's identifier.
- inputs
The assumptions, as given.
- raw
The unrounded size from the formula (per group 1 for two-group designs; events for the log-rank test; person-time for rates; clusters per arm for cluster trials).
- complete
Completed observations needed in all, before nonresponse.
- groups
Recruitment target per group, after nonresponse.
- total
The total recruitment target.
- unit
What is counted (participants, pairs).
- notes
Cautions about the calculation.
- extra
Method-specific details (events, clusters, design effect).