-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnbd_scale_adjust.stan
55 lines (40 loc) · 1.12 KB
/
pnbd_scale_adjust.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
//Copyright 2018 Aaron Goodman <[email protected]>. Licensed under the GPLv3 or later.
#include /pnbd_data.stan
parameters{
real log_buy_a;
real log_buy_b;
real log_die_a;
real log_die_b;
vector[NC] log_lambda_raw;
vector[NC] log_mu_raw;
}
transformed parameters{
vector[NC] likelihood;
real log_r = log_buy_a;
real log_alpha = log_buy_a - log_buy_b;
real log_s = log_die_b;
real log_beta = log_die_a - log_die_b;
real r = exp(log_r);
real alpha = exp(log_alpha);
real s = exp(log_s);
real beta = exp(log_beta);
vector[NC] log_lambda = log_lambda_raw - log_alpha;
vector[NC] log_mu = log_mu_raw - log_beta;
vector[NC] lambdamu = exp(log_lambda) + exp(log_mu);
#include /pnbdlikelihoodloop.stan
}
model{
target += -NC*lgamma(r);
target += r*log_lambda_raw - exp(log_lambda_raw);
target += -NC*lgamma(s);
target += s*log_mu_raw - exp(log_mu_raw);
target += log_r + log_alpha + log_s + log_beta;
r ~ normal(1,1);
alpha ~ normal(1,1);
s ~ normal(1,1);
beta ~ normal(1,1);
target += likelihood;
}
generated quantities{
#include /pnbd_generatedquantities.stan
}