0

I'm running mixed models with the database pasted below It`s a simple linear mixed model in which the particular situation is when I want to include the quadratic effect of time. For time being linear I don't have any convergence problem but including poly(time,2), problems come up. I have 3 time points, so quadratic term should be feasible. If it were because of the small sample size, shouldn't be an error with linear component as well?

I have 2 questions

  1. What is wrong with syntax or database for not converge.
  2. Is there any way to include in the code something if "Error in lme.formula(vas ~ poly(time, 2), random = ~poly(time, 2) | nhc, : optim problem, convergence error code = 1" next/skip or pass time == 2.
lme(vas ~ time, random= ~ time|nhc, control = lmeControl(opt = "optim"),
method="REML", data=df, na.action = na.omit)

# I get results

Linear mixed-effects model fit by REML
  Data: df 
  Log-restricted-likelihood: -32.69369
  Fixed: vas ~ time 
(Intercept)        time 
   6.528095   -1.391640 


#including quadratic term
lme(vas ~ poly(time, 2), random= ~ poly(time,2)|nhc, control = lmeControl(opt = "optim"),
method="REML", data=df, na.action = na.omit)


Error in lme.formula(vas ~ poly(time, 2), random = ~poly(time, 2) | nhc,  : 
  optim problem, convergence error code = 1
  message = ...

I have tried modifications that succeded in the past like this:


#not working
lme(vas ~ poly(time, 2), random= ~ poly(time,2)|nhc, control =**lmeControl(msMaxIter = 1000, msMaxEval = 1000)**, method="REML", data=df, na.action = na.omit)

The df

df <-structure(list(nhc = structure(c(20121491, 20121491, 20121491, 
20121491, 20121491, 19217499, 19217499, 19217499, 19217499, 19217499, 
20336737, 20336737, 20336737, 20336737, 20336737, 14682006, 14682006, 
14682006, 14682006, 14682006, 18454625, 18454625, 18454625, 18454625, 
18454625, 20109250, 20109250, 20109250, 20109250, 20109250, 19117092, 
19117092, 19117092, 19117092, 19117092, 12618871, 12618871, 12618871, 
12618871, 12618871, 19620863, 19620863, 19620863, 19620863, 19620863, 
18190617, 18190617, 18190617, 18190617, 18190617, 15286988, 15286988, 
15286988, 15286988, 15286988, 521462, 521462, 521462, 521462, 
521462, 19434947, 19434947, 19434947, 19434947, 19434947, 20841801, 
20841801, 20841801, 20841801, 20841801, 19788686, 19788686, 19788686, 
19788686, 19788686, 12574473, 12574473, 12574473, 12574473, 12574473, 
15294473, 15294473, 15294473, 15294473, 15294473), format.spss = "F8.0"), 
    time = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 
    2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 
    1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 
    5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 
    4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5), vas = c(5, 4, 4, NA, 
    NA, NA, NA, NA, NA, NA, 5, NA, 4, NA, NA, 5, 1, 1, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, 4, 2, 2, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    5, NA, NA, NA, NA, 5, 4, NA, NA, NA, 9, NA, 3, NA, NA, 5, 
    2, 2, NA, NA)), row.names = c(NA, -85L), class = c("tbl_df", 
"tbl", "data.frame"))
  • A quadratic regression has 3 parameters, so in fact you have no degrees of freedom if you try to fit a quadratic trend to 3 time points. You get a "perfect fit." And because of the missing values in your dataset, some `nhc` only have 2 non-missing time points. If you want to fit a nonlinear trend to time I would recommend converting time to a discrete categorical variable. In general you are trying to fit a too complex model to this dataset. – qdread Apr 20 '23 at 10:20
  • So time as.factor() would adapt the model to fit a possible nonlinear trend? – Javier Hernando Apr 20 '23 at 10:28
  • 1
    Well, it would compare discrete time points instead of fitting a quadratic trend to them. It is probably your best options with so few time points. – qdread Apr 20 '23 at 13:07

0 Answers0