Hi all,
I've been trying to work an eigen decomposition into a nimble model, but am running into an issue. When I try to manipulate the extracted eigenvalue by adding or multiplying it by another parameter, I get the error "cannot coerce type 'closure' to vector of type 'double'."
But it only seems to happen when the other parameter is drawn from a normal distribution, and if I instead draw it from a uniform distribution, it works. I can't understand why those would produce different behavior. Simplified example below.
Thanks,
Franny
pumpCode <- nimbleCode({
S ~ dunif(0,2)
V ~ dunif(0,2)
for (t in 1:T){
D[1,1,t]<-0
D[1,2,t]<-V
D[1,3,t]<-V
D[2,1,t]<-S
D[2,2,t]<-0
D[2,3,t]<-0
D[3,1,t]<-0
D[3,2,t]<-S
D[3,3,t]<-S
lambda_d[t]<-eigen(D[1:3,1:3,t])$values[1]
C[t]~dpois(phi[t])
log(phi[t])~dnorm(a+log(lambda_d[t]),sd=0.01)
}
#a~dunif(-1,1)
a~dnorm(0,sd=0.0001)
})
S<-0.95
V<-0.25
T<-50
D<-matrix(c(0,V,V,S,0,0,0,S,S),byrow=T,nrow=3)
lambda_d<-eigen(D)$values[1]
C<-rep(0,T)
for (t in 2:T){
log.lambda_d<-0.1+log(lambda_d)
C[t]<-rpois(1,exp(log.lambda_d))
}
pumpInits <- list(S = 1, V = 1, a=0)
pumpConsts <- list(T=T)
pumpData <- list(C=C)
out<-nimbleMCMC(code = pumpCode, constants = pumpConsts,
data = pumpData,inits=pumpInits,
nchains = 1, niter = 60000,
monitors = c("a"))