Posterior predictive check (plot_ppc) with dataframe encoding.
See original GitHub issueHello everyone!
I have a model which has two cases enconded in df[‘membrane_enc’], so this should give two indepently modelled likelyhoods and posteriors. I train the model in this fashion:
shape = df['membrane_enc'].unique().shape
with pm.Model() as my_model:
tau = pm.HalfNormal('tau', sigma=1.,shape =shape)
tau_0 = pm.TruncatedNormal('tau_0', mu = min_val, sigma = 1, lower = 0, upper = min_val, shape =shape)
like = DensityDist('like', logp_exp_lag(tau_0[df['membrane_enc']],tau[df['membrane_enc']]), observed=df['tpore'], random=custom_random, shape = (2,180))
with my_model:
my_model_trace = pm.sample(4000, tune=3000, random_seed=RANDOM_SEED)
ppc = pm.sample_posterior_predictive(my_model_trace, var_names = ['like'], random_seed=RANDOM_SEED)
my_model_trace = az.from_pymc3(trace=my_model_trace, model=my_model, posterior_predictive=ppc)
my_model_trace.to_netcdf(model_path)
The model converges nicely and gives reasonable posteriors for the two encodings. The problem comes when I try to plot the posterior predictive. I cannot find the way to plot the two distinct ppc’s in two graphs:
az.plot_ppc(my_model_trace, random_seed=RANDOM_SEED, var_names = ['like'], flatten = [])
This code fails and I am not sure which dimension I should flatten since there is only one in my_model_trace
, like_dim_0
and it doesn’t work. All this code works nicely if you only work with one dimension.
Can someone please help me make this plotting work?
By the way, I am using arviz 0.10.0.
Thank you very much in advance! Best, Sergio
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Chapter 20 Posterior Predictive Checks
A posterior predictive check compares simulated data using a draw of your posterior distribution to the observed data you are modelling - usually...
Read more >Graphical posterior predictive checks using the bayesplot ...
This vignette focuses on graphical posterior predictive checks (PPC). Plots of parameter estimates from MCMC draws are covered in the ...
Read more >Posterior Prediction from Logit Regression - The Stan Forums
I ran the model as a logistic regression with levels-means coding of group factors (each group getting their own intercept parameter). Here is ......
Read more >posterior predictive check for hddmRegression model
Hi,. I tried to implement a simple posterior predictive check for a simple hddm regression model (using patsy to implement contrast coding of...
Read more >Posterior Predictive Checks for brmsfit Objects — pp_check ...
Perform posterior predictive checks with the help of the bayesplot package. # S3 method for brmsfit pp_check( object, type, ndraws = NULL, nsamples...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the pointers, now the code looks like:
I have added labels to `like_dim_1’ and renamed the coordinates that represent the encoding. Now I get the result I was looking for:
Thanks a lot for your help!
Glad I could be of help!