Bayesplot not plotting fully and refusing xlim and ylim arguments

I am failing to have the bayesplot(pp-check()) command function well. The plot results seem to be centred around the “0” mark, and it refuses the Xlim and ylim arguments that would scale the plot to a clear view of the plot. Is there anything I am missing, kindly help. Here below is my model.

library(ProbBayes)
library(brms)
library(dplyr)
library(ggplot2)

options(brms.backend = "cmdstanr")
prior1 <- c(set_prior("normal(49.21, 3.23)", class = "b", coef = "Age"),
            set_prior("normal(-0.5, 0.25)", class = "b", coef = "Gender"),
            set_prior("normal(2, 2.5)", class = "b", coef = "Education"),
            set_prior("normal(5, 2.5)", class = "b", coef = "MonNetInc"),
            set_prior("normal(500, 250)", class = "b", coef = "OwnrCosts"),
            set_prior("normal(500, 250)", class = "b", coef = "VOwnerTarget"),
            set_prior("normal(0, 1)", class = "b", coef = "PrevUseCFCs"),
            set_prior("normal(500, 250)", class = "b", coef = "CashToAcceptCFC"),
            set_prior("normal(0, 2.5)", class = "b", coef = "CFCPercpt"),
            set_prior("normal(0, 2.5)", class = "b", coef = "SocInflc"),
            set_prior("normal(0, 2.5)", class = "b", coef = "InflcdWTA"),
            set_prior("normal(0, 2.5)", class = "b", coef = "Complx"),
            set_prior("normal(0,2.5)", class = "b", coef = "Compblty"),
            set_prior("normal(0, 2.5)", class = "b", coef = "Interests"),
            set_prior("normal(0, 2.5)", class = "Intercept"),
            set_prior("cauchy(0, 2.5)", class = "sigma")
            ) 

fit_VehOwnsWTA_CFC1 <- brm(WTACFCPresState~.,
                      data =  FullVehicleOwnersDtset3, family = gaussian(link = "identity"),
                      warmup = 1000, iter = 5000, seed = 123, chains = 4, prior = prior1, 
                      control = list(adapt_delta = 0.99), cores = 2)

summary(fit_VehOwnsWTA_CFC1)
bayesplot_grid(pp_check(fit_VehOwnsWTA_CFC1, type = "hist", ndraws = 200,
                   xlim = c(-100, 100)))

Can you try putting the xlim in the call to bayesplot_grid instead of pp_check?

Also I’m not sure you need bayesplot_grid here at all. Doesn’t this pp_check call return just a single plot? You only need the grid if you’re combining multiple plots into a single grid of plots. So you can maybe just add + ggplot2::xlim() after pp_check() and not use the grid at all.

Dear Jonah,
Thanks for your advice, but this still refuses!
pp_check(fit_VehOwnsWTA_CFC1, type = “dens_overlay”, ndraws = 100)

     + ggplot2::xlim = c(-500, 500)

Error: object ‘ggplot2’ not found

it prints a very small image centred around 0, and Xlimits still goes to -2000 and 2000.

This should be ... + ggplot2::xlim(-500, 500). Does that help?

Dear Jonah,
Thank you, this works!!

1 Like