Skip to content

ppc_bars (and similar) throws error with negative integers #172

Closed
@jeffpollock9

Description

@jeffpollock9

Hi, may I ask why ppc_bars (and other discrete outcome functions, I think) throws an error when y or yrep contain negative values? For example I would like to use this function with the skellam distribution as follows:

library(bayesplot)
library(skellam)

n <- 1000
m <- 500

y <- rskellam(n, 1.5, 2.5)
yrep <- matrix(rskellam(m * n, 1.4, 2.6), m, n)

ppc_bars(y, yrep)

which currently outputs:

> ppc_bars(y, yrep)
Error in ppc_bars(y, yrep) : 
  ppc_bars expects only non-negative integers in 'y'.

If I remove the checks, which are:

if (!all_counts(y)) 
    stop("ppc_bars expects only non-negative integers in 'y'.")
if (!all_counts(yrep)) 
    stop("ppc_bars expects only non-negative integers in 'yrep'.")

Then the plot works as expected:

plt

I appreciate that the majority of the time the outcomes are non-negative, but it is not always the case and I don't think that this function should error here. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions