-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiremodel_predict.stan
75 lines (62 loc) · 1.67 KB
/
firemodel_predict.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
data {
int<lower=0> N;
int<lower=0> J;
int<lower=1,upper=J> pid[N];
vector[N] age;
vector[N] nd;
vector[J] envg1;
vector[J] envg2;
}
parameters {
vector[J] alpha;
vector[J] gamma;
vector[J] lambda;
real alpha_mu;
real gamma_b1;
real gamma_b2;
real lambda_b1;
real lambda_b2;
real<lower=0> tau_sq;
real<lower=0> gamma_tau_sq;
real<lower=0> lambda_tau_sq;
real<lower=0> alpha_tau_sq;
}
transformed parameters {
vector[N] mu;
vector[J] gamma_mu;
vector[J] lambda_mu;
real tau = sqrt(tau_sq);
real gamma_tau = sqrt(gamma_tau_sq);
real lambda_tau = sqrt(lambda_tau_sq);
real alpha_tau = sqrt(alpha_tau_sq);
for (j in 1:J){
gamma_mu[j] = (envg1[j]*gamma_b1) + (envg2[j]*gamma_b2);
lambda_mu[j] = (envg1[j]*lambda_b1) + (envg2[j]*lambda_b2);
}
for (i in 1:N){
// bid=pid[i] # pixel id for this observation
// mu[i] = exp(alpha[bid])+exp(gamma[bid])-exp(gamma[bid])*exp(-(age[i]/exp(lambda[bid])));
mu[i] = exp(alpha[pid[i]])+exp(gamma[pid[i]])-exp(gamma[pid[i]])*exp(-(age[i]/exp(lambda[pid[i]])));
}
}
model {
tau ~ student_t(4,0,1); //#inv_gamma(0.01, 0.01);
gamma_tau ~ student_t(4,0,1); //#inv_gamma(0.01, 0.01);
lambda_tau ~ student_t(4,0,1); //#inv_gamma(0.01, 0.01);
alpha_tau ~ student_t(4,0,1); //#inv_gamma(0.01, 0.01);
alpha_mu ~ normal(0.15,3);
gamma_b1 ~ normal(0,3);
gamma_b2 ~ normal(0,3);
lambda_b1 ~ normal(0,3);
lambda_b2 ~ normal(0,3);
alpha ~ normal(alpha_mu, alpha_tau);
gamma ~ normal(gamma_mu,gamma_tau);
lambda ~ normal(lambda_mu,lambda_tau);
nd ~ normal(mu, tau);
}
generated quantities {
vector[N] nd_new;
for (n in 1:N){
nd_new[n] = normal_rng(mu[n], tau);
}
}