Learn R Programming

power4mome (version 0.1.1)

gen_boot: Generate Bootstrap Estimates

Description

Get a list of the output of lavaan::sem() or lmhelprs::many_lm() and generate bootstrap estimates of model parameters.

Usage

gen_boot(
  fit_all,
  R = 100,
  ...,
  iseed = NULL,
  parallel = FALSE,
  progress = FALSE,
  ncores = max(1, parallel::detectCores(logical = FALSE) - 1),
  compute_implied_stats = FALSE
)

Value

A boot_list object, which is a list of the output of manymome::do_boot().

Arguments

fit_all

The output of fit_model() or an object of the class fit_out.

R

The number of replications to generate the bootstrap estimates for each fit output.

...

Optional arguments to be passed to manymome::do_boot() when generating the bootstrap estimates.

iseed

The seed for the random number generator. Default is NULL and the seed is not changed.

parallel

If TRUE, parallel processing will be used to generate bootstrap estimates for the fit outputs. Default is FALSE.

progress

If TRUE, the progress will be displayed. Default is `FALSE.

ncores

The number of CPU cores to use if parallel processing is used.

compute_implied_stats

Whether implied statistics are computed in each bootstrap samples. Usually not needed and so default to FALSE

The role of <code>gen_boot()</code>

This function is used by the all-in-one function power4test(). Users usually do not call this function directly, though developers can use this function to customize the workflow of the power analysis.

Details

The function gen_boot() simply calls manymome::do_boot() on each output of lavaan::sem() or lmhelprs::many_lm() in fit_all. The simulated estimates can then be used to test effects such as indirect effects, usually by functions from the manymome package, such as manymome::indirect_effect().

See Also

See power4test() for the all-in-one function that uses this function.

Examples

Run this code

# Specify the population model

mod <-
"m ~ x
 y ~ m + x"

# Specify the effect sizes (population parameter values)

es <-
"
y ~ m: m
m ~ x: m
y ~ x: n
"

# Generate several simulated datasets

data_all <- sim_data(nrep = 2,
                     model = mod,
                     pop_es = es,
                     n = 50,
                     iseed = 1234)

# Fit the population model to each datasets

fit_all <- fit_model(data_all)

# Generate bootstrap estimates for each replication

boot_all <- gen_boot(fit_all,
                     R = 10,
                     iseed = 4567)
boot_all


Run the code above in your browser using DataLab