1

I am trying to fit a linear growth model (LGM) in R, and I understand that the primary steps would be to fit a Null model with time as a predictor of my independent variable Y (allowing for random effects) and a Null model not allowing for random effects, then compare the two and see whether the random effect is strong enough to justify the usage of the model with random intercept.

I managed to fit the model with random intercept with the lmer function of the lme4 package, but I can't find a function in that package that allows me to fit a model without random intercept.

I have tried to fit models both with random intercept (lme function) and without (gls function) with the nlme package, but neither of them have been working for me.

My original code was:

library(nlme)

LMModel <- lme(Y~Time, random=~Time| ID, data=dataset,  
               method="ML")

and running that, I got an error saying "missing values in object" (apparently referring to my Time variable). I thus added a transformation of my dataset into a matrix with "matr <- as.matrix(dataset)" and added the missing data management part to my code, which ended up being:

LMModel <- lme(Y~Time, random=~Time| ID, data=dataset,   
               method="ML",  na.action = na.exclude(matr))

Running this, I get the error: ' could not find function "1" '

I further tried to fit a model with no random effect with the gls function of nlme and got the exact same error.

I feel quite lost as I can't seem to figure out what that function 1 means. Any ideas of what might be happening here?

Thanks a lot in advance for the help!

Federico

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Federico
  • 11
  • 2
  • You don't need `matr`, exclude the `NA`'s directly from `dataset`. lme(etc, na.action = na.exclude)` is enough. (And `"1"` is the intercept term.) – Rui Barradas Oct 31 '18 at 07:06
  • Just removing the (matr) part of the code solved my problem, the model ran with no error. I'm still confused as to what was going wrong, but I guess I shouldn't care too much..! Thanks a lot Rui! – Federico Oct 31 '18 at 13:01
  • You have a formula, `Y~Time, random=~Time| ID`. And data, `dataset`. The formula's variables are taken from the data. And it is the missing values present in those data that must be excluded. Another unrelated `matr` has nothing to do with any of this. This is valid for all R modeling functions. (As far as I know, there are no exceptions.) – Rui Barradas Oct 31 '18 at 13:21

0 Answers0