# Diagnosing "Fixed-effects matrix is rank-deficient"

**URL:** <https://discourse.julialang.org/t/diagnosing-fixed-effects-matrix-is-rank-deficient/63471>\
**Category:** Statistics\
**Created:** [June 23, 2021, 11:25pm UTC](https://discourse.julialang.org/t/diagnosing-fixed-effects-matrix-is-rank-deficient/63471 "2021-06-23T23:25:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 23, 2021, 11:25pm UTC](https://discourse.julialang.org/t/diagnosing-fixed-effects-matrix-is-rank-deficient/63471/1 "2021-06-23T23:25:35Z")

</div>

I am using MixedModels `fit(@formula(y ~ a + b + c + d + e), data)` and it says “Warning: Fixed-effects matrix is rank-deficient”. I want to diagnose the problem. Can I find out which combinations of columns are not full rank? For example, is it a single categorical variable `c` that has only one value, or a pair of columns `a` and `b` that are dependent? Can I easily extract this information from the formula and data?

* * *

cc @dmbates @palday

---

<div class="post-metadata">

**Author:** ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)\
**Post date:** [June 24, 2021, 12:45am UTC](https://discourse.julialang.org/t/diagnosing-fixed-effects-matrix-is-rank-deficient/63471/2 "2021-06-24T00:45:23Z")

</div>

The fundamental problem and why a universal solution is difficult is discussed in the [docs](https://juliastats.org/MixedModels.jl/stable/rankdeficiency/).

You can look at the numerical rank of the model matrix to get an idea about how many “extra” columns there are, but that doesn’t tell you how many extra terms you have in your formula. Using orthogonal contrasts for categorical variables may help with _numerical_ rank.

In practice, you can also see which predictors were dropped as part of the automatic attempts to handle rank deficiency – their estimate will be `-0.0` (note the negative sign) and their standard error will be `NaN`.

---

<div class="post-metadata">

**Author:** ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Post date:** [June 24, 2021, 2:32pm UTC](https://discourse.julialang.org/t/diagnosing-fixed-effects-matrix-is-rank-deficient/63471/3 "2021-06-24T14:32:57Z")

</div>

Alternatively, the evaluated rank, `rank`, and the pivot vector, `piv`, can be retrieved from the `feterm` (fixed-effects term) object. In the current release (v3.8.0) this is the first element of the `feterms` field in the fitted model

```julia
julia> first(m1.feterms).rank
32

julia> show(first(m1.feterms).piv)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]

```

(When the fixed-effects model matrix is deemed full rank the pivot vector is always `1:size(X, 2)`.)

In the development version of `MixedModels`, v4.0.0-DEV, replace `first(m1.feterms)` by `m1.feterm`.
