statmerkur
statmerkur

Reputation: 479

What is the lmer/nlme equivalent of the REPEATED subcommand in SPSS's MIXED procedure?

I came across an SPSS syntax like this

MIXED value BY factor1
    /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1) SINGULAR(0.000000000001)
    HCONVERGE(0, ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001,
    ABSOLUTE)
    /FIXED=factor1 | SSTYPE(3)
    /METHOD=REML
    /REPEATED=factor1 | SUBJECT(participant) COVTYPE(UN).

and struggle to find an equivalent lmer/nlme (or R in general) formulation for this kind of models.

Does anybody know how to convert the REPEATED subcommand into R code?

Upvotes: 2

Views: 889

Answers (3)

Daniel
Daniel

Reputation: 7832

We have run some mixed models in a paper where we replicated all SPSS-results in R. This was our syntax:

MIXED y BY x1 WITH x2 x3
  /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1) SINGULAR(0.000000000001) HCONVERGE(0, 
    ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)
  /FIXED=x1 x2 x3 | SSTYPE(3)
  /METHOD=REML
  /PRINT=G  R SOLUTION TESTCOV
  /RANDOM=INTERCEPT x1 | SUBJECT(id) COVTYPE(UN)
  /REPEATED=x1| SUBJECT(id) COVTYPE(UN).


lmer(
  y ~ x1 + x2 + x3 + (1 + x1 | id),
  data = data,
  # this one is required because the random slope
  # is categorical. else, you could model uncorrelated
  # slope / intercept, see below 
  control = lmerControl(check.nobs.vs.nRE = "ignore")
)

or

lmer(
  y ~ x1 + x2 + x3 + (1 + x1 || id),
  data = data
)

We have converted our time-variable x1 to a factor, because it seemed like SPSS cannot deal with numeric time-variables in the REPEATED-statement.

To get the same standard errors, p-values and confidence intervals, use lmerTest::summary(..., ddf = "Satterthwaite"), because SPSS uses Satterthwaite-approximation as default.

Upvotes: 1

statmerkur
statmerkur

Reputation: 479

This summarizes the answers I got on the r-sig-mixed-models mailing list:
The REPEATED command specifies the structure in the residual variance-covariance matrix (R matrix), the so-called R-side structure, of the model. For lme4::lmer() this structure is fixed to a multiple of the identity matrix. However, one can specify the R-side structure using the weights and correlation arguments in nlme::gls() as follows:

gls(value ~ factor1,
    correlation = corSymm(form = ~ 1|participant),
    weights = varIdent(form = ~1|factor1),
    method = "REML", 
    data = data)

If one needs G-side effects in addition to the R-side structure, nlme::lme() provides the appropriate extensions.

Upvotes: 2

Livius
Livius

Reputation: 3388

I believe that /REPEATED is just the way to specify random effects, so

random=~factor1|participant in nlme.

I'm also guessing that the intercept in both the fixed and the random effects is implicit.

So in lme4 + lmerTest the whole model might be:

m <- lmerTest::lmer(value ~ 1 + factor1 + (1+factor1|participant))
lmerTest::anova(m, type=3,ddf='Satterthwaite')

Upvotes: 0

Related Questions