jeff-hughes / reghelper

R package with regression helper functions
5 stars 5 forks source link

Simple slopes fails for nlme models when nlme library not imported #21

Open jeff-hughes opened 4 months ago

jeff-hughes commented 4 months ago

Reproducible example:

set.seed(123)
pre_treat <- rnorm(50)
post_treat <- 2 + rnorm(50)
pre_control <- rnorm(50)
post_control <- rnorm(50)
dv <- c(pre_treat, post_treat, pre_control, post_control)

pre_post <- factor(rep(c(rep(0, 50), rep(1, 50)), 2))
condition <- factor(c(rep(0, 100), rep(1, 100)))
id <- c(rep(1:50, 2), rep(51:100, 2))

data <- data.frame(id, condition, pre_post, dv)

model <- nlme::lme(dv ~ condition * pre_post, random=~1|id, data)
slopes <- reghelper::simple_slopes(model)

Code fails with error:

Error in lme.formula(fixed = dv ~ condition * pre_post, data = mdata, : could not find function "lme.formula"

Importing nlme library first with library(nlme) seems to correct the issue.