Hi everyone,
This is a relatively simple question and hopefully is a simple answer. I am trying to sample using a vectorized poisson to see if it will speed my model up. I have gotten the distribution function correct but it seems that I have the random generation function incorrect. Could someone look this code over and see if there are any errors?
# Vectorized poisson
dpois_vec <- nimbleFunction(
run = function(x = double(1),
lambda = double(1),
log = integer(0, default = 0)){
returnType(double(0))
logProb <- sum(dpois(x, lambda, log = TRUE))
if(log) return(logProb)
else return(exp(logProb))
}
)
# Random generation
rpois_vec <- nimbleFunction(
run = function(n = integer(0, default = 1),
lambda = double(1)){
returnType(double(1))
return(rpois(length(lambda), lambda))
}
)