Create data and plot power curves calculated using functions in power_linear() for a list of formulas/models
Source: R/repeat_power_plot.R
repeat_power_linear.RdEstimate a variance for power approximation using variance_ancova() for each formula
in formula_list on train_data. Then calculate power using the function with name
specified in power_fun across a number of sample sizes ns for an assumed average
treatment effect of ate.
Usage
repeat_power_linear(
ate,
formula_list,
train_data,
power_fun = c("power_gs", "power_nc"),
ns = 10:400,
desired_power = 0.9,
...
)
# S3 method for class 'postcard_rpl'
plot(x, cols = NULL, ...)
# S3 method for class 'postcard_rpl'
summary(object, ...)
# S3 method for class 'summary.postcard_rpl'
print(x, digits = max(3L, getOption("digits") - 3L), ...)Arguments
- ate
Passed to
power_gs()orpower_nc()- formula_list
a named
listof formulas that are element wise passed tovariance_ancova()- train_data
Passed as the
dataargument invariance_ancova()- power_fun
a
characterstring with value"power_gs"or"power_nc", specifying what function in thepower_linear()topic to use- ns
a
numericvector of sample sizes- desired_power
a
numericbetween 0 and 1 indicating the desired power level- ...
Arguments passed to
variance_ancova()andpower_gs()orpower_nc()- x
an object of class
postcard_rplcreated byrepeat_power_linear()- cols
a (potentially named)
charactervector of colors for the different models informula_list- object
an object of class
postcard_rplcreated byrepeat_power_linear()- digits
a
numericwith the number of digits to display when printing.
Value
repeat_power_linear returns an object of class postcard_rpl, which is
just a data.frame with plot and summary methods defined. The plot method
returns a ggplot2 object. The summary method returns an object of class
summary.postcard_rpl with the same structure as described in
repeat_power_marginaleffect().
See also
repeat_power_marginaleffect() for a similar implementation to iterate the
process of approximating power with the power_marginaleffect()
Examples
train_data <- glm_data(
Y ~ 1+1.5*log(W)+2*X,
W = runif(1e3, min = 1, max = 10),
X = rnorm(1e3, sd = 3)
)
rpl <- repeat_power_linear(
ate = 0.5,
formula_list = list("ANCOVA 1 covariate" = Y ~ X, "ANCOVA 2 covariates" = Y ~ W + X),
train_data = train_data)
rpl_nc <- repeat_power_linear(
ate = 0.5,
formula_list = list("ANCOVA 1 covariate" = Y ~ X, "ANCOVA 2 covariates" = Y ~ W + X),
train_data = train_data,
power_fun = "power_nc",
df = 1e3-3,
deflation = 0.95,
margin = -0.2,
r = 2)
if (FALSE) { # \dontrun{
plot(rpl)
plot(rpl_nc)
} # }