0

I'm trying to fit a mixed-effects model in which I have covariates that are nested (VarX5 | VarX6) and are considered fixed effects.

However, I am trying to adjust the data and the following message appears:

library(nlme)
library(lme4)

dados$VarCat=as.factor(dados$VarCat)
dados$VarX5=as.factor(dados$VarX5)
dados$VarX6=as.factor(dados$VarX6)

model <- lme(log(Resp)~log(VarX1)+log(VarX2)+(VarX3)+(VarX4)+VarX5|VarX6 ,random = ~1|VarCat, 
                 dados, method="REML")

Error in if (any(notIntX <- !apply(X, 2, const))) { : 
  valor ausente onde TRUE/FALSE necessário

user55546
  • 37
  • 1
  • 15

1 Answers1

0

You're not specifying the categorical variables properly. In nlme:lme they go in the random option (the error is for trying to pass factors direct into the formula). In lme4: lmer they are enclosed in parentheses inside the formula.

model <- nlme::lme(
  log(Resp) ~ log(VarX1) + log(VarX2) + VarX3 + VarX4,
  random = ~ VarCat | VarX5:VarX6,
  data = dados)

model <- lme4::lmer(
  log(Resp) ~ log(VarX1) + log(VarX2) + VarX3 + VarX4 + (VarCat | VarX5:VarX6),
  data = dados)

I don't know what you want with the model, so maybe the : operator is not the most appropriate. Check the details for the formula parameter in the lmer help page.

user55546
  • 37
  • 1
  • 15