-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
11-sparse_horseshoe_regression.stan
84 lines (83 loc) · 5.72 KB
/
11-sparse_horseshoe_regression.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
76
77
78
79
80
81
82
83
84
// run with 4 chains and 2k iters.
// all data should be scaled to mean 0 and std 1:
// sparse_regression data
data {
int<lower=1> N; // number of observations
int<lower=1> K; // number of independent variables
matrix[N, K] X; // data matrix
vector[N] y; // dependent variable vector
}
parameters {
real alpha; // intercept
vector<lower=0>[K] lambda; // local shrinkage factor
real<lower=0> sigma; // model error
real<lower=0> tau; // global shinkrage factor
vector[K] beta; // coefficients for independent variables
}
model {
// priors
alpha ~ student_t(3, 0, 2.5);
lambda ~ cauchy(0, 1);
sigma ~ exponential(1);
tau ~ cauchy(0, 1);
beta ~ normal(0, lambda * tau);
// likelihood
y ~ normal(alpha + X * beta, sigma);
}
// results:
//Warmup took (0.53, 0.48, 0.53, 0.48) seconds, 2.0 seconds total
//Sampling took (0.40, 0.32, 0.21, 0.17) seconds, 1.1 seconds total
//
// Mean MCSE StdDev 5% 50% 95% N_Eff N_Eff/s R_hat
//
//lp__ -5.6e+01 1.8e-01 5.1 -6.5e+01 -5.5e+01 -47 802 722 1.0
//accept_stat__ 0.78 0.063 0.32 2.3e-03 0.95 1.00 26 24 1.1e+00
//stepsize__ 0.084 0.017 0.024 5.1e-02 0.10 0.11 2.0 1.8 7.4e+13
//treedepth__ 5.0 0.40 1.2 2.0e+00 5.0 6.0 9.2 8.2 1.2e+00
//n_leapfrog__ 44 11 23 4.0e+00 31 63 4.1 3.7 1.4e+00
//divergent__ 0.14 0.033 0.35 0.0e+00 0.00 1.0 112 100 1.0e+00
//energy__ 77 0.23 6.9 6.6e+01 77 89 888 799 1.0e+00
//
//alpha 1.2e-01 4.6e-03 0.11 -6.8e-02 1.1e-01 0.29 565 509 1.0
//lambda[1] 7.1e+00 2.7e-01 8.3 1.7e+00 4.5e+00 21 928 835 1.0
//lambda[2] 7.8e-01 3.6e-02 1.5 4.2e-02 4.4e-01 2.6 1703 1533 1.0
//lambda[3] 3.9e+00 1.4e-01 4.9 1.0e+00 2.7e+00 10 1217 1095 1.0
//lambda[4] 8.2e-01 4.7e-02 1.4 4.1e-02 4.4e-01 2.8 883 795 1.0
//lambda[5] 4.6e+00 1.5e-01 5.5 1.1e+00 3.0e+00 13 1292 1163 1.0
//lambda[6] 3.5e+00 1.7e-01 5.5 7.9e-01 2.2e+00 9.2 986 887 1.0
//lambda[7] 8.8e-01 3.7e-02 1.8 4.1e-02 5.0e-01 2.6 2436 2192 1.0
//lambda[8] 2.2e+00 7.1e-02 2.4 4.9e-01 1.6e+00 5.8 1135 1022 1.0
//lambda[9] 7.2e-01 2.9e-02 1.2 4.5e-02 4.1e-01 2.3 1658 1493 1.0
//lambda[10] 1.1e+00 1.0e-01 2.0 6.0e-02 5.3e-01 3.4 365 329 1.0
//lambda[11] 1.9e+00 4.3e-01 7.3 1.7e-01 9.2e-01 4.0 287 259 1.0
//lambda[12] 7.3e-01 3.6e-02 1.2 1.7e-02 3.9e-01 2.5 1107 997 1.0
//lambda[13] 8.8e-01 4.2e-02 1.8 4.8e-02 4.9e-01 2.6 1708 1537 1.0
//lambda[14] 6.3e+00 6.2e-01 19 1.4e+00 4.0e+00 15 966 869 1.0
//lambda[15] 8.3e-01 3.0e-02 1.3 6.2e-02 5.0e-01 2.5 1834 1651 1.0
//lambda[16] 7.3e-01 2.8e-02 1.2 4.4e-02 4.2e-01 2.2 1889 1700 1.0
//lambda[17] 8.2e-01 8.5e-02 1.5 5.0e-02 4.2e-01 2.9 305 274 1.0
//lambda[18] 6.9e-01 2.3e-02 0.98 4.9e-02 3.9e-01 2.3 1845 1661 1.0
//lambda[19] 7.2e-01 3.7e-02 1.1 4.2e-02 4.3e-01 2.3 980 882 1.0
//lambda[20] 6.0e+00 2.7e-01 10 1.4e+00 3.9e+00 17 1414 1273 1.0
//sigma 9.6e-01 1.6e-03 0.072 8.5e-01 9.5e-01 1.1 2052 1847 1.0
//tau 3.0e-01 4.8e-03 0.13 1.3e-01 2.8e-01 0.54 788 710 1.0
//beta[1] 1.4e+00 2.7e-03 0.10 1.2e+00 1.4e+00 1.6 1470 1323 1.0
//beta[2] 2.0e-02 1.7e-03 0.074 -9.1e-02 1.1e-02 0.15 1789 1610 1.0
//beta[3] 7.5e-01 2.8e-03 0.10 5.9e-01 7.5e-01 0.92 1323 1191 1.0
//beta[4] 3.5e-02 2.5e-03 0.078 -7.8e-02 2.2e-02 0.18 947 852 1.0
//beta[5] -8.9e-01 2.2e-03 0.10 -1.1e+00 -8.8e-01 -0.72 2132 1919 1.00
//beta[6] 5.9e-01 4.3e-03 0.099 4.2e-01 5.9e-01 0.75 536 482 1.0
//beta[7] 6.6e-02 3.1e-03 0.086 -5.6e-02 5.1e-02 0.22 754 679 1.0
//beta[8] 3.7e-01 3.9e-03 0.10 2.1e-01 3.7e-01 0.53 679 611 1.0
//beta[9] -1.3e-02 2.1e-03 0.073 -1.5e-01 -6.4e-03 0.11 1264 1138 1.0
//beta[10] 7.1e-02 9.3e-03 0.10 -6.2e-02 5.0e-02 0.26 119 107 1.0
//beta[11] 1.8e-01 5.7e-03 0.11 -5.9e-03 1.9e-01 0.38 393 354 1.0
//beta[12] -3.2e-02 2.1e-03 0.079 -1.8e-01 -1.7e-02 0.079 1430 1287 1.0
//beta[13] -3.1e-02 4.0e-03 0.082 -1.7e-01 -2.1e-02 0.096 425 383 1.0
//beta[14] -1.1e+00 4.2e-03 0.097 -1.3e+00 -1.1e+00 -0.98 523 471 1.0
//beta[15] -6.2e-02 5.0e-03 0.098 -2.4e-01 -4.3e-02 0.069 379 341 1.0
//beta[16] -2.0e-02 2.3e-03 0.074 -1.6e-01 -1.1e-02 0.087 1040 936 1.0
//beta[17] -1.6e-02 2.1e-03 0.073 -1.5e-01 -8.0e-03 0.095 1208 1087 1.0
//beta[18] 3.0e-02 3.3e-03 0.076 -8.4e-02 2.0e-02 0.17 525 473 1.0
//beta[19] -5.3e-03 2.9e-03 0.064 -1.1e-01 -4.2e-03 0.11 491 442 1.0
//beta[20] -1.1e+00 5.1e-03 0.12 -1.3e+00 -1.1e+00 -0.93 557 501 1.0