I have a doubt about how to calculate the Jacobian adjustment for a change of variables. The problem is somewhat related wit this post: https://groups.google.com/g/stan-users/c/04GSu-ql3vM.

I have a vector or parameters deltas and parameters max_time_{1} , max_time_{2} ,… that are drawn

from a custom conditional distribution given the corresponding delta.

max_time_{i} \sim conditionalDensityTime(deltas_{i}, total_sample_size) .

And max_time_{1}< max_time_{2} <…(I can have several max_times)

Now I have an array of positive_ordered vector: inner_times. The inner_times[1] is an ordered vector of times between 0 and max_time_{1} *x[1]/x[2], the inner_times[2] is an ordered vector of times between

max_time_{1} *x[1]/x[2] and max_time_{2} *x[2]/x[2]= max_time_{2}.

I managed to do that using simplex vectors, one per each interval

max_time_{i-1} *x[i-1]/x[2] and max_time_{i}*x[i]/x[2].( following this post : https://groups.google.com/g/stan-users/c/04GSu-ql3vM.)

But in that case the limits of the intervals were constants and in my case, in my case are drawn from a distribution: conditionalDensityTime.

How should I include the Jacobian adjustment I this case?.( In particular for the extra terms I needed to add to padd

the positive ordered vectors inner_times to have the same length).

(The distribution for the inner time conditionalDensityInnerTimes also have a _rng function given: deltas, [max_time1, max_time2]’, max_times_in_oldest_population_scale,sample_sizes but it seems that _rng are just

for generated_quantities block and post analysis)

```
functions{
vector padd_vector(vector ordered_vector1, int total_padded ){
vector[total_padded] result;
real max_value= ordered_vector1[rows(ordered_vector1)];
int pos=rows(ordered_vector1)+1;
result[1:rows(ordered_vector1)]= ordered_vector1;
while(pos<=total_padded){
result[pos]=max_value + pos;
pos=pos+1;
}
return(result);
}
real conditionalDensityTime_lpdf(vector delta, int total_sample_size){
...........
}
real conditionalDensityInnerTimes_lpdf(vector[] inner_times, vector deltas, vector max_times, vector max_times_in_oldest_population_scale, vector x){
...........
}
//some other functions
}
data{
//some other data
int<lower=2> total_sample_size;
int<lower=0> sample_sizes[2];
simplex[2] x;
}
parameters{
vector<lower=0>[2] deltas;
real<lower=0.0> max_time1;
real<lower=(max_time1*x[1]/x[2])> max_time2;
simplex[sample_sizes[1]] simplex1;
simplex[sample_sizes[2]] simplex2;
//some other parameters
}
transformed parameters {
positive_ordered[N] times_in_oldest_population_scale;
positive_ordered[total_sample_size-1] inner_times[2];
times_in_oldest_population_scale[1] = (x[1]/x[2])* max_time1;
times_in_oldest_population_scale[2] = max_time2;
inner_times[1]=padd_vector(head(cumulative_sum(simplex1), sample_sizes[1]) * max_time1,
total_sample_size-1) ;// add some increasing values after the first sample_sizes[1]
//elements
inner_times[2]=padd_vector(max_time1 +head(cumulative_sum(simplex2), sample_sizes[2]) * (max_time2-max_time1),
total_sample_size-1) ;// add some increasing values after the first sample_sizes[2]
//elements
}
model {
deltas ~ exponential(rep(1, 2));
max_time1 ~conditionalDensityTime(deltas[1], total_sample_size);
max_time2~ conditionalDensityTime(deltas[2], total_sample_size);
inner_times~contionalDensityInnerTimes(deltas, [max_time1, max_time2]', times_in_oldest_population_scale, x);
//some other model statements
}
```