Hi all,
I was introduced to OpenBUGS by a colleague and has been using it since. Recently I came across STAN and thought maybe I could give it a try. However there seems to be some error. Is there anyone who is kind enough to vet through my code below and enlightened me. Many thanks.
model{
mu ~ dnorm(0,1.0E-6)
beta ~ dgamma(1.0E-5,1.0E-5)
for (i in 1:6){
delta[i] ~ dnorm(mu,beta)
prec[i] <- 1/(u[i] * u[i])
x[i] ~ dnorm(delta[i],prec[i])
pred[i] ~ dnorm(mu,prec[i])
DOE[i] <- x[i] - pred[i]
}
}
list(
x = c(34.30,32.90,34.53,32.42,31.90,35.80),
u = c(1.03,0.69,0.83,0.29,0.40,0.38)
)
list(beta=1)
I am trying to convert the above into:
data {
int<lower=0> N;
real x[N];
real<lower=0> u[N];
}
parameters {
real mu;
real <lower=0> beta;
real <lower=0> delta[N];
real <lower=0> pred[N];
}
transformed parameters{
real uu[N];
uu[N] = u[N] * u[N];
}
model {
mu ~ normal(0,1E-6); //prior for mu
beta ~ gamma(1E-5,1E-5); //prior for beta
delta[N]~normal(mu,beta);
x[N] ~ normal(delta[N],uu[N]);
pred[N]~normal(mu,uu[N]);
}
generated quantities{
real DOE[N];
DOE[N] = x[N] -pred[N];
}
I saved the above as STAN extension and calling it in R with the following:
```R script
library(rstan)
library(shinystan)
options(mc.cores = 4)
data <-list(N=6, y = c(34.3,32.9,34.53,32.42,31.9,35.8), u=c(1.03,0.69,0.83,0.29,0.4,0.38))
model1 <- stan(file='Openbugs convert HB REM1.stan', data=data)
print(model1)