Repository: statsmodels/statsmodels

Issue:
Cannot access random_effects parameter after training mixedlm with regularization.
#### Describe the bug

Cannot access random_effects parameter after training mixedlm with regularization (```fit_regularized()```).

After successfully fitting LME model with ```fit_regularized```, when I try to access random_effects from ```MixedLMResults``` object, I'll get error: 

```AttributeError: 'MixedLMResults' object has no attribute 'vcomp'```

![image](https://user-images.githubusercontent.com/32110440/219611344-e636d84c-52e3-4687-9a28-ee488f33f868.png)


This does not happen when fitting LME model with ```fit``` function. 
It is caused by missing attribute 'vcomp', that is not assigned in ```fit_regularized()``` function, when creating results. 

Also, when trying to call summary function on MixedLMResults object that was fitted with fit_regularized, it fails with this error:

![image](https://user-images.githubusercontent.com/32110440/219617827-8e766760-251a-446f-a502-d38abbb53ce6.png)


#### Code Sample, a copy-pastable example if possible


```python
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf


data = {'target': np.random.randint(2, size=10),
     'feature_1': np.random.randint(2, size=10),
     'feature_2': np.random.randint(2, size=10),
     'group': ['a','a','a','a','a','b','b','b','b','b']}
df = pd.DataFrame(data=data)
md = smf.mixedlm(formula=f"target ~ feature_1 + feature_2",
                data=df, groups=df["group"],
                re_formula=f"~ feature_1")

results = md.fit_regularized()
results.random_effects
```




#### Expected Output

Should return dictionary with random_effects.

#### Output of ``import statsmodels.api as sm; sm.show_versions()``

<details>

[paste the output of ``import statsmodels.api as sm; sm.show_versions()`` here below this line]
INSTALLED VERSIONS
------------------
Python: 3.10.5.final.0

statsmodels
===========

Installed: 0.13.5 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\statsmodels)

Required Dependencies
=====================

cython: Not installed
numpy: 1.22.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\numpy)
scipy: 1.7.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\scipy)
pandas: 1.5.1 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\pandas)
    dateutil: 2.8.2 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\dateutil)
patsy: 0.5.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\patsy)

Optional Dependencies
=====================

matplotlib: 3.6.0 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\matplotlib)
    backend: module://matplotlib_inline.backend_inline 
cvxopt: Not installed
joblib: 1.2.0 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\joblib)

Developer Tools
================

IPython: 8.7.0 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\IPython)
    jinja2: 3.1.2 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\jinja2)
sphinx: Not installed
    pygments: 2.13.0 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\pygments)
pytest: Not installed
virtualenv: Not installed




</details>

Cannot access random_effects parameter after training mixedlm with regularization.
#### Describe the bug

Cannot access random_effects parameter after training mixedlm with regularization (```fit_regularized()```).

After successfully fitting LME model with ```fit_regularized```, when I try to access random_effects from ```MixedLMResults``` object, I'll get error: 

```AttributeError: 'MixedLMResults' object has no attribute 'vcomp'```

![image](https://user-images.githubusercontent.com/32110440/219611344-e636d84c-52e3-4687-9a28-ee488f33f868.png)


This does not happen when fitting LME model with ```fit``` function. 
It is caused by missing attribute 'vcomp', that is not assigned in ```fit_regularized()``` function, when creating results. 

Also, when trying to call summary function on MixedLMResults object that was fitted with fit_regularized, it fails with this error:

![image](https://user-images.githubusercontent.com/32110440/219617827-8e766760-251a-446f-a502-d38abbb53ce6.png)


#### Code Sample, a copy-pastable example if possible


```python
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf


data = {'target': np.random.randint(2, size=10),
     'feature_1': np.random.randint(2, size=10),
     'feature_2': np.random.randint(2, size=10),
     'group': ['a','a','a','a','a','b','b','b','b','b']}
df = pd.DataFrame(data=data)
md = smf.mixedlm(formula=f"target ~ feature_1 + feature_2",
                data=df, groups=df["group"],
                re_formula=f"~ feature_1")

results = md.fit_regularized()
results.random_effects
```




#### Expected Output

Should return dictionary with random_effects.

#### Output of ``import statsmodels.api as sm; sm.show_versions()``

<details>

[paste the output of ``import statsmodels.api as sm; sm.show_versions()`` here below this line]
INSTALLED VERSIONS
------------------
Python: 3.10.5.final.0

statsmodels
===========

Installed: 0.13.5 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\statsmodels)

Required Dependencies
=====================

cython: Not installed
numpy: 1.22.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\numpy)
scipy: 1.7.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\scipy)
pandas: 1.5.1 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\pandas)
    dateutil: 2.8.2 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\dateutil)
patsy: 0.5.3 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\patsy)

Optional Dependencies
=====================

matplotlib: 3.6.0 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\matplotlib)
    backend: module://matplotlib_inline.backend_inline 
cvxopt: Not installed
joblib: 1.2.0 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\joblib)

Developer Tools
================

IPython: 8.7.0 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\IPython)
    jinja2: 3.1.2 (c:\Users\Juraj_Mecir\.pyenv\pyenv-win\versions\3.10.5\lib\site-packages\jinja2)
sphinx: Not installed
    pygments: 2.13.0 (C:\Users\Juraj_Mecir\AppData\Roaming\Python\Python310\site-packages\pygments)
pytest: Not installed
virtualenv: Not installed




</details>



Discussion:

Resolving patch:
diff --git a/statsmodels/regression/mixed_linear_model.py b/statsmodels/regression/mixed_linear_model.py
--- a/statsmodels/regression/mixed_linear_model.py
+++ b/statsmodels/regression/mixed_linear_model.py
@@ -1254,6 +1254,7 @@ def fit_regularized(self, start_params=None, method='l1', alpha=0,
         results.params_object = params_object
         results.fe_params = fe_params
         results.cov_re = cov_re
+        results.vcomp = vcomp
         results.scale = scale
         results.cov_re_unscaled = mdf.cov_re_unscaled
         results.method = mdf.method


Test patch:
diff --git a/statsmodels/regression/tests/test_lme.py b/statsmodels/regression/tests/test_lme.py
--- a/statsmodels/regression/tests/test_lme.py
+++ b/statsmodels/regression/tests/test_lme.py
@@ -803,6 +803,27 @@ def test_summary_xname_re(self):
 # ------------------------------------------------------------------
 
 
+class TestMixedLMSummaryRegularized(TestMixedLMSummary):
+    # Test various aspects of the MixedLM summary
+    # after fitting model with fit_regularized function
+    @classmethod
+    def setup_class(cls):
+        # Setup the model and estimate it.
+        pid = np.repeat([0, 1], 5)
+        x0 = np.repeat([1], 10)
+        x1 = [1, 5, 7, 3, 5, 1, 2, 6, 9, 8]
+        x2 = [6, 2, 1, 0, 1, 4, 3, 8, 2, 1]
+        y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+        df = pd.DataFrame({"y": y, "pid": pid, "x0": x0, "x1": x1, "x2": x2})
+        endog = df["y"].values
+        exog = df[["x0", "x1", "x2"]].values
+        groups = df["pid"].values
+        cls.res = MixedLM(endog, exog, groups=groups).fit_regularized()
+
+
+# ------------------------------------------------------------------
+
+
 # TODO: better name
 def do1(reml, irf, ds_ix):