Search code examples
pythonstatsmodels

Python cov_struct attribute for MixedLM


I would like to specify the cov_struct attribute when calling the method MixedLM (statsmodels package) but it doesn't work.

On the contrary, when specifying this parameter to the method GEE (statsmodels), it works!

More precisely :

sm.GEE.from_formula("Y ~ X1 + X2 - 1", data=data,groups=Xg, cov_struct=sm.genmod.cov_struct.Exchangeable()).fit()

works.

But

sm.MixedLM.from_formula("Y ~ X1 + X2 - 1", data=data,groups=Xg, cov_struct=sm.genmod.cov_struct.Exchangeable()).fit()

Does not Work

The error I get is :

{AttributeError}'Exchangeable' object has no attribute 'ndim'

Also, I don t really understand the groups attribute.


Solution

  • cov_struct is only for GEE. If you want to specify the covariance structure in MixedLM use 're_formula'.

    Note that GEE in statsmodels is much more mature than MixedLM.