A Multi-Design Sample Size Calculator for Public Health Research
A fully functional, modular, and extensible R Shiny application that calculates sample sizes for different study designs using established statistical formulas used in public health research, DHS-type surveys, and clinical studies.
Try it now: https://mnakjp-steven-nanga.shinyapps.io/SampleSizeR/
- Epidemiologists designing cross-sectional or cohort studies
- Biostatisticians computing sample sizes for grant proposals
- DHS/MICS analysts planning multi-stage cluster surveys
- Clinical researchers designing RCTs and case-control studies
- Public health students learning sample size methodology
| Category | Details |
|---|---|
| 10 Study Designs | Single Proportion, Two Proportions, Mean Estimation, Two Means, Case-Control, Cohort, Cluster Sampling, Finite Population Correction, DHS Survey, Power Analysis |
| Reactive Calculations | Results update instantly as parameters change |
| Step-by-Step Explanations | Every calculation displays the formula and detailed derivation steps |
| Sensitivity Analysis | Interactive plots with current-value markers showing how sample size responds to parameter changes |
| Plain-Language Interpretation | Each result includes a human-readable explanation tailored to the study design |
| Preset Scenarios | Quick-load common epidemiological scenarios (DHS Vaccination Coverage, HIV Prevalence, RCT Drug vs Placebo, etc.) |
| Cross-Design Comparison | Side-by-side bar chart and table comparing results across all active designs |
| Calculation History | Session log of all calculations with timestamps |
| Export | Download structured CSV or generate HTML reports with full methodology documentation |
| Tooltips | Info icons on every parameter with contextual statistical explanations |
| DHS Survey Mode | Specialized multi-stage calculator combining cluster sampling, DEFF, FPC, and non-response adjustments |
Visit the live app:
# 1. Install dependencies
install.packages(c("shiny", "shinydashboard", "ggplot2", "dplyr", "DT",
"scales", "rmarkdown", "knitr"))
# 2. Clone and run
shiny::runGitHub("SampleSizeR", "mnakjp-steven-nanga")Or clone the repo manually:
git clone https://github.com/mnakjp-steven-nanga/SampleSizeR.gitshiny::runApp("SampleSizeR")SampleSizeR/
├── global.R # Package loading, module sourcing, design registry
├── ui.R # Dashboard UI layout (shinydashboard)
├── server.R # Server logic, output wiring, downloads
├── helpers/
│ ├── formulas.R # All sample size calculation formulas (11 functions)
│ └── utils.R # Validation, formatting, tooltips, presets, interpretation
├── modules/
│ ├── mod_single_proportion.R # Cross-sectional study
│ ├── mod_two_proportions.R # Comparative / RCT
│ ├── mod_mean_estimation.R # Single mean estimation
│ ├── mod_two_means.R # Independent samples comparison
│ ├── mod_case_control.R # Case-control with OR calculation
│ ├── mod_cohort.R # Cohort study with RR calculation
│ ├── mod_cluster_sampling.R # Cluster design with DEFF/ICC
│ ├── mod_finite_population.R # FPC with multiple base methods
│ ├── mod_dhs_survey.R # Full DHS/MICS-style survey
│ └── mod_power_based.R # Power analysis
├── www/
│ └── custom.css # Custom styling (Material-inspired theme)
├── report_template.Rmd # R Markdown template for HTML reports
├── LICENSE # MIT License
└── README.md
SampleSizeR uses a registry-driven architecture that makes it trivial to add new study designs:
design_registry (global.R)
│
├──► ui.R reads the registry → auto-generates sidebar items, tab panels,
│ value boxes, plots, tables, export buttons
│
└──► server.R reads the registry → auto-wires module servers, renders
outputs, handles downloads, logs history
Each module follows a consistent contract:
- UI function:
mod_<name>_ui(id)returns atagListof input widgets - Server function:
mod_<name>_server(id)returnslist(result = reactive(...), sensitivity = reactive(...))
Adding a new design requires zero changes to ui.R or server.R.
-
Add the formula to
helpers/formulas.R:calc_new_design <- function(confidence, ...) { z <- get_z_value(confidence) n <- # ... your formula ... list( n = ceiling(n), formula = "$$n = ...$$", steps = c("Step 1: ...", "Step 2: ..."), params = list(confidence = confidence, ...) ) }
-
Create a module in
modules/mod_new_design.R:mod_new_design_ui <- function(id) { ns <- NS(id) tagList( # ... input widgets using ns() for namespacing ... ) } mod_new_design_server <- function(id) { moduleServer(id, function(input, output, session) { result <- reactive({ ... }) sensitivity <- reactive({ ... }) list(result = result, sensitivity = sensitivity) }) }
-
Register in
global.R:design_registry$new_design <- list( label = "New Design", desc = "Description", icon = "icon-name", ui_func = mod_new_design_ui, srv_func = mod_new_design_server )
-
Source the module in
global.R:source("modules/mod_new_design.R") -
Add a sidebar entry in
ui.R(optional — the tab itself is auto-generated).
The UI tab, value boxes, interpretation, sensitivity plots, parameter table, export buttons, history logging, and comparison chart are all auto-wired from the registry.
Add entries to the presets list in helpers/utils.R:
presets$new_design <- list(
"Custom" = list(),
"Scenario Name" = list(confidence = 0.95, param1 = value1, ...)
)- Cochran, W.G. (1977). Sampling Techniques, 3rd Edition. Wiley.
- Kelsey, J.L., Whittemore, A.S., Evans, A.S., & Thompson, W.D. (1996). Methods in Observational Epidemiology, 2nd Edition. Oxford University Press.
- ICF International. DHS Survey Design Manual. The DHS Program.
- Lwanga, S.K. & Lemeshow, S. (1991). Sample Size Determination in Health Studies: A Practical Manual. WHO.
- Fleiss, J.L., Levin, B., & Paik, M.C. (2003). Statistical Methods for Rates and Proportions, 3rd Edition. Wiley.
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-design) - Add your formula, module, and registry entry following the patterns above
- Test locally with
shiny::runApp() - Submit a pull request
Please ensure all formulas include proper citations and step-by-step documentation.
This project is licensed under the MIT License — see the LICENSE file for details.
You are free to use, modify, and distribute this software for any purpose, including commercial use.
Disclaimer: This tool is intended for planning purposes. Final sample size decisions should be reviewed by a qualified biostatistician and account for practical field considerations.
Built with R Shiny • Designed for epidemiologists, biostatisticians, and DHS analysts
Launch App •
Formulas •
Extend •
Contribute