boot.coef.plot: Plot Distribution of Bootstrapped Coefficients

Description Usage Arguments Value See Also Examples

Description

Create histograms of bootstrapped estimates for all coefficients in a model, adding reference lines at values of coefficients from model fit to original data.

Usage

1
boot.coef.plot(coef.matrix, org.coefs, plot.ints = FALSE)

Arguments

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.

Value

List of data frame of all estimates and final plot, faceted by coefficient.

See Also

Uses ggplot2 and dplyr.

Examples

 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')

jenniferthompson/ClusterBootMultinom documentation built on May 19, 2019, 4:03 a.m.