1

I am using lme function in R to run a model:

f0 <- lme(value ~ -1 + cs_d0 + va_d0 + cs_d0:visitmse + va_d0:visitmse + cs_d0:ageb + va_d0:ageb +
+           cs_d0:lesionse + va_d0:lesionse, random =  
+            ~ -1 + (cs_d0 + va_d0) + visitmse:( cs_d0 + va_d0)|pat , weights = 
+             varIdent(form=~1| cs_d0), control=lmeControl(opt="optim"), data =D0Train)

but I faced an error

Error in MEEM(object, conLin, control$niterEM) : 
  Singularity in backsolve at level 0, block 1

When I searched about that and tried to look at model matrix I found this problem :

> m <- model.matrix(value ~ -1 + cs_d0 + va_d0 + cs_d0:visitmse + va_d0:visitmse + cs_d0:ageb + va_d0:ageb +
+           cs_d0:lesionse + va_d0:lesionse + va_d0:gender   ,data =D0Train)
> m[1:10,]
   cs_d0 va_d0 cs_d0:visitmse va_d0:visitmse cs_d0:ageb va_d0:ageb cs_d0:lesionse0 cs_d0:lesionse1 va_d0:lesionse1 va_d0:gender2
1      1     0            0.0              0         70          0               0               1               0             0
2      1     0            0.5              0         70          0               0               1               0             0
3      1     0            1.0              0         70          0               0               1               0             0
4      1     0            9.0              0         70          0               0               1               0             0
5      1     0            0.0              0         80          0               1               0               0             0
6      1     0            3.0              0         80          0               1               0               0             0
7      1     0            6.0              0         80          0               1               0               0             0
8      1     0            0.0              0         77          0               1               0               0             0
9      1     0            3.0              0         77          0               1               0               0             0
10     1     0            6.0              0         77          0               1               0               0             0

The lesionse is factor that has two levels (0,1),

str(D0Train$lesionse)
 Factor w/ 2 levels "0","1": 2 2 2 2 1 1 1 1 1 1 ...

but in the model (cs_d0:lesionse0 , cs_d0:lesionse1 ) it seems has more than two levels.

Here an example :

# lesion type
lesion = factor(c(rep(0,150),rep(1,50))) 
# gender
sex = factor(c(rep(0,150),rep(1,50)), label=c("Female","Male"))
# visiting time by months
time = rep(c(0,3,6,9),time = 4, 200)
# subjects 
subject = rep(1:50, each = 4)
# first  response variable "identity"
x_1 = c(rep(0, 100), rep(1,100)) 
# second  response variable "identity"
x_2 = c(rep(1, 100), rep(0,100))
# values of both reponses variables (x_1, x_2)
value = c(rnorm(100,20,1),rnorm(100,48,1))
# variables refer to reponses variables (x_1, x_2)
variable = factor(c(rep(0,150),rep(1,50)), label=c("X2","X1"))

df = data.frame(subject , time, sex, lesion, x_1,x_2,value, variable)

library(nlme)
# fit the model that each response variable has intercept and slope (time) for each random and fixed effects
# as well as fixed effects slopes for sex and lesion, and each response has different variance 
f=  lme(value ~ -1 + x_1 + x_2 + x_1:time + x_2:time +  x_1:lesion + x_2:lesion + 
               x_1:sex + x_2:sex, random = ~ -1 + (x_1 + x_2) + time:( x_1 + x_2)|subject , 
       weights = varIdent(form=~1| x_1), control=lmeControl(opt="optim"), data =df)

fm = model.matrix(value ~ -1 + x_1 + x_2 + x_1:time + x_2:time +  x_1:lesion + x_2:lesion + 
               x_1:sex + x_2:sex,data=df)

May you help me or give some suggestions?

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
R. Saeiti
  • 89
  • 3
  • 11

1 Answers1

0

Given your example data, the error is correct. You have a singularity.

x_1:time and x_2:time are duplicate columns--when x_1:time == 0, x_2:time == time. And when x_1:time == time, x_2:time == 0. The same is true of the main effects of x_1 and x_2.

Your model is overspecified.

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
  • So, how to solve it out? as I am trying to add lesion and sex as well to multivariate linear mixed model. – R. Saeiti Jan 26 '16 at 07:52
  • @R.Saeiti I'm not sure that I understand this comment. Your model is overspecified. You "solve it" by removing the extra terms. Perhaps you need to refresh your memory on this concept. – alexwhitworth Jan 26 '16 at 16:25