Comprehensive power analysis and sample size calculation for clinical trial design. Covers the most common clinical trial types with appropriate statistical tests, effect size calculations, and regulatory considerations for clinical research.
Usage
clinicaltrialdesign(
data,
trial_type = "superiority",
outcome_type = "continuous",
test_type = "two_sample_ttest",
calculation_type = "sample_size",
alpha = 0.05,
power = 0.8,
sample_size = 100,
effect_size = 0.5,
mean_difference = 1,
common_sd = 2,
proportion1 = 0.3,
proportion2 = 0.5,
allocation_ratio = 1,
two_sided = TRUE,
continuity_correction = TRUE,
margin = 0.1,
margin_type = "absolute",
dropout_rate = 10,
interim_analyses = 0,
multiple_comparisons = "none",
show_assumptions = TRUE,
show_interpretation = TRUE,
show_sensitivity = TRUE,
show_plots = TRUE,
regulatory_context = "ich"
)Arguments
- data
the data as a data frame (optional for power calculations)
- trial_type
Type of clinical trial design for appropriate power calculations
- outcome_type
Type of primary outcome variable determining appropriate statistical test
- test_type
Statistical test appropriate for the outcome type and study design
- calculation_type
What to calculate - power, sample size, or detectable effect size
- alpha
Significance level (typically 0.05 for superiority, 0.025 for non-inferiority)
- power
Desired statistical power (typically 0.80 or 0.90)
- sample_size
Total sample size for power calculation
- effect_size
Standardized effect size (Cohen's d for continuous outcomes)
- mean_difference
Expected difference in means between groups
- common_sd
Pooled standard deviation for continuous outcomes
- proportion1
Expected proportion in control/reference group
- proportion2
Expected proportion in treatment/experimental group
- allocation_ratio
Ratio of treatment to control group sizes (1 = equal allocation)
- two_sided
Use two-sided statistical test (recommended for most trials)
- continuity_correction
Apply continuity correction for proportion tests
- margin
Non-inferiority or equivalence margin (absolute difference)
- margin_type
Type of margin for non-inferiority/equivalence testing
- dropout_rate
Expected dropout/loss to follow-up rate for sample size inflation
- interim_analyses
Number of planned interim analyses (affects alpha spending)
- multiple_comparisons
Adjustment for multiple testing (when applicable)
- show_assumptions
Display assumptions for the selected statistical test
- show_interpretation
Include clinical interpretation and regulatory considerations
- show_sensitivity
Perform sensitivity analysis across parameter ranges
- show_plots
Generate power/sample size relationship plots
- regulatory_context
Regulatory context for power analysis considerations
Value
A results object containing:
results$instructions | Instructions for clinical trial design and power analysis | ||||
results$design_summary | Summary of trial design parameters and recommendations | ||||
results$power_results | Primary power analysis calculations and results | ||||
results$sample_size_breakdown | Detailed sample size calculations with adjustments | ||||
results$effect_size_analysis | Effect size calculations and clinical significance assessment | ||||
results$assumptions_check | Key assumptions for the selected statistical test | ||||
results$sensitivity_analysis | Power/sample size sensitivity across parameter ranges | ||||
results$regulatory_considerations | Regulatory guidance and compliance considerations | ||||
results$power_curve | Power curves showing relationship between sample size and statistical power | ||||
results$effect_size_plot | Effect size distribution and clinical significance thresholds | ||||
results$sample_size_plot | Sample size requirements across different effect sizes and power levels | ||||
results$clinical_interpretation | Clinical context, interpretation guidelines, and next steps | ||||
results$study_protocol_template | Template sections for study protocol statistical analysis plan |
Tables can be converted to data frames with asDF or as.data.frame. For example:
results$design_summary$asDF
as.data.frame(results$design_summary)
Details
Supports randomized controlled trials (RCTs), equivalence trials, non-inferiority trials, superiority trials, and observational studies with proper power calculations.
Examples
data('your_data')
#> Warning: data set ‘your_data’ not found
clinicaltrialdesign(
trial_type = "superiority",
outcome_type = "continuous",
test_type = "two_sample_ttest",
effect_size = 0.5,
alpha = 0.05,
power = 0.80
)
#>
#> CLINICAL TRIAL DESIGN & POWER ANALYSIS
#>
#> <p style='color: red;'>Analysis Error: 'isVisible' does not exist in
#> this results element
#>
#> Trial Design Summary
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Design Parameter Selected Value Recommendation Rationale
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Trial Design Type superiority Superiority trial - demonstrates new treatment is better Determines statistical approach and regulatory requirements
#> Primary Outcome Type continuous Continuous outcome - use parametric tests if assumptions met Determines appropriate statistical test and effect size measure
#> Statistical Test two_sample_ttest Compare means between two independent groups Standard test for continuous outcomes in RCTs
#> Significance Level (α) 0.05000000 Standard α=0.05 appropriate for superiority trials Balances Type I error risk with study feasibility
#> Statistical Power (1-β) 0.80000000 Adequate power (80-89%) - standard for most trials Higher power reduces risk of missing true effects
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Power Analysis Results
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Parameter Input Value Calculated Value 95% CI Interpretation
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Required Sample Size 256 Large study - high power but requires substantial resources
#> Statistical Power (Input) 0.8 Desired power for sample size calculation
#> Effect Size (Input) 0.5 Expected effect size based on literature or pilot data
#> Significance Level (Input) 0.05 Type I error rate for hypothesis testing
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Sample Size Breakdown
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Sample Size Component Per Group Total Adjustment Factor Rationale
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Base Sample Size 128 / 128 256 1.0000000 Statistical power requirement without adjustments
#> Dropout Adjustment 143 / 143 285 1.1111111 Accounts for 10% expected dropout rate
#> **Final Recommendation** ** 143 / 143 ** **285** 0.8949559 Total sample size including all adjustments
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Effect Size Analysis
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Effect Measure Value Magnitude Clinical Significance Statistical Significance
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Cohen's d 0.5000000 Medium effect Likely clinically meaningful Depends on sample size and alpha level
#> Mean Difference 1.0000000 Raw difference in outcome units Evaluate against minimal clinically important difference Raw effect size for clinical interpretation
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Statistical Assumptions
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Assumption Description Assessment Method Impact if Violated Alternative Tests
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Normality Data should be approximately normally distributed Shapiro-Wilk test, Q-Q plots, histograms Inflated Type I error, reduced power Wilcoxon tests, Bootstrap methods
#> Independence Observations should be independent Study design review, clustering assessment Severely inflated Type I error Mixed-effects models, GEE
#> Equal Variances Groups should have similar variances (two-sample) Levene's test, F-test Type I error inflation Welch's t-test, non-parametric tests
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Sensitivity Analysis
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Parameter Low Value Base Value High Value Impact Assessment
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Effect Size 0.37500000 0.50000000 0.6250000 25% change in effect size significantly impacts power/sample size
#> Statistical Power 0.70000000 0.80000000 0.9000000 10% power change moderately impacts required sample size
#> Significance Level 0.02500000 0.05000000 0.1000000 More stringent alpha increases required sample size
#> Dropout Rate (%) 5% 10% 20% Higher dropout rates require substantial sample size inflation
#> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> Regulatory Considerations
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Regulatory Aspect Requirement/Guideline Compliance Status Recommendation Reference
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> Statistical Power ≥80% power recommended, ≥90% for pivotal trials Compliant Consider increasing power for regulatory submission FDA Statistical Guidance (2018)
#> Multiple Testing Control family-wise error rate for multiple endpoints Needs Attention Implement appropriate multiplicity adjustments FDA Multiple Endpoints Guidance (2017)
#> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>
#>
#> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
#>
#> Clinical Trial Design - Interpretation & Guidelines
#>
#> Study Design Summary
#>
#> Trial Type: superiority trial with continuous primary outcome
#>
#> Statistical Approach: two_sample_ttest with α=0.05 and power=0.8
#>
#> Sample Size Interpretation
#>
#> The calculated sample size ensures adequate statistical power to
#> detect clinically meaningful differences. Consider the following
#> factors in your interpretation:
#>
#> Effect Size: Based on Cohen's d - ensure this represents a clinically
#> meaningful changeFeasibility: Assess recruitment capacity and timeline
#> constraintsDropout Adjustment: 10% dropout rate assumed - monitor
#> closely during studyInterim Analyses: No interim analyses planned -
#> consider for long studies
#>
#> Clinical Significance
#>
#> Minimal Clinically Important Difference (MCID): Ensure your effect
#> size aligns with established MCID values from literature. The
#> statistical significance should be accompanied by clinical relevance
#> assessment.
#>
#> Regulatory Considerations
#>
#> Regulatory Context: ich guidelines considered
#>
#> Ensure pre-specification of all analyses in protocolConsider
#> regulatory precedent for similar indicationsPlan for sensitivity
#> analyses and robustness assessments
#>
#> Study Conduct Recommendations
#>
#> Randomization: Use appropriate randomization scheme (stratified,
#> blocked, adaptive)Blinding: Implement double-blinding when feasible
#> for outcome assessmentData Monitoring: Establish independent DSMB for
#> safety and efficacy monitoringQuality Assurance: Plan for data quality
#> monitoring and source data verificationAnalysis Plan: Develop detailed
#> statistical analysis plan before database lock
#>
#> Next Steps
#>
#> Validate sample size assumptions with pilot data or literature
#> reviewDevelop comprehensive study protocol with statistical analysis
#> planConsider adaptive design elements if appropriatePlan for
#> regulatory interactions (pre-IND, Type C meetings)Establish study
#> infrastructure and monitoring procedures
#>
#> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
#>
#> Study Protocol - Statistical Analysis Plan Template
#>
#> 9. STATISTICAL CONSIDERATIONS
#>
#> 9.1 Study Design
#>
#> This is a superiority trial designed to evaluate [intervention]
#> compared to [control] with respect to [primary outcome]. The study
#> follows a randomized, controlled design with 1:1 randomization.
#>
#> 9.2 Sample Size Calculation
#>
#> Primary Outcome: continuous outcome analyzed using two_sample_ttest
#>
#> Statistical Parameters:
#>
#> Type I error rate (α): 0.05Statistical power (1-β): 0.8Effect size:
#> Cohen's d = 0.5Two-sided testing: Yes
#>
#> Sample Size Justification: Based on [literature/pilot data reference],
#> we expect [effect size rationale]. With the specified parameters, the
#> calculated sample size provides adequate power to detect clinically
#> meaningful differences.
#>
#> 9.3 Randomization and Blinding
#>
#> [Describe randomization scheme, stratification factors, and blinding
#> procedures]
#>
#> 9.4 Statistical Analysis Plan
#>
#> Primary Analysis: two_sample_ttest will be used to compare [outcome]
#> between treatment groups. Analysis will follow the intention-to-treat
#> principle.
#>
#> Secondary Analyses:
#>
#> Per-protocol analysis for sensitivity assessmentSubgroup analyses for
#> [specify subgroups]Safety analyses (all randomized subjects)
#>
#> 9.6 Missing Data
#>
#> Missing data will be minimized through [specify procedures]. For
#> primary analysis, [specify approach - complete case, multiple
#> imputation, etc.]. Sensitivity analyses will assess robustness to
#> missing data assumptions.
#>
#> 9.7 Multiple Testing
#>
#> No adjustment for multiple testing planned for primary endpoint.
#> Secondary endpoints will be considered exploratory.
#> Error: no render function