View source: R/take-draws_poststrat.R
pivot_celldraws_longer | R Documentation |
Take output from brms prediction and turn to tidy form
pivot_celldraws_longer(mod_draws, data_strat, yhat_name = "pred_n_yes")
mod_draws |
Output from |
data_strat |
Covariates to append to. The number of rows should be
the number of |
yhat_name |
The name of the value for the predicted outcome. |
A tidy long dataset with Iter
x Cells
rows. Columns
will include the columns of data_strat
, the iteration and cell ID, and
the predicted value for that cell at that iteration.
library(dplyr)
library(brms)
pred_df <- rename(acs_GA, n_response = count) # match variables with model call
posterior_draws <- posterior_epred(object = fit_GA, # stanfit
newdata = pred_df)
# output is matrix, not tidy form
class(posterior_draws)
dim(posterior_draws)
# tidy out
out <- pivot_celldraws_longer(mod_draws = posterior_draws,
data_strat = pred_df,
yhat_name = "pred_n_yes")
dim(out)
select(out, cd, n_response, cell, iter, pred_n_yes)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.