Different hyperparameters for random effects mean #914
Unanswered
ericb-ambevtech
asked this question in
Q&A
Replies: 2 comments
-
I think you would need to assign fixed effects for each pig and then assign hyper-parameters. So think like weight ~ 1 + pig then pig ~ Normal(mu: [-1, 1, 0, ..., 0]), , sigma: HalfNormal(sigma: 133.0346)) |
Beta Was this translation helpful? Give feedback.
0 replies
-
@ericb-ambevtech, you can do the following: import bambi as bmb
import numpy as np
import statsmodels.api as sm
data = sm.datasets.get_rdataset("dietox", "geepack").data
n_pigs = data["Pig"].nunique() # 72
mu_vector = np.array([-1, 1] + [0] * (n_pigs - 2)) # Subtract 2 since you set it for two pigs
priors = {
"1|Pig": bmb.Prior("Normal", mu=mu_vector, sigma=bmb.Prior("HalfNormal", sigma=1))
}
model = bmb.Model("Weight ~ Time + (Time|Pig)", data, priors=priors)
model
However, make sure you do know what are the first two groups (pigs in this case). You can explore it like this model.components["mu"].design.group
And you can see they're order from smallest to largest... but anyway, always double-check it |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
In light of the discussion #808 , I would like to know if it's possible to further choose the hyperparameters for each individual mean in a mixed effects model. For example, in the Pigs dataset, if I wanted to influence the random intercept of the first two pigs, but in different directions:
1|Pig ~ Normal(mu: [-1, +1, 0, ..., 0], sigma: HalfNormal(sigma: 133.0346))
.I'm aware that this may violate the theory behind random effects modeling in the sense that the estimates are draws of a distribution. But still, is there a way to "tweak" the model specification to set this influence while having the pooling behavior from the mixed effects model?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions