@@ -656,16 +656,14 @@ data {
656656 int<lower=0> N;
657657 int<lower=1> D;
658658 array[N] int<lower=1, upper=K> y;
659- array[N] row_vector[ D] x;
659+ matrix[N, D] x;
660660}
661661parameters {
662662 vector[D] beta;
663663 ordered[K - 1] c;
664664}
665665model {
666- for (n in 1:N) {
667- y[n] ~ ordered_logistic(x[n] * beta, c);
668- }
666+ y ~ ordered_logistic(x * beta, c);
669667}
670668```
671669
@@ -678,47 +676,27 @@ satisfy the ordering constraint. Luckily, Stan does not need to
678676compute the effect of the constraint on the normalizing term because
679677the probability is needed only up to a proportion.
680678
679+ The equivalent model can be written using ` ordered_logistic_glm `
680+ distribution, which can provide more efficient computation in case of
681+ higher dimensional ` beta ` .
682+
683+ ``` stan
684+ y ~ ordered_logistic_glm(x, beta, c);
685+ ```
681686
682687#### Ordered probit {-}
683688
684- An ordered probit model could be coded in exactly the same way by
685- swapping the cumulative logistic (` inv_logit ` ) for the cumulative
686- normal (` Phi ` ).
689+ An ordered probit model can be coded in exactly the same way by
690+ using the built-in ` ordered_probit ` distribution.
687691
688692
689693``` stan
690- data {
691- int<lower=2> K;
692- int<lower=0> N;
693- int<lower=1> D;
694- array[N] int<lower=1, upper=K> y;
695- array[N] row_vector[D] x;
696- }
697- parameters {
698- vector[D] beta;
699- ordered[K - 1] c;
700- }
701694model {
702- vector[K] theta;
703- for (n in 1:N) {
704- real eta;
705- eta = x[n] * beta;
706- theta[1] = 1 - Phi(eta - c[1]);
707- for (k in 2:(K - 1)) {
708- theta[k] = Phi(eta - c[k - 1]) - Phi(eta - c[k]);
709- }
710- theta[K] = Phi(eta - c[K - 1]);
711- y[n] ~ categorical(theta);
712- }
695+ ordered_probit(x * beta, c);
713696}
714697```
715698
716- The logistic model could also be coded this way by replacing
717- ` Phi ` with ` inv_logit ` , though the built-in encoding based
718- on the softmax transform is more efficient and more numerically
719- stable. A small efficiency gain could be achieved by computing the
720- values ` Phi(eta - c[k]) ` once and storing them for re-use.
721-
699+ There is not yet an ` ordered_probit_glm ` distribution in Stan.
722700
723701## Hierarchical regression
724702
0 commit comments