Problems with the lme function with nested variables (any(notIntX <- ! apply(X, 2, const))

Asked

Viewed 66 times

0

I’m trying to adjust a mixed effects model in which I have covariables 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

  • Have you tested by clearing empty fields?

  • @lmonferrari there are no empty fields..

1 answer

1


You are not specifying categorical variables in the appropriate way. In nlme:lme they stay out of the formula, in the option random. In the lme4:lmer they go directly in the formula, but bounded by parentheses.

dados <- read.csv2("https://docs.google.com/uc?id=1hKfYpcgAV4gdDPHXv_4EQpiO0Y31_ZVo&export=download")

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)

The operator : is an example, I’m assuming you want the conditional effect. For cross-purpose use /. Check the details for formula in aid of lmer for different specifications.

  • Thank you @Carlos Eduardo Lagosta, however, considering that Varx5 and Varx6 are nested and are of fixed effects, if I consider within the function Andom that it is for random effects would be correct anyway? that is to say random = ~ VarCat | VarX5/VarX6 ,so you say??

  • No, in this case, no. I assumed I wanted to because I converted to factor and used the "|" operator. This text might help you: https://rpsychologist.com/r-guide-longitudinal-lme-lmer#three-level-models

  • Thank you @Carlos Eduardo Lagosta. But I still can’t solve ..

  • If the code runs but the difficulty is with specifying the model, the Cross Validated is best suited to seek help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.