# Singular matrix error - LME

**URL:** https://forum.qiime2.org/t/singular-matrix-error-lme/13848
**Category:** User Support
**Created:** [March 2, 2020, 9:50am UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848 "2020-03-02T09:50:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![AnnaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/annac/32/9279_2.png) [@AnnaC](https://forum.qiime2.org/u/AnnaC)
#### Post date: [March 2, 2020, 9:50am UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/1 "2020-03-02T09:50:53Z")

</div>

Hello everyone,

I am trying to use the longitudinal plugin and I am getting as I have seen a common error, however, I cannot understand why I am getting it.

Plugin error from longitudinal:

Linear model will not compute due to singular matrix error. This may occur if input variables correlate closely or exhibit zero variance. Please check your input variables. Removing potential covariates may resolve this issue.

This is the initial command:

> qiime longitudinal linear-mixed-effects   
> --m-metadata-file sample-metadata\_cats\_all\_wo\_blanks\_def\_AC.tsv   
> --m-metadata-file ../FD\_obs-otus.qza   
> --p-metric Difference   
> --p-state-column Time   
> --p-group-columns Group,BCS,sex   
> --p-individual-id-column Subject   
> --o-visualization ../LME\_FD\_obs-otus\_group-BCS-sex.qzv

If I run the command without the Group variable it works perfectly, and if I run it without the BCS and sex variables it also works. However, when putting together the three variables I get the error. I attach here the metadata I am using for this analysis. The variables are not confounded among "group", "BCS" and "sex", not quite sure what I am missing.

[sample-metadata\_cats\_all\_wo\_blanks\_def\_AC.tsv](https://forum.qiime2.org/uploads/short-url/kP5gPTQhpDspru6aih2BdHh0xLO.tsv) (4.9 KB)

Many thanks for your time.  
Best regards,

Anna

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [March 2, 2020, 3:36pm UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/2 "2020-03-02T15:36:54Z")

</div>

Hi @AnnaC,  
I think the issue is that you are inputting too many variables/have no replicates with those variables. It looks like you have one time point per subject per Group/BCS/sex category. So even though the variables are not cofounders, you just don't have the biological replication needed to test all of those variables together.

The interaction terms could be part of this problem though — as a last-ditch attempt, you could try using this line:

```auto
--p-formula 'Group+BCS+sex'

```

Instead of this line:

```auto
--p-group-columns Group,BCS,sex

```

(when inputting a list of group columns to set independent factors, all interactions are tested, it is the equivalent of `Group*BCS*sex` — and I am merely speculating that removing these interaction terms may solve the replication issue)

Let me know if that helps!

---

<div class="post-metadata">

### Author: ![AnnaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/annac/32/9279_2.png) [@AnnaC](https://forum.qiime2.org/u/AnnaC)
#### Post date: [March 3, 2020, 10:31am UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/3 "2020-03-03T10:31:26Z")

</div>

Many thanks @Nicholas_Bokulich! It worked and I got the results.

Could you please further explain that "It looks like you have one time point per subject per Group/BCS/sex category." Several subjects belong to the same group and have the same sex and BCS, I think I am missing something. Thanks again!

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [March 3, 2020, 3:23pm UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/4 "2020-03-03T15:23:09Z")

</div>

> [@AnnaC](#):
>
> Could you please further explain that “It looks like you have one time point per subject per Group/BCS/sex category.” Several subjects belong to the same group and have the same sex and BCS, I think I am missing something.

Sorry, I misspoke. I did not mean that all timepoints/groups/BCS/sex categories have only one subject, but it looks like there may be some that have only one or two subjects (not enough replication). This is the number of subjects per grouping when grouping by all fixed effects, so the number of replicates you would have when testing the interaction between all effects (which is why using an additive formula without interaction works) — here's some python code to demonstrate:

```python
>>> import qiime2 as q2, pandas as pd
>>> md = q2.Metadata.load('sample-metadata_cats_all_wo_blanks_def_AC.tsv').to_dataframe()
>>> md.groupby(['Group','BCS','sex','Time']).count()['Subject']
Group BCS sex Time
G1 LEAN F 0.0 2
                  2.0 2
                  4.0 2
             M 0.0 3
                  2.0 4
                  4.0 4
       OW F 0.0 6
                  2.0 6
                  4.0 6
             M 0.0 1
                  4.0 1
G2 LEAN F 0.0 2
                  2.0 2
                  4.0 2
             M 0.0 2
                  2.0 3
                  4.0 2
       OW F 0.0 4
                  2.0 4
                  4.0 4
             M 0.0 4
                  2.0 4
                  4.0 4

```

The numbers in there indicate the number of subjects per timepoint X group X sex X BCS

---

<div class="post-metadata">

### Author: ![AnnaC](https://forum.qiime2.org/user_avatar/forum.qiime2.org/annac/32/9279_2.png) [@AnnaC](https://forum.qiime2.org/u/AnnaC)
#### Post date: [March 3, 2020, 3:29pm UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/5 "2020-03-03T15:29:16Z")

</div>

Super clear now! 🙂 Many thanks again @Nicholas_Bokulich!

---

<div class="post-metadata">

### Author: ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)
#### Post date: [April 3, 2020, 9:29pm UTC](https://forum.qiime2.org/t/singular-matrix-error-lme/13848/6 "2020-04-03T21:29:18Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
