Skip to content

Use Stan's "Affine Transformation" syntax #440

@gowerc

Description

@gowerc

Stan offers helper syntax to make converting between the centered / non-centered parameterisations smoother. That is instead of

parameters {
    vector[K] beta_raw;
}

transformed parameters {
    vector[K] beta;
    beta = mu_beta + sigma_beta * beta_raw;
}

model {
    beta_raw ~ std_normal();
}

You can specify the identical model as:

parameters {
    real mu_beta;
    real<lower=0> sigma_beta;
    vector<offset=mu_beta, multiplier=sigma_beta>[K] beta;
}

model {
    beta ~ normal(mu_beta, sigma_beta);
}

Whilst not the clearest of syntax's this has the added benefit of being almost identical to the centered parameterisation setup which is just:

parameters {
    real mu_beta;
    real<lower=0> sigma_beta;
    vector[K] beta;
}

model {
    beta ~ normal(mu_beta, sigma_beta);
}

If we were to adopt this syntax it would in theory GREATLY reduce the amount of conditional Jinja code that we have within our Stan files hopefully making them much easier to manage.

See https://mc-stan.org/docs/reference-manual/types.html#affine-transform.section

Only downside to this is that it would mean we need to convert all of our parameters to be on the log-scale (currently they are on the "regular" scale) which might be a pain in terms of updating all our test code / priors and documentation accordingly. Considering @danielinteractive & @mercifr1 are currently rolling out training it may be best to wait until that is finished ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions