I am trying to pass a function effectfrom the effects package along with an object (gl)merModfrom lme4 through a loop lapplyand encounter an error that I do not expect. It seems that the function is effectnot looking for objects inside the loop. What am I doing wrong and how to make the loop work without manually placing a data frame in the workspace?
library(lme4)
library(reshape2)
library(effects)
dat <- data.frame(var = rep(c("A", "B", "C"), 100), treat = rep(c("T1", "T2"),
each = 150), rand = rep(c("B", "C", "A"), 100), value = rep(c(1,0), 150))
lapply(levels(dat$treat), function(k) {
y <- subset(dat, treat == k)
mod <- glmer(value ~ var + (1|rand), data = y, family = binomial)
})
lapply(levels(dat$treat), function(k) {
y <- subset(dat, treat == k)
mod <- glmer(value ~ var + (1|rand), data = y, family = binomial)
effects::effect("var", mod)
})
y <- subset(dat, treat == "T1")
mod <- glmer(value ~ var + (1|rand), data = y, family = binomial)
effects::effect("var", mod)
lapply(levels(dat$treat), function(k) {
y <- subset(dat, treat == k)
mod <- glmer(value ~ var + (1|rand), data = y, family = binomial)
effects::effect("var", mod)
})
source
share