fit_multinom: Fit multinomial logistic regression model on a single object

Description Usage Arguments Details See Also Examples

Description

This function runs a multinomial logistic regression model on a data.frame or 'mice::mids' object, currently using try_vglm (which runs VGAM::vglm(..., family = multinomial(...)), but if the model fails to converge - ie, warning or error - the warning/error message is returned instead).

Usage

1
fit_multinom(formula, df, ref_level, fitter = try_vglm)

Arguments

formula

formula; see formula for more details.

df

data.frame or mice::mids object on which to run model.

ref_level

numeric (representing factor level) or character; level of outcome variable to use as reference.

fitter

Function to use for model fitting. Currently only option is try_vglm.

Details

This wrapper function is necessary to perform this operation on mids objects, which require a with(..., ) syntax.

See Also

vglm; multinomial for model fitting. mice for imputation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
my_df <- data.frame(
  id = sample(1:50, size = 500, replace = TRUE),
  x1 = sample(c(NA, 1:100), size = 500, replace = TRUE),
  x2 = sample(c(NA, 1:100), size = 500, replace = TRUE),
  y = sample(c(NA, LETTERS[1:3]), size = 500, replace = TRUE)
)

## Works whether df is a data.frame or mice() object
fit_multinom(y ~ x1 + x2, my_df, ref_level = "A")
fit_multinom(y ~ x1 + x2, mice::mice(my_df), ref_level = "A")

jenniferthompson/ClusterMultinom documentation built on May 7, 2019, 8:59 p.m.