greta-dev / greta

simple and scalable statistical modelling in R
https://greta-stats.org
Other
537 stars 63 forks source link

calculate doesn't work on data array? #520

Open hrlai opened 2 years ago

hrlai commented 2 years ago

Hi, I wish to simulate observations after fitting a greta model with mixture likelihood, but couldn't get it to work. Below is the example in ?mixture. I only modified the first line with as_data to be able to use calculate on x. Perhaps I missed something?

library(greta)

x <- as_data(c(
  rpois(800, 3),
  rpois(200, 10)
))

weights <- uniform(0, 1, dim = 2)
rates <- normal(0, 10, truncation = c(0, Inf), dim = 2)
distribution(x) <- mixture(poisson(rates[1]),
                           poisson(rates[2]),
                           weights = weights
)
m <- model(rates)
draws_rates <- mcmc(m, n_samples = 500)

calculate(x, values = draws_rates, nsim = 1)   # will fail with error

Thanks in advance!

njtierney commented 1 year ago

Talking with @goldingn about this, if you want to do posterior predictive checks, it would be best to create a new variable that's distributed the same but doens't have fixed values.

That being said we could improve the documentation on this to make this clearer, so I'll leave this open and move it to the next milestone