Fixing the value of one element of an ordered variable

How can I create a positive ordered variable where the largest element is constrained to be 1.0?

positive_ordered does not allow an <upper=X> specification unfortunately…

Suppose I have a positive ordered variable A with n elements, ie

  positive_ordered[k] A;

Now suppose that I require that the last element of A is equal to 1.0.

One way to do this would be as follows

  positive_ordered[k] A_prime;
transformed parameters{
  vector[k] A;

  A = A_prime/A_prime[k];

My worry is that this leaves A_prime unidentified - multiplication of all elements of A_prime by the same number leaves the likelihood unchanged.

Other possible options:

  • Put a prior on A eg A ~ normal(1, 0.0001) for an approximate constraint, although this is likely to have crappy sampling
  • Define positive_ordered[k-1] A_prime then require have A_prime[k-1] ~ uniform(0,1), although this breaches the warning on p125 of the manual about having interval constraints that are lower than the support of the parameter.
  • Define positive_ordered[k-1] B and then calculate A = tanh(B) and fill in A[k]=1.0. The hyperbolic tangent function will map the range (0,infinity) to (0,1).

The last one seems like the most reasonable…

[@Bob_Carpenter edited this to get the formatting for the code right.]

cumulative_sum of a simplex vector

1 Like


and thanks @Bob_Carpenter! formatting helps.