View source: R/COMMA_OLS_bootstrap_SE.R
COMMA_OLS_bootstrap_SE | R Documentation |
Estimate Bootstrap Standard Errors using OLS
COMMA_OLS_bootstrap_SE(
parameter_estimates,
sigma_estimate = 1,
n_bootstrap,
n_parallel,
x_matrix,
z_matrix,
c_matrix,
tolerance = 1e-07,
max_em_iterations = 1500,
em_method = "squarem",
random_seed = NULL
)
parameter_estimates |
A column matrix of |
sigma_estimate |
A numeric value specifying the estimated standard deviation. Default is 1. |
n_bootstrap |
A numeric value specifying the number of bootstrap samples to draw. |
n_parallel |
A numeric value specifying the number of parallel cores to run the computation on. |
x_matrix |
A numeric matrix of predictors in the true mediator and outcome mechanisms.
|
z_matrix |
A numeric matrix of covariates in the observation mechanism.
|
c_matrix |
A numeric matrix of covariates in the true mediator and outcome mechanisms.
|
tolerance |
A numeric value specifying when to stop estimation, based on
the difference of subsequent log-likelihood estimates. The default is |
max_em_iterations |
A numeric value specifying when to stop estimation, based on
the difference of subsequent log-likelihood estimates. The default is |
em_method |
A character string specifying which EM algorithm will be applied.
Options are |
random_seed |
A numeric value specifying the random seed to set for bootstrap
sampling. Default is |
COMMA_OLS_bootstrap_SE
returns a list with two elements: 1)
bootstrap_df
and 2) bootstrap_SE
. bootstrap_df
is a data
frame containing COMMA_OLS
output for each bootstrap sample. bootstrap_SE
is a data frame containing bootstrap standard error estimates for each parameter.
set.seed(20240709)
sample_size <- 2000
n_cat <- 2 # Number of categories in the binary mediator
# Data generation settings
x_mu <- 0
x_sigma <- 1
z_shape <- 1
c_shape <- 1
# True parameter values (gamma terms set the misclassification rate)
true_beta <- matrix(c(1, -2, .5), ncol = 1)
true_gamma <- matrix(c(1, 1, -.5, -1.5), nrow = 2, byrow = FALSE)
true_theta <- matrix(c(1, 1.5, -2, 2), ncol = 1)
example_data <- COMMA_data(sample_size, x_mu, x_sigma, z_shape, c_shape,
interaction_indicator = FALSE,
outcome_distribution = "Normal",
true_beta, true_gamma, true_theta)
beta_start <- matrix(rep(1, 3), ncol = 1)
gamma_start <- matrix(rep(1, 4), nrow = 2, ncol = 2)
theta_start <- matrix(rep(1, 4), ncol = 1)
Mstar = example_data[["obs_mediator"]]
outcome = example_data[["outcome"]]
x_matrix = example_data[["x"]]
z_matrix = example_data[["z"]]
c_matrix = example_data[["c"]]
OLS_results <- COMMA_OLS(Mstar, outcome,
x_matrix, z_matrix, c_matrix,
beta_start, gamma_start, theta_start)
OLS_results
OLS_SEs <- COMMA_OLS_bootstrap_SE(OLS_results$Estimates, sigma_estimate = 1,
n_bootstrap = 3,
n_parallel = 1,
x_matrix, z_matrix, c_matrix,
random_seed = 1)
OLS_SEs$bootstrap_SE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.