-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.stan
44 lines (40 loc) · 910 Bytes
/
model.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
data{
int<lower=0> N; // No. samples
int<lower=0> K; // No. predictors
vector[N] log_y; // whole-leaf LMA
vector[N] log_lma_disc; // Leaf disc LMA
matrix[N, K] x; // predictors
}
parameters{
vector[K] beta;
vector[K] gamma;
real<lower=0,upper=pi()/2> omega_unif;
vector[N] z;
}
transformed parameters {
real<lower=0> omega;
vector[N] log_sigma;
omega = 2.5 * tan(omega_unif);
log_sigma = x * gamma + z * omega;
}
model {
vector[N] log_mu;
vector[N] sigma;
sigma = exp(log_sigma);
log_mu = x * beta + log_lma_disc;
z ~ std_normal();
beta ~ normal(0, 5);
gamma ~ normal(0, 5);
log_y ~ normal(log_mu, sigma);
}
// for model selection
generated quantities {
vector[N] log_lik;
vector[N] log_mu;
vector[N] sigma;
sigma = exp(log_sigma);
log_mu = x * beta + log_lma_disc ;
for (n in 1:N) {
log_lik[n] = normal_lpdf(log_y[n] | log_mu[n], sigma[n]);
}
}