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
parameters{
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
parameters{
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_primethen require haveA_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] Band then calculateA = tanh(B)and fill inA[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.]