-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcornwall_suicides.stan
More file actions
49 lines (44 loc) · 2.07 KB
/
cornwall_suicides.stan
File metadata and controls
49 lines (44 loc) · 2.07 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
data {
int<lower=0> N;
int<lower=0> N_edges;
array[N_edges] int<lower=1, upper=N> node1;
array[N_edges] int<lower=1, upper=N> node2;
array[N] int<lower=0> Y;
vector[N] X;
vector[N] X2; // <-- NEW
vector<lower=0>[N] Off_set;
}
transformed data {
vector[N] log_Offset = log(Off_set); // use the expected cases as an offset and add to the regression model
}
parameters {
real alpha;
real beta;
real beta2; // <-- NEW
real<lower=0> sigma;
real<lower=0, upper=1> rho;
vector[N] theta;
vector[N] phi;
}
transformed parameters {
vector[N] combined; // values derived from adding the unstructure and structured effect of each area
combined = sqrt(1 - rho) * theta + sqrt(rho) * phi; // formulation for the combined random effect
}
model {
Y ~ poisson_log(log_Offset + alpha + X * beta + X2 * beta2 + combined * sigma); // likelihood function: multivariable Poisson ICAR regression model
// setting priors
alpha ~ normal(0.0, 1.0); // prior for alpha: weakly informative
beta ~ normal(0.0, 1.0); // prior for betas: weakly informative
theta ~ normal(0.0, 1.0); // prior for theta: weakly informative
sigma ~ normal(0.0, 1.0); // prior for sigma: weakly informative
rho ~ beta(0.5, 0.5); // prior for rho
target += -0.5 * dot_self(phi[node1] - phi[node2]); // calculates the spatial weights
sum(phi) ~ normal(0, 0.001 * N); // priors for phi
}
generated quantities {
vector[N] eta = alpha + X * beta + X2 * beta2 + combined * sigma;
vector[N] rr_mu = exp(eta);
real rr_beta = exp(beta);
real rr_beta2 = exp(beta2); // <-- NEW
real rr_alpha = exp(alpha);
}