I am trying to simulate data to use for posterior predictive checks in JAGS running through R, which is relatively simple for pre-loaded distributions, but I am looking to simulate data when I have fit the parameters with the "ones trick" to the Gumbel distribution for extreme values. What follows is my code:

data <- list(mx=annualMaximumSeries,

params <- c("lo", "sc", "sh")


  # priors
  lo ~ dnorm(0,precision)
  sc ~ dunif(0,100)  # scale must be greater than zero

  C <- 10000  # scaling constant to ensure that p[i]'s < 1

  # likelihood
  for(i in 1:n){
    # Gumbel Likelihood:
    L[i] <- ((1.0/sc)*(exp(((-mx[i]+lo)/sc)-exp((-mx[i]+lo)/sc))))

    # Get probabilities for Bernoulli:
    p[i] <- L[i]/C

    # Evaluate Likelihood using Bernoulli ones trick:
    ones[i] ~ dbern(p[i])


Effectively what I want to have is another loop to simulate my data, calculate some metric on which I want to do posterior predictive check with each estimated set of parameters and new data, and construct a Bayesian p-value as per Gelman, A., Meng, X., & Stern, H. (1996). Posterior Predictive Assessment of Model Fitness via Realized Discrepancies. Statistica Sinica, 6, 733–807. (more specifically as in Marc Kery "Introduction to WinBUGS for Ecologists"). However, because the Gumbel likelihood is not pre-loaded, I cannot simply do


So, how can I simulate new data in this context? Is there a way to work with the "Ones trick" to simulate new data, or is there a way to program the dgum function into JAGS somehow so I can use it without the "ones trick"?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.