Closed jebyrnes closed 3 years ago
Hm, good question. Originally I did not add this because in most cases this is just add_fitted_draws
or add_predicted_draws
(depending on type of residual) followed by a mutate
. On the other hand, it could be nice as a convenience function, and standardizing it may reduce errors.
Probably I would pattern this after [add_][fitted|predicted]_draws
, so there would be a residual_draws
and add_residual_draws
function. Output column name would then be .residual
.
Looking at residuals.stanreg
and predictive_error.stanreg
, there will have to be some argument standardization... brms seems to merge these two into one function where method = "fitted"
gives the former and method = "predict"
gives the latter; rstanarm does not merge these into one function. I would probably standardize this usage and give one function (then document arg standardization in #70).
My preference would maybe be for method = "predicted"
to be the default. Annoyingly type
would also need standardization, as that argument in brms uses "ordinary"
instead of "response"
(which is what rstanarm uses to mean the same thing, seemingly patterned after residuals
from base R).
Something that has been on my internal TODO list is to figure out where (if at all) doing randomized quantile residuals would fit into tidybayes. It occurs to me that with method = "predict"
it might be possible to roll those in without much overhead, say as another value of type
.
Thoughts on any of this?
At some point, we have to align the arguments names of the brms and rstanarm methods, but I don't think this will happen this year. So it's probably better to align in inside tidybayes for the time being.
Cool - so, using add_predicted_draws
and a little rlang (to grab the first column), do you think I could just go through the predicted_draws.R file and throw something back and you?
Oh! I've already started down that path. Jussec, I'll commit something...
Check out the dev branch now. I think it should work...
still needs:
Oh! Cool! Thanks! Will look!
Closing this old issue (it is mostly implemented anyway).
Have you thought about putting in some tidy output for residuals? Could be very convenient for, say, finite population standard deviation calculations. See some code below I developed with
brms
which I think could be easily extended.