Hello, Pystan champions,
I have fitted a structural time series model in Stan and used arviz to plot posterior predictive distribution.
here is my code:
import arviz as az
idata = az.from_pystan(posterior=fit_TOUR_model, posterior_predictive=[“y_predict”], observed_data=[“y”])
az.plot_ppc(idata, num_pp_samples=2000,data_pairs={“y”: “y_predict”},mean=False)
But I would like to see the posterior plot with time in the horizontal axis and the actual and predictive draws in the vertical axis. Is there any way this can be done using arviz?
Thanks Champs,
Antony
Our GSOC student has started working on regression plots, but currently, these are not yet merged into the codebase.
arviz-devs:main
← utkarsh-maheshwari:lin-reg
opened 03:25PM - 15 Jun 21 UTC
## Description
Here is my initial prototype for linear regression plot. I am ch… ecking if input data is correct in the the user API function. Backend function is quite small, only does the plotting part.
Example Notebook : https://gist.github.com/utkarsh-maheshwari/8d4cd2fd84c763bf85291c3f0881d588
High level design:
We accept 5 args
1. y_model : (Necessary) linear relationship in the form of `y = m1*x1 + m2*x2 + c`
2. idata : (Necessary if any of other args are string) should contain all the necessary variable names in any of the groups.
3. x_data : (Necessary because we cannot identify the x variable name from y_model) seq/str
4. y_data : (Necessary if y_model is Sequence. We can identify the name from y_model) seq/str
5. y_ppc : (Necessary is y_model is sequence. Assumed to be same as y_data if absent) seq/str
Function call:
`plot_lm(y_model = "kid_score ~ Intercept + slope * mom_iq", idata = idata, x_data = "mom_iq")
`
Output :
![image](https://user-images.githubusercontent.com/32706356/122080753-27f97c80-ce1c-11eb-8979-062a3dc4b923.png)
Shows uncertainty in y_data in orange, uncertainty in y_model in black, OLS regression line in yellow.
Should regression lines be plotted instead of filling the area?
-----------------------------------------------------------------------------------------------------
If y_model is sequence, we're good with plotting it.
If y_model is string like `y ~ slope * x_name + Intercept`, it should be converted to sequence by
- correctly identifying the variable names present in the string.
- look for variable names in inferenceData groups.
- Compute y_model term by term to form desired sequence.
To begin with, we can do it like :
```
rhs, lhs = y_model.split('~')
terms = rhs.split('+') : gives terms of the expression.
var_name = terms.split('*') : gives variable names to be searched in data
```
Iterate over terms
calculate value of each term
add it to the y_model_values
It works well with parsing GLM because I am keeping track of functions in function stack.
Any better way to parse `y_model` to extract the variable names from the string?
Love to know suggestions/reccomendations.
<!--
Thank you so much for your PR! To help us review your contribution, please consider the following points:
- The PR title should summarize the changes, for example "Add new group argument for the pair plot".
Avoid non-descriptive titles such as "Addresses issue #348".
- The description should provide at least 1-2 sentences describing the pull request in detail and
link to any relevant issues.
- Please prefix the title of incomplete contributions with [WIP] (to indicate a work in
progress). WIPs may be useful to (1) indicate you are working on something to avoid
duplicated work, (2) request broad review of functionality or API, or (3) seek collaborators. -->
## Checklist
- [ ] Follows [official](https://github.com/arviz-devs/arviz/blob/main/CONTRIBUTING.md#pull-request-checklist) PR format
- [ ] Includes a sample plot to visually illustrate the changes (only for plot-related functions)
- [ ] New features are properly documented (with an example if appropriate)?
- [ ] Includes new or updated tests to cover the new feature
- [ ] Code style correct (follows pylint and black guidelines)
- [ ] Changes are listed in [changelog](https://github.com/arviz-devs/arviz/blob/main/CHANGELOG.md#v0xx-unreleased)
<!--
Also, please consider reading the contributing guidelines and code of conduct carefully before submitting the PR. They are available at
- https://github.com/arviz-devs/arviz/blob/main/CONTRIBUTING.md
- https://github.com/arviz-devs/arviz/blob/main/CODE_OF_CONDUCT.md
We understand that PRs can sometimes be overwhelming, especially as the
reviews start coming in. Please let us know if the reviews are unclear or
the recommended next step seems overly demanding, if you would like help in
addressing a reviewer's comments, or if you have been waiting too long to hear
back on your PR.
-->
1 Like
Thank you, I will keep an eye on the updates.
Thanks for your work in PyStan.
1 Like