-
Notifications
You must be signed in to change notification settings - Fork 9
using yaps to access stansummary command #3
Comments
Thank you for your interest in the project. I think that you could directly use |
Hi, See #4 for accessing the pycmdstan original API. import pandas as pd
import pycmdstan
cmdstan_model = pycmdstan.Model(code=str(constrained_coin.model))
run = cmdstan_model.sample(data=constrained_coin.data)
run_set = pycmdstan.model.RunSet(run)
pd.DataFrame({k:list(v[0]) for k,v in run_set.summary.items()}, index=run_set.summary['lp__'].dtype.fields).transpose() Output:
|
@mandel @gbdrt thank you both for your responses clarifying further and with examples. I'm coming from an applied statistical domain of modeling, segmentation, and quasi-experimentation with many years of experience. I'm an intermediary level programmer in Python, learning by example. I have been using rstan, pystan and pymc3 quite a bit and in one of those posts I read about Your examples are very helpful as I will look to develop some Bayesian modeling examples (Linear Mixed Effects, GLMs, GLMMs,and GAMs and share them back here with you so that others can use these as starters. |
@gbdrt I have tried to run the model you shared and I get an error about
I have already defined a CMDSTAN variable set to cmdstan location CMDSTAN="~/cmdstan/" and can run the same model directly from cmdstan. |
What is your OS? How do you launch the example? Instead of doing simply
|
I'm working with Ubuntu 20.04LTS. I did it both ways. Here is my entire code:
Error Output is as follows:
|
@sreedta8 Does the command |
Maybe you could also try to add
|
I solved the error with the following changes: At the beginning (where the import statements are) I added
then later I added the following statements before executing the model sampling
Output is as follows without errors:
Then I used with this tabular output
|
Thank you @sreedta8 for finding a solution! |
@mandel thank you for taking the time to help with your feedback. |
@sreedta8 that is a bit strange. Jupyter should inherit local env variables (I cannot reproduce your error). |
@gbdrt you surmised correctly. I did do that. I got the code about using the os.environ from another Stan development called CmdStanPy (a python wrapper for running CmdStan https://github.com/stan-dev/cmdstanpy ) Thanks again for your help - Sree |
Yes CmdStanPy is great! from cmdstanpy import CmdStanModel
with open("coin.stan", "w") as model_file:
model_file.write(str(constrained_coin.model))
coin_model = CmdStanModel(stan_file="coin.stan")
coin_fit = coin_model.sample(data=constrained_coin.data)
print(coin_fit.summary()) Output:
If you find this useful, we could update the YAPS wrapper to use CmdStanPy. |
Hi
I learned about yaps for the first time today and I could install
yaps
(with its dependencies) andcmdstan
and successfully run the example model of thecoin
toss.In addition to examining the parameter
theta
, I want to execute thestansummary
command on theoutput.csv
created bycmdstan
which summarizes all the parameters. Please see the desired output I get fromcmdstan
The text was updated successfully, but these errors were encountered: