calc_nb_ratioci: Calculate incidence rate ratio and confidence limits from a...

Description Usage Arguments Details Value Methods (by class) See Also Examples

View source: R/calc_nb_ratioci.R

Description

The most common way to express incidence rate ratios is simply exp(beta), representing a one-unit increase in the covariate value; however, in the case of continuous covariates, this is often not a practically meaningful difference (one year of age among adults, eg, or a one-unit change in mean arterial pressure). This function allows you to specify a clinically meaningful comparison in the case of continuous covariates, defaulting to the 75th vs the 25th percentiles of values in the data frame specified.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
calc_nb_ratioci(nbObj = NULL, ...)

## Default S3 method:
calc_nb_ratioci(nbObj = NULL, nbCoefs, nbVcov, predVar,
  adjustTo = NULL, df, alpha = 0.05)

## S3 method for class 'mira'
calc_nb_ratioci(nbObj, predVar, adjustTo = NULL, df,
  alpha = 0.05)

## S3 method for class 'negbin'
calc_nb_ratioci(nbObj, predVar, adjustTo = NULL, df,
  alpha = 0.05)

Arguments

nbObj

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

nbCoefs

Vector of coefficients from a glm.nb.

nbVcov

Variance-covariance matrix from a glm.nb fit.

predVar

Character string; name of main predictor variable.

adjustTo

Numeric vector of length 2; values to adjust predVar to if predVar is continuous. Defaults to c(25th, 75th percentiles).

df

Data frame used to determine type of predVar, get defaults for adjustTo and to calculate nonlinear terms if applicable.

alpha

Alpha level for confidence limits. Defaults to 0.05.

Details

Currently does not handle interaction terms.

Value

matrix with one row per comparison, containing columns for point estimate, confidence limits, and reference and comparison levels used.

Methods (by class)

See Also

glm.nb; mice, pool; rcspline.eval for nonlinear terms.

glm.nb; rcspline.eval for nonlinear terms.

glm.nb; mice rcspline.eval for nonlinear terms.

glm.nb; rcspline.eval for nonlinear terms.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## 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)

calc_nb_ratioci(mymod, predVar = 'v1', df = df)


## 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)
mycoefs <- coef(mymod)
myvcov <- vcov(mymod)

calc_nb_ratioci(nbCoefs = mycoefs, nbVcov = myvcov, predVar = 'v1', df = df)


## Create data frame
df <- data.frame(y = round(rexp(n = 100, rate = 0.5)),
                 v1 = sample(c(1:5, NA), size = 100, replace = TRUE),
                 v2 = rnorm(n = 100))

## Impute missing data using mice
mids.df <- mice(df)

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

calc_nb_ratioci(mymod, predVar = 'v1', df = df)


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

calc_nb_ratioci(mymod, predVar = 'v1', df = df)

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