Package {SampleSizeR}


Type: Package
Title: Sample Size Calculations for Epidemiological, Clinical, and Diagnostic Studies
Version: 0.1.0
Description: Provides comprehensive methods for sample size determination for epidemiological studies, clinical trials, diagnostic accuracy studies, and diagnostic agreement studies. The package supports prevalence surveys, cluster prevalence studies, unmatched case-control studies, cohort studies, superiority, non-inferiority, and equivalence clinical trials, diagnostic sensitivity, diagnostic specificity, receiver operating characteristic (ROC) area under the curve (AUC), and diagnostic agreement studies. Functions include optional adjustments for finite population correction, design effect, unequal allocation, anticipated response rate, and dropout. Results are returned as standardized 'SampleSizeR' objects with print, summary, plot, and data frame methods.
License: GPL-3
Encoding: UTF-8
Depends: R (≥ 4.2.0)
Imports: stats, ggplot2, rlang
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown, covr
VignetteBuilder: knitr
Config/testthat/edition: 3
URL: https://github.com/vinodhpmd/SampleSizeR
BugReports: https://github.com/vinodhpmd/SampleSizeR/issues
Language: en-US
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-07-25 16:22:33 UTC; m
Author: Vinodh Kumar Obli Rajendran [aut, cre], Keerthi Aaradhana [aut]
Maintainer: Vinodh Kumar Obli Rajendran <vinodhkumar.rajendran@gmail.com>
Repository: CRAN
Date/Publication: 2026-08-05 06:20:03 UTC

Convert SampleSizeR Object to Data Frame

Description

Convert SampleSizeR Object to Data Frame

Usage

## S3 method for class 'SampleSizeR'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

x

A SampleSizeR object.

row.names

NULL.

optional

ignored.

...

Additional arguments.

Value

Data frame.


Plot Sample Size Result

Description

Plot Sample Size Result

Usage

## S3 method for class 'SampleSizeR'
plot(x, ...)

Arguments

x

A SampleSizeR object.

...

Additional arguments.

Value

ggplot object.


Print Sample Size Result

Description

Prints a SampleSizeR object in a user-friendly format.

Usage

## S3 method for class 'SampleSizeR'
print(x, digits = 2, ...)

Arguments

x

A SampleSizeR object.

digits

Number of decimal places.

...

Additional arguments.

Value

Invisible x.


Sample Size for an Unmatched Case-Control Study

Description

Calculates the required sample size for an unmatched case-control study based on the expected odds ratio, exposure prevalence among controls, desired statistical power and significance level.

Usage

ss_case_control(
  odds.ratio,
  p0,
  alpha = 0.05,
  power = 0.8,
  ratio = 1,
  dropout = 0
)

Arguments

odds.ratio

Expected odds ratio (>0).

p0

Expected exposure prevalence among controls (0-1).

alpha

Type I error. Default = 0.05.

power

Statistical power. Default = 0.80.

ratio

Number of controls per case. Default = 1.

dropout

Expected dropout/non-response proportion (0-1).

Details

The implementation follows the Kelsey/Fleiss approach and supports unequal control-to-case allocation ratios.

Exposure prevalence among cases is estimated from

p_1=\frac{OR\times p_0} {1+p_0(OR-1)}

Sample size is then calculated using the Kelsey/Fleiss unmatched case-control formula.

Value

Object of class SampleSizeR

References

Kelsey JL, Whittemore AS, Evans AS, Thompson WD. Methods in Observational Epidemiology.

Fleiss JL, Levin B, Paik MC. Statistical Methods for Rates and Proportions.

Schlesselman JJ. Case-Control Studies: Design, Conduct and Analysis.

Examples


ss_case_control(
    odds.ratio = 2,
    p0 = 0.20
)

ss_case_control(
    odds.ratio = 3,
    p0 = 0.15,
    ratio = 2
)


Sample Size for a Two-Arm Parallel Clinical Trial

Description

Calculates the required sample size for superiority clinical trials with either continuous or binary outcomes.

Usage

ss_clinical_trial(
  outcome = c("continuous", "binary"),
  alpha = 0.05,
  power = 0.8,
  ratio = 1,
  dropout = 0,
  mean1 = NULL,
  mean2 = NULL,
  sd = NULL,
  p1 = NULL,
  p2 = NULL
)

Arguments

outcome

Character string specifying outcome type. One of "continuous" or "binary".

alpha

Type I error. Default = 0.05.

power

Statistical power. Default = 0.80.

ratio

Allocation ratio (Control : Treatment). Default = 1.

dropout

Expected dropout proportion (0-1).

mean1

Mean of treatment group.

mean2

Mean of control group.

sd

Common standard deviation.

p1

Expected event proportion in treatment group.

p2

Expected event proportion in control group.

Details

Supported outcome types:

Supports unequal allocation ratios.

Value

Object of class SampleSizeR

References

Chow SC, Shao J, Wang H. Sample Size Calculations in Clinical Research.

Julious SA. Sample Sizes for Clinical Trials.

Fleiss JL et al. Statistical Methods for Rates and Proportions.

Examples


## Continuous endpoint

ss_clinical_trial(
    outcome="continuous",
    mean1=15,
    mean2=12,
    sd=5
)

## Binary endpoint

ss_clinical_trial(
    outcome="binary",
    p1=0.30,
    p2=0.50
)


Sample Size for an Unmatched Cohort Study

Description

Calculates the required sample size for an unmatched cohort study based on the expected risk ratio, incidence among the unexposed group, statistical power and significance level.

Usage

ss_cohort(risk.ratio, p0, alpha = 0.05, power = 0.8, ratio = 1, dropout = 0)

Arguments

risk.ratio

Expected relative risk (>0).

p0

Expected incidence (risk) in the unexposed group (0-1).

alpha

Type I error. Default = 0.05.

power

Statistical power. Default = 0.80.

ratio

Number of unexposed subjects per exposed subject. Default = 1.

dropout

Expected dropout/non-response proportion (0-1).

Details

Supports unequal exposed:unexposed allocation ratios.

Incidence among the exposed group is estimated as

p_1 = RR \times p_0

The required sample size is calculated using the Fleiss/Kelsey two-proportion formula.

Value

Object of class SampleSizeR

References

Kelsey JL et al. Methods in Observational Epidemiology.

Fleiss JL, Levin B, Paik MC. Statistical Methods for Rates and Proportions.

Chow SC, Shao J, Wang H. Sample Size Calculations in Clinical Research.

Examples


ss_cohort(
    risk.ratio = 2,
    p0 = 0.10
)

ss_cohort(
    risk.ratio = 1.8,
    p0 = 0.15,
    ratio = 2
)


Sample Size for Diagnostic Agreement Studies

Description

Estimates the required sample size for testing agreement using Cohen's kappa.

The default implementation ("pearson") is based on the multinomial agreement model and Pearson goodness-of-fit effect size.

This implementation is not the original Donner & Eliasziw (1992) sample size method.

Usage

ss_diagnostic_agreement(
  kappa1,
  kappa0 = 0.4,
  prevalence = 0.5,
  alpha = 0.05,
  power = 0.8,
  response.rate = 1,
  dropout = 0,
  method = c("pearson")
)

Arguments

kappa1

Expected agreement under the alternative hypothesis.

kappa0

Agreement under the null hypothesis.

prevalence

Expected prevalence.

alpha

Type I error.

power

Desired power.

response.rate

Expected response rate.

dropout

Expected dropout proportion.

method

Character string.

Details

Computes the required sample size for studies evaluating agreement between two binary diagnostic methods.

Value

SampleSizeR object.


Sample Size for ROC Area Under the Curve (AUC)

Description

Calculates the required sample size for studies evaluating the area under the receiver operating characteristic (ROC) curve.

Usage

ss_diagnostic_auc(
  auc,
  auc0 = 0.5,
  prevalence,
  precision = NULL,
  alpha = 0.05,
  power = 0.8,
  ratio = 1,
  design = c("precision", "hypothesis"),
  alternative = c("two.sided", "one.sided"),
  method = c("obuchowski", "hanley"),
  response.rate = 1,
  dropout = 0
)

Arguments

auc

Expected AUC.

auc0

Null AUC for hypothesis testing.

prevalence

Expected disease prevalence.

precision

Desired half-width of the confidence interval. Required only when design="precision".

alpha

Type I error.

power

Statistical power.

ratio

Ratio of non-diseased:diseased subjects.

design

Either "precision" or "hypothesis".

alternative

One- or two-sided hypothesis.

method

Variance estimator.

response.rate

Expected response rate.

dropout

Expected dropout proportion.

Details

Two study designs are supported:

Two variance estimators are available:

Value

Object of class SampleSizeR.

References

Obuchowski NA. Statistics in Medicine. 1994.

Hanley JA, McNeil BJ. Radiology. 1982.

Zhou XH, Obuchowski NA, McClish DK. Statistical Methods in Diagnostic Medicine.


Sample Size for Diagnostic Test Sensitivity

Description

Calculates the required sample size to estimate the sensitivity of a diagnostic test with a specified confidence interval precision using the method of Buderer (1996).

Usage

ss_diagnostic_sensitivity(
  sensitivity,
  prevalence,
  precision = 0.05,
  conf.level = 0.95,
  finite.population = NULL,
  response.rate = 1,
  dropout = 0
)

Arguments

sensitivity

Expected sensitivity of the diagnostic test (0 < sensitivity < 1).

prevalence

Expected disease prevalence (0 < prevalence < 1).

precision

Desired absolute precision (half-width of the confidence interval).

conf.level

Confidence level.

finite.population

Optional finite population size.

response.rate

Expected response rate (0 < response.rate \le 1).

dropout

Expected dropout proportion (0 \le dropout < 1).

Details

The Buderer (1996) method estimates the total sample size required to achieve the desired precision for the sensitivity estimate while accounting for the expected prevalence of disease.

The required number of diseased subjects is

n_D = \frac{Z^2 Se(1-Se)}{L^2}

The total sample size is

n = \frac{n_D}{Prev}

Value

An object of class "SampleSizeR".

References

Buderer NM. Statistical Methodology: Incorporating the Prevalence of Disease into the Sample Size Calculation for Sensitivity and Specificity. Academic Emergency Medicine. 1996.

Flahault A, Cadilhac M, Thomas G. Sample size calculation should be performed for design accuracy in diagnostic test studies. Journal of Clinical Epidemiology. 2005.

Examples

ss_diagnostic_sensitivity(
    sensitivity = 0.90,
    prevalence = 0.25,
    precision = 0.05
)


Sample Size for Diagnostic Test Specificity

Description

Calculates the required sample size to estimate the specificity of a diagnostic test with a specified confidence interval precision using the method of Buderer (1996).

Usage

ss_diagnostic_specificity(
  specificity,
  prevalence,
  precision = 0.05,
  conf.level = 0.95,
  finite.population = NULL,
  response.rate = 1,
  dropout = 0
)

Arguments

specificity

Expected specificity of the diagnostic test (0 < specificity < 1).

prevalence

Expected disease prevalence (0 < prevalence < 1).

precision

Desired absolute precision (half-width of the confidence interval).

conf.level

Confidence level.

finite.population

Optional finite population size.

response.rate

Expected response rate (0 < response.rate \le 1).

dropout

Expected dropout proportion (0 \le dropout < 1).

Details

The Buderer (1996) method estimates the total sample size required to achieve the desired precision for the specificity estimate while accounting for the expected prevalence of disease.

The required number of non-diseased subjects is

n_{ND} = \frac{Z^2 Sp(1-Sp)}{L^2}

The total sample size is

n = \frac{n_{ND}}{1-Prev}

Value

An object of class "SampleSizeR".

References

Buderer NM. Statistical Methodology: Incorporating the Prevalence of Disease into the Sample Size Calculation for Sensitivity and Specificity. Academic Emergency Medicine. 1996.

Flahault A, Cadilhac M, Thomas G. Sample size calculation should be performed for design accuracy in diagnostic test studies. Journal of Clinical Epidemiology. 2005.

Examples

ss_diagnostic_specificity(
    specificity = 0.95,
    prevalence = 0.30,
    precision = 0.05
)


Sample Size for an Equivalence Trial

Description

Calculates the required sample size for a two-arm parallel equivalence clinical trial using the Two One-Sided Tests (TOST) procedure.

Usage

ss_equivalence_trial(
  outcome = c("continuous", "binary"),
  alpha = 0.05,
  power = 0.8,
  ratio = 1,
  dropout = 0,
  delta,
  mean1 = NULL,
  mean2 = NULL,
  sd = NULL,
  p1 = NULL,
  p2 = NULL
)

Arguments

outcome

Either "continuous" or "binary".

alpha

Type I error (typically 0.05).

power

Statistical power.

ratio

Allocation ratio (Control : Treatment).

dropout

Expected dropout proportion.

delta

Positive equivalence margin.

mean1

Treatment mean.

mean2

Control mean.

sd

Common standard deviation.

p1

Treatment event probability.

p2

Control event probability.

Details

Supported endpoints:

Supports equal or unequal allocation ratios.

Value

Object of class "SampleSizeR".

References

Chow SC, Shao J, Wang H. Sample Size Calculations in Clinical Research.

Piaggio G et al. Reporting of Noninferiority and Equivalence Randomized Trials.

ICH E9 Statistical Principles for Clinical Trials.

Examples


ss_equivalence_trial(
    outcome = "continuous",
    mean1 = 100,
    mean2 = 102,
    sd = 12,
    delta = 5
)

ss_equivalence_trial(
    outcome = "binary",
    p1 = 0.80,
    p2 = 0.78,
    delta = 0.10
)


Sample Size for a Non-Inferiority Trial

Description

Calculates the required sample size for a two-arm parallel non-inferiority clinical trial.

Usage

ss_noninferiority_trial(
  outcome = c("continuous", "binary"),
  alpha = 0.025,
  power = 0.8,
  alternative = c("one.sided", "two.sided"),
  ratio = 1,
  dropout = 0,
  delta,
  mean1 = NULL,
  mean2 = NULL,
  sd = NULL,
  p1 = NULL,
  p2 = NULL
)

Arguments

outcome

Either "continuous" or "binary".

alpha

Type I error.

power

Statistical power.

alternative

One-sided or two-sided test.

ratio

Allocation ratio (Control : Treatment).

dropout

Dropout proportion.

delta

Non-inferiority margin (positive).

mean1

Treatment mean.

mean2

Control mean.

sd

Common standard deviation.

p1

Treatment event probability.

p2

Control event probability.

Details

Supported endpoints:

Supports equal or unequal allocation ratios.

Value

Object of class SampleSizeR.

References

Chow SC, Shao J, Wang H. Sample Size Calculations in Clinical Research.

ICH E9.

Piaggio G et al. Reporting of Noninferiority and Equivalence Randomized Trials.


Sample Size for a Prevalence Study

Description

Calculates the minimum required sample size for estimating disease prevalence with a specified confidence level and desired precision.

Usage

ss_prevalence(
  prevalence,
  precision = NULL,
  relative.precision = NULL,
  conf.level = 0.95,
  finite.population = NULL,
  design.effect = 1,
  response.rate = 1,
  dropout = 0
)

Arguments

prevalence

Expected prevalence (0–1).

precision

Absolute precision (0–1). Ignored if relative.precision is supplied.

relative.precision

Relative precision expressed as a proportion of prevalence (e.g. 0.20 = ±20% of prevalence).

conf.level

Confidence level. Default is 0.95.

finite.population

Population size for finite population correction. Default is NULL.

design.effect

Design effect (>=1). Default is 1.

response.rate

Expected response rate (0–1). Default is 1.

dropout

Expected dropout proportion (0–1). Default is 0.

Details

The function implements Cochran's sample size formula and optionally adjusts for:

Relative precision can also be specified.

Cochran's formula

n=\frac{Z^2P(1-P)}{d^2}

where

If a finite population size is supplied, finite population correction is applied.

The resulting sample size is subsequently adjusted for

Value

An object of class SampleSizeR.

References

Cochran WG (1977). Sampling Techniques. Third Edition. John Wiley & Sons.

Lwanga SK, Lemeshow S (1991). Sample Size Determination in Health Studies. WHO.

Naing L, Winn T, Rusli BN (2006). Practical issues in calculating the sample size for prevalence studies. Archives of Orofacial Sciences.

Examples


ss_prevalence(
  prevalence = 0.20,
  precision = 0.05
)

ss_prevalence(
  prevalence = 0.10,
  relative.precision = 0.20
)

ss_prevalence(
  prevalence = 0.15,
  precision = 0.04,
  finite.population = 2500
)


Sample Size for Cluster Prevalence Studies

Description

Calculates the required sample size for estimating prevalence using a cluster sampling design.

Usage

ss_prevalence_cluster(
  prevalence,
  precision = NULL,
  relative.precision = NULL,
  cluster.size,
  icc,
  conf.level = 0.95,
  finite.population = NULL,
  response.rate = 1,
  dropout = 0
)

Arguments

prevalence

Expected prevalence (0–1).

precision

Absolute precision.

relative.precision

Relative precision.

cluster.size

Average number of subjects per cluster.

icc

Intra-cluster correlation coefficient.

conf.level

Confidence level.

finite.population

Population size.

response.rate

Expected response proportion.

dropout

Expected dropout proportion.

Details

The function first computes the simple random sample size using Cochran's formula and then inflates the sample size using the cluster design effect:

DEFF = 1 + (m-1)\rho

where

The function optionally adjusts for

Value

Object of class SampleSizeR

References

Cochran WG (1977). Sampling Techniques.

Donner A, Klar N (2000). Design and Analysis of Cluster Randomization Trials.

Hayes RJ, Bennett S (1999). Simple sample size calculation for cluster-randomized trials.

Examples


ss_prevalence_cluster(
prevalence=0.20,
precision=0.05,
cluster.size=20,
icc=0.05
)


Sample Size for a Superiority Trial

Description

Calculates the required sample size for a two-arm superiority clinical trial with either continuous or binary endpoints.

Usage

ss_superiority_trial(
  outcome = c("continuous", "binary"),
  alpha = 0.05,
  power = 0.8,
  alternative = c("two.sided", "one.sided"),
  ratio = 1,
  dropout = 0,
  delta,
  mean1 = NULL,
  mean2 = NULL,
  sd = NULL,
  p1 = NULL,
  p2 = NULL
)

Arguments

outcome

Character string. Either "continuous" or "binary".

alpha

Type I error.

power

Statistical power.

alternative

"one.sided" or "two.sided".

ratio

Allocation ratio (Control : Treatment).

dropout

Expected dropout proportion.

delta

Superiority margin.

mean1

Treatment mean.

mean2

Control mean.

sd

Common standard deviation.

p1

Treatment event probability.

p2

Control event probability.

Details

Supports

Value

Object of class SampleSizeR.

References

Chow SC, Shao J, Wang H. Sample Size Calculations in Clinical Research.

ICH E9 Statistical Principles for Clinical Trials.

Julious SA. Sample Sizes for Clinical Trials.

Examples


ss_superiority_trial(
    outcome="continuous",
    mean1=16,
    mean2=12,
    sd=6,
    delta=2
)

ss_superiority_trial(
    outcome="binary",
    p1=0.70,
    p2=0.55,
    delta=0.05
)


Summary of Sample Size Result

Description

Summary of Sample Size Result

Usage

## S3 method for class 'SampleSizeR'
summary(object, ...)

Arguments

object

A SampleSizeR object.

...

Additional arguments.

Value

Object of class summary.SampleSizeR.