0

Until recently I used SPSS for my statistics, but since I am not in University any more, I am changing to R. Things are going well, but I can't seem to replicate the results I obtained for repeated effect LMM in SPSS. I did find some treads here which seemed relevant, but those didn't solve my issues.

This is the SPSS script I am trying to replicate in R

MIXED TriDen_L BY Campaign Watering Heating
  /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1)
  SINGULAR(0.000000000001) HCONVERGE(0,
  ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)
  /FIXED=Campaign Watering Heating Campaign*Watering Campaign*Heating
   Watering*Heating Campaign*Watering*Heating | SSTYPE(3)
  /METHOD=REML
  /PRINT=TESTCOV
  /RANDOM=Genotype | SUBJECT(Plant_id) COVTYPE(AD1)
  /REPEATED=Week | SUBJECT(Plant_id) COVTYPE(AD1)
  /SAVE=PRED RESID

Using the lme4 package in R I have tried:

lmm <- lmer(lnTriNU ~ Campaign + Watering + Heating + Campaign*Watering
       + Campaign*Heating + Watering*Heating + Campaign*Watering*Heating 
       + (1|Genotype) + (1|Week:Plant_id), pg)

But this -and the other options I have tried for the random part- keep producing an error:

Error: number of levels of each grouping factor must be < number of observations

Obviously in SPSS everything is fine. I am suspecting I am not correctly modelling the repeated effect? Also saving predicted and residual values is not yet straightforward for me...

I hope anyone can point me in the right direction.

lmo
  • 37,904
  • 9
  • 56
  • 69
  • 2
    You should provide sample input data to make the problem [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Also, include the output you expect to get from SPSS so the R results can be compared. – MrFlick Apr 27 '16 at 17:52
  • For saving output, see `?save` and `?write.csv`. To access model estimates, take a look at the Values section of `?lmer` as well as `?summary.lmer`. – lmo Apr 27 '16 at 19:15
  • Shouldn't it be `(Week|Plant_id)`? – Roland Apr 27 '16 at 19:18
  • Thanks for all the help so far. The dataset is rather large and with a subset the model (SPSS) won't work properly, sadly. Iw as hoping it would be possible to compare "formula's", so to speak. – B.J.H.M. Possen May 01 '16 at 08:42

2 Answers2

0

You probably need to take out either Week or Plant_id, as I think you have as many values for either variable as you have cases. You can nest observations within a larger unit if you add a variable to model time. I am not familiar with SPSS, but if your time variable is Week (i.e., if week has a value of 1 for the first observation, 2 for the second etc.), then it should not be a grouping factor but a random effect in the model. Something like <snip> week + (1 + week|Plant_id).

k.

r.kaiza
  • 145
  • 8
0

Is Plant_id nested within Genotype, and Week indicate different measure points? If so, I assume that following formula leads to the required result:

lmm <- lmer(lnTriNU ~ Campaign + Watering + Heating + Campaign*Watering
       + Campaign*Heating + Watering*Heating + Campaign*Watering*Heating 
       + (1+Week|Genotype/Plant_id), pg)

Also saving predicted and residual values is not yet straightforward for me...

Do you mean "computing" by "saving"? In R, all relevant information are in the returned object, and accessible through functions like residuals() or predict() etc., called on the saved object (in your case, residuals(lmm)).

Note that, by default, lmer does not use AD1-covtype.

Daniel
  • 7,252
  • 6
  • 26
  • 38
  • Hi Daniel, Thanks! (I thought I already wrote this months ago, but apparently I didn't). Plant_Id identifies each individual plant so SPSS can track it over time (Week). Also, thanks for helping out on the predicted and residuals and AD1-covtype! I am still learning in R, but things are coming along all the time. – B.J.H.M. Possen Nov 15 '16 at 21:13