How to Fix error in meem(object, conlin, control$niterem) : singularity in backsolve at level 0, block 1

The “error in meem(object, conlin, control$niterem) : singularity in backsolve at level 0, block 1” error message occurs when working with the data table and several other packages. It is easy to get but also easy to fix since it just requires using another function.

Description of the error

This error message occurs when you are using the data.table, lme4, nlme, magrittr, and dplyr packages together and use the lme function on a dated table. Before using this type of linear regression function, you have to change the original data table by changing two out of the three columns and adding three more. In this case, when you use the lme function on the second data table it produces our error message. The irony of this situation is the fact that this error message does not result from a mistake in encoding the function, but it results from using the wrong function.

Explanation of the error

Here is an example of code that produces this error message.

> library(data.table)
> library(lme4)
> library(nlme)
> library(magrittr)
> library(dplyr)
>
> t = as.numeric(Sys.time())
> set.seed(t)
>
> dt_1 = data.table(id = rep(1:10, each=4),
+ time = as.factor(rep(1:4, 10)),
+ x = rnorm(40),
+ m = rnorm(40),
+ y = rnorm(40))
> head(dt_1,4)
id time x m y
1: 1 1 0.5694669 0.8202003 -0.7798263
2: 1 2 0.6114785 1.5937991 -1.1551952
3: 1 3 -0.4748983 0.6455328 0.1987284
4: 1 4 0.5486912 1.0864545 0.4713384
> dt_2 = dt_1 %>%
+ mutate(mm = m, .after=x) %>%
+ melt(id.vars = c(“id”,”time”,”x”,”mm”),
+ na.rm = F,
+ variable.name = “dv”,
+ value.name = “z”) %>%
+ within({
+ dy = as.integer(dv == “y”)
+ dm = as.integer(dv == “m”)
+ }) %>%
+ arrange(id,time)
> head(dt_2,4)
id time x mm dv z dm dy
1: 1 1 0.5694669 0.8202003 m 0.8202003 1 0
2: 1 1 0.5694669 0.8202003 y -0.7798263 0 1
3: 1 2 0.6114785 1.5937991 m 1.5937991 1 0
4: 1 2 0.6114785 1.5937991 y -1.1551952 0 1
> model1 = lme(fixed = z ~ 0 +
+ dm + dm:x + dm:time + #m as outcome
+ dy + dy:mm + dy:x + dy:time, #y as outcome
+ random = ~ 0 + dm:x + dy:mm + dy:x | id,
+ weights = varIdent(form = ~ 1 | dm), #separate sigma^{2}_{e} for each outcome
+ data = dt_2,
+ na.action = na.exclude)
Error in MEEM(object, conLin, control$niterEM) :
Singularity in backsolve at level 0, block 1

Here you can see the process leading to the error message along with the conversion process for changing the first data table to the second. You can also see how when you apply the lme function to it that you get our error message

How to fix the error

Fixing this problem is a simple matter of switching from the lme function to the lmer function.

> model2 = lmer(z ~ 0 + dm + dm:x + dm:time + dy + dy:mm + dy:x + dy:time +
+ (0 + dm:x + dy:mm + dy:x | id) + (0 + dm | time),
+ data = dt_2,
+ na.action = na.exclude)
fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
boundary (singular) fit: see ?isSingular
> model2
Linear mixed model fit by REML [‘lmerMod’]
Formula: z ~ 0 + dm + dm:x + dm:time + dy + dy:mm + dy:x + dy:time + (0 +
dm:x + dy:mm + dy:x | id) + (0 + dm | time)
Data: dt_2
REML criterion at convergence: 212.3788
Random effects:
Groups Name Std.Dev. Corr
id dm:x 0.1631
dy:mm 0.5361 1.00
x:dy 0.4397 -1.00 -1.00
time dm 0.5607
Residual 0.8580
Number of obs: 80, groups: id, 10; time, 4
Fixed Effects:
dm dy dm:x dm:time1 dm:time2 dm:time3 dy:mm x:dy time2:dy time3:dy time4:dy
0.01626 -0.33660 -0.01193 0.01437 0.69598 0.43550 -0.06976 0.06317 -0.47845 0.66522 0.90200
fit warnings:
fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
optimizer (nloptwrap) convergence code: 0 (OK) ; 0 optimizer warnings; 1 lme4 warnings

As you can tell using this new function fixes the problem and produces results.

This is an extremely easy error message to get but an even easier one to fix because all it requires is using a different function. You probably will not be able to completely avoid this message, but you will be able to fix it.

Scroll to top