@cache_readonly
    def random_effects(self):
        try:
            cov_re_inv = np.linalg.inv(self.cov_re)
        except np.linalg.LinAlgError:
            raise ValueError("Cannot predict random effects from singular covariance structure.")

        vcomp = self.vcomp
        k_re = self.k_re

        ranef_dict = {}
        for group_ix, group in enumerate(self.model.group_labels):

            endog = self.model.endog_li[group_ix]
            exog = self.model.exog_li[group_ix]
            ex_r, ex2_r = self.model._aex_r[group_ix], self.model._aex_r2[group_ix]
            vc_var = self.model._expand_vcomp(vcomp, group)

            # Get the residuals relative to fixed effects
            resid = endog
            if self.k_fe > 0:
                expval = np.dot(exog, self.fe_params)
                resid = resid - expval

            solver = _smw_solver(self.scale, ex_r, ex2_r, cov_re_inv, 1 / vc_var)
            vir = solver(resid)

            xtvir = _dot(ex_r.T, vir)

            xtvir[0:k_re] = np.dot(self.cov_re, xtvir[0:k_re])
            xtvir[k_re:] *= vc_var
            ranef_dict[group] = pd.Series(xtvir, index=self._expand_re_names(group))

        return ranef_dict
Choose agents from candidates based on a specific policy.
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/regression/mixed_linear_model.py/MixedLMResults.random_effects--crossover with--dataset/ETHPy150Open openstack/neutron/neutron/scheduler/l3_agent_scheduler.py/L3Scheduler._choose_router_agents_for_ha