power_curve | R Documentation |
Estimate the relation between power and a characteristic, such as sample size or population effect size (population value of a model parameter).
power_curve(
object,
formula = NULL,
start = NULL,
lower_bound = NULL,
upper_bound = NULL,
nls_args = list(),
nls_control = list(),
verbose = FALSE,
models = c("nls", "logistic", "lm")
)
## S3 method for class 'power_curve'
print(x, data_used = FALSE, digits = 3, right = FALSE, row.names = FALSE, ...)
object |
An object of the class
|
formula |
A formula of the model
for |
start |
Either a named vector
of the start value(s) of parameter(s)
in |
lower_bound |
Either a named vector
of the lower bound(s) of parameter(s)
in |
upper_bound |
Either a named vector
of the upper bound(s) of parameter(s)
in |
nls_args |
A named list of
arguments to be used when calling
|
nls_control |
A named list of
arguments to be passed the |
verbose |
Logical. Whether messages will be printed when trying different models. |
models |
Models to try. Support
|
x |
A |
data_used |
Logical. Whether the rejection rates data frame used to fit the model is printed. |
digits , right , row.names |
Arguments of the same names used
by the |
... |
For the |
The function power_curve()
retrieves the information
from the output of
power4test_by_n()
or
power4test_by_es()
, and
estimate the power curve: the
relation between the characteristic
varied, sample size for
power4test_by_n()
and the
population effect size for
power4test_by_es()
, and the
rejection rate of the test conducted
by power4test_by_n()
or
power4test_by_es()
. This
rejection rate is the power when the
null hypothesis is false (e.g., the
population value of the effect size
being tested is nonzero).
The model fitted is not intended to
be a precise model for the relation
across a wide range. It is only a
crude estimate based on the limited
number of values of the
characteristic (e.g., sample size)
examined, which can be as small as
four or even smaller. The model is
intended to be
used for only for the range covered,
and for estimating the probable
sample size or effect size with a
desirable level of power. This value
should then be studied by higher
precision through simulation
using functions such as
power4test()
.
These are the models to be tried, in the following order:
One or nonlinear models, to be
fitted by stats::nls()
. If
several models are specified, all
will be fitted and the one with the
smallest deviance will be used.
If all the nonlinear models failed,
for whatever reason, a logistic
regression will be fitted by
stats::glm()
to predict the
binary significant test results.
If the logistic model also failed, for whatever reason, a simple linear regression model will be fitted. Although the power curve is nonlinear across a wide range of, say, sample size, a linear model can still be a good enough approximation for a narrow range of the predictor.
The output can then be plotted to
visualize the power curve, using
the plot
method (plot.power_curve()
)
for the output
of power_curve()
.
This function can be used directly,
but is also used internally by
functions such as x_from_power()
.
It returns a list which is a
power_curve
object, with the
following elements:
fit
: The model fitted, which is the
output of stats::nls()
,
stats::glm()
, or stats::lm()
.
reject_df
: The table of reject
rates and other characteristics,
which is generated by
rejection_rates()
.
predictor
: The predictor or the
power curve, ether "n"
(sample
size) or "es"
(population effect
size).
call
: The call used to run this
function.
The print
method of power_curve
object returns x
invisibly. Called
for its side-effect.
power4test_by_n()
and power4test_by_es()
for the output supported by
power_curve()
, plot.power_curve()
for the plot
method and
predict.power_curve()
for the predict
method of the output
of power_curve()
.
# Specify the population model
model_simple_med <-
"
m ~ x
y ~ m + x
"
# Specify the effect sizes (population parameter values)
model_simple_med_es <-
"
y ~ m: l
m ~ x: m
y ~ x: s
"
# Simulate datasets to check the model
# Set `parallel` to TRUE for faster, usually much faster, analysis
# Set `progress` to TRUE to display the progress of the analysis
sim_only <- power4test(nrep = 10,
model = model_simple_med,
pop_es = model_simple_med_es,
n = 50,
fit_model_args = list(fit_function = "lm"),
do_the_test = FALSE,
iseed = 1234,
parallel = FALSE,
progress = FALSE)
# By n: Do a test for different sample sizes
out1 <- power4test_by_n(sim_only,
nrep = 10,
test_fun = test_parameters,
test_args = list(par = "y~x"),
n = c(25, 50, 100),
by_seed = 1234,
parallel = FALSE,
progress = FALSE)
pout1 <- power_curve(out1)
pout1
plot(pout1)
# By pop_es: Do a test for different population values of a model parameter
out2 <- power4test_by_es(sim_only,
nrep = 10,
test_fun = test_parameters,
test_args = list(par = "y~x"),
pop_es_name = "y ~ x",
pop_es_values = c(0, .3, .5),
by_seed = 1234,
parallel = FALSE,
progress = FALSE)
pout2 <- power_curve(out2)
pout2
plot(pout2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.