Solved – Bayesian Analysis in R/WinBUGS and SAS (Proc MCMC)

bayesianbugsmarkov-chain-montecarlorsas

I have a Bayesian model here in R/WinBUGS. This data "pumps" has two columns, time and fail. Each observation is a pump and fail[1] tells how many failures there were in time[1]. I want to know how I can write this same model in SAS using Proc MCMC. Thank you!

pump <- function() {
    for(i in 1:10){
        fail[i] ~ dpois(lam[i])
        theta[i] ~ dgamma(a,b)
        lam[i] <- theta[i]*time[i]
    }
    a ~ dgamma(1.5,.25) 
    b ~ dgamma(1.5,.25)
}

filename <- file.path(tempdir(),'pump.bug') 
write.model(pump,filename)
time <- pumps[,1]
fail <- pumps[,2]

data <- c('time','fail')
parameters <- c('fail','lam','theta','a','b')
pump.sim <- bugs(data, inits=NULL, parameters, model.file='pump.bug',
    n.iter=20000, n.burnin=1000, n.chains=1, n.thin=1, debug=T) 

Best Answer

See if something like this works:

proc mcmc
 data = /* your data here */
 nmc = 20000, nbi = 1000; /* iterations and burn-in */

 /* Specify parameters -- separate statements means they're proposed separately */
 parms a;
 parms b;
 parms theta;

 /* Specify priors */
 hyper a ~ gamma(1.5, scale = .25);
 hyper b ~ gamma(1.5, scale = .25); 
 prior theta ~ gamma(a, scale = b);

 /* Sampling model */
 lam = theta*time;
 model fail ~ poisson(lam);
run;