calc_nb_counts: Calculate predicted value and standard error of a negative...

Description Usage Arguments Value See Also Examples

View source: R/calc_nb_counts.R

Description

Calculate predicted value and standard error of a negative binomial regression model for each row in a design matrix.

Usage

1
calc_nb_counts(nbObj, designMatrix, predVar = NULL, intVar = NULL)

Arguments

nbObj

Model fit of class glm.nb, or mice::mira object fit using glm.nb.

designMatrix

Matrix of covariate values. Number of columns = number of coefficients in nbObj.

predVar

Character string; name of main predictor variable. Defaults to NULL, in which case predictor variable values will not be included in resulting data.frame.

intVar

Character string (optional); name of interacting variable. Defaults to NULL. If included, nothing changes except this column in designMatrix will also be included in the returned data.frame.

Value

data.frame containing columns for main predictor variable; interacting variable (if given); linear predictor and its SE; adjusted count and its lower and upper confidence limits.

See Also

glm.nb; is.mice, pool.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Create data frame
df <- data.frame(y = round(rexp(n = 100, rate = 0.5)),
                 v1 = sample(1:5, size = 100, replace = TRUE),
                 v2 = rnorm(n = 100))

## Fit negative binomial model
mymod <- MASS::glm.nb(y ~ v1 * v2, data = df)

## Create design matrix
mydmat <- matrix(c(rep(1, 5), 1:5, rep(median(df$v2), 5)), ncol = 3)
mydmat <- cbind(mydmat, mydmat[,2] * mydmat[,3])
colnames(mydmat) <- c('(Intercept)', 'v1', 'v2', 'v1:v2')

calc_nb_counts(mymod, designMatrix = mydmat, predVar = 'v1', intVar = 'v2')

jenniferthompson/JTHelpers documentation built on May 19, 2019, 4:04 a.m.