Thanks for your quick reply! I can't spot anything where I'm looping over node names but I might be wrong. Here's my (almost unabridged) code:
totalT <- 5
theta_init <- c(0.3, 0.95, 0.9, 2.0e-04, 8, 120)
phi_p_init <- theta_init[1]
phi_a_init <- theta_init[2]
alpha_init <- theta_init[3]
beta_init <- theta_init[4]
rho_init <- theta_init[5]
tau_init <- theta_init[6]
y0 <- 500
y <- c(668,649,834,747,903)
code <- nimbleCode({
##### Priors
phi_p ~ dbeta(2.87, 1.78)
phi_a ~ dbeta(1.6, 1.2)
alpha ~ dbeta(2, 1.5)
beta ~ dgamma(2, 1/(3.7e-04/2))
rho ~ dgamma(4, 1/2.5)
tau ~ dgamma(2.1, 1/66.67)
##### Initialisation
x_upd[, ] <- matrix(nrow = totalT+1, ncol = 2)
x_pred[, ] <- matrix(nrow = totalT, ncol = 2)
x0[1:2] <- y0*c(1, 1/alpha)
sigma2 <- y0^2/tau
P011 <- sigma2
P022 <- 1/(alpha^2)*((1-alpha)*y0+sigma2)
P012 <- 1/alpha*sigma2
P021 <- 1/alpha*sigma2
T12 <- alpha*phi_a
T22 <- phi_a
x_upd[1, 1:2] <- x0[1:2]
P_upd11[1] <- P011
P_upd12[1] <- P012
P_upd21[1] <- P021
P_upd22[1] <- P022
for(t in 1:totalT){
real_phi_p[t] <- phi_p/(1+(beta*x_upd[t, 1])^rho)
T21[t] <- 0.5*real_phi_p[t]
T11[t] <- alpha*0.5*real_phi_p[t]
Q11[t] <- alpha*(1-alpha)*(0.5*real_phi_p[t]*x_upd[t, 1]+phi_a*x_upd[t, 2])
Q22[t] <- 0.5*real_phi_p[t]*(1-0.5*real_phi_p[t])*x_upd[t, 1] + phi_a*(1-phi_a)*x_upd[t, 2]
Q12[t] <- alpha*(0.5*real_phi_p[t]*(1-0.5*real_phi_p[t])*x_upd[t, 1] + phi_a*(1-phi_a)*x_upd[t, 2])
Q21[t] <- alpha*(0.5*real_phi_p[t]*(1-0.5*real_phi_p[t])*x_upd[t, 1] + phi_a*(1-phi_a)*x_upd[t, 2])
R_matrix[t] <- x_upd[t, 1]^2/tau
# Prediction
x_pred[t, 1] <- T11[t]*x_upd[t, 1] + T12*x_upd[t, 2]
x_pred[t, 2] <- T21[t]*x_upd[t, 1] + T22*x_upd[t, 2]
P_pred11[t] <- (T11[t]*P_upd11[t]+T12*P_upd21[t])*T11[t]+(T11[t]*P_upd12[t]+T12*P_upd22[t])*T12+Q11[t]
P_pred12[t] <- (T11[t]*P_upd11[t]+T12*P_upd21[t])*T21[t]+(T11[t]*P_upd12[t]+T12*P_upd22[t])*T22+Q12[t]
P_pred21[t] <- (T21[t]*P_upd11[t]+T22*P_upd21[t])*T11[t]+(T21[t]*P_upd12[t]+T22*P_upd22[t])*T12+Q21[t]
P_pred22[t] <- (T21[t]*P_upd11[t]+T22*P_upd21[t])*T21[t]+(T21[t]*P_upd12[t]+T22*P_upd22[t])*T22+Q22[t]
# Aid variables
y_pred[t] <- x_pred[t, 1]
v_pred[t] <- y[t] - y_pred[t]
F_matrix[t] <-P_pred11[t] + R_matrix[t]
G1[t] <- P_pred11[t]
G2[t] <- P_pred21[t]
F_inv[t] <- F_matrix[t]^(-1)
K1[t] <- G1[t]*F_inv[t]
K2[t] <- G2[t]*F_inv[t]
# Distribution of y
y[t] ~ dnorm(y_pred[t], var = F_matrix[t])
# Update
x_upd[t+1, 1] <- x_pred[t, 1] + K1[t]*v_pred[t]
x_upd[t+1, 2] <- x_pred[t, 2] + K2[t]*v_pred[t]
P_upd11[t+1] <- P_pred11[t] - F_inv[t]*G1[t]^2
P_upd12[t+1] <- P_pred12[t] - F_inv[t]*G1[t]*G2[t]
P_upd21[t+1] <- P_pred21[t] - F_inv[t]*G1[t]*G2[t]
P_upd22[t+1] <- P_pred22[t] - F_inv[t]*G2[t]^2
}
})
mNimble_seal2 <- nimbleModel(code,
dimensions = list(x_upd = c(totalT+1,2),
x_pred = c(totalT,2)),
data = list(y=y, y0 = y0),
constants = list(totalT = totalT),
inits = list(phi_p = phi_p_init,
phi_a = phi_a_init,
alpha = alpha_init,
beta = beta_init,
rho = rho_init,
tau = tau_init),
check = FALSE)
compNimble_seal2 <- compileNimble(mNimble_seal2)
confNimble_seal2 <- configureMCMC(mNimble_seal2,
print = TRUE, useConjugacy = FALSE)
mcmcNimble_seal2 <- buildMCMC(confNimble_seal2)
# This runs but slowly
# fNimble_seal2 <- runMCMC(mcmcNimble_seal2,
# nburnin = 10,
# nchains = 2,
# niter = 110)
# This is where the error happens
mcmccNimble_seal2 <- compileNimble(mcmcNimble_seal2,
project = mNimble_seal2,
resetFunctions = TRUE,
showCompilerOutput = TRUE)