def test_distribute_random_effect_over(diabetes_data): # Random slopes model = Model(diabetes_data) model.add(random='C(age_grp)|BMI') assert model.terms['C(age_grp)[T.1]|BMI'].data.shape == (442, 163) # Nested or crossed random intercepts model.reset() model.add(random='0+C(age_grp)|BMI') assert model.terms['C(age_grp)[0]|BMI'].data.shape == (442, 163)
def test_distribute_random_effect_over(diabetes_data): # Random slopes model = Model(diabetes_data) model.add_term('age_grp', over='BMI', categorical=False, random=True) assert model.terms['age_grp|BMI'].data.shape == (442, 163) # Nested or crossed random intercepts model.reset() model.add_term('age_grp', over='BMI', categorical=True, random=True, drop_first=False) t = model.terms['age_grp|BMI'].data assert isinstance(t, dict) assert t['age_grp[0]'].shape == (442, 83)
def test_distribute_random_effect_over(diabetes_data): # Random slopes model = Model(diabetes_data) model.add("BP ~ 1") model.add(random="C(age_grp)|BMI") model.build(backend="pymc") assert model.terms["C(age_grp)[T.1]|BMI"].data.shape == (442, 163) # Nested or crossed random intercepts model.reset() model.add("BP ~ 1") model.add(random="0+C(age_grp)|BMI") model.build(backend="pymc") assert model.terms["C(age_grp)[0]|BMI"].data.shape == (442, 163)
def test_distribute_group_specific_effect_over(diabetes_data): # 163 unique levels of BMI in diabetes_data # With intercept model = Model(diabetes_data) model.fit("BP ~ (C(age_grp)|BMI)", run=False) # Since intercept is present, it uses treatment encoding lvls = sorted(list(diabetes_data["age_grp"].unique()))[1:] for lvl in lvls: assert model.terms[f"C(age_grp)[{lvl}]|BMI"].data.shape == (442, 163) assert "1|BMI" in model.terms # Without intercept model.reset() model.fit("BP ~ (0 + C(age_grp)|BMI)", run=False) assert model.terms["C(age_grp)[0]|BMI"].data.shape == (442, 163) assert model.terms["C(age_grp)[1]|BMI"].data.shape == (442, 163) assert model.terms["C(age_grp)[2]|BMI"].data.shape == (442, 163) assert not "1|BMI" in model.terms