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 didnt work #296

Closed Taeyeon1607 closed 2 years ago

Taeyeon1607 commented 2 years ago

Hello!

I made a regression model using rstanarm, and below are the output results of get_variables and spred_draws.

get_variables(stan_model) [1] "(Intercept)" "mom_iq" "sigma" "accept_stat" [5] "stepsize" "treedepth__" "n_leapfrog" "divergent"
[9] "energy__"

stan_model %>%

  • spread_draws("Intercept", mom_iq) Error: x must be a vector

When only the mom_iq at the back is input, it is output without any abnormality, but that intercept seems to be the problem. How can I solve this?

mjskay commented 2 years ago

Variables with spread_draws must be specified as bare names (ie using backticks or no quotes at all), not strings. Does this work?

stab_model %>%
  spread_draws(`(Intercept)`, mom_iq)
Taeyeon1607 commented 2 years ago

Thanks for replying!

I wrote it wrongly in the text. I entered it correctly as below and got the same error.

stan_model %>%

  • spread_draws('(Intercept)', mom_iq) Error: x must be a vector
mjskay commented 2 years ago

Looks like you are using single quotes ('), not backticks (`)

Taeyeon1607 commented 2 years ago

The problem has been resolved.

Since I'm a beginner, I'm bothered by an easy problem.

I've been struggling with this problem all day yesterday.

Thank you very much.

mjskay commented 2 years ago

No worries, glad it is resolved! Quoting in R can be very confusing. Apologies the error message wasn't more helpful to start with.