[ede2d4]: / inst / stan / hs_logit.stan

Download this file

99 lines (70 with data), 2.1 kB

 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Hierarchical shrinkage prior on regression coeffs (logistic regression)
//
// This implements the regularized horseshoe prior according to the simple
// parametrization presented in:
//
// Piironen, Vehtari (2017), Sparsity information and regularization in the
// horseshoe and other shrinkage priors, Electronic Journal of Statistics
functions {
#include /chunks/hs.fun
}
data {
// number of columns in model matrix
int P;
// number of unpenalized columns in model matrix
int U;
// number of observations
int N;
// design matrix
matrix[N, P] X;
// binary response variable
array[N] int<lower=0, upper=1> y;
// prior standard deviation for the unpenalised variables
real<lower=0> scale_u;
// whether the regularized horseshoe should be used
int<lower=0, upper=1> regularized;
// degrees of freedom for the half-t priors on lambda
real<lower=1> nu;
// scale for the half-t prior on tau
real<lower=0> global_scale;
// degrees of freedom for the half-t prior on tau
real<lower=1> global_df;
// slab scale for the regularized horseshoe
real<lower=0> slab_scale;
// slab degrees of freedom for the regularized horseshoe
real<lower=0> slab_df;
}
parameters {
// unpenalized regression parameters
vector[U] beta_u;
// global shrinkage parameter
real<lower=0> tau;
// local shrinkage parameter
vector<lower=0>[P-U] lambda;
// auxiliary variables
vector[P-U] z;
real<lower=0> c2;
}
transformed parameters {
// penalized regression parameters
vector[P-U] beta_p;
if (regularized)
beta_p = reg_hs(z, lambda, tau, slab_scale^2 * c2);
else
beta_p = hs(z, lambda, tau);
}
model {
// regression coefficients
vector[P] beta = append_row(beta_u, beta_p);
// half t-priors for lambdas and tau
z ~ std_normal();
lambda ~ student_t(nu, 0, 1);
tau ~ student_t(global_df, 0, global_scale);
// inverse-gamma prior for c^2
c2 ~ inv_gamma(0.5 * slab_df, 0.5 * slab_df);
// unpenalized coefficients including intercept
beta_u ~ normal(0, scale_u);
// likelihood
y ~ bernoulli_logit_glm(X, 0, beta);
}