Skip to contents

Estimate conditional effects with generalized linear mixed-effects models. Data must be in long format.

Usage

fit_glmm(data, formula, family)

Examples

# Load repeated measures of adolescent tooth growth (must be of long format)
data <- read.csv("https://raw.githubusercontent.com/alejandroh3005/modelLong/main/data/ortho.csv")[-1]

# Fit a GLMM model of adolescent tooth growth from age and sex
mod_glmm <- modelLong::fit_glmm(
  data = data,
  formula = formula(distance ~ age + Sex + (1 | Subject)),
  family = gaussian)
#> Loading required package: Matrix
#> Warning: calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is deprecated; please call lmer() directly

# Fitted coefficients
coef(mod_glmm$fit)
#> $Subject
#>     (Intercept)       age  SexMale
#> F01    16.44088 0.4263492 2.737311
#> F02    17.96976 0.4263492 2.737311
#> F03    18.53544 0.4263492 2.737311
#> F04    19.46805 0.4263492 2.737311
#> F05    17.64869 0.4263492 2.737311
#> F06    16.19626 0.4263492 2.737311
#> F07    18.06149 0.4263492 2.737311
#> F08    18.15322 0.4263492 2.737311
#> F09    15.81404 0.4263492 2.737311
#> F10    13.39842 0.4263492 2.737311
#> F11    21.37915 0.4263492 2.737311
#> M01    20.36644 0.4263492 2.737311
#> M02    15.82568 0.4263492 2.737311
#> M03    17.43100 0.4263492 2.737311
#> M04    18.47064 0.4263492 2.737311
#> M05    16.39137 0.4263492 2.737311
#> M06    18.66939 0.4263492 2.737311
#> M07    15.71866 0.4263492 2.737311
#> M08    16.19261 0.4263492 2.737311
#> M09    17.55331 0.4263492 2.737311
#> M10    21.91060 0.4263492 2.737311
#> M11    16.13146 0.4263492 2.737311
#> M12    17.03349 0.4263492 2.737311
#> M13    17.59918 0.4263492 2.737311
#> M14    17.09465 0.4263492 2.737311
#> M15    18.74583 0.4263492 2.737311
#> M16    15.68808 0.4263492 2.737311
#> 
#> attr(,"class")
#> [1] "coef.mer"

# Full model
mod_glmm$fit
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: distance ~ age + Sex + (1 | Subject)
#>    Data: data
#> REML criterion at convergence: 648.4082
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Subject  (Intercept) 1.974   
#>  Residual             1.452   
#> Number of obs: 162, groups:  Subject, 27
#> Fixed Effects:
#> (Intercept)          age      SexMale  
#>     17.5514       0.4263       2.7373