Skip to content

Instantly share code, notes, and snippets.

@messefor
Created September 5, 2020 23:06
Show Gist options
  • Save messefor/43acc8bbd2205383bf9689e439a203b4 to your computer and use it in GitHub Desktop.
Save messefor/43acc8bbd2205383bf9689e439a203b4 to your computer and use it in GitHub Desktop.
data {
int N;
vector[N] x;
vector[N] y;
}
parameters {
real<lower=0> a;
real<lower=0> phi; // variance of gamma
real<lower=0> b0;
real<lower=0> b1;
}
transformed parameters {
vector<lower=0>[N] alpha; // shape parameter of gamma
vector<lower=0>[N] beta; // rate parameter of gamma
vector<lower=0>[N] mu; // mean of gamma
for (n in 1:N) {
mu[n] = b0 + b1 * pow(x[n], a);
}
for (n in 1:N) {
alpha[n] = pow(mu[n], 2.) / phi;
}
beta = mu / phi;
}
model {
y ~ gamma(alpha, beta); // likelihood
}
generated quantities {
vector<lower=0>[N] y_new;
for (n in 1:N) {
y_new[n] = gamma_rng(alpha[n], beta[n]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment