Hi again,
I was previously able to get my code to run, but I'm now getting the following error and I don't believe I've changed anything. I've attached sample data if that's helpful. I have the following code, and get an error that I need to define the random function for my user-defined distribution. After reading the user manual, it doesn't appear that I should need it. Furthermore, this code previously ran without issue. Any thoughts as to what is happening here?
Thanks!
Annie
Here is my code:
#====================================================================
# functions
#====================================================================
f_vec <- nimbleFunction(
run = function(x = double(0)){
# #Phl:
k <- 6.06
r <- 2.94
tmp_vec <- rep(NA, x)
for (i in 1:x) {
tmp_vec[i] <- pgamma(x-(i-1), k, rate = r) - pgamma(x-i, k, rate = r)
}
return(tmp_vec)
returnType(double(1))
})
# code penalty as prior
dpen <- nimbleFunction(
run = function(x = double(1),
theta = double(0), L = double(0),
log = integer(0, default = 0)) {
returnType(double(0))
logProb <- -(theta/2)*sum((log(x[1:(L-2)]) - 2*log(x[2:(L-1)]) + log(x[3:L]))^2)
if(log) return(logProb)
else return(exp(logProb))
})
#====================================================================
# set up MCMC
#====================================================================
modelCode <- nimbleCode({
for (i in 1:L){
#get mu
mu[i] <- sum(f_vec(i)*lambda[1:i])
#likelihood
x[i] ~ dpois(mu[i])}
#priors
lambda[1:L] ~ dpen(theta = theta, L = L)
# k ~ T(dnorm(6.06, .1), 0, )
# r ~ T(dnorm(2.94, .05), 0, )
#hyperprior
theta ~ dunif(1, 100)
})
modelConsts <- list(L = nrow(dat))
modelData <- list(x = dat$Notifications)
# initsList <- list(lambda = abs(rnorm(nrow(dat), mean(dat$Notifications), sd(dat$Notifications))))
model <- nimbleModel(modelCode, data = modelData, constants = modelConsts) #inits = initsList,
#====================================================================
# Compile and run model
#====================================================================
# compile into nimble
Cmodel <- compileNimble(model)
And here is the error I get when compiling my model:
Error: In sizeAssignAfterRecursing: 'rpen' is not available or its output type is unknown.
This occurred for: eigenBlock(model_lambda,1:29) <<- rpen(=1,theta=model_theta[1],L=29)
This was part of the call: {
eigenBlock(model_lambda,1:29) <<- rpen(=1,theta=model_theta[1],L=29)
}