本文整理汇总了Python中statsmodels.regression.mixed_linear_model.MixedLMParams.set_fe_params方法的典型用法代码示例。如果您正苦于以下问题:Python MixedLMParams.set_fe_params方法的具体用法?Python MixedLMParams.set_fe_params怎么用?Python MixedLMParams.set_fe_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.regression.mixed_linear_model.MixedLMParams
的用法示例。
在下文中一共展示了MixedLMParams.set_fe_params方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do1
# 需要导入模块: from statsmodels.regression.mixed_linear_model import MixedLMParams [as 别名]
# 或者: from statsmodels.regression.mixed_linear_model.MixedLMParams import set_fe_params [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)
示例2: MixedLMParams
# 需要导入模块: from statsmodels.regression.mixed_linear_model import MixedLMParams [as 别名]
# 或者: from statsmodels.regression.mixed_linear_model.MixedLMParams import set_fe_params [as 别名]
# priors.setD4(pinv(result.cov_params().iloc[:mousediet.p,
# :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)