Naming help on function in CmdStanR and CmdStanPy to get variable from sample

Not yet — I plan to rebuild some internals on top of posterior::as_draws_df, at which point (I assume) that should start working.

In the meantime, if you have a data frame in the format expected by spread_draws() (which as_draws_df should give you unless I’m mistaken), it should work to pass that directly into spread_draws() / gather_draws() / whatever instead of passing in the model. (If that doesn’t work please file an issue :) ).

3 Likes

Indeed!

This worked:

fit_labeled = fit$draws() %>%
  as_draws_df %>%
  recover_types(df)

fit_labeled %>%
  spread_draws(mu[age, income])

Thanks!

3 Likes

Oh perfect! It’s nice when things work properly together even when you haven’t tested them yet :)

5 Likes

tidybayes looks awesome!

I think that the CmdStanX interfaces should have a standard set of function names
so that we can talk about the workflow in an interface language agnostic way,
therefore I think that we still want to have named functions that wrap tidybayes and pandas.

for CmdStanPy, there’s PR to introduce functions stan_variable and stan_variables which return the draws for specified variable or a dictionary over all variables, respectively.
I think it would be good to have similarly named functions in CmdStanR, which can call tidybayes under the hood - does this make sense?

1 Like

tidybayes is indeed great, but it’s not quite what we need for cmdstanr to have a replacement for rstan::extract(). for that we need the additional “random variable” functionality in posterior
that @mjskay and @paul.buerkner mentioned above. But it sounds like that might be coming this summer!

1 Like

that’s the important thing - how it gets implemented is up to CmdStanR devs.

2 Likes