tidymodels / multilevelmod

Parsnip wrappers for mixed-level and hierarchical models
https://multilevelmod.tidymodels.org/
Other
74 stars 3 forks source link

Add glmer engine for linear regression #40

Closed a-difabio closed 2 years ago

a-difabio commented 2 years ago

The glmer engine was available only for logistic regression, this PR adds it as an engine for linear_reg(). I tried to follow the code already present for the lmer engine as an example.

topepo commented 2 years ago

Thanks! It looks fine but we'll have to write in the engine docs that people might expect to get a warning:

library(tidymodels)
library(multilevelmod)

tidymodels_prefer()
theme_set(theme_bw())

data(sleepstudy, package = "lme4")

lmer_spec <- 
  linear_reg() %>% 
  set_engine("glmer")

lmer_fit <- 
  lmer_spec %>% 
  fit(Reaction ~ Days + (1|Subject), data = sleepstudy)
#> Warning in lme4::glmer(formula = Reaction ~ Days + (1 | Subject), data = data, :
#> calling glmer() with family=gaussian (identity link) as a shortcut to lmer() is
#> deprecated; please call lmer() directly

lmer_fit
#> parsnip model object
#> 
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Reaction ~ Days + (1 | Subject)
#>    Data: data
#> REML criterion at convergence: 1786.465
#> Random effects:
#>  Groups   Name        Std.Dev.
#>  Subject  (Intercept) 37.12   
#>  Residual             30.99   
#> Number of obs: 180, groups:  Subject, 18
#> Fixed Effects:
#> (Intercept)         Days  
#>      251.41        10.47

Created on 2022-06-16 by the reprex package (v2.0.1)

github-actions[bot] commented 2 years ago

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.