-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Issues getting variable in hierarchical model to update #2271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The Binomial distribution is not working in your model because: Tobs_new.logp(model2.test_point)
model2.logp(model2.test_point) Maybe you can try to reparameterize your model into a centered model, for example |
Seems to work with a small constraint on with model2:
# Co-efficients
alpha = pm.Normal('alpha', mu=0.0, sd=1000)
beta = pm.Deterministic('beta', tt.exp(alpha))
lamda = pm.Gamma('lamda', mu=1.0e-2, sd=100)
# Population Effect
pop_eff= pm.Deterministic('pop_eff', tt.exp(-1e-10+(-1*beta)/tt.exp(pop_den_all)))
# Mean/Expected Event Occurrence Rate
lamdal = pm.Deterministic('lamdal', lamda*5625)
# Actual Occurrence of Events
Tlatent_new = pm.Poisson('Tlatent_new', mu=lamdal, shape=56, testval=Tlatent)
# Observed Event Counts
Tobs_new = pm.Binomial('Tobs_new', n=Tlatent_new, p=pop_eff, observed=Tobs)
trace1 = pm.sample(3000) |
I see, I assumes that it would be bounded to be equal to or larger than Tobs as that is how it was dealt with in BUGS. Thanks for pointing that out. I assume that PYMC3 doesn't offer a way to have Tobs set as a lower bound for Tlatent_new in the model? |
There is |
I am going to close this because it is not an issue but feel free to continue the conversation. |
I've tried constraining I tired to use |
Okay, I see why it wasn't outputting, had to do with the sampling method I was using. I now get the same output as you have shown. I understand that Thanks! |
No problem! You can have a look at the more general tips about porting Bugs/JAGS model into pymc3 here: |
@aspassiani you could also try to use a continuous variable for BoundStudentT = pm.Bound(pm.StudentT, lower=Tobs) # or whatever dist seems appropriate
Tlatent_new = BoundStudentT('Tlatent_new', nu=3, sd=sd) If you need a Poisson you might be able to define a continuous version of it using |
@aseyboldt I dont think it works with the lower bound being a vector in |
@junpenglao @aspassiani oh. There is even some with pm.Model() as model:
trafo = pm.distributions.transforms.lowerbound([1., 2.])
pm.Normal('a', mu=0, sd=1, transform=trafo, shape=2, testval=[3., 3.]) |
xref #2277 |
@aseyboldt is it not possible to use the transformation you showed for a Poisson distribution? I get this error when using it for a Poisson,
But if I use the same data for example a Normal distribution, like your example, I don't get that error. I would like to try defining a continuous version of Poisson like you suggested in your earlier comment but I'm not quite sure how to use pm.DensityDist. Do you know of a good example that uses it that I could try to follow/re-create? Thanks! |
The transformation is only defined for continuous distributions. |
@aseyboldt I'm not sure about that. But I'm still unsure of about changing the Poisson distribution. The reasoning behind using the Poisson is because I am trying to model the occurrence of weather events. The Poisson distribution was chosen since it expresses the probability of a given number of events and it assumes the events occur independently. I then used this in the Binomial distribution since not all events that occur are observed. Population density is utilized to determine the probability of observing an event ( As @junpenglao pointed out apparently my |
I have previously been working with OpenBUGS/WinBUGS to perform my Bayesian statistics but have decided to move over to using the PYMC3 package in Python. I believe I have correctly converted my code to be used with PYMC3 but I am having issues with getting my output from PYMC3 to match my output from BUGS, specifically one of my variables does not update from its initialized values. My code is written as follows:
with sample data:
When I run the model, the variable
Tlatent_new
does not update from the initialized values I give it inTlatent
. This occurs when I want to include the effects of population density in my model using this lineTobs_new = pm.Binomial('Tobs_new', n=Tlatent_new, p=pop_eff, shape=56, observed=Tobs)
. When I do not include this line the output ofTlatent_new
differs from the initial guessTlatent
.I cannot figure out what is wrong with that additional line. I think it might have something to do with the use of the Binomial distribution because if I change it to a different distribution I will see a change in
Tlatent_new
from the initial guessTlatent
. I don't see why the Binomial distribution would not work. I thought my choice of sampling method might be an issue but I have tried changing that as well with no luck.Any help as to why this does not work is greatly appreciated.
Thanks in advance,
The text was updated successfully, but these errors were encountered: