Hi all!
I have a question related to fitting distributions to vectors of data in Nimble, and I wonder if somebody could help me with a couple of things I am struggling with. I will try to provide it as an understandable example!
My aim here is to see how parameters of a distribution vary after I bias a vector of data in particular ways. I start by fitting a distribution (gamma) to a vector that is a combination of observed and unobserved (NA) values.
for(i in 1:nvec1){
vec1 ~ dgamma(shape1,rate1)
}
shape1 ~ dgamma(1,1)
rate1 ~ dgamma(1,1)
Here the model imputes values to the NAs, which I want. My second step here is to remove some values of this vector (or turning them into NAs again, whichever is easiest) following a probability that varies depending on the values of the vector themselves, but for the ease of this example, let's assume it is a fixed probability. I thought about doing it this way. First, create a vector of 0s and 1s (removed) and then multiply it with vec1.
for(i in 1:nvec1){
removed[i] ~ dbern(0.5) #Either remove or not following a probability
vec2[i] <- vec1[i] * removed[i] #The ones to remove well become a 0
}
Now, I expect that vec2 is a combination of 0s and values originally obtained at vec1. My aim as I said before is to now either get rid of these 0s or turn them into NAs, because I would like to fit a gamma distribution to it again and see how the parameters of the distribution have changed after removing these values (that is, after "biasing" the data in particular ways, as I said above). Here is where problems starts, as I do not figure out any way to do it.
First, by using a nimbleFunction, I guess it would be easy to do:
vec3 <- vec2[vec2>0]
Or
vec2[vec2 == 0] <- NA
And then, fit a distribution to this vector:
vec3 (or vec2)[i] ~ dgamma(shape2, rate2)
shape2 ~ dgamma(1,1)
shape3 ~ dgamma(1,1)
The issue here is: I am getting an undefined node error, and I guess it is due to the fact that either way I try to implement this solution, my vector appears twice in the left side of a relationship:
Either as vec3 <- (...) or vec2 <- (...).
And also either as vec2 ~ or vec3 ~ dgamma(...)
Does anybody have a suggestion on how to deal with this, or any other type of approach to try? I hope I explained myself clearly enough!
Thanks in advance,
Jaume