glmmRefit: Refit mixed effects model

View source: R/glmmRefit.R

glmmRefitR Documentation

Refit mixed effects model

Description

Based on a 'GlmmSeq' or 'lmmSeq' class result object, this function attempts to refit an identical model for a specific gene based on the data and fitting parameters stored in the results object and refitting using either lme4::glmer() for GlmmSeq objects or lmer() for lmmSeq objects. The fitted model can then be passed on to other packages such as emmeans to look at estimated marginal means for the model.

Usage

glmmRefit(object, gene, ...)

## S3 method for class 'lmmSeq'
glmmRefit(object, gene, formula = object@formula, ...)

## S3 method for class 'GlmmSeq'
glmmRefit(
  object,
  gene,
  formula = object@formula,
  control = object@info$control,
  family = NULL,
  ...
)

Arguments

object

A fitted results object of class GlmmSeq or lmmSeq

gene

A character value specifying a single gene to extract a fitted model for

...

Optional arguments passed to either lme4::glmer() or lme4::lmer()

formula

Optional formula to use when refitting model

control

Optional control parameters, see lme4::lmerControl() or lme4::glmerControl()

family

Optional GLM family when refitting GLMM using lme4::glmer() or glmmTMB()

Value

Fitted model of class lmerMod in the case of LMM, or glmerMod or glmmTMB for a GLMM dependent on the original method.

Examples

data(PEAC_minimal_load)
disp <- apply(tpm, 1, function(x) {
  (var(x, na.rm = TRUE)-mean(x, na.rm = TRUE))/(mean(x, na.rm = TRUE)**2)
})
glmmtest <- glmmSeq(~ Timepoint * EULAR_6m + (1 | PATID),
                     countdata = tpm[1:2, ],
                     metadata = metadata,
                     dispersion = disp,
                     verbose = FALSE)

# show summary for single gene
summary(glmmtest, "MS4A1")

# refit a single model using lme4::glmer()
fit <- glmmRefit(glmmtest, "MS4A1")

# refit model with reduced formula
fit2 <- glmmRefit(glmmtest, "MS4A1",
                  formula = count ~ Timepoint + EULAR_6m + (1 | PATID))

# LRT
anova(fit, fit2)


glmmSeq documentation built on Oct. 8, 2022, 5:05 p.m.