[R-sig-ME] What is the lmer/nlme equivalent of the REPEATED subcommand in SPSS's MIXED procedure?

Maarten Jung Maarten.Jung at mailbox.tu-dresden.de
Thu Mar 22 10:05:34 CET 2018


I think the problem is that there is only one observation per
subject-occasion-combination in this example.
In this case the random slopes are confounded with the residual variation
(see [1]).

One *can* fit this model using lmer(test ~ 1 + occ2 + occ3 + (1 + occ2 +
occ3|person), data = mydata,  control = lmerControl(check.nobs.vs.nRE =
"ignore")) or
lme(test ~ 1 + occ2 + occ3, mydata, random = ~ occ2 + occ3|person).

However, I don't know if the gls() fit ist more trustworthy than the
lmer/lme fit here.
I would be grateful if somebody more experienced in mixed models could
comment on this.

Best regards,
Maarten

[1]
https://stackoverflow.com/questions/26465215/random-slope-for-time-in-subject-not-working-in-lme4?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

On Wed, Mar 21, 2018 at 9:27 PM, Ben Pelzer <b.pelzer at maw.ru.nl> wrote:

> Hi Maarten,
>
> Here is an example which shows the unstructured model with gls and the
> not converging model with lmer. In this example, we have three occasions
> on which the dependent variable "test" was observed, for each of 20
> persons. In total then we have 60 observations, with the "occasion"
> variable taking values 1, 2, 3. The data also contain the person id
> variable "person" and dummy variables "occ1", "occ2", "occ3" as (0 or 1)
> indicators of the occasion.  In the syntax below, a factor variable
> "factor1" is created also, to be in line with your question.
>
> I used two different specifications for the unstructured model with gls,
> depending on whether dummies or factor1 was used. For lmer, I used these
> three different specifications, none of which converges.
>
> The lmer syntax was added only to show the problem which lmer has with
> estimating an unstructured correlation pattern.
>
>
> #-----------------------------------------------------------
> ------------------------------------------------------------
> -------------------------------------
> mydata <-
> read.table(url("https://surfdrive.surf.nl/files/index.
> php/s/XfE3mtbFCTUejIz/download"),
> header=TRUE)
>
>
> #-------------------  unstructured correlation matrix
> -----------------------
>
>
> # Before applying a model, let's first examine the variances and
> correlations
> # for the three occasions. We have a strong violation of the assumptions
> # of homoscedasticity and compound symmetry.
> test1 <- mydata[mydata$occasion==1,"test"]
> test2 <- mydata[mydata$occasion==2,"test"]
> test3 <- mydata[mydata$occasion==3,"test"]
> cor(cbind(test1, test2, test3))
> var(cbind(test1, test2, test3))
>
> # Unstructured model using gls from package nlme and dummies for occasion.
> # This model exactly reproduces the observed correlations between
> occasions.
> unstruc.gls1 <- gls(test ~ 1+ occ2 + occ3,
>                             method="REML", data=mydata,
>                             correlation=corSymm(form = ~ 1 |person),
>                             weights = varIdent(form = ~1|occasion))
> summary(unstruc.gls1)
>
>
> # Unstructured model using factor1 for occasion instead of dummies.
> # The results are exactly the same as those above, as should be.
> mydata$factor1 <- as.factor(mydata$occasion)
> unstruc.gls2 <- gls(test ~ factor1,
>                      method="REML", data=mydata,
>                      correlation=corSymm(form = ~ 1|person),
>                      weights = varIdent(form = ~1|factor1))
> summary(unstruc.gls2)
>
>
> # Unstructured model using lmer and dummies for occasion: does not
> converge.
> unstruc.lmer <- lmer(test ~ 1+ occ2 + occ3 + (1+occ2+occ3|person),
>                       data=mydata, REML=TRUE)
> summary(unstruc.lmer)
>
>
> # Unstructured model using lmer and factor1 for occasion: does not
> converge.
> unstruc.lmer <- lmer(test ~ 1+ factor1 + (1+factor1|person),
>                       data=mydata, REML=TRUE)
> summary(unstruc.lmer)
>
>
> # Unstructured model using lmer and factor1 for occasion, no intercept
> specified: does not converge.
> unstruc.lmer <- lmer(test ~ factor1 + (factor1|person),
>                       data=mydata, REML=TRUE)
> summary(unstruc.lmer)
>
>
>
> On 21/03/2018 13:07, Maarten Jung wrote:
> > Dear Ben,
> >
> > I am a bit puzzled.
> >
> > Do you mean that
> >
> > m1 <- gls(value ~ factor1, data, correlation = corSymm(form = ~
> > 1|participant), weights = varIdent(form = ~ 1|factor))
> >
> > would be equivalent to
> >
> > m2 <- lmer(value ~ factor1 + (factor1|participant), data)
> >
> > and one should use gls() because it allows for the same covariance
> > structures as /REPEATED does?
> >
>
>
> the two specifications are not equivalent in the sense that lmer also
> tries to estimate residual variance. However, with the given lmer model
> specification, the random factor1 effects capture all variance there is
> and no residual variance remains.
>
>
> > And, if so, why should m2 cause an identification problem and m1 doesn't?
> >
> > Regards,
> > Maarten
> >
> Regards, Ben.
>
>
>
> >
> > On Wed, Mar 21, 2018 at 12:03 PM, Ben Pelzer <b.pelzer at maw.ru.nl
> > <mailto:b.pelzer at maw.ru.nl>> wrote:
> >
> >     Dear all,
> >
> >     As far as I know, the specification for lmer using
> >
> >          value ~ factor1 + (factor1 | participant)
> >
> >     causes an identification problem, because the residual variance is
> not
> >     excluded from the estimations. It would indeed work (e.g. in MlWin
> >     this
> >     can be done) if we could constrain that residual variance to zero.
> >     There
> >     have been some mails in this list about whether or not constraining
> >     residual variance to zero is possible in lmer, but I believe this
> >     is not
> >     possible. Would be nice if we could do this in lmer!
> >
> >     Best regards, Ben.
> >
> >
> >     On 20-3-2018 18:34, Douglas Bates wrote:
> >     > Kind of looks like SPSS went for bug-for-bug compatibility with
> >     SAS on
> >     > this one.  In SAS PROC MIXED, "REPEATED" and "RANDOM" are two
> >     ways of
> >     > specifying the random effects variance structure but they often
> boil
> >     > down to the same model.
> >     >
> >     > I believe the model can be specified in lme4 as
> >     >
> >     >     value ~ factor1 + (factor1 | participant)
> >     >
> >     > This is what the mis-named* "UNSTRUCTURED" covariance type means
> >     >
> >     > * Old-guy, get off my lawn rant about terminology *
> >     > As a recovering mathematician I find the name "unstructured" being
> >     > used to denote a positive-definite symmetric matrix to be, well,
> >     > inaccurate.
> >     >
> >     > On Tue, Mar 20, 2018 at 12:19 PM Mollie Brooks
> >     > <mollieebrooks at gmail.com <mailto:mollieebrooks at gmail.com>
> >     <mailto:mollieebrooks at gmail.com <mailto:mollieebrooks at gmail.com>>>
> >     wrote:
> >     >
> >     >     I don’t know anything about spss, but if you basically want
> lme4
> >     >     with more correlation structures, you could look at the
> >     structures
> >     >     available with glmmTMB.
> >     >
> >     https://cran.r-project.org/web/packages/glmmTMB/
> vignettes/covstruct.html
> >     <https://cran.r-project.org/web/packages/glmmTMB/
> vignettes/covstruct.html>
> >     >
> >     >     cheers,
> >     >     Mollie
> >     >
> >     >     > On 20Mar 2018, at 18:11, Ben Pelzer <b.pelzer at maw.ru.nl
> >     <mailto:b.pelzer at maw.ru.nl>
> >     >     <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>>>
> wrote:
> >     >     >
> >     >     > Hi Maarten,
> >     >     >
> >     >     > You are right: you need nlme and NOT lme4 to specify
> >     particular
> >     >     > correlation structures. Also, in nlme you would need gls
> >     to make it
> >     >     > similar to mixed in spss. The repeated command in spss
> >     gives the
> >     >     same
> >     >     > results as gls does for any of the covariance structures.
> >     >     >
> >     >     > Regards, Ben.
> >     >     >
> >     >     >
> >     >     > On 20/03/2018 17:30, Maarten Jung wrote:
> >     >     >> Dear Ben, dear Phillip,
> >     >     >>
> >     >     >> comparing [1] with [2] I think the /REPEATED command
> >     specifies
> >     >     >> the error (co)variance structure of the model. Would you
> >     agree
> >     >     with that?
> >     >     >> If so, AFAIK this is not possible with lmer and thus the
> >     answer on
> >     >     >> Stack Overflow [3] would be wrong.
> >     >     >>
> >     >     >> [1]
> >     >     >>
> >     >
> >     https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/
> >     <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/>
> >     >     >> [2]
> >     >     >>
> >     >
> >     https://stats.idre.ucla.edu/spss/examples/alda/chapter7/
> applied-longitudinal-data-analysis-modeling-change-and-
> event-occurrenceby-judith-d-singer-and-john-b-willett-
> chapter-7-examining-the-multilevel-model-s-erro/
> >     <https://stats.idre.ucla.edu/spss/examples/alda/chapter7/
> applied-longitudinal-data-analysis-modeling-change-and-
> event-occurrenceby-judith-d-singer-and-john-b-willett-
> chapter-7-examining-the-multilevel-model-s-erro/>
> >     >     >> [3]
> >     >     >>
> >     >
> >     https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc
> >     <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc>
> >     >     >>
> >     >     >> Regards,
> >     >     >> Maarten
> >     >     >>
> >     >     >> On Tue, Mar 20, 2018 at 2:10 PM, Ben Pelzer
> >     <b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>
> >     >     <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>>
> >     >     >> <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>
> >     <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>>
> >     >     <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>
> >     <mailto:b.pelzer at maw.ru.nl <mailto:b.pelzer at maw.ru.nl>>>>> wrote:
> >     >     >>
> >     >     >>    Dear Maarten,
> >     >     >>
> >     >     >>    Take a look at
> >     >     >>
> >     >     >>
> >     >
> >     https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/
> >     <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/>
> >     >
> >      <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/
> >     <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/>>
> >     >     >>
> >     >
> >      <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/
> >     <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/>
> >     >
> >      <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/
> >     <https://stats.idre.ucla.edu/r/examples/alda/r-applied-
> longitudinal-data-analysis-ch-7/>>>
> >     >     >>
> >     >     >>    which shows you a number of covariance structures, among
> >     >     which is
> >     >     >>    the unstructured matrix, for repeated measures in R
> >     with lme. It
> >     >     >>    refers to chapter 7 of Singer and Willett where they
> >     discuss all
> >     >     >>    these different structures and how to choose among them.
> >     >     Regards,
> >     >     >>
> >     >     >>    Ben.
> >     >     >>
> >     >     >>    On 20-3-2018 9:00, Maarten Jung wrote:
> >     >     >>
> >     >     >>        Dear list,
> >     >     >>        I came across a 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?
> >     >     >>
> >     >     >>        Please note that I asked the question on Stack
> >     Overflow
> >     >     about
> >     >     >>        two month ago:
> >     >     >>
> >     >
> >     https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc
> >     <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc>
> >     >
> >      <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc
> >     <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc>>
> >     >     >>
> >     >
> >      <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc
> >     <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc>
> >     >
> >      <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc
> >     <https://stackoverflow.com/questions/48518514/what-is-
> the-lmer-nlme-equivalent-of-the-repeated-subcommand-in-spsss-mixed-proc>>>
> >     >     >>
> >     >     >>        Best regards,
> >     >     >>        Maarten
> >     >     >>
> >     >     >>                [[alternative HTML version deleted]]
> >     >     >>
> >     >     >> _______________________________________________
> >     >     >> R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>>
> >     >     >>        <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>>> mailing list
> >     >     >> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>
> >     >     >>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>>
> >     >     >>
> >     >     >>
> >     >     >>    _______________________________________________
> >     >     >> R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>>
> >     >     >>    <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>>> mailing list
> >     >     >> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>
> >     >     >>
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>>
> >     >     >>
> >     >     >>
> >     >     >
> >     >     >
> >     >     >       [[alternative HTML version deleted]]
> >     >     >
> >     >     > _______________________________________________
> >     >     > R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>>> mailing list
> >     >     > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>
> >     >
> >     >             [[alternative HTML version deleted]]
> >     >
> >     >     _______________________________________________
> >     > R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>
> >     >     <mailto:R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org>> mailing list
> >     > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >     >
> >
> >
> >             [[alternative HTML version deleted]]
> >
> >     _______________________________________________
> >     R-sig-mixed-models at r-project.org
> >     <mailto:R-sig-mixed-models at r-project.org> mailing list
> >     https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> >     <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
> >
> >
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list