Jacobian adjustment for parameters with parameter-based upper/lower bounds


Hi all,

I’m trying to understand whether Jacobian adjustment is needed when a parameter is used as the upper and/or lower bound for other parameters.

For example,

parameters {
  vector<lower=0, upper=10>[k] a1;
  vector<lower=a1, upper=10>[k] a2;
  vector<lower=a2, upper=10>[k] a3;

  vector<lower=0, upper=10>[k] b1;
  vector<lower=b1, upper=10>[k] b2;
  vector<lower=b1 + b2, upper=10>[k] b3;
}

model {
  a1 ~ normal(0, 2);
  a2 ~ normal(0, 2);
  a3 ~ normal(0, 2);
  
  b1 ~ normal(0, 2);
  b2 ~ normal(0, 2);
  b3 ~ normal(0, 2);
}

I believe that when the upper and lower bounds are constants, as in a1 and b1, no additional Jacobian adjustment is needed.

My questions are:

  • Does Stan automatically handle the constraint transformation for a2 and a3, or do we need to add an explicit Jacobian adjustment in the model block?

  • Does the answer change when the upper and lower bounds are parameters, for example vector<lower=a1, upper=a3>[k] a2?

  • Does it make a difference if we include multiple parameters with parameter-dependent upper and lower bounds, as shown in the code for b3?

Any clarification would be greatly appreciated.

Thanks.


When using the built-in constraints in the parameters block the Jacobian adjustments are performed automatically.

For upper or lower bound constraints the Jacobian adjustment is non-linear and whether the bounds are parameters or not doesn’t matter. Typically the adjustment is desirable because then you can use the adjusted parameter on its constrained domain like any other parameter in your model. There are occasions when placing a prior on the unadjusted parameter(s) are preferred but these would be declared without bounds or other constraints. For example, take a standard deviation parameter sigma, I might want to place a skew_normal prior on log(sigma). I could declare sigma with a lower bound of 0 then take the log of it and place the prior on this but I would need a Jacobian adjustment. More efficiently I could declare an unbounded parameter log_sigma and place the prior directly on this. Subsequently, I would put exp(log_sigma) as the standard deviation into the normal density (let’s assume I’m modeling the s.d. of the normal) and I don’t need any Jacobian adjustment.

Thanks @spinkney

In my case, the parameters are regression coefficients. Let’s say a1, a2, and a3 are the raw, unconstrained parameters, and then in the transformed parameters block I construct b1, b2, and b3 using parameter-dependent upper and lower bounds.

For example, something like:

parameters {
  vector[k] a1;
  vector[k] a2;
  vector[k] a3;
}
transformed parameters {
  vector<lower=0, upper=a2>[k] b1;
  vector<lower=a1, upper=a3>[k] b2;
  vector<lower=a2, upper=10>[k] b3;
}
model {
  a1 ~ normal(0, 2);
  a2 ~ normal(0, 2);
  a3 ~ normal(0, 2);
}

In this setup, my priors are on the unconstrained a1, a2, and a3, not on the bounded b1, b2, and b3. In that case, would I still need to include an explicit Jacobian adjustment, if so, then could you please show how to add the Jacobian

My understanding is that if the priors are assigned to the unconstrained parameters, then the bounded parameters are just deterministic transformations, so the Jacobian would only be needed if I wanted to write the prior on the constrained scale instead. Is that correct?

I want b1, b2, and b3 to be ordered / constrained 0 < b1 < b2 < b3 < 10
Could you please confirm whether this transformed-parameters setup is correct in Stan?

Thanks

You can use the _jacobian functions to perform the adjustments as I do in Random walk with positive differences and missing data - #4 by spinkney. You can find more documentation at Variable Transformation Functions.

Thank you for the pointer — that’s very helpful. I’ll look into the these functions.

Regards