How can I fix this: Error in pp_check.default : argument "fun" is missing, with no default

Hei all, I am a complete newbie to this but trying to get a model going, the code comes from a former lab member, and I try to learn enough to use and adjust it for our projects. I managed to get the model going but I get an error in my second posterior check that neither her nor google can solve, so I ask here. As I am not sure if it is needed I put the model here too, sorry for the long post!
Thanks for your answers!

fit_model <- function (Data) {
fit<- brm(
LDL ~ (1 + exp ((gamma-Time) / delta)) / (15*exp((gamma-Time) / delta) + alpha),
alpha ~ 1 + (1 | Pat),
gamma ~ 1 + (1 | Pat) ,
delta ~ 1 ,
nl = TRUE

# Declaring priors  

prior = c(
  #(1) Priors for fixed effects

  prior (normal (4000,2000), class="b", lb=0, nlpar = "alpha"),
  prior (normal (3,2), class="b", lb=0, nlpar = "gamma"),
  prior (normal (0.2,1), class="b", lb=0, ub=1, nlpar = "delta"),
  #(2) Priors for the extra fixed effects added to the parameters (if any are added). 
  # prior (normal (4000,2000), class="b", coef="", nlpar = "alpha"),
  # prior (normal (3,2), class="b", coef="", nlpar = "gamma"),
  # prior (normal (0.2,1), class="b", coef="", nlpar = "delta"),
  #(3) Prior for family distribution parameter
  prior(gamma(0.01, 0.01), class="shape"),
  # (4)Priors for SD of random effects  
  prior (normal (1000,1000), class="sd", group="Pat", nlpar="alpha"),
  prior (normal (1,1), class="sd", group="Pat", nlpar="gamma")), 

#(5) Data
data = Data, 

#(6) Distribution family and link function

family = Gamma (link="inverse"),

#(7) Number of chains
chains = 4,

#(8) Number of iterations 

iter = 5000,

#(9) Number of warm-up iterations

warmup = 1000,

#(10) Enabling sampler to run on all available processor cores.

cores = getOption ("mc.cores",1L),

#(11) Thinning
thin = 1,

# (12) Sampler parameters

  control = list (adapt_delta = 0.99999, max_treedepth=15),

# (13) Verbose
verbose = TRUE


run the fit_model function (given above) to actually fit the model

fit <- fit_model(ldlData)

check the model output summary to see if the model converged


save fitted model


Posterior Predictive Checks


pp_check (fit)


pp_check (fit_model , type=“stat”, stat=“mean”, nsamples = 100)

And there I get the error:
Error in pp_check.default(fit_model, type = “stat”, stat = “mean”, nsamples = 100) :
argument “fun” is missing, with no default

In your second posterior predictive check, shouldn’t you pass fit rather than fit_model to the pp_check function?
If I understand correctly, fit_model is a function you created to perform model fitting via brms, whereas fit is the fitted model object that you’re actually interested in (i.e. the output of fit_model).

Oh gods yes, thanks so much. I just took the code as is, and all other tests were also on the fit_model, this fixed it!