multi.plot.ors: Calculate and plot odds ratios, 95 models

Description Usage Arguments Value See Also Examples

Description

From a matrix of bootstrapped coefficients, calculate and plot odds ratios, 95 and Wald p-values for all coefficients, then plot.

Usage

1
2
3
multi.plot.ors(coef.list, label.data = NULL, remove.vars = NULL,
  round.vars = NULL, round.digits = NULL, out.strings.list,
  delete.row = "none", yval.offset = 0.25)

Arguments

coef.list

List of matrices including coefficients from bootstrapped models (columns = coefficients).

label.data

If desired, data frame with two columns, variable and var.label, containing variable names and strings to use in plot labels, respectively. Default is NULL.

remove.vars

Character vector of variable names to **not** include in calculations/plots. Defaults to NULL (show all variables). Passed to get.or.results.

round.vars

Character vector of variable names whose results should be rounded to something other than two decimal places. Useful for variables with very small changes in odds for one-unit change in variable. Defaults to NULL. Passed to get.or.results.

round.digits

Integer; number of digits to round [round.vars] to. Passed to get.or.results.

out.strings.list

List of character vectors to label outcome comparisons.

delete.row

Row to delete from plots and calculations. Used in situations where models are run twice with different reference levels; in this case, one comparison is redundant (eg, 'B vs. A' is reciprocal of 'A vs. B').

yval.offset

Numeric; amount to offset lines for each outcome level in final plot.

Value

List of 1) or.data, a data frame containing odds ratios, confidence limits, p-values and accompanying information; 2) or.plot, a ggplot2 object which plots ORs and CIs for all variables and outcome comparisons included, adding p-values to axis labels.

See Also

ggplot2.

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

## Calculate and plot odds ratios and CIs, Wald p-values for x2
covariate.ors <- multi.plot.ors(coef.list = list(boot.matrix.a),
                                out.strings = list(c('B vs A', 'C vs A')),
                                remove.vars = 'x1')

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