Skip to content

Include "transformed data" to argument of az.from_pystan() #2423

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

Open
HJA24 opened this issue Feb 11, 2025 · 3 comments
Open

Include "transformed data" to argument of az.from_pystan() #2423

HJA24 opened this issue Feb 11, 2025 · 3 comments

Comments

@HJA24
Copy link

HJA24 commented Feb 11, 2025

Hi,

One of the arguments for the function az.from_pystan() is "observed_data". According to the docs "observed data" is extracted from the posterior.data.
My Stan model uses the "transformed data"-section extensively and I would like to extract variables defined here intoaz.InferenceData-object.

Is it possible to make sure that also the data from "transformed data" can be selected for "observed data"?

The corresponding error-log:

File "/Users/HJA/PycharmProjects/ufc/scripts/sample.py", line 58, in sample
    return az.from_pystan(
  File "/Users/HJA/opt/anaconda3/envs/ufc/lib/python3.10/site-packages/arviz/data/io_pystan.py", line 1079, in from_pystan
    ).to_inference_data()
  File "/Users/HJA/opt/anaconda3/envs/ufc/lib/python3.10/site-packages/arviz/data/io_pystan.py", line 609, in to_inference_data
    obs_const_dict = self.observed_and_constant_data_to_xarray()
  File "/Users/HJA/opt/anaconda3/envs/ufc/lib/python3.10/site-packages/arviz/data/base.py", line 65, in wrapped
    return func(cls)
  File "/Users/HJA/opt/anaconda3/envs/ufc/lib/python3.10/site-packages/arviz/data/base.py", line 65, in wrapped
    return func(cls)
  File "/Users/HJA/opt/anaconda3/envs/ufc/lib/python3.10/site-packages/arviz/data/io_pystan.py", line 573, in observed_and_constant_data_to_xarray
    vals = np.atleast_1d(posterior_model.data[key])
KeyError: 'y1'
@aloctavodia
Copy link
Contributor

@ahartikainen can you check this?

@ahartikainen
Copy link
Contributor

Are we talking about pystan 2.x or 3.x? I need to refresh my memory (I nowdays mostly use cmdstanpy), but if the transformed data is available then we can pull it from the sampling object.

@HJA24
Copy link
Author

HJA24 commented Feb 18, 2025

@ahartikainen Pystan 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants