Error using pp_check using truncated response variable in brms

bayesplot

#1

Hello,

I’m getting started with brms, trying to fit a count model with zeros truncated out (as opposed to zero-inflating them). I noticed that running pp_check (of type rootogram) doesn’t work on the fitted model in this case.

Example code:

library(brms)

fishdata <- read.csv("https://paul-buerkner.github.io/data/fish.csv")
fishdata_filt = fishdata[fishdata$count > 0, ]

fit_pois <- brm(count | trunc(lb=1) ~ persons + child + camper,
                 data = fishdata_filt, family = poisson())

pp_check(fit_pois, type = "rootogram", style="hanging")

Returns the error message:

Error in .fun(.x1, .x2, style = .x3): ppc_rootogram expects counts as inputs to 'yrep'.
Traceback:

1. pp_check(fit_pois, type = "rootogram", style = "hanging")
2. pp_check.brmsfit(fit_pois, type = "rootogram", style = "hanging")
3. run(ppc_fun, ppc_args)
4. eval2(call, envir = args, enclos = parent.frame())
5. eval(expr, envir, ...)
6. eval(expr, envir, ...)
7. .fun(.x1, .x2, style = .x3)
8. stop("ppc_rootogram expects counts as inputs to 'yrep'.")

If I remove the | trunc(lb=1) part of the formula, everything works fine (although the model fits poorly).

Unfortunately I don’t understand R well enough to parse the error message. Is pp_check expected to work under circumstances like these?

Thanks in advance for your help.

Version information:

  • Operating System: macOS 10.12.6
  • brms Version: 2.7.0

#2

Thanks for reporting this issue and also, in particular, for directly providing a reproducible example!

I have fixed the problem in github version of brms to be installed via

if (!requireNamespace("devtools")) {
  install.packages("devtools")
}
devtools::install_github("paul-buerkner/brms")

#3

Thanks for fixing! My error is resolved by using the github version.