mjskay / tidybayes

Bayesian analysis + tidy data + geoms (R package)
http://mjskay.github.io/tidybayes
GNU General Public License v3.0
710 stars 59 forks source link

`spread_draws()` with rstanarm glmer? #308

Closed potash closed 1 year ago

potash commented 1 year ago

I am having trouble applying spread_draws() to a varying intercept varying slope model fit with the following formula and stan_glmer()

y ~ log(x) + (log(x) | site)

Calling get_variables() returns something like this:

[1] "(Intercept)"                                
[2] "log(x)"                            
[3] "b[(Intercept) site:A]"                
[4] "b[log(x) site:A]"            
[5] "b[(Intercept) site:B]"                     
[6] "b[log(x) site:B]"
...

Is this naming convention compatible with spread_draws()? I'd like to extract a dataframe that looks like this:

.draw, site,(Intercept),log(x)
1,A,...,...
1.B,...,...
...
potash commented 1 year ago

Simply spread_draws(fit, b[i,j]) works. I was backticking b[i,j] and that was breaking it with:

No variables found matching spec: b\[i\,j\]

Is that a bug?

mjskay commented 1 year ago

Yeah b[i, j] should work, and if you want the i as columns b[i, j] | i would do that.

Using backticks like `b[i,j]` doesn't work because that means you are asking for a variable named "b[i,j]" exactly.

potash commented 1 year ago

Ah that explains it, thanks

mjskay commented 1 year ago

great, happy to help!