-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathregression_model_example_2.stan
More file actions
40 lines (33 loc) · 960 Bytes
/
regression_model_example_2.stan
File metadata and controls
40 lines (33 loc) · 960 Bytes
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
data { // Data block
int<lower=1> N; // Sample size
int<lower=1> K; // Dimension of model matrix
matrix [N, K] X; // Model Matrix
vector[N] y; // Target variable
}
/*
transformed data { // Transformed data block. Not used presently.
}
*/
parameters { // Parameters block; declarations only
vector[K] beta; // Coefficient vector
real<lower=0> sigma; // Error scale
}
model { // Model block
vector[N] mu;
mu <- X * beta; // Creation of linear predictor
// priors
beta ~ normal(0, 10);
sigma ~ cauchy(0, 5); // With sigma bounded at 0, this is half-cauchy
// likelihood
y ~ normal(mu, sigma);
}
generated quantities {
real rss;
real totalss;
real<lower=0, upper=1> R2;
vector[N] mu;
mu <- X * beta;
rss <- dot_self(y-mu);
totalss <- dot_self(y-mean(y));
R2 <- 1 - rss/totalss;
}