Skip to content

Commit 438b8c5

Browse files
committed
Added priors in fx_factor.stan and added data files for knitr\simplest-regression\ and knitr\chapter1"
1 parent 6b07319 commit 438b8c5

File tree

6 files changed

+255
-6
lines changed

6 files changed

+255
-6
lines changed

knitr/chapter1/fake-data.data.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
N <-
2+
100
3+
a <-
4+
2
5+
b <-
6+
3
7+
sigma <-
8+
5
9+
x <-
10+
c(2.2853296995163, 0.674138290341944, 2.97911234200001, 7.25195993902162,
11+
5.48518705647439, 6.16006637923419, 9.12475175224245, 7.85220248624682,
12+
4.64161953656003, 9.81822612928227, 7.95531257521361, 4.29855593945831,
13+
5.55137525312603, 1.71344911446795, 4.05352542409673, 8.81462065735832,
14+
2.18668370507658, 9.97622460359707, 7.72820800775662, 2.90110652800649,
15+
6.35918467305601, 0.231357580050826, 4.19029676821083, 9.08321775961667,
16+
3.3600021735765, 8.67224041838199, 8.59367203898728, 4.31982519337907,
17+
4.18018239783123, 3.95117466570809, 4.53975410433486, 9.65833041351289,
18+
5.05022519268095, 8.77252815989777, 5.1377896242775, 7.61265947949141,
19+
9.20889288419858, 4.62758573470637, 9.81446951394901, 9.87865060800686,
20+
8.17965957103297, 3.01347282482311, 1.82404764462262, 3.38288246886805,
21+
5.80676758894697, 2.80335777206346, 4.61396040162072, 4.53697587829083,
22+
9.61025682976469, 3.46600423566997, 0.817313937004656, 6.8241445091553,
23+
5.6719551468268, 7.14498632820323, 3.53087692754343, 1.55980194685981,
24+
2.46012952644378, 3.98026936454698, 8.03334353491664, 2.7307740971446,
25+
6.58313227817416, 2.37085219938308, 2.48372358735651, 6.203433717601,
26+
8.11904138652608, 4.05982252210379, 5.01939266454428, 5.41474604280666,
27+
4.45003962609917, 0.451937709003687, 3.18692218745127, 1.42222109017894,
28+
6.08129358151928, 8.47746526822448, 6.61727556958795, 0.536629417911172,
29+
1.31974522257224, 3.49203322548419, 8.39104288257658, 5.05498125916347,
30+
6.55772913945839, 9.14206789340824, 8.55886349920183, 1.42991979140788,
31+
2.15637924149632, 7.85603262018412, 8.54894736781716, 8.66789509309456,
32+
8.87904351809993, 2.55191378993914, 7.99239561660215, 6.19454300496727,
33+
2.15904936660081, 3.43557879095897, 7.7779614389874, 3.05063382489607,
34+
6.50456659263, 2.30009848019108, 0.329714738763869, 0.149868202861398
35+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
N <-
2+
100
3+
x <-
4+
c(0.507328067906201, 1.53260154882446, 3.91292023472488, 8.07886009570211,
5+
5.12549930950627, 9.0857648360543, 3.72509124688804, 5.95977402059361,
6+
8.65114396205172, 9.69724742230028, 8.82765574846417, 8.0464987992309,
7+
1.91117837559432, 5.97621644148603, 9.69551225891337, 9.40746597247198,
8+
7.42127377772704, 4.46606757584959, 4.91346358787268, 5.20750917261466,
9+
8.60888902796432, 7.89303531637415, 2.3096569837071, 6.31758658215404,
10+
2.26071157725528, 0.708643249236047, 2.31518820859492, 4.82616354012862,
11+
7.73621813859791, 7.39101707469672, 3.18168679485098, 7.61797866784036,
12+
1.94191251182929, 1.08615981647745, 6.01567466277629, 8.80545222433284,
13+
6.80963168852031, 1.12651099683717, 9.22755726147443, 4.82936889166012,
14+
2.83023830736056, 3.06597816525027, 2.98667514929548, 2.29693892644718,
15+
7.09124287823215, 7.1630224189721, 6.46266162861139, 7.16923107160255,
16+
1.23017649631947, 9.85442902194336, 4.10298435948789, 9.44249524036422,
17+
5.01679378096014, 3.50627436768264, 3.23523359140381, 8.11959446407855,
18+
0.318629154935479, 8.19387938827276, 2.80205589719117, 7.90206669131294,
19+
2.91444341884926, 0.501565947197378, 4.12775222444907, 1.25772389350459,
20+
3.26489231549203, 8.03326084045693, 5.52027114434168, 9.49844204820693,
21+
9.83832313679159, 6.06833420228213, 5.78228635713458, 0.159530621021986,
22+
6.15989632671699, 0.565385406371206, 3.32634499762207, 5.99907119991258,
23+
6.42221869435161, 7.78480920242146, 1.6154010198079, 6.40206620562822,
24+
2.20054193399847, 3.67591219721362, 9.65326205827296, 4.24420014023781,
25+
9.98306149151176, 8.26122796628624, 7.49002234777436, 6.38011312345043,
26+
8.77622718457133, 4.10558220697567, 5.46563858631998, 2.48607469722629,
27+
3.68429954629391, 3.36249730316922, 7.73126894375309, 1.9974720152095,
28+
1.90315729007125, 5.13465406373143, 3.16930384142324, 2.34431644668803
29+
)
30+
y <-
31+
c(7.56552006313076, 9.76939121749182, 24.2448359410629, 20.9821514358478,
32+
24.9962784837968, 26.8915997662255, 13.5881436017663, 19.6545045571507,
33+
19.1911128631036, 30.8837628430223, 34.8955632358237, 18.8870707062523,
34+
10.6975736476306, 15.5098375621426, 26.7910429618714, 21.9293182116884,
35+
29.9959641528661, 14.4336073380027, 10.1660540700647, 17.663470456751,
36+
35.4119442930633, 22.404822512505, -1.22042046262689, 23.4344635414683,
37+
14.811312738173, 4.18069318567838, 12.5180973861314, 7.19119270574544,
38+
24.1295396797915, 20.4869594668355, 13.213607838582, 29.777945592468,
39+
12.2245266270612, 8.10797586076861, 19.8171814400653, 24.1081160733131,
40+
22.9087287329155, 12.6086166985308, 32.0757649197201, 15.3861261517808,
41+
8.61150222703634, 10.962062247365, 8.27427001372424, 11.508717141065,
42+
35.5241284496367, 13.7909400941573, 18.6517195943646, 29.6273245188661,
43+
2.04731665131452, 26.7040875860107, 11.4057023383477, 26.7880889846927,
44+
20.0020738656452, 18.2364874544682, 7.44406620641143, 20.7642578817391,
45+
2.05870239595777, 25.5704502520692, 16.6620364567942, 26.3144188598547,
46+
10.8802999470338, -4.30981317344027, 23.1527270482452, -2.11294361574222,
47+
9.16930389643637, 28.756143132455, 15.1350701685981, 26.7684106673939,
48+
37.0069536323432, 29.3135092857704, 16.952588572893, 0.354036449175697,
49+
16.330557176018, -13.7571897636472, 10.1466768142457, 18.7250139648418,
50+
27.3524614620177, 22.0018363467837, 13.0654884830186, 24.4052030316632,
51+
7.67434195964745, 10.2971540250292, 32.1844941240187, 20.3158889108271,
52+
32.2194118439009, 19.2800804786584, 24.3680263777705, 22.9323155709183,
53+
27.7139321374481, 10.1573110372689, 18.701397759763, 8.0429159918026,
54+
12.4139349424528, 9.39088662208607, 20.7470342090419, 12.365636243757,
55+
12.1422242014525, 26.5921509715383, 8.36492785003775, 16.6142577646007
56+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
N <-
2+
100
3+
K <-
4+
2
5+
X <-
6+
structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
9+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
10+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.507328067906201,
11+
1.53260154882446, 3.91292023472488, 8.07886009570211, 5.12549930950627,
12+
9.0857648360543, 3.72509124688804, 5.95977402059361, 8.65114396205172,
13+
9.69724742230028, 8.82765574846417, 8.0464987992309, 1.91117837559432,
14+
5.97621644148603, 9.69551225891337, 9.40746597247198, 7.42127377772704,
15+
4.46606757584959, 4.91346358787268, 5.20750917261466, 8.60888902796432,
16+
7.89303531637415, 2.3096569837071, 6.31758658215404, 2.26071157725528,
17+
0.708643249236047, 2.31518820859492, 4.82616354012862, 7.73621813859791,
18+
7.39101707469672, 3.18168679485098, 7.61797866784036, 1.94191251182929,
19+
1.08615981647745, 6.01567466277629, 8.80545222433284, 6.80963168852031,
20+
1.12651099683717, 9.22755726147443, 4.82936889166012, 2.83023830736056,
21+
3.06597816525027, 2.98667514929548, 2.29693892644718, 7.09124287823215,
22+
7.1630224189721, 6.46266162861139, 7.16923107160255, 1.23017649631947,
23+
9.85442902194336, 4.10298435948789, 9.44249524036422, 5.01679378096014,
24+
3.50627436768264, 3.23523359140381, 8.11959446407855, 0.318629154935479,
25+
8.19387938827276, 2.80205589719117, 7.90206669131294, 2.91444341884926,
26+
0.501565947197378, 4.12775222444907, 1.25772389350459, 3.26489231549203,
27+
8.03326084045693, 5.52027114434168, 9.49844204820693, 9.83832313679159,
28+
6.06833420228213, 5.78228635713458, 0.159530621021986, 6.15989632671699,
29+
0.565385406371206, 3.32634499762207, 5.99907119991258, 6.42221869435161,
30+
7.78480920242146, 1.6154010198079, 6.40206620562822, 2.20054193399847,
31+
3.67591219721362, 9.65326205827296, 4.24420014023781, 9.98306149151176,
32+
8.26122796628624, 7.49002234777436, 6.38011312345043, 8.77622718457133,
33+
4.10558220697567, 5.46563858631998, 2.48607469722629, 3.68429954629391,
34+
3.36249730316922, 7.73126894375309, 1.9974720152095, 1.90315729007125,
35+
5.13465406373143, 3.16930384142324, 2.34431644668803), .Dim = c(100L,
36+
2L), .Dimnames = list(NULL, c("ones", "x")))
37+
y <-
38+
c(7.56552006313076, 9.76939121749182, 24.2448359410629, 20.9821514358478,
39+
24.9962784837968, 26.8915997662255, 13.5881436017663, 19.6545045571507,
40+
19.1911128631036, 30.8837628430223, 34.8955632358237, 18.8870707062523,
41+
10.6975736476306, 15.5098375621426, 26.7910429618714, 21.9293182116884,
42+
29.9959641528661, 14.4336073380027, 10.1660540700647, 17.663470456751,
43+
35.4119442930633, 22.404822512505, -1.22042046262689, 23.4344635414683,
44+
14.811312738173, 4.18069318567838, 12.5180973861314, 7.19119270574544,
45+
24.1295396797915, 20.4869594668355, 13.213607838582, 29.777945592468,
46+
12.2245266270612, 8.10797586076861, 19.8171814400653, 24.1081160733131,
47+
22.9087287329155, 12.6086166985308, 32.0757649197201, 15.3861261517808,
48+
8.61150222703634, 10.962062247365, 8.27427001372424, 11.508717141065,
49+
35.5241284496367, 13.7909400941573, 18.6517195943646, 29.6273245188661,
50+
2.04731665131452, 26.7040875860107, 11.4057023383477, 26.7880889846927,
51+
20.0020738656452, 18.2364874544682, 7.44406620641143, 20.7642578817391,
52+
2.05870239595777, 25.5704502520692, 16.6620364567942, 26.3144188598547,
53+
10.8802999470338, -4.30981317344027, 23.1527270482452, -2.11294361574222,
54+
9.16930389643637, 28.756143132455, 15.1350701685981, 26.7684106673939,
55+
37.0069536323432, 29.3135092857704, 16.952588572893, 0.354036449175697,
56+
16.330557176018, -13.7571897636472, 10.1466768142457, 18.7250139648418,
57+
27.3524614620177, 22.0018363467837, 13.0654884830186, 24.4052030316632,
58+
7.67434195964745, 10.2971540250292, 32.1844941240187, 20.3158889108271,
59+
32.2194118439009, 19.2800804786584, 24.3680263777705, 22.9323155709183,
60+
27.7139321374481, 10.1573110372689, 18.701397759763, 8.0429159918026,
61+
12.4139349424528, 9.39088662208607, 20.7470342090419, 12.365636243757,
62+
12.1422242014525, 26.5921509715383, 8.36492785003775, 16.6142577646007
63+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
N <-
2+
100
3+
a <-
4+
2
5+
b <-
6+
3
7+
sigma <-
8+
5
9+
x <-
10+
c(2.2853296995163, 0.674138290341944, 2.97911234200001, 7.25195993902162,
11+
5.48518705647439, 6.16006637923419, 9.12475175224245, 7.85220248624682,
12+
4.64161953656003, 9.81822612928227, 7.95531257521361, 4.29855593945831,
13+
5.55137525312603, 1.71344911446795, 4.05352542409673, 8.81462065735832,
14+
2.18668370507658, 9.97622460359707, 7.72820800775662, 2.90110652800649,
15+
6.35918467305601, 0.231357580050826, 4.19029676821083, 9.08321775961667,
16+
3.3600021735765, 8.67224041838199, 8.59367203898728, 4.31982519337907,
17+
4.18018239783123, 3.95117466570809, 4.53975410433486, 9.65833041351289,
18+
5.05022519268095, 8.77252815989777, 5.1377896242775, 7.61265947949141,
19+
9.20889288419858, 4.62758573470637, 9.81446951394901, 9.87865060800686,
20+
8.17965957103297, 3.01347282482311, 1.82404764462262, 3.38288246886805,
21+
5.80676758894697, 2.80335777206346, 4.61396040162072, 4.53697587829083,
22+
9.61025682976469, 3.46600423566997, 0.817313937004656, 6.8241445091553,
23+
5.6719551468268, 7.14498632820323, 3.53087692754343, 1.55980194685981,
24+
2.46012952644378, 3.98026936454698, 8.03334353491664, 2.7307740971446,
25+
6.58313227817416, 2.37085219938308, 2.48372358735651, 6.203433717601,
26+
8.11904138652608, 4.05982252210379, 5.01939266454428, 5.41474604280666,
27+
4.45003962609917, 0.451937709003687, 3.18692218745127, 1.42222109017894,
28+
6.08129358151928, 8.47746526822448, 6.61727556958795, 0.536629417911172,
29+
1.31974522257224, 3.49203322548419, 8.39104288257658, 5.05498125916347,
30+
6.55772913945839, 9.14206789340824, 8.55886349920183, 1.42991979140788,
31+
2.15637924149632, 7.85603262018412, 8.54894736781716, 8.66789509309456,
32+
8.87904351809993, 2.55191378993914, 7.99239561660215, 6.19454300496727,
33+
2.15904936660081, 3.43557879095897, 7.7779614389874, 3.05063382489607,
34+
6.50456659263, 2.30009848019108, 0.329714738763869, 0.149868202861398
35+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
N <-
2+
100
3+
x <-
4+
c(0.507328067906201, 1.53260154882446, 3.91292023472488, 8.07886009570211,
5+
5.12549930950627, 9.0857648360543, 3.72509124688804, 5.95977402059361,
6+
8.65114396205172, 9.69724742230028, 8.82765574846417, 8.0464987992309,
7+
1.91117837559432, 5.97621644148603, 9.69551225891337, 9.40746597247198,
8+
7.42127377772704, 4.46606757584959, 4.91346358787268, 5.20750917261466,
9+
8.60888902796432, 7.89303531637415, 2.3096569837071, 6.31758658215404,
10+
2.26071157725528, 0.708643249236047, 2.31518820859492, 4.82616354012862,
11+
7.73621813859791, 7.39101707469672, 3.18168679485098, 7.61797866784036,
12+
1.94191251182929, 1.08615981647745, 6.01567466277629, 8.80545222433284,
13+
6.80963168852031, 1.12651099683717, 9.22755726147443, 4.82936889166012,
14+
2.83023830736056, 3.06597816525027, 2.98667514929548, 2.29693892644718,
15+
7.09124287823215, 7.1630224189721, 6.46266162861139, 7.16923107160255,
16+
1.23017649631947, 9.85442902194336, 4.10298435948789, 9.44249524036422,
17+
5.01679378096014, 3.50627436768264, 3.23523359140381, 8.11959446407855,
18+
0.318629154935479, 8.19387938827276, 2.80205589719117, 7.90206669131294,
19+
2.91444341884926, 0.501565947197378, 4.12775222444907, 1.25772389350459,
20+
3.26489231549203, 8.03326084045693, 5.52027114434168, 9.49844204820693,
21+
9.83832313679159, 6.06833420228213, 5.78228635713458, 0.159530621021986,
22+
6.15989632671699, 0.565385406371206, 3.32634499762207, 5.99907119991258,
23+
6.42221869435161, 7.78480920242146, 1.6154010198079, 6.40206620562822,
24+
2.20054193399847, 3.67591219721362, 9.65326205827296, 4.24420014023781,
25+
9.98306149151176, 8.26122796628624, 7.49002234777436, 6.38011312345043,
26+
8.77622718457133, 4.10558220697567, 5.46563858631998, 2.48607469722629,
27+
3.68429954629391, 3.36249730316922, 7.73126894375309, 1.9974720152095,
28+
1.90315729007125, 5.13465406373143, 3.16930384142324, 2.34431644668803
29+
)
30+
y <-
31+
c(7.56552006313076, 9.76939121749182, 24.2448359410629, 20.9821514358478,
32+
24.9962784837968, 26.8915997662255, 13.5881436017663, 19.6545045571507,
33+
19.1911128631036, 30.8837628430223, 34.8955632358237, 18.8870707062523,
34+
10.6975736476306, 15.5098375621426, 26.7910429618714, 21.9293182116884,
35+
29.9959641528661, 14.4336073380027, 10.1660540700647, 17.663470456751,
36+
35.4119442930633, 22.404822512505, -1.22042046262689, 23.4344635414683,
37+
14.811312738173, 4.18069318567838, 12.5180973861314, 7.19119270574544,
38+
24.1295396797915, 20.4869594668355, 13.213607838582, 29.777945592468,
39+
12.2245266270612, 8.10797586076861, 19.8171814400653, 24.1081160733131,
40+
22.9087287329155, 12.6086166985308, 32.0757649197201, 15.3861261517808,
41+
8.61150222703634, 10.962062247365, 8.27427001372424, 11.508717141065,
42+
35.5241284496367, 13.7909400941573, 18.6517195943646, 29.6273245188661,
43+
2.04731665131452, 26.7040875860107, 11.4057023383477, 26.7880889846927,
44+
20.0020738656452, 18.2364874544682, 7.44406620641143, 20.7642578817391,
45+
2.05870239595777, 25.5704502520692, 16.6620364567942, 26.3144188598547,
46+
10.8802999470338, -4.30981317344027, 23.1527270482452, -2.11294361574222,
47+
9.16930389643637, 28.756143132455, 15.1350701685981, 26.7684106673939,
48+
37.0069536323432, 29.3135092857704, 16.952588572893, 0.354036449175697,
49+
16.330557176018, -13.7571897636472, 10.1466768142457, 18.7250139648418,
50+
27.3524614620177, 22.0018363467837, 13.0654884830186, 24.4052030316632,
51+
7.67434195964745, 10.2971540250292, 32.1844941240187, 20.3158889108271,
52+
32.2194118439009, 19.2800804786584, 24.3680263777705, 22.9323155709183,
53+
27.7139321374481, 10.1573110372689, 18.701397759763, 8.0429159918026,
54+
12.4139349424528, 9.39088662208607, 20.7470342090419, 12.365636243757,
55+
12.1422242014525, 26.5921509715383, 8.36492785003775, 16.6142577646007
56+
)

misc/dlm/fx_factor.stan

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ data {
88
vector[1] m0;
99
cov_matrix[1] C0;
1010
}
11-
transformed data {
12-
matrix[1, 1] G;
13-
}
1411
parameters {
12+
matrix[1, 1] G;
1513
vector[r - 1] lambda;
1614
vector<lower=0.0>[r] V;
1715
cov_matrix[1] W;
1816
}
1917
transformed parameters {
2018
matrix[1, r] F;
21-
F[1, 1] <- 1;
19+
F[1, 1] = 1;
2220
for (i in 1:(r - 1)) {
23-
F[1, i + 1] <- lambda[i];
21+
F[1, i + 1] = lambda[i];
2422
}
2523
}
2624
model {
25+
matrix[1,1] identity;
26+
identity <- diag_matrix(rep_vector(1.0,1));
27+
W ~ inv_wishart(1, identity);
28+
to_vector(G) ~ normal(0, 10);
29+
lambda ~ normal(0, 10);
30+
V ~ normal(0, 10);
2731
y ~ gaussian_dlm_obs(F, G, V, W, m0, C0);
28-
}
32+
}

0 commit comments

Comments
 (0)