def test_logistic_lmm():
df = pd.read_csv(os.path.join(get_resource_path(),'sample_data.csv'))
model = Lmer('DV_l ~ IV1+ (IV1|Group)',data=df,family='binomial')
model.fit(summarize=False)
assert model.coefs.shape == (2,13)
estimates = np.array([-0.16098421, 0.00296261])
assert np.allclose(model.coefs['Estimate'],estimates,atol=.001)
assert isinstance(model.fixef,pd.core.frame.DataFrame)
assert model.fixef.shape == (47,2)
assert isinstance(model.ranef,pd.core.frame.DataFrame)
assert model.ranef.shape == (47,2)
assert np.allclose(model.coefs.loc[:,'Estimate'],model.fixef.mean(),atol=.01)
# Test prediction
assert np.allclose(model.predict(model.data,use_rfx=True),model.data.fits)
assert np.allclose(model.predict(model.data,use_rfx=True,pred_type='link'),logit(model.data.fits))
评论列表
文章目录