Skip to content

Inverse transform in sum-to-zero constraint #922

@rtrangucci

Description

@rtrangucci

I believe the code shown here (link to manual section):

Image

is the Stan code matching the inverse sum-to-zero transform in the next section. Stan code implementing the sum-to-zero transform is here:

vector sum_to_zero_transform(vector x) {
  int N = size(x) - 1;
  vector[N] y;
  y[N] = -x[N+1] * sqrt(1 + 1. / N);
  real sum_w = 0;
  for (n in 1:(N-1)) {
    int i = N - n;
    int i_p_1 = i + 1;
    real w = y[i_p_1] * inv_sqrt(i_p_1 * (i_p_1 + 1));
    sum_w += w;
    y[i] = (sum_w - x[i_p_1]) * sqrt(i_p_1 * i) / i;
  }
  return(y);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions