Skip to content

bug or numerical problem in nlme's corCAR1

7 messages · Ferenci Tamas, John Fox, Ben Bolker

#
Dear Tamas Farenci,

You're mistaken: For the continuous first-order AR process, the unit of time matters. Measuring time in months implies a much larger autocorrelation at lag 1 than measuring time in years. As it turns out, 0.2 is a poor start values for the former:
+     cor=corCAR1(form=~age|Subject),data = Orthodont)
Linear mixed-effects model fit by REML
  Data: Orthodont 
  Log-restricted-likelihood: -218.6984
  Fixed: distance ~ age + factor(Sex) 
      (Intercept)               age factor(Sex)Female 
       17.7214161         0.6594049        -2.3274848 

Random effects:
 Formula: ~1 | Subject
        (Intercept) Residual
StdDev:    1.788899 1.454494

Correlation Structure: Continuous AR(1)
 Formula: ~age | Subject 
 Parameter estimate(s):
      Phi 
0.2418536 
Number of Observations: 108
Number of Groups: 27
+     cor=corCAR1(0.8, form=~agemos|Subject),data = Orthodont)
Linear mixed-effects model fit by REML
  Data: Orthodont 
  Log-restricted-likelihood: -221.1833
  Fixed: distance ~ agemos + factor(Sex) 
      (Intercept)            agemos factor(Sex)Female 
      17.72141619        0.05495041       -2.32748480 

Random effects:
 Formula: ~1 | Subject
        (Intercept) Residual
StdDev:    1.788899 1.454494

Correlation Structure: Continuous AR(1)
 Formula: ~agemos | Subject 
 Parameter estimate(s):
      Phi 
0.8884427 
Number of Observations: 108
Number of Groups: 27
[1] 0.2418539

Thus, the two solutions agree. I agree, however, that it's slightly disconcerting that lme() can't overcome the poor start value.

I hope this helps,
 John

-----------------------------
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socialsciences.mcmaster.ca/jfox/
#
The alarming part is the lack of any warning.  I don't know whether
there's any easy way to detect this case, though ...  FWIW the
starting value has to be above about 0.62 before it works

ff <- function(rhostart) {
  m <- lme(distance ~ agemos + factor(Sex),random = ~ 1 | Subject,
    cor=corCAR1(rhostart,form=~agemos|Subject),
    data = Orthodont)
  return(coef(m$modelStruct$corStruct,unconstrained=FALSE))
}

startvec <- seq(0.02,0.98,by=0.02)
estvec <- sapply(startvec,ff)

plot(startvec,estvec)
On Thu, Jan 25, 2018 at 12:40 PM, Fox, John <jfox at mcmaster.ca> wrote:
#
Hi Ben,

A possible solution would be to see whether the estimated autoregressive parameter is stuck at the start value and then try something like a bisection search. That's pretty crude and I bet there's a smarter way to do it.

Best,
 John
#
Dear Ben,

In addition to that, if you run that script with age, it will be
correct... *regardless* of the starting value!
Yes, what I found suspicious was that it was _exactly_ 0.2... and it
was only accidental that I remembered that it is the default value in
corCAR1, so I realized what is going on. But I can imagine that it
might go unnoticed...

Tamas


2018. janu?r 25., 18:57:25, ?rtad:
#
Dear John,

That's a possible solution IF you realize something is wrong, but what
I find problematic is that one might not realize at all that such
measures are needed!

Tamas


2018. janu?r 25., 19:18:40, ?rtad:
#
Dear Tamas,
I was suggesting to Ben that lme() might do it.

John
#
Yes (although I'd like to remind everyone that I am *not* the
maintainer of nlme; R-core is).

  cheers
   Ben
On 18-01-25 05:43 PM, Fox, John wrote: