nimble
nimble copied to clipboard
Dynamic indexing with imputed nodes
Hi there,
Sorry for the vague title. I'm trying to run a model with an ordinal covariate, but some missing values are present in the covariate. When I try to impute the missing values from a categorical distribution, I get the following error when I try to include dynamic indexing later on in the model:
Dynamic indexing found in a vector of indices, 1:x[i]. Only scalar indices, such as 'idx' in 'x[idx]', can be dynamic. One can instead use dynamic indexing in a vector of indices inside a nimbleFunction.
I'm following McElreath for including an ordinal covariate, e.g.:
mu[i] <- mu.alpha + mu.beta * sum(delta[1:x[i]])
I'm attaching a reproducible example showing that the problem only occurs when the covariate needs to be imputed. I suppose this is more of a feature request than anything, but I just wanted to see if anything can be done.
Cheers,
Matt impute-dynamic.txt
@MHollanders Give this code a try, in the attached file. Needed to push the dynamic indexing into a nimbleFunction, but it should work the same as your code.
Thanks Daniel! That did the trick. I'm going to get into nimbleFunctions for real!
@MHollanders Good to hear, you won't regret it.
I've noted this situation in our converting_to_nimble
example.