| Title: | Interactive 3D Visualization of p-Value Surfaces |
|---|---|
| Description: | Provides interactive three-dimensional visualization of p-value surfaces for single-sample t-tests. Enables simultaneous exploration of effect size, sample size, and significance level, making the continuous nature of p-values and the moderating effect of sample size visually apparent. Includes both interactive ('rgl', 'plotly') and static (persp()) rendering options. The p-value surface is based on the approach of Infanger and Schmidt-Trucksäss (2019) <doi:10.1002/sim.8293>. |
| Authors: | Ahmet Kutuk [aut, cre] |
| Maintainer: | Ahmet Kutuk <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-10-24 21:08:33 UTC |
| Source: | https://github.com/cran/p3d |
Computes the p-value as a function of effect size (Cohen's d)
for a single, fixed sample size. This is the 2D analogue of
p_surface and is provided for comparison with
existing 2D visualization packages such as pvaluefunctions.
p_curve_2d(d, n, alpha = 0.05)p_curve_2d(d, n, alpha = 0.05)
d |
Numeric vector of effect sizes (Cohen's d). |
n |
Single sample size. Must be >= 2. |
alpha |
Significance level. Default: 0.05. |
The p-value is computed as:
A data frame with columns:
Effect sizes.
Two-sided p-values.
Logical; whether p < alpha.
# 2D curve for n = 30 curve_30 <- p_curve_2d(d = seq(-2, 2, 0.1), n = 30) head(curve_30) # Compare with 3D surface surface <- p_surface(d = seq(-2, 2, 0.1), n = c(10, 30, 100))# 2D curve for n = 30 curve_30 <- p_curve_2d(d = seq(-2, 2, 0.1), n = 30) head(curve_30) # Compare with 3D surface surface <- p_surface(d = seq(-2, 2, 0.1), n = c(10, 30, 100))
Computes the p-value of a single-sample t-test as a function of effect size (Cohen's d) and sample size (n). Returns a grid of p-values suitable for 3D visualization.
p_surface(d, n, alpha = 0.05)p_surface(d, n, alpha = 0.05)
d |
Numeric vector of effect sizes (Cohen's d). Typical range: -2 to 2. |
n |
Numeric vector of sample sizes. Must be >= 2. Typical range: 5 to 200. |
alpha |
Significance level for the critical effect size. Default: 0.05. |
The p-value is computed using the formula:
where is the cumulative distribution function
of the t-distribution with degrees of freedom.
The critical effect size at level is:
A list with the following elements:
The input vector of effect sizes.
The input vector of sample sizes.
A matrix of p-values with dimensions
length(d) x length(n).
A numeric vector of critical effect sizes
for each sample size at level alpha.
The significance level used.
A data frame with the full grid of (d, n, p) combinations.
# Small example result <- p_surface(d = seq(-1, 1, 0.1), n = c(10, 30, 100)) str(result) # Typical use result <- p_surface(d = seq(-2, 2, 0.05), n = seq(5, 200, 5)) image(result$d, result$n, result$p)# Small example result <- p_surface(d = seq(-1, 1, 0.1), n = c(10, 30, 100)) str(result) # Typical use result <- p_surface(d = seq(-2, 2, 0.05), n = seq(5, 200, 5)) image(result$d, result$n, result$p)
Plots the output of p_surface using base R's
persp function. This produces a static
3D perspective plot with no external dependencies, making it
suitable for PDF output, journal figures, and CRAN checks.
plot_p_static( surface, theta = 30, phi = 20, col = "steelblue", shade = TRUE, alpha = 0.05 )plot_p_static( surface, theta = 30, phi = 20, col = "steelblue", shade = TRUE, alpha = 0.05 )
surface |
A list returned by |
theta, phi
|
Viewing angles in degrees. See
|
col |
Color palette for the surface. Either a single
color or a vector of colors matching the number of
|
shade |
Logical; if |
alpha |
Significance level. A horizontal plane at
|
Unlike plot_p_surface, which requires
rgl or plotly, this function uses only base R
graphics. It is ideal for inclusion in static documents
such as PDF articles and printed reports.
Invisibly returns the input surface object.
Called for its side effect (a plot).
# Compute surface surface <- p_surface(d = seq(-2, 2, 0.1), n = seq(5, 200, 5)) # Static perspective plot plot_p_static(surface) # Different viewing angle plot_p_static(surface, theta = 45, phi = 30)# Compute surface surface <- p_surface(d = seq(-2, 2, 0.1), n = seq(5, 200, 5)) # Static perspective plot plot_p_static(surface) # Different viewing angle plot_p_static(surface, theta = 45, phi = 30)
Plots the output of p_surface as an interactive
three-dimensional surface. Two rendering engines are supported:
"rgl" (default, interactive window) and "plotly"
(HTML widget, ideal for R Markdown / Quarto documents).
plot_p_surface( surface, engine = c("rgl", "plotly"), alpha = 0.05, col = NULL, show_boundary = TRUE )plot_p_surface( surface, engine = c("rgl", "plotly"), alpha = 0.05, col = NULL, show_boundary = TRUE )
surface |
A list returned by |
engine |
Character; either |
alpha |
Significance level. A horizontal plane at
|
col |
Color palette for the surface. If |
show_boundary |
Logical; if |
The 3D surface shows the p-value as a function of both
effect size () and sample size (). The
-plane visualizes the conventional significance
threshold. The intersection curve marks the boundary between
"significant" and "non-significant" regions.
For engine = "rgl", the rgl package must be
installed. For engine = "plotly", the plotly
package must be installed. Both are listed in Suggests.
Invisibly returns the input surface object.
Called for its side effect (a plot).
# Compute surface (non-interactive part) surface <- p_surface(d = seq(-2, 2, 0.1), n = seq(5, 200, 5)) str(surface, max.level = 1) # Interactive visualization (only in interactive sessions) if (interactive()) { # rgl engine (interactive window) plot_p_surface(surface) # plotly engine (HTML widget) plot_p_surface(surface, engine = "plotly") }# Compute surface (non-interactive part) surface <- p_surface(d = seq(-2, 2, 0.1), n = seq(5, 200, 5)) str(surface, max.level = 1) # Interactive visualization (only in interactive sessions) if (interactive()) { # rgl engine (interactive window) plot_p_surface(surface) # plotly engine (HTML widget) plot_p_surface(surface, engine = "plotly") }