Description Usage Arguments Value See Also Examples
Create histograms of bootstrapped estimates for all coefficients in a model, adding reference lines at values of coefficients from model fit to original data.
1 | boot.coef.plot(coef.matrix, org.coefs, plot.ints = FALSE)
|
coef.matrix |
Matrix of bootstrapped coefficients (rows = data sets, columns = coefficients). |
org.coefs |
Numeric vector to plot as reference, usually coefficients from model fit on original data. |
plot.ints |
Whether to plot intercept terms. Defaults to FALSE. |
List of data frame of all estimates and final plot, faceted by coefficient.
Uses ggplot2 and dplyr.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ## Create data frame
df <- data.frame(id = sample(1:20, size = 100, replace = TRUE),
x1 = rnorm(n = 100),
x2 = rbinom(p = 0.75, n = 100, size = 1),
y = sample(LETTERS[1:3], size = 100, replace = TRUE))
df <- df[order(df$id),]
df$time <- unlist(lapply(1:length(unique(df$id)),
FUN = function(idnum){ 1:nrow(df[df$id == unique(df$id)[idnum],]) }))
## Using create.sampdata(), generate list of cluster bootstrapped data sets
bootdata.list <- create.sampdata(org.data = df,
id.var = 'id',
n.sets = 25)
## Fit model to original and bootstrapped data frame, saving errors and warnings to .txt file
boot.fits.a <- multi.bootstrap(org.data = df,
data.sets = bootdata.list,
ref.outcome = grep('A', levels(df$y)),
multi.form = as.formula('y ~ x1 + x2'))
## Create matrices of coefficients for all bootstrap fits
boot.matrix.a <- do.call(rbind,
lapply(boot.fits.a$boot.models,
FUN = function(x){ x@coefficients }))
## Check distribution of bootstrapped estimates
coefplot.a <- boot.coef.plot(coef.matrix = boot.matrix.a,
org.coefs = boot.fits.a$org.model@coefficients,
plot.ints = FALSE)
coefplot.a$coef.plot + ggplot2::ggtitle('Reference = A')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.