Created
September 5, 2020 23:06
-
-
Save messefor/43acc8bbd2205383bf9689e439a203b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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