SpowerCurve: Draw power curve from simulation functions

View source: R/SpowerCurve.R

SpowerCurveR Documentation

Draw power curve from simulation functions

Description

Draws power curves that either a) estimate the power given a set of varying conditions or b) solves a set of root conditions given fixed values of power. Confidence/prediction intervals are included in the output to reflect the estimate uncertainties, though note that fewer replications/iterations are used compared to Spower as the goal is visualization of competing variable inputs rather than precision of a given input.

Usage

SpowerCurve(
  ...,
  interval = NULL,
  power = NA,
  sig.level = 0.05,
  replications = 2500,
  integer,
  plotCI = TRUE,
  plotly = TRUE,
  parallel = FALSE,
  cl = NULL,
  ncores = parallelly::availableCores(omit = 1L),
  predCI = 0.95,
  predCI.tol = 0.01,
  verbose = TRUE,
  check.interval = FALSE,
  maxiter = 50,
  wait.time = NULL,
  control = list()
)

Arguments

...

first expression input must be identical to ... in Spower, while the remaining named inputs must match the arguments to this expression to indicate which variables should be modified in the resulting power curves. Providing NA values is also supported to solve the missing component

Note that only the first three named arguments will be plotted using the x-y, colour, and facet wrap aesthetics, respectively. However, if necessary the data can be extracted for further visualizations via ggplot_build to provide more customized control

interval

search interval to use when SimSolve is required. Can be a vector of length two to apply the same interval across the varying information or a matrix with two columns to apply intervals on a per-row basis

power

power level to use. If set to NA then the empirical power will be estimated given the fixed ... input; otherwise, can be specified as a vector to solve the missing elements in ...

sig.level

see Spower

replications

see Spower, though set to 2500 instead of 10000

integer

see Spower

plotCI

logical; include confidence/prediction intervals in plots?

plotly

logical; draw the graphic into the interactive plotly interface? If FALSE the ggplot2 object will be returned instead

parallel

see Spower

cl

see Spower

ncores

see Spower

predCI

see Spower

predCI.tol

see Spower

verbose

see Spower

check.interval

see Spower, though is set to FALSE by default instead

maxiter

see Spower, though set to 50 instead of 150

wait.time

see Spower

control

see Spower

Value

a ggplot2 object automatically rendered with plotly for interactivity

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

See Also

Spower

Examples



# estimate power given varying sample sizes
gg <- p_t.test(d=0.2) |> SpowerCurve(n=c(30, 90, 270, 550))

# Output is a ggplot2 (rendered with plotly by default); hence, can be modified
library(ggplot2)
gg + geom_text(aes(label=power), size=5, colour='red', nudge_y=.05) +
  ylab(expression(1-beta)) + theme_grey()

# Increase precision by using 10000 replications. Parallel computations
#   generally recommended in this case to save time
p_t.test(d=0.2) |> SpowerCurve(n=c(30, 90, 270, 550), replications=10000)

# estimate sample sizes given varying power
p_t.test(n=NA, d=0.2) |>
  SpowerCurve(power=c(.2, .4, .6, .8), interval=c(10, 1000))

# get information from last printed graphic instead of saving
gg <- last_plot()
gg + coord_flip() # flip coordinates to put power on y-axis

# estimate power varying d
p_t.test(n=50) |> SpowerCurve(d=seq(.1, 1, by=.2))

# estimate d varying power
p_t.test(n=50, d=NA) |>
  SpowerCurve(power=c(.2, .4, .6, .8), interval=c(.01, 1))


#####

# vary two inputs instead of one (second input uses colour aesthetic)
p_t.test() |> SpowerCurve(n=c(30, 90, 270, 550),
                         d=c(.2, .5, .8))

# extract data for alternative presentations
build <- ggplot_build(last_plot())
build

df <- build$plot$data
head(df)
ggplot(df, aes(n, power, linetype=d)) + geom_line()

# vary three arguments (third uses facet_wrap ... any more than that and
#   you're on your own!)
p_t.test() |> SpowerCurve(n=c(30, 90, 270, 550),
                         d=c(.2, .5, .8),
                         var.equal=c(FALSE, TRUE))




Spower documentation built on April 4, 2025, 5:11 a.m.