當前位置: 首頁>>代碼示例>>Python>>正文


Python MixedLMParams.set_cov_re方法代碼示例

本文整理匯總了Python中statsmodels.regression.mixed_linear_model.MixedLMParams.set_cov_re方法的典型用法代碼示例。如果您正苦於以下問題:Python MixedLMParams.set_cov_re方法的具體用法?Python MixedLMParams.set_cov_re怎麽用?Python MixedLMParams.set_cov_re使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在statsmodels.regression.mixed_linear_model.MixedLMParams的用法示例。


在下文中一共展示了MixedLMParams.set_cov_re方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: do1

# 需要導入模塊: from statsmodels.regression.mixed_linear_model import MixedLMParams [as 別名]
# 或者: from statsmodels.regression.mixed_linear_model.MixedLMParams import set_cov_re [as 別名]
    def do1(self, reml, irf, ds_ix):

        # No need to check independent random effects when there is
        # only one of them.
        if irf and ds_ix < 6:
            return

        irfs = "irf" if irf else "drf"
        meth = "reml" if reml else "ml"

        rslt = R_Results(meth, irfs, ds_ix)

        # Fit the model
        md = MixedLM(rslt.endog, rslt.exog_fe, rslt.groups,
                     rslt.exog_re)
        if not irf: # Free random effects covariance
            mdf = md.fit(gtol=1e-7, reml=reml)
        else: # Independent random effects
            k_fe = rslt.exog_fe.shape[1]
            k_re = rslt.exog_re.shape[1]
            free = MixedLMParams(k_fe, k_re)
            free.set_fe_params(np.ones(k_fe))
            free.set_cov_re(np.eye(k_re))
            mdf = md.fit(reml=reml, gtol=1e-7, free=free)

        assert_almost_equal(mdf.fe_params, rslt.coef, decimal=4)
        assert_almost_equal(mdf.cov_re, rslt.cov_re_r, decimal=4)
        assert_almost_equal(mdf.scale, rslt.scale_r, decimal=4)

        pf = rslt.exog_fe.shape[1]
        assert_almost_equal(rslt.vcov_r, mdf.cov_params()[0:pf,0:pf],
                            decimal=3)

        assert_almost_equal(mdf.likeval, rslt.loglike[0], decimal=2)

        # Not supported in R
        if not irf:
            assert_almost_equal(mdf.ranef()[0], rslt.ranef_postmean,
                                decimal=3)
            assert_almost_equal(mdf.ranef_cov()[0],
                                rslt.ranef_condvar,
                                decimal=3)
開發者ID:philippmuller,項目名稱:statsmodels,代碼行數:44,代碼來源:test_lme.py

示例2: MixedLMParams

# 需要導入模塊: from statsmodels.regression.mixed_linear_model import MixedLMParams [as 別名]
# 或者: from statsmodels.regression.mixed_linear_model.MixedLMParams import set_cov_re [as 別名]
    #                                            :mousediet.p].values))
    # priors.setPai(0.5*np.ones(mousediet.grp))
    # priors.setSigma2(result.scale)


    ## quadratic
    mousediet.setParams(p=3)

    data = mousediet.rawdata[mousediet.rawdata['diet'] == 99]
    data['days2'] = data['days']**2
    model = sm.MixedLM.from_formula('weight ~ days + days2', data,
                                    re_formula='1 + days + days2',
                                    groups=data['id'])
    free = MixedLMParams(3, 3)
    free.set_fe_params(np.ones(3))
    free.set_cov_re(np.eye(3))
    result = model.fit(free=free)

    # uninformative prior
    priors.setD1(0.001)
    priors.setD2(0.001)

    priors.setD3(result.fe_params.values.reshape(mousediet.p, 1))
    priors.setD4(pinv(result.cov_params().iloc[:mousediet.p,
                                               :mousediet.p].values))
    priors.setPai(0.5*np.ones(mousediet.grp))
    priors.setSigma2(result.scale)


    mcmcrun(mousediet, priors, dirname)
開發者ID:LeiG,項目名稱:MouseWeights,代碼行數:32,代碼來源:main.py


注:本文中的statsmodels.regression.mixed_linear_model.MixedLMParams.set_cov_re方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。