Hi Nimble expert,
I am trying to use nimble to simulate 100 datasets based on different simulated variables. However, when I replace different variables, I always get the same simulated dataset, I guess it might be because I did not change the initials...I have attached the code and could anyone please let me know if I messed something up? Thanks in advance!
simCode <- nimbleCode(
{
for (i in 1:N){
O[i] ~ dpois(mu[i])
log(mu[i]) <- log(expected[i])+alpha+ice[i]*betai[i]+u[i]+v[i]+b0*ice[i]
betai[i]<-inprod(beta_sm[], X_sm[i,])+inprod(beta_pm[],X_pm[i,])+
inprod(beta_un[],X_un[i,]) #this is from spline function
v[i] ~ dnorm(0, tau = tau.v)
}
u[1:N]~dcar_normal(adj[1:L], weights[1:L], num[1:N], tau1, zero_mean = 1)
# Priors:
alpha ~dnorm(0,sd=100)
b0~dnorm(0,sd=100)
tau1~dgamma(1,0.01)
tau.v~dgamma(1,0.01)
for(j in 1:7){
beta_sm[j] ~ dnorm(0, sd=100)
beta_pm[j] ~ dnorm(0, sd=100)
beta_un[j] ~ dnorm(0, sd=100)
}
}
)
**each simulated dataset should be based on different values of X_sm, X_pm and X_un.
bsMat.s, bsMat.p and bs.Mat.u are the predefined matrix**
simModel <- nimbleModel(code = simCode,
data=list(X_sm=bsMat.s, X_pm=bsMat.p, X_un=bsMat.u),
constants = list(expected =n,ice=mergeus$ICEwbinc,
N = Nareas, L=length(adj), adj=adj, weights=weights,
num=num),
inits = list(alpha=0.01, betai=rep(0.1,3108),beta_sm=rep(0,7),beta_pm=rep(0,7),
beta_un=rep(0,7),u=rep(1,3108),v= rep(1,3108),tau1=3, tau.v=1, b0=1))
simModel$calculate('mu')
nodesToSim <- simModel$getDependencies(c("alpha", "betai","beta_sm","beta_pm","beta_un","u","v",
"tau1","tau.v","b0"),self = F, downstream = T)
simModel$simulate(nodesToSim,includeData = FALSE)
simModel$mu
I tried to replace different values for X_sm, X_pm, X_un, but always get the same mu.
Many thanks!
Bill