The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Getting Started with SampleSizeR

Introduction

SampleSizeR provides functions for sample size determination in epidemiological, clinical, and diagnostic studies. The package provides a consistent interface and returns standardized SampleSizeR objects.

Prevalence Study

The required sample size for estimating a prevalence of 20% with an absolute precision of 5% can be calculated as follows:

ss_prevalence(
  prevalence = 0.20,
  precision = 0.05
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Cross-sectional Prevalence Study
## Method                 : Cochran (1977)
## Required Sample Size   : 246
## 
## Parameters
## -----------------------------------------
## Prevalence             : 0.2
## Precision              : 0.05
## ConfidenceLevel        : 0.95
## Z                      : 1.96
## InitialSampleSize      : 246
## FPCAdjusted            : 246
## DesignAdjusted         : 246
## ResponseAdjusted       : 246
## FinalSampleSize        : 246
## 
## Assumptions
## -----------------------------------------
## Formula                : Cochran (1977)
## ConfidenceLevel        : 0.95
## DesignEffect           : 1
## ResponseRate           : 1
## Dropout                : 0
## FinitePopulation       : Not Applied

Cohort Study

For a cohort study with a baseline risk of 10% and a risk ratio of 2:

ss_cohort(
  p0 = 0.10,
  risk.ratio = 2
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Unmatched Cohort Study
## Method                 : Kelsey/Fleiss
## Required Sample Size   : 398
## 
## Parameters
## -----------------------------------------
## RiskRatio              : 2
## RiskUnexposed          : 0.1
## RiskExposed            : 0.2
## Alpha                  : 0.05
## Power                  : 0.8
## Ratio                  : 1
## ZAlpha                 : 1.96
## ZBeta                  : 0.84
## Exposed                : 199
## Unexposed              : 199
## Total                  : 398
## AdjustedExposed        : 199
## AdjustedUnexposed      : 199
## FinalSampleSize        : 398
## 
## Assumptions
## -----------------------------------------
## Formula                : Kelsey/Fleiss Cohort Study
## Alpha                  : 0.05
## Power                  : 0.8
## RiskRatio              : 2
## RiskUnexposed          : 0.1
## RiskExposed            : 0.2
## AllocationRatio        : 1
## Dropout                : 0

Case-Control Study

For an unmatched case-control study designed to detect an odds ratio of 2 when the exposure proportion among controls is 15%:

ss_case_control(
  odds.ratio = 2.0,
  p0 = 0.15,
  alpha = 0.05,
  power = 0.80,
  ratio = 1
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Unmatched Case-Control Study
## Method                 : Kelsey/Fleiss
## Required Sample Size   : 416
## 
## Parameters
## -----------------------------------------
## OddsRatio              : 2
## ExposureControls       : 0.15
## ExposureCases          : 0.26
## Alpha                  : 0.05
## Power                  : 0.8
## Ratio                  : 1
## ZAlpha                 : 1.96
## ZBeta                  : 0.84
## Cases                  : 208
## Controls               : 208
## Total                  : 415
## AdjustedCases          : 208
## AdjustedControls       : 208
## FinalSampleSize        : 416
## 
## Assumptions
## -----------------------------------------
## Formula                : Kelsey/Fleiss Unmatched Case-Control
## Alpha                  : 0.05
## Power                  : 0.8
## OddsRatio              : 2
## ExposurePrevalenceControls : 0.15
## ExposurePrevalenceCases : 0.26
## CaseControlRatio       : 1
## Dropout                : 0

Diagnostic Sensitivity

For a diagnostic test with an anticipated sensitivity of 90%, disease prevalence of 20%, and desired absolute precision of 5%:

ss_diagnostic_sensitivity(
  sensitivity = 0.90,
  prevalence = 0.20,
  precision = 0.05,
  conf.level = 0.95
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Diagnostic Sensitivity
## Method                 : Buderer (1996)
## Required Sample Size   : 692
## 
## Parameters
## -----------------------------------------
## Sensitivity            : 0.9
## Prevalence             : 0.2
## Precision              : 0.05
## ConfidenceLevel        : 0.95
## Alpha                  : 0.05
## Z                      : 1.96
## DiseasedSubjects       : 139
## TotalSubjects          : 692
## ResponseRate           : 1
## Dropout                : 0
## AdjustedDiseasedSubjects : 139
## FinalSampleSize        : 692
## 
## Assumptions
## -----------------------------------------
## StudyType              : Diagnostic Accuracy Study
## Objective              : Estimate Sensitivity
## Method                 : Buderer (1996)
## ConfidenceLevel        : 0.95
## ExpectedSensitivity    : 0.9
## DiseasePrevalence      : 0.2
## Precision              : 0.05
## ResponseRate           : 1
## Dropout                : 0
## FinitePopulationCorrection : FALSE

Diagnostic Specificity

The required sample size for estimating diagnostic specificity can be calculated similarly:

ss_diagnostic_specificity(
  specificity = 0.90,
  prevalence = 0.20,
  precision = 0.05,
  conf.level = 0.95
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Diagnostic Specificity
## Method                 : Buderer (1996)
## Required Sample Size   : 173
## 
## Parameters
## -----------------------------------------
## Specificity            : 0.9
## Prevalence             : 0.2
## Precision              : 0.05
## ConfidenceLevel        : 0.95
## Alpha                  : 0.05
## Z                      : 1.96
## NonDiseasedSubjects    : 139
## TotalSubjects          : 173
## ResponseRate           : 1
## Dropout                : 0
## AdjustedNonDiseasedSubjects : 139
## FinalSampleSize        : 173
## 
## Assumptions
## -----------------------------------------
## StudyType              : Diagnostic Accuracy Study
## Objective              : Estimate Specificity
## Method                 : Buderer (1996)
## ConfidenceLevel        : 0.95
## ExpectedSpecificity    : 0.9
## DiseasePrevalence      : 0.2
## Precision              : 0.05
## ResponseRate           : 1
## Dropout                : 0
## FinitePopulationCorrection : FALSE

ROC AUC

A precision-based sample size calculation for an anticipated ROC AUC of 0.80 can be performed as follows:

ss_diagnostic_auc(
  auc = 0.80,
  prevalence = 0.20,
  precision = 0.05,
  design = "precision",
  method = "obuchowski"
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Diagnostic ROC AUC
## Method                 : Obuchowski - Precision
## Required Sample Size   : 2
## 
## Parameters
## -----------------------------------------
## Design                 : precision
## Method                 : obuchowski
## AUC                    : 0.8
## NullAUC                : 0.5
## Alpha                  : 0.05
## Power                  : 0.8
## Ratio                  : 1
## Prevalence             : 0.2
## Alternative            : two.sided
## ZAlpha                 : 1.96
## ZBeta                  : 0.84
## ResponseRate           : 1
## Dropout                : 0
## DiseasedSubjects       : 1
## NonDiseasedSubjects    : 1
## AdjustedDiseasedSubjects : 1
## AdjustedNonDiseasedSubjects : 1
## FinalSampleSize        : 2
## 
## Assumptions
## -----------------------------------------
## StudyType              : Diagnostic Accuracy Study
## Objective              : Estimate ROC Area Under the Curve
## Method                 : Obuchowski
## Design                 : precision
## Alternative            : two.sided
## ExpectedAUC            : 0.8
## NullAUC                : NA
## DiseasePrevalence      : 0.2
## AllocationRatio        : 1
## ConfidenceLevel        : 0.95
## Alpha                  : 0.05
## Power                  : 0.8
## Precision              : 0.05
## ResponseRate           : 1
## Dropout                : 0

Diagnostic Agreement

For a diagnostic agreement study, the Pearson method uses a multinomial Pearson goodness-of-fit effect size with a non-central chi-square approximation.

ss_diagnostic_agreement(
  kappa1 = 0.70,
  kappa0 = 0.40,
  prevalence = 0.50,
  alpha = 0.05,
  power = 0.80,
  method = "pearson"
)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Diagnostic Agreement Study
## Method                 : Pearson Goodness-of-Fit
## Required Sample Size   : 74
## 
## Parameters
## -----------------------------------------
## Method                 : Pearson Goodness-of-Fit
## Kappa0                 : 0.4
## Kappa1                 : 0.7
## Prevalence             : 0.5
## Alpha                  : 0.05
## Power                  : 0.8
## Delta                  : 0.11
## Lambda                 : 7.85
## ResponseRate           : 1
## Dropout                : 0
## Diseased               : 37
## NonDiseased            : 37
## Total                  : 74
## 
## Assumptions
## -----------------------------------------

Working with Results

Functions in SampleSizeR return objects of class SampleSizeR. Standard S3 methods can therefore be used to inspect and manipulate results.

result <- ss_prevalence(
  prevalence = 0.20,
  precision = 0.05
)

print(result)
## 
## =========================================
##             SampleSizeR
## =========================================
## 
## Study Design           : Cross-sectional Prevalence Study
## Method                 : Cochran (1977)
## Required Sample Size   : 246
## 
## Parameters
## -----------------------------------------
## Prevalence             : 0.2
## Precision              : 0.05
## ConfidenceLevel        : 0.95
## Z                      : 1.96
## InitialSampleSize      : 246
## FPCAdjusted            : 246
## DesignAdjusted         : 246
## ResponseAdjusted       : 246
## FinalSampleSize        : 246
## 
## Assumptions
## -----------------------------------------
## Formula                : Cochran (1977)
## ConfidenceLevel        : 0.95
## DesignEffect           : 1
## ResponseRate           : 1
## Dropout                : 0
## FinitePopulation       : Not Applied
summary(result)
## 
## Summary
## =========================================
## 
## Study Design
## ------------
## Cross-sectional Prevalence Study 
## 
## Method
## ------
## Cochran (1977) 
## 
## Required Sample Size
## --------------------
## 246 
## 
## Parameters
## ----------
## Prevalence           : 0.2
## Precision            : 0.05
## ConfidenceLevel      : 0.95
## Z                    : 1.96
## InitialSampleSize    : 246
## FPCAdjusted          : 246
## DesignAdjusted       : 246
## ResponseAdjusted     : 246
## FinalSampleSize      : 246
## 
## Assumptions
## -----------
## Formula              : Cochran (1977)
## ConfidenceLevel      : 0.95
## DesignEffect         : 1
## ResponseRate         : 1
## Dropout              : 0
## FinitePopulation     : Not Applied
as.data.frame(result)
##                              Study         Method SampleSize
## 1 Cross-sectional Prevalence Study Cochran (1977)        246

A graphical representation can also be produced:

plot(result)

Summary

SampleSizeR provides a unified interface for sample size determination across epidemiological, clinical, and diagnostic study designs. Optional adjustments available across applicable functions include finite population correction, design effects, anticipated response rates, and dropout.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.