grabModelEstimates: Wrangle important information from fitted models

Description Usage Arguments Details Value Examples

View source: R/grabModelEstimates.R

Description

This function selects the estimated coefficients from each model, and the estimated variance component from the clogit model object. It then attempts to match the coefficients, if possible, and throws errors if not.

Usage

1
grabModelEstimates(fitted_model_clogit, fitted_model_glmm)

Arguments

fitted_model_clogit

A fitted conditional logistic model object, from clogit.

fitted_model_glmm

A fitted generalized linear (logistic) mixed model object, from glmer.

Details

It is important to use the same coefficient names in the model formulas for both models. It is required that the coefficients names in the clogit model are a subset of those from the glmm. Future versions may have improved matching functionality without this requirement.

Value

A list including the estimated components from the clogit model object, the estimated coefficients from the glmer model object, and a vector of indices to match the coefficient names between the models.

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
library(glmerGOF)
set.seed(1)
n <- 50
m <- 4
beta <- c(2, 2)
id <- rep(1:n, each=m)
x <- rnorm(m*n)
b <- rep(rnorm(n), each=m)
y <- rbinom(m*n, 1, plogis(cbind(1, x) %*% beta + b))
my_data <- data.frame(y,x,id)

variable_names <- list(DV = "y", grouping = "id")

library(lme4)
fit_glmm <- lme4::glmer(
  formula = y ~ x + (1|id),
  family = "binomial",
  data = my_data
)
library(survival)
fit_clogit <- survival::clogit(
  formula = y ~ x + strata(id),
  data = my_data,
  method = "exact"
)

model_ests <- grabModelEstimates(
  fitted_model_clogit = fit_clogit,
  fitted_model_glmm = fit_glmm
)
names(model_ests)

BarkleyBG/glmerGOF documentation built on July 18, 2019, 6:43 p.m.