-
Notifications
You must be signed in to change notification settings - Fork 0
/
model2_shrink.stan
57 lines (53 loc) · 1.27 KB
/
model2_shrink.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
data {
int<lower=0> N;
real ssat;
real sspend;
real sptake;
real msat;
real mspend;
real mptake;
real mint;
real sint;
vector[N] z_sat;
vector[N] z_spend;
vector[N] z_ptake;
vector[N] z_int;
int J;
real<lower=0> hypers[2];
real<lower=0> spend[N];
real<lower=0> ptake[N];
real<lower=0> inter[N];
}
parameters {
real z_beta0;
real z_beta[J];
real<lower=0> z_sigma;
real<lower=0> numinusone;
real<lower=0> sigmah[J+1];
}
transformed parameters{
real<lower = 0> nu;
nu = numinusone + 1;
}
model {
numinusone ~ exponential(1/29.0);
sigmah ~ gamma(hypers[1], hypers[2]);
z_beta0 ~ student_t(1, 0,1);
z_beta[J] ~ student_t(1,0,sigmah);
z_sigma ~ normal(0,1);
z_sat ~ student_t(nu, z_beta0 + z_beta[1]*z_spend + z_beta[2]*z_ptake + z_beta[3]*z_int, z_sigma);
}
generated quantities{
real beta0;
real beta[J];
real<lower=0> sigma;
real y_fake[N];
sigma = ssat*z_sigma;
beta0 = z_beta0*ssat + msat - z_beta[1]*mspend*ssat/sspend - z_beta[2]*mptake*ssat/sptake - z_beta[3]*mint*ssat/sint;
beta[1] = z_beta[1]*ssat/sspend;
beta[2] = z_beta[2]*ssat/sptake;
beta[3] = z_beta[3]*ssat/sint;
for (i in 1:N) {
y_fake[i] = student_t_rng(nu, beta0 + beta[1]*spend[i] + beta[2]*ptake[i] + beta[3]*inter[i], sigma);
}
}