Hi Perry, thank you for your answer!
Yes I'm sorry about the indexing, as I didn't know how to end my model because I could not figure out how to format my data, I did not write the model code in a functionnal way, apologies!
I tried building up the model piece by piece until I had an issue, and I encountered my first issue when adding the j loop (what's commented here)
my_nimble_code <- nimbleCode({
# Priors
lambda_intercept ~ dnorm(0, sd = 1)
my_covariate_coef ~ dnorm(1, sd = 1)
# Compute lambda with my data
my_lambda_values[1:nb_covariate_measures] <- nimCompute_lambda(
lambda_intercept = lambda_intercept,
my_covariate_coef = my_covariate_coef,
my_covariate = my_covariate_values[1:nb_covariate_measures]
)
# The maximum lambda for oversampling events (with a margin)
oversampling_lambda <- max(my_lambda_values[1:nb_covariate_measures]) * 1.1
for (i in 1:nb_repet) {
# Homogeneous Poisson process with this oversampling_lambda
oversampling_nb_events[i] ~ dpois(lambda = oversampling_lambda)
# for (j in 1:oversampling_nb_events[i]) {
# oversampling_event_time[i, j] ~ dunif(min = min(my_time[1:nb_covariate_measures]),
# max = max(my_time[1:nb_covariate_measures]))
# }
}
})
my_nimble_model <- nimbleModel(
code = my_nimble_code,
constants = list(
nb_covariate_measures = nb_covariate_measures, # 13
nb_repet = nb_repet, # 10
my_time = my_time, # seq(0,24,by=2)
my_covariate_values = my_covariate_values # rnorm(nb_covariate_measures, mean = 0)
),
inits = list(
"lambda_intercept" = 0.1,
"my_covariate_coef" = 1
)
)
# Check results with init (without the j loop)
my_nimble_model$calculate()
my_nimble_model$my_lambda_values # works, same as my_lambda_values calculated above
my_nimble_model$oversampling_lambda # works
my_nimble_model$oversampling_nb_events # only NAs
# Compile
c_my_nimble_model <- compileNimble(my_nimble_model)
c_my_nimble_model$calculate()When adding the j loop, it returns this error:
Could not evaluate loop syntax: is indexing information provided via 'constants'? . Is it not possible to use loop indexing outside of constants? That's not very practical in my case, I can't really see a workaround.
Regarding the data structure issue, I'm not sure that the matrix form would suit my need very well, as I don't know the dimensions of this matrix. And as you said, I have data with extent 0. Basically, to explain a bit my statistical model process in a non-code way, for a given repetition:
1. I want to simulate a number of events (oversampling_nb_events). I can have 0 event, and there is no known upper limit in the number of events
2. For each event (so I can't know the number of events in advance, can't put it in a constant, cause it depends step 1.):
2.1. I find the time of this event (oversampling_event_time)
2.2. I calculate a probability to keep this event (oversampling_lambda_ratio), and that depends on the time of the event (step 2.1.)
2.3. I run a Bernoulli trial to see if I keep this event or not (so this depends on the the probability calculated in step 2.2.)
Therefore, I have no idea of the dimension of my final data for a given repetition (nor of my intermediate data, whose dimension depends on the result of step 1.). As you said, I indeed have subsets of data with different extents (for my different repetitions).
So I'm not sure if a nested indexing in a matrix would work well. The two main limitations I see are:
- If I choose arbitrarily a matrix size, and if during a simulation (an iteration of the MCMC), the number of events exceed this matrix size, what will happen ? I guess it will return an error
- Otherwise, I might need a gigantic matrix and therefore probably a lot of computing resources
Also, I can not really see how to format the data part of the model so that it matches.
I did not find in the user manual what you talk about in the end of your message, I'm not sure what you mean by that.