Hi Dipankar,
I provide an example, showing how to generate replicates using zeros trick.
Hope this helps.
Zane
model {
for (i in 1:8) {
zeros[i] <- 0 # trick using zeros
zeros[i] ~ dpois(phi[i]) # likelihood is exp(-phi[i])
phi[i] <- -0.5 * log(tau[1]) + 0.5 * tau[1] * pow((x[i] - mu[1]) , 2) # -log(likelihood)
x[i] ~ dnorm(0, 0.000001) # very vague normal prior on x's
}
for (i in 1:8) { # check using normal distribution
x.rep[i] ~ dnorm(mu[2], tau[2])
}
for (k in 1:2) {
mu[k] ~ dnorm(0, 0.000001)
tau[k] ~ dgamma(0.001, 0.0001)
}
}
Data:
list(x = c(-1, -0.3, 0.1, 0.2, 0.7, 1.2, 1.7, NA), x.rep=c(-1, -0.3, 0.1, 0.2, 0.7, 1.2, 1.7, NA))
Initial values:
list(tau = c(1, 1), mu = c(0, 0), x = c(NA, NA, NA, NA, NA, NA, NA, 0))
--------------------------------
Thank you Pablo for this solution, but how would I generate "replicates" of the first element in your data-vector (i.e. 2) coming from the posterior predictive distribution?
Dipankar
On Thu, Feb 2, 2012 at 10:16 AM, Dr. Pablo E. Verde <[log in to unmask]> wrote:
Hi Dipankar,
The answer is not, you cannot sample from the predictive posterior in your way.
The easy way to sample from the predictive posterior while you using the zeros trick is
by adding artificial missing data to your data vector.
So if your data set is in a list:
list(x =c(2,5,6,2,4,7,8))
Then do
list(x =c(2,5,6,2,4,7,8, NA, , NA, NA, NA, NA))
the values of x[8:12] are sampled automatically from the predictive posterior.
Hope it helps,
Pablo
----- Original Message -----
From: Dipankar Bandyopadhyay
To: [log in to unmask]
Sent: Tuesday, January 31, 2012 8:35 PM
Subject: [BUGS] generating replicates from zeros trick
Hi,
I am interested in generating replicates from the posterior predictive distribution of a r.v. X, which has been programmed in WinBUGS using the zeros trick. Can someone suggest whether I am doing it correctly? So, zeros.rep[] in the code below are my replicates.
K <- 1000
ll[i] <- ...... ## Log-likelihood of X
zeros[i] < - 0
zeros[i] ~ dpois(phi[i]) ## Zeros trick
phi[i] <- - ll[i] + K
zeros.rep[i] ~ dpois(phi[i]) ## Replicates of y[i] ?
Thanks a bunch,
Dipankar
______________________________
Dipankar Bandyopadhyay, PhD
Associate Professor,
Division of Biostatistics, School of Public Health,
University of Minnesota
Minneapolis, MN 55455 USA
http://www.biostat.umn.edu/~dipankar
------------------------------------------------------------------- This list is for discussion of modelling issues and the BUGS software. For help with crashes and error messages, first mail [log in to unmask] To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments to the list. To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list
------------------------------------------------------------------- This list is for discussion of modelling issues and the BUGS software. For help with crashes and error messages, first mail [log in to unmask] To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments to the list. To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list
------------------------------------------------------------------- This list is for discussion of modelling issues and the BUGS software. For help with crashes and error messages, first mail [log in to unmask] To mail the BUGS list, mail to [log in to unmask] Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html Please do not mail attachments to the list. To leave the BUGS list, send LEAVE BUGS to [log in to unmask] If this fails, mail [log in to unmask], NOT the whole list