Problem with predicting Posterior Predictive Distributions

Hi fellows

I am trying to use rstanarm for plotting posterior predictive distributions and related results. However I receive errors when i use functions such as “yrep = posterior_predict(stanfit, draws = 500)” . The error is:

Error in UseMethod("posterior_predict") : 
  no applicable method for 'posterior_predict' applied to an object of class "stanfit"

while I manually draw my posterior “f” value to a new variable like f_results then I use codes as follow:

'...
f_results = subset(draws2, variable="f") %>%  
  as_draws_df()

y=standata2$y
yrep=f_results[,1:174]
ppc_dens_overlay(y, yrep[1:50,])

I kept f_results[,1:174] and drop out the last three column which was related to chain numbers and other stuff. Also y is a one colomn with 174 rows. however when I use ppc_dens_overlay command then i got this error:

Error in validate_yrep(yrep, y) : is.matrix(yrep) is not TRUE

I guess there is something wrong with my yrep which is not defined as matrix by r. Otherwise all the dimensions are correct so why i cannot run it?

Could you kindly advice me for these two errors?

Hello and sorry about the delay. I did a few edits using ``` to enclose your lines of code. Can you post what version of R, rstan, and if using RStudio. Oh and your OS. That can help folks help out. Thanks!

Dear Ara, thank you for your message. I am using the last version R and implementing codes in Rstudio on Windows OS.

Actually, I could eventually plot predictive posterior distribution buy extracting my stan results and draw from all posteriors manually. However I could not yet use “yrep = posterior_predict(stanfit, draws = 500)” function which is more easy for my future running. I am not sure if i should add something in my stan file code or not.