Skip to content

Commit 506a9ab

Browse files
authored
Merge pull request #171 from PhilClemson/master
Fixed models / data files for cmdstan
2 parents 123e574 + 9e196b3 commit 506a9ab

File tree

106 files changed

+25523
-1138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+25523
-1138
lines changed

ARM/Ch.17/latent_glm_17.7.data.R

+1,155-391
Large diffs are not rendered by default.

ARM/Ch.17/latent_glm_17.7.stan

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ data {
1616
vector[N] z;
1717
}
1818
parameters {
19-
real<lower=0> sigma;
2019
real<lower=0> sigma_age;
2120
real<lower=0> sigma_edu;
2221
real<lower=0> sigma_state;
@@ -47,6 +46,12 @@ model {
4746
b_female ~ normal(0, 100);
4847
b_black ~ normal(0, 100);
4948
b_female_black ~ normal(0, 100);
49+
50+
sigma_age ~ normal(0, 10);
51+
sigma_edu ~ normal(0, 10);
52+
sigma_state ~ normal(0, 10);
53+
sigma_region ~ normal(0, 10);
54+
sigma_age_edu ~ normal(0, 10);
5055

5156
b_age ~ normal(0, sigma_age);
5257
b_edu ~ normal(0, sigma_edu);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
N <-
2+
100
3+
n_cut <-
4+
2
5+
n_player <-
6+
5
7+
player <-
8+
c(3, 2, 1, 2, 4, 3, 3, 5, 5, 3, 3, 3, 4, 5, 5, 4, 5, 2, 2, 4,
9+
2, 3, 2, 2, 1, 5, 3, 5, 4, 4, 4, 5, 3, 5, 2, 4, 1, 2, 4, 4, 5,
10+
5, 3, 2, 2, 2, 1, 2, 4, 2, 3, 2, 5, 1, 1, 1, 5, 2, 3, 2, 4, 2,
11+
2, 5, 4, 1, 4, 2, 1, 5, 3, 2, 5, 5, 5, 2, 1, 4, 1, 5, 4, 2, 1,
12+
3, 2, 3, 2, 3, 2, 1, 1, 1, 3, 4, 5, 4, 3, 2, 5, 1)
13+
y <-
14+
c(1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1,
15+
2, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 2, 2, 1,
16+
1, 1, 2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 2, 1, 1, 2, 1, 1,
17+
1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1,
18+
1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 1, 2, 2, 1, 1)
19+
x <-
20+
c(0.876459347549826, 0.94552709441632, 0.379680620040745, 0.219244197010994,
21+
0.032204027986154, 0.501873050816357, 0.91952364356257, 0.204486317699775,
22+
0.465604034485295, 0.193179059308022, 0.807848534779623, 0.136463716626167,
23+
0.58082992141135, 0.522358619142324, 0.249525807099417, 0.747587669175118,
24+
0.561783782904968, 0.707277777139097, 0.252917441539466, 0.319943462032825,
25+
0.175028294324875, 0.575390010140836, 0.751595235429704, 0.506773706758395,
26+
0.822272704914212, 0.883299466455355, 0.122583804884925, 0.612658169353381,
27+
0.399398803943768, 0.519211766542867, 0.553035432705656, 0.364366877824068,
28+
0.990204400382936, 0.979995706351474, 0.274602472083643, 0.946819088887423,
29+
0.67284260247834, 0.994728937977925, 0.292697216849774, 0.0111141889356077,
30+
0.797478761291131, 0.472787593025714, 0.0889191201422364, 0.730681328568608,
31+
0.993295247200876, 0.0910165079403669, 0.541658846195787, 0.167015166254714,
32+
0.199509128928185, 0.420785219874233, 0.111460458487272, 0.78926312783733,
33+
0.627885694848374, 0.465886945603415, 0.684862856054679, 0.270942791132256,
34+
0.202441103756428, 0.977098781382665, 0.606753138359636, 0.81810313090682,
35+
0.062712682178244, 0.691455142339692, 0.925387117313221, 0.915808056248352,
36+
0.0373755777254701, 0.416192142991349, 0.197934444760904, 0.522862639278173,
37+
0.3995981158223, 0.207565931836143, 0.766014510998502, 0.225867514265701,
38+
0.985176953254268, 0.0127217643894255, 0.412924433825538, 0.272256464697421,
39+
0.51302864542231, 0.179800998419523, 0.771019102074206, 0.832560452399775,
40+
0.0185076335910708, 0.918299656594172, 0.3187188974116, 0.878578629344702,
41+
0.660703920759261, 0.0978191271424294, 0.676573234377429, 0.714977518422529,
42+
0.25360164558515, 0.315959327388555, 0.826745369005948, 0.402351861121133,
43+
0.698947778204456, 0.410614568740129, 0.34994190488942, 0.143103830749169,
44+
0.421381167601794, 0.97658223612234, 0.909887991845608, 0.129774280125275
45+
)

ARM/Ch.17/multilevel_ordered_categorical_17.6.stan

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ parameters {
2020
model {
2121
real mu_adj;
2222
matrix[N,n_cut] Q;
23-
matrix[N,n_cut] P;
23+
matrix[N,n_cut+1] P;
2424

2525
mu_c ~ normal(0, 1000);
2626
mu_log_s ~ normal(0, 100);
27+
28+
sigma_c ~ normal(0, 10);
29+
sigma_log_s ~ normal(0, 10);
2730

2831
for (i in 1:n_player) {
2932
C[i,1] ~ normal(mu_c[1], sigma_c[1]) T[0,C[i,2]];

ARM/Ch.17/multilevel_poisson_17.5.data.R

+436
Large diffs are not rendered by default.

ARM/Ch.17/multilevel_poisson_17.5.stan

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ model {
2626

2727
mu ~ normal(0, 100);
2828
mu_adj = mu + mean(b_eth) + mean(b_precint);
29+
30+
sigma_epsilon ~ normal(0, 10);
31+
sigma_eth ~ normal(0, 10);
32+
sigma_precint ~ normal(0, 10);
2933

3034
b_eth ~ normal(0, sigma_eth);
3135
b_eth_adj = b_eth - mean(b_eth);
@@ -41,3 +45,5 @@ model {
4145

4246
stops ~ poisson_log(lambda);
4347
}
48+
// Information on the data can be found in this blog:
49+
// http://www.clayford.net/statistics/poisson-regression-ch-6-of-gelman-and-hill/

ARM/Ch.17/robit_17.7.data.R

+1,155-391
Large diffs are not rendered by default.

ARM/Ch.17/robit_17.7.stan

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ data {
1212
int<lower=0, upper=n_state> region[n_state];
1313
int<lower=0, upper=n_state> state[N];
1414
int<lower=0, upper=1> y[N];
15-
vector[N] z;
16-
vector[N] v_prev;
15+
vector[N] z; // latent variable initialisation values
16+
vector[n_state] v_prev;
1717
}
1818
parameters {
1919
real<lower=0> sigma_age;
@@ -48,6 +48,12 @@ model {
4848
b_female ~ normal(0, 100);
4949
b_black ~ normal(0, 100);
5050
b_female_black ~ normal(0, 100);
51+
52+
sigma_age ~ normal(0, 10);
53+
sigma_edu ~ normal(0, 10);
54+
sigma_state ~ normal(0, 10);
55+
sigma_region ~ normal(0, 10);
56+
sigma_age_edu ~ normal(0, 10);
5157

5258
b_age ~ normal(0, sigma_age);
5359
b_edu ~ normal(0, sigma_edu);

0 commit comments

Comments
 (0)