This function performs parametric bootstrap simulations by generating new response values based on the fitted model, refitting the model on these new responses, and computing a user-defined statistic for each simulated model.
parametric_bootstrap(
model,
statistic,
nsim,
responses = NULL,
refit_fn = NULL,
show_progress = TRUE,
simplify = TRUE,
stat_hc = NULL,
show_message_count = TRUE,
show_warning_count = TRUE,
show_not_converged_count = TRUE,
...
)
A list containing the following elements:
result
A list of length nsim if simplify
is FALSE
.
Otherwise an atomic vector or matrix or list of length nsim.
responses
The list of simulated response values.
simulation_warning
A logical vector indicating whether a warning occurred during model refitting for each simulation.
converged
A logical vector indicating whether the model refit converged for each simulation.
A fitted model object that will be used to simulate responses.
A function that computes the desired statistic from the refitted model. It must take the refitted model as an argument.
The number of simulations to perform.
An optional list of values to be used as response variables to refit the model.
Function to refit the model with new responses. If NULL
,
defaults to get_refit(model, y, ...)
.
Display a progress bar for the simulation iteration.
logical or character string; should the result be simplified to a vector, matrix or higher dimensional array if possible? If occurs any errors during the refit procedure, the results will be a list, regardless of the value of this argument.
A function that verifies if the computed statistic is correct. It should return nothing, just throw errors to halt execution.
Show total of captured messages from refit_fn
as a message.
It only shows if the number of messages is greater than 0.
Show total of captured warnings from refit_fn
as a warning.
It only shows if the number of warnings is greater than 0.
Show total of models that didn't converge as a warning. It only shows if the number of models that didn't converged is greater than 0.
Additional arguments to be passed to refit_fn
.
This function implements a parametric bootstrap procedure.
It generates new response values from the fitted model, refits
the model for each simulated response, and computes a user-defined statistic on the refitted model.
The refit function can be customized through the refit_fn
argument.
If show_progress
is TRUE
, the progress of the simulations will be
displayed using a progress bar from the cli
package.
model <- lm(mpg ~ wt + hp, data = mtcars)
statistic <- function(model) coef(model)[["wt"]]
bootstrap_results <- parametric_bootstrap(model, statistic, nsim = 100)
wt_coefs <- Reduce(c, bootstrap_results$result)
summary(wt_coefs)
Run the code above in your browser using DataLab