| Title: | Publication-Ready Power Analysis and Visualization |
|---|---|
| Description: | Provides statistical power analysis and sample size calculations for t-tests, ANOVA, regression, chi-square, proportion, correlation, nonparametric, biomarker, and clinical trial designs. Includes a scriptable API via power_compute(), publication-ready 'ggplot2' visualizations, and an optional 'Shiny' application. |
| Authors: | Yaoxiang Li [aut, cre] |
| Maintainer: | Yaoxiang Li <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.3 |
| Built: | 2026-09-23 06:24:10 UTC |
| Source: | https://github.com/yaoxiangli/ggpower |
Compute Cohen's d from means and standard deviation
effect_size_d(mean_h1, mean_h0 = 0, sd)effect_size_d(mean_h1, mean_h0 = 0, sd)
mean_h1 |
Mean assumed under H1. |
mean_h0 |
Mean assumed under H0 or comparison group mean. |
sd |
Common standard deviation. |
Numeric effect size d.
Compute Cohen's f from eta-squared
effect_size_f(eta2)effect_size_f(eta2)
eta2 |
Proportion of variance explained. |
Numeric effect size f.
Compute Cohen's f2 from R-squared
effect_size_f2(r2)effect_size_f2(r2)
r2 |
Coefficient of determination. |
Numeric effect size f2.
Compute f2 for an R-squared increase
effect_size_f2_increase(r2_full, r2_reduced)effect_size_f2_increase(r2_full, r2_reduced)
r2_full |
R-squared for the full model. |
r2_reduced |
R-squared for the reduced model. |
Numeric effect size f2.
Compute Cohen's h for two proportions
effect_size_h(p1, p2)effect_size_h(p1, p2)
p1, p2
|
Proportions. |
Numeric h.
Compute Cohen's q for two correlations
effect_size_q(r1, r2)effect_size_q(r1, r2)
r1, r2
|
Correlations to compare. |
Numeric Fisher-z difference q.
Compute chi-square effect size w
effect_size_w(p0, p1)effect_size_w(p0, p1)
p0 |
Probabilities under H0. |
p1 |
Probabilities under H1. |
Numeric effect size w.
Convert Cohen's f to eta-squared
eta2_from_f(f)eta2_from_f(f)
f |
Cohen's f. |
Numeric eta-squared value.
Format a ggpower result as structured HTML for Shiny UI
format_result_html(x)format_result_html(x)
x |
A 'ggpower_result' object. |
A 'shiny.tag' list for 'renderUI'.
Evaluates distribution-function calculator expressions, including helpers such as
zcdf(), tinv(), ncfcdf(), and binocdf().
ggpower_calculator(script)ggpower_calculator(script)
script |
Character calculator script with arithmetic, assignments, comments, and supported distribution helper functions. |
The value of the final expression.
ggpower_calculator("x <- 2^3\nx + zinv(.975)")ggpower_calculator("x <- 2^3\nx + zinv(.975)")
Creates the common result object used by the scriptable API and Shiny GUI.
ggpower_result(test, analysis, inputs, outputs, notes = character(), distribution = list())ggpower_result(test, analysis, inputs, outputs, notes = character(), distribution = list())
test |
Character label for the selected test. |
analysis |
Character label for the selected analysis mode. |
inputs |
Named list of input parameters. |
outputs |
Named list of computed output parameters. |
notes |
Character vector with method notes or assumptions. |
distribution |
Named list describing the H0/H1 distributions. |
An object of class ggpower_result.
This function creates a ggplot2 power curve for a one-sample t test.
ggpower_t_one_sample( d, alpha = 0.05, n_range = seq(20, 100, by = 5), tails = "two" )ggpower_t_one_sample( d, alpha = 0.05, n_range = seq(20, 100, by = 5), tails = "two" )
d |
Numeric. The effect size (d). |
alpha |
Numeric. The significance level (default 0.05). |
n_range |
Numeric vector. A vector of total sample sizes (default is seq(20, 100, by = 5)). |
tails |
Character. '"two"' or '"one"'. |
A ggplot object showing the power curve.
# Plot power curve for d = 0.5 over sample sizes from 20 to 100 ggpower_t_one_sample(d = 0.5, alpha = 0.05, n_range = seq(20, 100, by = 5))# Plot power curve for d = 0.5 over sample sizes from 20 to 100 ggpower_t_one_sample(d = 0.5, alpha = 0.05, n_range = seq(20, 100, by = 5))
List supported statistical power tests
ggpower_tests(domain = NULL, module = NULL)ggpower_tests(domain = NULL, module = NULL)
domain |
Optional character vector to filter by domain ('general', 'biomarker', 'pharma'). |
module |
Optional character vector to filter by app module ('workspace', 'biomarker', 'clinical'). |
A data frame describing tests available to 'power_compute()'.
This function creates a ggplot2 power curve for a two-sample t test.
ggpower_ttest(d, alpha = 0.05, n_range = seq(10, 100, by = 5), tails = "two")ggpower_ttest(d, alpha = 0.05, n_range = seq(10, 100, by = 5), tails = "two")
d |
Numeric. The effect size (Cohen's d). |
alpha |
Numeric. The significance level (default 0.05). |
n_range |
Numeric vector. A vector of sample sizes per group (default is seq(10, 100, by = 5)). |
tails |
Character. '"two"' or '"one"'. |
A ggplot object showing the power curve.
# Create a power curve for d = 0.5 over a range of sample sizes per group ggpower_ttest(d = 0.5, alpha = 0.05, n_range = seq(10, 100, by = 5))# Create a power curve for d = 0.5 over a range of sample sizes per group ggpower_ttest(d = 0.5, alpha = 0.05, n_range = seq(10, 100, by = 5))
Compute odds ratio from two probabilities
odds_ratio_from_probs(p0, p1)odds_ratio_from_probs(p0, p1)
p0 |
Baseline event probability. |
p1 |
Event probability under H1. |
Numeric odds ratio.
Builds a publication-ready distribution overlay for a computed power-analysis result.
plot_distribution(result)plot_distribution(result)
result |
A |
A ggplot object.
result <- power_compute("t_one_sample", "post_hoc", d = 0.5, n = 40) plot_distribution(result)result <- power_compute("t_one_sample", "post_hoc", d = 0.5, n = 40) plot_distribution(result)
Builds a publication-ready power curve for a selected ggpower test.
plot_power_curve(test, n_values, analysis = "post_hoc", ...)plot_power_curve(test, n_values, analysis = "post_hoc", ...)
test |
Character test id. |
n_values |
Numeric vector of total sample sizes. |
analysis |
Power analysis mode used for fixed parameters. |
... |
Test-specific fixed parameters. |
A ggplot object.
plot_power_curve("t_one_sample", n_values = c(20, 30, 40), d = 0.5)plot_power_curve("t_one_sample", n_values = c(20, 30, 40), d = 0.5)
Runs a power analysis using the shared ggpower compute engine. The function supports classical test families and analysis modes.
power_compute(test, analysis = "post_hoc", ...)power_compute(test, analysis = "post_hoc", ...)
test |
Character test id. Use |
analysis |
One of |
... |
Test-specific input parameters. |
A ggpower_result list with components test, analysis,
inputs, outputs, and optional notes and distribution.
The outputs element contains the solved quantities (for example sample
size, power, or effect size depending on the analysis mode). See
ggpower_result.
power_compute("t_one_sample", "a_priori", d = 0.625, alpha = 0.05, power = 0.95, tails = "one")power_compute("t_one_sample", "a_priori", d = 0.625, alpha = 0.05, power = 0.95, tails = "one")
Calculates the power for a one-sample t-test given the effect size (d), total sample size (n), and significance level (alpha).
power_t_one_sample(d, n, alpha = 0.05, tails = "two")power_t_one_sample(d, n, alpha = 0.05, tails = "two")
d |
Numeric. The effect size (difference from the constant divided by sigma). |
n |
Integer. Total sample size. |
alpha |
Numeric. The significance level (default is 0.05). |
tails |
Character. '"two"' for a two-tailed test or '"one"' for a one-tailed test. |
Numeric. The computed power (1 - beta).
# Calculate power for an effect size of 0.5 with n = 40 subjects power_t_one_sample(d = 0.5, n = 40, alpha = 0.05)# Calculate power for an effect size of 0.5 with n = 40 subjects power_t_one_sample(d = 0.5, n = 40, alpha = 0.05)
Computes achieved power for a paired-samples t-test using the noncentral t kernel.
power_t_paired(d, n, alpha = 0.05, tails = "two")power_t_paired(d, n, alpha = 0.05, tails = "two")
d |
Numeric paired-samples effect size dz. |
n |
Integer number of pairs. |
alpha |
Numeric significance level. |
tails |
Character, |
Numeric power.
power_t_paired(d = 0.5, n = 40)power_t_paired(d = 0.5, n = 40)
This function calculates the power for a two-sample t-test when the two groups have equal sample sizes.
power_t_two_sample(d, n_per_group, alpha = 0.05, tails = "two", n2 = NULL)power_t_two_sample(d, n_per_group, alpha = 0.05, tails = "two", n2 = NULL)
d |
Numeric. The effect size (Cohen's d). |
n_per_group |
Integer. The sample size per group. |
alpha |
Numeric. The significance level (default is 0.05). |
tails |
Character. '"two"' for a two-tailed test or '"one"' for a one-tailed test. |
n2 |
Optional second-group sample size. If omitted, equal group sizes are used. |
Numeric. The computed power (1 - beta).
# Compute power for an effect size d = 0.5 with 30 subjects per group power_t_two_sample(d = 0.5, n_per_group = 30)# Compute power for an effect size d = 0.5 with 30 subjects per group power_t_two_sample(d = 0.5, n_per_group = 30)
Convert f2 to R-squared
r2_from_f2(f2)r2_from_f2(f2)
f2 |
Cohen's f2. |
Numeric R-squared value.
Run the Shiny Application
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
onStart |
A function that will be called before the app is actually run.
This is only needed for |
options |
Named options that should be passed to the |
enableBookmarking |
Can be one of |
uiPattern |
A regular expression that will be applied to each |
... |
arguments to pass to golem_opts. See '?golem::get_golem_options' for more details. |
A Shiny application object (class '"shiny.appobj"'). Launch the GUI with 'shiny::runApp(run_app())' or from the development helper described in the package overview.
Exports publication-ready ggpower plots through ggplot2::ggsave().
save_power_plot(plot, filename, width = 7, height = 5, dpi = 320) save_distribution_plot(plot, filename, width = 7, height = 5, dpi = 320)save_power_plot(plot, filename, width = 7, height = 5, dpi = 320) save_distribution_plot(plot, filename, width = 7, height = 5, dpi = 320)
plot |
A ggplot object. |
filename |
Output filename. |
width, height
|
Plot dimensions. |
dpi |
Resolution for raster outputs. |
The filename invisibly.
Provides consistent typography, spacing, and grid styling for ggpower figures.
theme_ggpower(base_size = 12, base_family = "")theme_ggpower(base_size = 12, base_family = "")
base_size |
Base font size. |
base_family |
Base font family. |
A ggplot2 theme.