Pp_check - quick way to change scale of y_rep variable?


Simple question, but is there a quick way to use pp_check while changing the scale of the y (dependant) variable such that I can get my y_rep on a linear scale (even though it is on log scale in the brms model object)? Adding this ggplot style line to the pp_check output is doing nothing for me:

" scale_x_continuous(trans="exp")"

As in:

 pp_checkobject <- pp_check( model_fit, newdata = newdataex, 
                type = "stat", stat="median",
                nsamples = 100) + 

The brms model fit object I have uses a log(dependant variable). This is the issue.

I see the output from pp_check is a ggplot compatible object but can’t seem to find an easy way to extract the value from the object and put it on the linear scale by exponentiating it when plotting it.

I know the value of y_rep is housed here such that this does what I want but not within the ggplot environment:


I also tried changing the scale in the option for “y=” within pp_check but did not change anything for me.

Thank you,


I don’t think that’s supported out of the box, but should be easy to write yourself. Note that pp_check(fit, type = 'stat', ...) is (very roughly) a shorthand for:

pred <- posterior_predict(fit, ...)
bayesplot::ppc_stat(y = data$response, yrep = pred, ...)

So an easy way to transform the values is to just transform both predicted and observed values manually, e.g.:

bayesplot::ppc_stat(exp(pred), exp(data$response), ...)

Also, I think that usually, you would call it a posterior-predictive check if you compare predictions for the data you fitted the model with to the observed response (i.e. without setting newdata). Using this visualisation with newdata set could definitely be useful, but I am not sure most people would understand this as “posterior predictive check”.

Best of luck with your model!