| 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.2 |
| Built: | 2026-07-10 23:42:42 UTC |
| Source: | https://github.com/cran/ggpower |
Helpers used by the GUI effect-size drawer and by scripting workflows.
effect_size_d(mean_h1, mean_h0 = 0, sd) effect_size_f(eta2) effect_size_f2(r2) effect_size_f2_increase(r2_full, r2_reduced) effect_size_h(p1, p2) effect_size_q(r1, r2) effect_size_w(p0, p1) eta2_from_f(f) odds_ratio_from_probs(p0, p1) r2_from_f2(f2)effect_size_d(mean_h1, mean_h0 = 0, sd) effect_size_f(eta2) effect_size_f2(r2) effect_size_f2_increase(r2_full, r2_reduced) effect_size_h(p1, p2) effect_size_q(r1, r2) effect_size_w(p0, p1) eta2_from_f(f) odds_ratio_from_probs(p0, p1) r2_from_f2(f2)
mean_h1, mean_h0
|
Means used to compute Cohen's d. |
sd |
Common standard deviation. |
eta2 |
Eta-squared value. |
r2, r2_full, r2_reduced
|
R-squared values; |
p0, p1, p2
|
Probabilities or probability vectors. |
r1 |
First correlation in |
f, f2
|
Cohen effect-size values. |
A numeric effect-size or converted variance-explained value.
Renders metric cards, input/output blocks, and notes for the Shiny app.
format_result_html(x)format_result_html(x)
x |
A |
A shiny.tag list suitable 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. |
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))
Lists the tests available to power_compute().
ggpower_tests(domain = NULL, module = NULL)ggpower_tests(domain = NULL, module = NULL)
domain |
Optional character vector to filter by domain ( |
module |
Optional character vector to filter by app module ( |
A data frame describing tests available to power_compute().
ggpower_tests() ggpower_tests(module = "biomarker")ggpower_tests() ggpower_tests(module = "biomarker")
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. |
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))
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. |
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. |
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)
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 |
A Shiny application object (class "shiny.appobj"), returned invisibly.
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.