# 第 68 章 贝叶斯层级模型

library(tidyverse)
library(tidybayes)
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

## 68.1 明尼苏达州房屋中氡的存在

radon <- readr::read_rds(here::here('demo_data', "radon.rds"))
head(radon)
##   floor county  log_radon log_uranium
## 1     1 AITKIN 0.83290912  -0.6890476
## 2     0 AITKIN 0.83290912  -0.6890476
## 3     0 AITKIN 1.09861229  -0.6890476
## 4     0 AITKIN 0.09531018  -0.6890476
## 5     0  ANOKA 1.16315081  -0.8473129
## 6     0  ANOKA 0.95551145  -0.8473129

• log_radon 房屋氡含量 (log scale)
• log_uranium 这个县放射性化学元素铀的等级 (log scale)
• floor 房屋楼层 (0 = basement, 1 = first floor)
• county 所在县 (factor)

## 68.2 任务

### 68.2.1 可视化探索

df_n_county <- radon %>%
group_by(county) %>%
summarise(
n = n()
)

df_n_county 
## # A tibble: 85 × 2
##    county        n
##    <fct>     <int>
##  1 AITKIN        4
##  2 ANOKA        52
##  3 BECKER        3
##  4 BELTRAMI      7
##  5 BENTON        4
##  6 BIGSTONE      3
##  7 BLUEEARTH    14
##  8 BROWN         4
##  9 CARLTON      10
## 10 CARVER        6
## # ℹ 75 more rows

radon_county <- radon %>%
group_by(county) %>%
summarise(
log_uranium    = mean(log_uranium),
n              = length(county)
) %>%

radon_county
## # A tibble: 85 × 6
##    <fct>              <dbl>        <dbl>       <dbl> <int>        <dbl>
##  1 AITKIN             0.715        0.432     -0.689      4       0.216
##  2 ANOKA              0.891        0.718     -0.847     52       0.0995
##  3 BECKER             1.09         0.717     -0.113      3       0.414
##  4 BELTRAMI           1.19         0.894     -0.593      7       0.338
##  5 BENTON             1.28         0.415     -0.143      4       0.207
##  6 BIGSTONE           1.54         0.504      0.387      3       0.291
##  7 BLUEEARTH          1.93         0.542      0.272     14       0.145
##  8 BROWN              1.65         0.595      0.278      4       0.298
##  9 CARLTON            0.977        0.585     -0.332     10       0.185
## 10 CARVER             1.22         1.90       0.0959     6       0.777
## # ℹ 75 more rows
ggplot() +
colour = "gray") +
colour = "gray") +
mapping = aes(x = fct_reorder(county, log_radon_mean),
colour = "red") +
coord_flip() +
labs(y = "log(radon)", x = "")

### 68.2.2 pooling model

\begin{aligned}[t] y_i &\sim \operatorname{normal}(\mu, \sigma) \\ \mu &\sim \operatorname{normal}(0, 10) \\ \sigma &\sim \operatorname{exp}(1) \end{aligned} 这里我们指定 $$\mu$$$$\sigma$$ 较弱的先验信息.

stan_program <- "
data {
int N;
vector[N] y;
}
parameters {
real mu;
real<lower=0> sigma;
}
model {
mu ~ normal(0, 10);
sigma ~ exponential(1);

y ~ normal(mu, sigma);
}
"

stan_data <- list(
y = radon$log_radon ) fit_pooling <- stan(model_code = stan_program, data = stan_data) 模型估计了均值和方差两个参数。 summary(fit_pooling)$summary
##               mean      se_mean         sd         2.5%          25%
## mu       1.2642340 0.0005205044 0.02742536    1.2104850    1.2450453
## sigma    0.8195736 0.0003149489 0.01917117    0.7823672    0.8063292
## lp__  -277.9433172 0.0239258806 0.98310328 -280.4665786 -278.3198548
##                50%          75%        97.5%    n_eff      Rhat
## mu       1.2646388    1.2832237    1.3173825 2776.233 1.0005855
## sigma    0.8193615    0.8321428    0.8580254 3705.248 0.9991691
## lp__  -277.6559459 -277.2370988 -276.9561998 1688.350 1.0010905

### 68.2.3 no-pooling model

\begin{aligned}[t] y_i &\sim \operatorname{normal}(\mu_{j[i]}, \sigma) \\ \mu_j &\sim \operatorname{normal}(0, 10) \\ \sigma &\sim \operatorname{exp}(1) \end{aligned} 其中， $$j[i]$$ 表示观测$$i$$对应的所在县。

stan_program <- "
data {
int<lower=1> N;
int<lower=2> J;
int<lower=1, upper=J> county[N];
vector[N] y;
}
parameters {
vector[J] mu;
real<lower=0> sigma;
}
model {
mu ~ normal(0, 10);
sigma ~ exponential(1);

for(i in 1:N) {
y[i] ~ normal(mu[county[i]], sigma);
}
}
"

stan_data <- list(
J      = length(unique(radon$county)), county = as.numeric(radon$county),
y      = radon$log_radon ) fit_no_pooling <- stan(model_code = stan_program, data = stan_data) summary(fit_no_pooling)$summary
##                mean      se_mean         sd          2.5%          25%
## mu[1]     0.7111322 0.0051471628 0.38775685   -0.04625801    0.4439757
## mu[2]     0.8886618 0.0014140589 0.10745053    0.68102047    0.8177827
## mu[3]     1.0851203 0.0057132158 0.44167254    0.21388813    0.7879462
## mu[4]     1.1989189 0.0042106519 0.29541091    0.62725943    0.9967546
## mu[5]     1.2801826 0.0046562256 0.38209277    0.54576821    1.0211879
## mu[6]     1.5398567 0.0054162314 0.43614443    0.69368134    1.2407143
## mu[7]     1.9301271 0.0026665838 0.20376830    1.53004430    1.7914584
## mu[8]     1.6517076 0.0054926203 0.37868107    0.92465085    1.3892574
## mu[9]     0.9736545 0.0030516408 0.24536681    0.50511530    0.8028961
## mu[10]    1.2239658 0.0043937616 0.31112190    0.63343938    1.0043179
## mu[11]    1.4320218 0.0046123848 0.35211394    0.74148794    1.1931877
## mu[12]    1.7477481 0.0047445242 0.37944918    0.98687967    1.4918186
## mu[13]    1.0821507 0.0040408488 0.30904492    0.47233140    0.8767577
## mu[14]    1.8058367 0.0026779801 0.20552421    1.41048441    1.6692026
## mu[15]    1.0262008 0.0054737795 0.37873815    0.27074663    0.7729473
## mu[16]    0.7139751 0.0069030541 0.53120257   -0.34942870    0.3612031
## mu[17]    0.7507313 0.0049128356 0.37722734    0.01536168    0.4913063
## mu[18]    0.9893581 0.0028808150 0.21987538    0.56845473    0.8404206
## mu[19]    1.3281471 0.0012683613 0.09832603    1.13961091    1.2637369
## mu[20]    1.8174455 0.0056020154 0.44054073    0.97569709    1.5178909
## mu[21]    1.6687423 0.0031702736 0.25326974    1.18389205    1.4937584
## mu[22]    0.6625477 0.0041832605 0.31544100    0.03252701    0.4518154
## mu[23]    1.0652039 0.0067220462 0.52677437    0.06136117    0.7024825
## mu[24]    1.9579887 0.0036258767 0.24841943    1.46634307    1.7954081
## mu[25]    1.8707021 0.0027126644 0.20963597    1.44578541    1.7295559
## mu[26]    1.3210896 0.0009618109 0.07411845    1.17683734    1.2723418
## mu[27]    1.5565117 0.0043983579 0.31399421    0.95723852    1.3414527
## mu[28]    0.8670729 0.0045567436 0.34164013    0.21001426    0.6373072
## mu[29]    1.0837716 0.0056298876 0.44265788    0.19966845    0.7879808
## mu[30]    0.9688479 0.0031841270 0.24094585    0.49370297    0.8051168
## mu[31]    2.0326059 0.0046560239 0.33852495    1.37991399    1.8010037
## mu[32]    1.2688706 0.0052809909 0.38303595    0.51662037    1.0041978
## mu[33]    2.0826321 0.0047194418 0.38194714    1.31687221    1.8244039
## mu[34]    1.1461042 0.0056247903 0.44077404    0.27959955    0.8468336
## mu[35]    0.4773884 0.0038767772 0.29049029   -0.08475653    0.2832415
## mu[36]    2.6093020 0.0070756347 0.54593391    1.52289758    2.2403150
## mu[37]    0.4103055 0.0032864692 0.26146579   -0.10644428    0.2353852
## mu[38]    1.5256009 0.0047589937 0.38069600    0.78782530    1.2740028
## mu[39]    1.6152248 0.0046746046 0.33835146    0.94622191    1.3840532
## mu[40]    2.1329294 0.0052197885 0.38264122    1.39062311    1.8792079
## mu[41]    1.8839113 0.0034272437 0.27090411    1.34039395    1.7018162
## mu[42]    1.3960887 0.0101643335 0.75418365   -0.07234397    0.8864505
## mu[43]    1.2581641 0.0033990456 0.25685625    0.76000193    1.0834345
## mu[44]    1.0117496 0.0036148456 0.28986289    0.45411756    0.8117379
## mu[45]    1.1106409 0.0028224274 0.22123883    0.68177335    0.9550247
## mu[46]    1.2449417 0.0043084845 0.34927111    0.57407837    1.0112484
## mu[47]    0.6180657 0.0068944006 0.55366424   -0.41855581    0.2302346
## mu[48]    1.1050019 0.0033578946 0.26317674    0.57465197    0.9324872
## mu[49]    1.6185611 0.0029361068 0.21826980    1.19405429    1.4702212
## mu[50]    2.4963361 0.0106982969 0.77082352    0.98054246    1.9618386
## mu[51]    2.1754868 0.0049363954 0.37835051    1.43585283    1.9183861
## mu[52]    1.9423815 0.0057155960 0.44375440    1.10039750    1.6438087
## mu[53]    1.0476503 0.0064917053 0.45042544    0.15936948    0.7408987
## mu[54]    1.2486106 0.0019289634 0.15766553    0.93177113    1.1413596
## mu[55]    1.3809118 0.0035577204 0.27054764    0.85581300    1.2007481
## mu[56]    0.7312310 0.0061036444 0.44815420   -0.13442477    0.4252391
## mu[57]    0.7001667 0.0040610189 0.31883564    0.07592075    0.4940726
## mu[58]    1.7069052 0.0053585822 0.38112609    0.96583104    1.4469458
## mu[59]    1.4005913 0.0051904390 0.39626860    0.60894228    1.1285244
## mu[60]    1.3205251 0.0073277858 0.54382986    0.25413808    0.9539209
## mu[61]    1.1363239 0.0017498655 0.13789472    0.86283225    1.0436752
## mu[62]    1.8525381 0.0044087540 0.34930638    1.15787773    1.6190477
## mu[63]    1.4513110 0.0058785878 0.45172528    0.57754720    1.1339691
## mu[64]    1.7976104 0.0033272273 0.23982557    1.33660803    1.6387128
## mu[65]    1.3354134 0.0067588265 0.53464544    0.24387360    0.9818927
## mu[66]    1.2907430 0.0025647927 0.20313431    0.89816136    1.1550542
## mu[67]    1.6035086 0.0027810100 0.20805121    1.19647307    1.4611291
## mu[68]    1.1297494 0.0035340659 0.26937701    0.61481023    0.9481912
## mu[69]    1.2704005 0.0051242622 0.38023359    0.51632306    1.0087094
## mu[70]    0.8267275 0.0009324458 0.06990462    0.68877514    0.7796967
## mu[71]    1.4065758 0.0019539633 0.15804281    1.10309026    1.3016637
## mu[72]    1.5957654 0.0033533368 0.24274406    1.12158755    1.4321495
## mu[73]    1.8061553 0.0071898441 0.55810818    0.72863295    1.4182185
## mu[74]    1.0262057 0.0048545001 0.38718572    0.28689061    0.7588639
## mu[75]    1.5016619 0.0062401585 0.44721657    0.62173391    1.1945653
## mu[76]    1.8420065 0.0049120096 0.37550944    1.11088609    1.5828323
## mu[77]    1.7380852 0.0040344069 0.29392294    1.14730674    1.5444603
## mu[78]    1.0369636 0.0043779603 0.33632314    0.38924035    0.8114321
## mu[79]    0.5253026 0.0050279678 0.39549618   -0.23971303    0.2532753
## mu[80]    1.2893947 0.0014496049 0.11212626    1.07102268    1.2155844
## mu[81]    2.2316430 0.0055623710 0.43935034    1.38360796    1.9319273
## mu[82]    2.2336444 0.0101277337 0.79276849    0.70942379    1.6823692
## mu[83]    1.4911503 0.0026868401 0.21063869    1.06638184    1.3558501
## mu[84]    1.6161087 0.0029609333 0.21549187    1.20161166    1.4723507
## mu[85]    1.2032884 0.0067918128 0.53911846    0.16211252    0.8384707
## sigma     0.7673864 0.0002965435 0.01886820    0.73099625    0.7546396
## lp__   -217.8570858 0.1714924991 6.91382182 -232.54899610 -222.3813022
##                 50%          75%        97.5%    n_eff      Rhat
## mu[1]     0.7155564    0.9775561    1.4531034 5675.226 0.9999096
## mu[2]     0.8898304    0.9592479    1.0995124 5774.071 1.0000975
## mu[3]     1.0889972    1.3948524    1.9294730 5976.398 0.9992129
## mu[4]     1.2023084    1.3989847    1.7714679 4922.145 1.0003925
## mu[5]     1.2782922    1.5420297    2.0132644 6733.946 0.9994417
## mu[6]     1.5370370    1.8309648    2.4260684 6484.347 0.9994143
## mu[7]     1.9306151    2.0674181    2.3236100 5839.327 0.9996558
## mu[8]     1.6526241    1.8998967    2.3842923 4753.221 1.0000686
## mu[9]     0.9742991    1.1424265    1.4512131 6464.945 0.9999780
## mu[10]    1.2212041    1.4487543    1.8184475 5014.045 0.9998495
## mu[11]    1.4315552    1.6673601    2.1267590 5827.944 0.9998963
## mu[12]    1.7454853    2.0089611    2.4741879 6396.198 0.9995963
## mu[13]    1.0805497    1.2915529    1.6721105 5849.221 0.9996375
## mu[14]    1.8030615    1.9438805    2.2080809 5889.945 0.9994039
## mu[15]    1.0223787    1.2784182    1.7606803 4787.442 1.0001804
## mu[16]    0.7170419    1.0667224    1.7655231 5921.582 0.9993209
## mu[17]    0.7488441    1.0063966    1.4914413 5895.788 0.9998403
## mu[18]    0.9853665    1.1339890    1.4339258 5825.356 1.0007978
## mu[19]    1.3287771    1.3936563    1.5208747 6009.677 0.9998554
## mu[20]    1.8195409    2.1202614    2.6642656 6184.200 0.9994298
## mu[21]    1.6690996    1.8420279    2.1658601 6382.240 1.0000075
## mu[22]    0.6598504    0.8719498    1.2863307 5685.995 0.9993541
## mu[23]    1.0694350    1.4260722    2.0865418 6141.102 0.9993030
## mu[24]    1.9610652    2.1271211    2.4370884 4694.021 0.9996936
## mu[25]    1.8718374    2.0097454    2.2857911 5972.271 0.9993332
## mu[26]    1.3213884    1.3712629    1.4672615 5938.453 0.9994468
## mu[27]    1.5606270    1.7675847    2.1721663 5096.384 0.9992942
## mu[28]    0.8652949    1.0936519    1.5436288 5621.194 0.9995402
## mu[29]    1.0895220    1.3784285    1.9514462 6182.113 0.9996947
## mu[30]    0.9686812    1.1333977    1.4474919 5726.089 0.9994782
## mu[31]    2.0292778    2.2618732    2.6940782 5286.290 0.9996295
## mu[32]    1.2673343    1.5289493    2.0124666 5260.757 0.9996388
## mu[33]    2.0798590    2.3448912    2.8457371 6549.758 0.9995523
## mu[34]    1.1483419    1.4424870    1.9996309 6140.721 0.9994833
## mu[35]    0.4742873    0.6720013    1.0358752 5614.635 0.9999449
## mu[36]    2.6094378    2.9775232    3.7118337 5953.184 0.9994911
## mu[37]    0.4081408    0.5844288    0.9206740 6329.518 0.9999563
## mu[38]    1.5260735    1.7756984    2.2859770 6399.210 0.9994045
## mu[39]    1.6185435    1.8398961    2.2772923 5238.975 0.9999099
## mu[40]    2.1344733    2.3895204    2.8940944 5373.753 0.9996265
## mu[41]    1.8815681    2.0671652    2.4162116 6248.003 0.9996148
## mu[42]    1.3865004    1.9058120    2.8970757 5505.496 0.9995579
## mu[43]    1.2627883    1.4348890    1.7435877 5710.397 0.9997667
## mu[44]    1.0089675    1.2086387    1.5701991 6429.922 0.9991866
## mu[45]    1.1105842    1.2626544    1.5504506 6144.367 0.9996543
## mu[46]    1.2465994    1.4744446    1.9206925 6571.678 0.9997690
## mu[47]    0.6037456    0.9944272    1.6984953 6449.112 0.9993302
## mu[48]    1.1019891    1.2808217    1.6224471 6142.723 0.9995302
## mu[49]    1.6166843    1.7662238    2.0428573 5526.416 0.9995966
## mu[50]    2.4887651    3.0275730    4.0023267 5191.354 1.0001714
## mu[51]    2.1743210    2.4319182    2.9099611 5874.471 0.9994947
## mu[52]    1.9433468    2.2412317    2.8243361 6027.848 0.9992974
## mu[53]    1.0477685    1.3666372    1.9134915 4814.245 1.0000262
## mu[54]    1.2503657    1.3568692    1.5616711 6680.755 0.9996161
## mu[55]    1.3777845    1.5673235    1.8963204 5782.876 0.9995429
## mu[56]    0.7312639    1.0316395    1.5982235 5391.089 0.9996533
## mu[57]    0.6998760    0.9134282    1.3160133 6164.015 1.0006425
## mu[58]    1.7023028    1.9615772    2.4689360 5058.684 0.9993778
## mu[59]    1.4051968    1.6681424    2.1586638 5828.692 0.9995257
## mu[60]    1.3246783    1.6734359    2.3961102 5507.831 0.9994979
## mu[61]    1.1375652    1.2301085    1.4066298 6209.919 0.9994934
## mu[62]    1.8513848    2.0853264    2.5436950 6277.422 0.9993999
## mu[63]    1.4592603    1.7616656    2.3147412 5904.767 0.9995695
## mu[64]    1.7937917    1.9559008    2.2783407 5195.484 0.9992241
## mu[65]    1.3330864    1.6926897    2.3877719 6257.331 0.9996593
## mu[66]    1.2886188    1.4231365    1.7009422 6272.809 1.0000191
## mu[67]    1.6014488    1.7435780    2.0091619 5596.743 0.9999109
## mu[68]    1.1246574    1.3135023    1.6656720 5809.942 0.9992656
## mu[69]    1.2733570    1.5363095    1.9979378 5506.026 0.9993673
## mu[70]    0.8262328    0.8737956    0.9645315 5620.365 0.9998041
## mu[71]    1.4068492    1.5110129    1.7167406 6542.092 0.9992257
## mu[72]    1.5969947    1.7590166    2.0795952 5240.140 0.9993436
## mu[73]    1.8100368    2.1851456    2.8797325 6025.566 0.9996684
## mu[74]    1.0221999    1.2954157    1.7816269 6361.355 0.9995297
## mu[75]    1.5090498    1.8081668    2.3846559 5136.231 0.9998098
## mu[76]    1.8410447    2.0933981    2.5654723 5844.176 0.9996260
## mu[77]    1.7399940    1.9365581    2.2964017 5307.715 0.9998699
## mu[78]    1.0355756    1.2621507    1.6977685 5901.601 0.9992444
## mu[79]    0.5279796    0.8050489    1.2915812 6187.278 0.9993945
## mu[80]    1.2877908    1.3644046    1.5164391 5982.950 0.9996766
## mu[81]    2.2327981    2.5361098    3.0765737 6238.814 0.9992648
## mu[82]    2.2240799    2.7956624    3.7761321 6127.287 0.9999655
## mu[83]    1.4935295    1.6298332    1.9056314 6146.001 0.9995169
## mu[84]    1.6176148    1.7627565    2.0404349 5296.689 1.0013096
## mu[85]    1.1931093    1.5755865    2.2460814 6300.819 0.9993381
## sigma     0.7672921    0.7800309    0.8047443 4048.408 1.0002868
## lp__   -217.4686179 -213.0385412 -205.4721038 1625.347 1.0017040

### 68.2.4 partially pooled model

• 模型同时考虑各个类别数据中的信息以及整个群体中的信息
• 怎么叫共享信息？参数来自同一个分布
• 怎么做到的呢？通过先验

\begin{aligned}[t] y_i &\sim \operatorname{normal}(\mu_{j[i]}, \sigma) \\ \mu_j &\sim \operatorname{normal}(\gamma, \tau) \\ \gamma &\sim \operatorname{normal}(0, 5) \\ \tau &\sim \operatorname{exp}(1) \end{aligned}

• $$\gamma$$$$\tau$$ 的先验称为 超先验分布
• 超参数是多层模型的标志。
stan_program <- "
data {
int<lower=1> N;
int<lower=2> J;
int<lower=1, upper=J> county[N];
vector[N] y;
}
parameters {
vector[J] mu;
real mu_a;
real<lower=0> sigma_y;
real<lower=0> sigma_a;
}
model {
mu_a ~ normal(0, 5);
sigma_a ~ exponential(1);
sigma_y ~ exponential(1);

mu ~ normal(mu_a, sigma_a);

for(i in 1:N) {
y[i] ~ normal(mu[county[i]], sigma_y);
}
}
"

stan_data <- list(
J      = length(unique(radon$county)), county = as.numeric(radon$county),
y      = radon$log_radon ) fit_partial_pooling <- stan(model_code = stan_program, data = stan_data) summary(fit_partial_pooling)$summary
##                 mean      se_mean         sd         2.5%          25%
## mu[1]      1.1078355 0.0027454493 0.23834601    0.6333122    0.9508426
## mu[2]      0.9450242 0.0012467073 0.10212212    0.7448281    0.8773785
## mu[3]      1.2652001 0.0027689918 0.25439763    0.7598871    1.1002471
## mu[4]      1.2684206 0.0021953750 0.20880167    0.8712869    1.1211045
## mu[5]      1.3235012 0.0025281996 0.24150064    0.8399759    1.1615953
## mu[6]      1.4074491 0.0026596465 0.24914916    0.9185417    1.2415848
## mu[7]      1.7417078 0.0021005395 0.17267697    1.4182688    1.6207701
## mu[8]      1.4700642 0.0024939837 0.24197816    1.0081738    1.3070037
## mu[9]      1.1268923 0.0021501773 0.19106740    0.7543447    0.9974486
## mu[10]     1.2881253 0.0022317497 0.21277997    0.8594222    1.1481606
## mu[11]     1.3860896 0.0022952865 0.22273198    0.9643650    1.2358524
## mu[12]     1.5028724 0.0026767133 0.24320235    1.0375237    1.3372851
## mu[13]     1.2232756 0.0023687785 0.21251024    0.8181867    1.0807665
## mu[14]     1.6613298 0.0019433911 0.17346129    1.3191756    1.5457948
## mu[15]     1.2241526 0.0027789696 0.24108917    0.7381662    1.0724035
## mu[16]     1.1993859 0.0028921285 0.26138496    0.6717348    1.0340207
## mu[17]     1.1203480 0.0028025503 0.24585634    0.6248790    0.9559731
## mu[18]     1.1167916 0.0019972236 0.17954754    0.7561280    0.9992883
## mu[19]     1.3310413 0.0010344161 0.09268103    1.1427419    1.2693385
## mu[20]     1.5046668 0.0029289711 0.24938811    1.0276605    1.3386367
## mu[21]     1.5370235 0.0021610435 0.20241806    1.1508433    1.3992822
## mu[22]     1.0179385 0.0028713891 0.22659123    0.5595025    0.8638776
## mu[23]     1.2832841 0.0029636194 0.28276491    0.7258049    1.1002855
## mu[24]     1.7022146 0.0022809246 0.20165238    1.3231889    1.5643004
## mu[25]     1.6999415 0.0021051267 0.17189976    1.3716837    1.5855441
## mu[26]     1.3233230 0.0008389469 0.07301332    1.1787336    1.2746605
## mu[27]     1.4436584 0.0025523248 0.21631564    1.0270983    1.2961917
## mu[28]     1.1290467 0.0027981257 0.22821873    0.6845372    0.9707580
## mu[29]     1.2649408 0.0026131028 0.25169714    0.7652296    1.0945358
## mu[30]     1.1147893 0.0020343747 0.18420346    0.7479824    0.9923177
## mu[31]     1.6470717 0.0030044569 0.23390177    1.1891265    1.4901458
## mu[32]     1.3149453 0.0026688135 0.24380948    0.8260011    1.1567885
## mu[33]     1.6284786 0.0029143338 0.24652058    1.1528643    1.4616859
## mu[34]     1.2843639 0.0027345359 0.25385377    0.7770673    1.1171266
## mu[35]     0.8981030 0.0030812740 0.21981805    0.4583350    0.7542704
## mu[36]     1.6528116 0.0036981329 0.26835832    1.1472550    1.4708911
## mu[37]     0.8026789 0.0029104334 0.20333472    0.3810473    0.6726981
## mu[38]     1.4159214 0.0025286409 0.23762590    0.9548412    1.2542099
## mu[39]     1.4670920 0.0025477790 0.23028118    1.0173879    1.3117021
## mu[40]     1.6578907 0.0030432670 0.24381499    1.1940901    1.4897338
## mu[41]     1.6476624 0.0026473896 0.20898938    1.2488275    1.5043861
## mu[42]     1.3582240 0.0033584898 0.28556575    0.7860746    1.1731364
## mu[43]     1.2956667 0.0021837916 0.19644247    0.9013475    1.1689808
## mu[44]     1.1731198 0.0023990249 0.20899782    0.7578611    1.0358474
## mu[45]     1.1910305 0.0019748210 0.17358656    0.8476617    1.0738521
## mu[46]     1.3016272 0.0025960697 0.22863654    0.8493190    1.1494103
## mu[47]     1.1711470 0.0030616725 0.27453042    0.6035732    0.9896220
## mu[48]     1.2058997 0.0020400972 0.19682140    0.8202083    1.0707590
## mu[49]     1.5302808 0.0017653463 0.17353190    1.1982175    1.4148151
## mu[50]     1.5087962 0.0031449562 0.29428669    0.9321895    1.3162862
## mu[51]     1.6702379 0.0030468484 0.24361835    1.2085620    1.5021277
## mu[52]     1.5335939 0.0029539824 0.25273123    1.0485275    1.3606160
## mu[53]     1.2546903 0.0029376055 0.24750353    0.7636885    1.0946190
## mu[54]     1.2741097 0.0014988336 0.13969700    1.0030774    1.1794097
## mu[55]     1.3688785 0.0023237886 0.20564361    0.9580721    1.2344322
## mu[56]     1.1536089 0.0029655102 0.26151546    0.6238667    0.9766329
## mu[57]     1.0389823 0.0024205383 0.21869385    0.5921468    0.8888190
## mu[58]     1.4855410 0.0028367425 0.24563658    1.0076856    1.3208399
## mu[59]     1.3677210 0.0026679875 0.23754562    0.9034060    1.2117265
## mu[60]     1.3396296 0.0027861916 0.28478249    0.7751571    1.1509544
## mu[61]     1.1685084 0.0012836093 0.12099807    0.9290895    1.0864858
## mu[62]     1.5744808 0.0026958433 0.22876036    1.1388601    1.4264548
## mu[63]     1.3871896 0.0027158083 0.25815502    0.8952266    1.2125363
## mu[64]     1.6307898 0.0022918320 0.18611776    1.2749660    1.5008903
## mu[65]     1.3435299 0.0027961447 0.26775321    0.8135972    1.1679293
## mu[66]     1.3077750 0.0020990968 0.17310151    0.9735963    1.1875085
## mu[67]     1.5234797 0.0019611773 0.17766022    1.1703005    1.4043789
## mu[68]     1.2223014 0.0020751412 0.20465642    0.8180204    1.0918267
## mu[69]     1.3181098 0.0026330743 0.24057484    0.8462605    1.1546964
## mu[70]     0.8568514 0.0008051756 0.06961936    0.7188560    0.8118551
## mu[71]     1.3984328 0.0014652834 0.13960688    1.1309018    1.3031781
## mu[72]     1.5031999 0.0020917972 0.18895453    1.1257356    1.3758769
## mu[73]     1.4616715 0.0031974708 0.27411601    0.9258221    1.2774809
## mu[74]     1.2254111 0.0025624477 0.23841042    0.7578354    1.0651079
## mu[75]     1.3974931 0.0026269731 0.24700308    0.9116682    1.2399500
## mu[76]     1.5383816 0.0029332661 0.24131978    1.0668479    1.3745173
## mu[77]     1.5500975 0.0024993243 0.21217175    1.1314780    1.4039038
## mu[78]     1.2200589 0.0024576596 0.22796389    0.7654840    1.0661569
## mu[79]     1.0393686 0.0029341686 0.24315110    0.5416823    0.8776455
## mu[80]     1.2971427 0.0012350127 0.10447206    1.0857010    1.2273055
## mu[81]     1.6287420 0.0034583395 0.25604453    1.1421543    1.4544480
## mu[82]     1.4778907 0.0034190386 0.28702685    0.9260767    1.2888288
## mu[83]     1.4476175 0.0019163190 0.17871488    1.1006388    1.3284018
## mu[84]     1.5248573 0.0018659167 0.17722966    1.1809732    1.4035755
## mu[85]     1.3178735 0.0028987471 0.26051106    0.7974437    1.1413241
## mu_a       1.3499440 0.0006989300 0.04579328    1.2622459    1.3190204
## sigma_y    0.7670301 0.0002319138 0.01917573    0.7318580    0.7534510
## sigma_a    0.3035564 0.0013170502 0.04584803    0.2209930    0.2718363
## lp__    -157.8015346 0.3584503656 9.52369007 -176.9315963 -163.9781383
##                  50%          75%        97.5%      n_eff      Rhat
## mu[1]      1.1169384    1.2657447    1.5647613  7536.8335 0.9993684
## mu[2]      0.9452647    1.0130696    1.1483541  6709.8164 0.9993822
## mu[3]      1.2645587    1.4287342    1.7667652  8440.7839 0.9992430
## mu[4]      1.2693453    1.4115832    1.6660971  9045.8729 0.9995937
## mu[5]      1.3203998    1.4881061    1.7960894  9124.6008 0.9993487
## mu[6]      1.4075062    1.5720227    1.8923654  8775.4826 0.9993286
## mu[7]      1.7435297    1.8555346    2.0873844  6757.8285 0.9994379
## mu[8]      1.4677138    1.6295159    1.9430145  9413.8037 1.0001544
## mu[9]      1.1268087    1.2558056    1.5003476  7896.3179 0.9991831
## mu[10]     1.2890894    1.4290256    1.7030453  9090.1391 0.9992794
## mu[11]     1.3860542    1.5345644    1.8208000  9416.5401 0.9990889
## mu[12]     1.4988774    1.6648891    1.9694471  8255.2808 0.9995079
## mu[13]     1.2211518    1.3633913    1.6415599  8048.4239 0.9995119
## mu[14]     1.6608617    1.7798213    2.0036146  7966.8144 1.0004857
## mu[15]     1.2262217    1.3810271    1.6885138  7526.4089 1.0000322
## mu[16]     1.2035107    1.3721524    1.7026946  8168.1933 0.9995079
## mu[17]     1.1226915    1.2906682    1.5885962  7695.8395 0.9997217
## mu[18]     1.1176956    1.2370039    1.4754812  8081.7527 0.9992661
## mu[19]     1.3324428    1.3954516    1.5069882  8027.7010 0.9994481
## mu[20]     1.5015584    1.6627226    2.0131753  7249.7214 0.9994163
## mu[21]     1.5364731    1.6675143    1.9463748  8773.4718 0.9994722
## mu[22]     1.0218569    1.1732538    1.4516953  6227.3331 0.9997092
## mu[23]     1.2835248    1.4716841    1.8434120  9103.4535 0.9992049
## mu[24]     1.6985973    1.8324651    2.1026265  7816.0053 0.9993975
## mu[25]     1.6971506    1.8133396    2.0462826  6667.9771 0.9991344
## mu[26]     1.3235673    1.3716243    1.4695491  7574.1725 0.9992996
## mu[27]     1.4449960    1.5914248    1.8759235  7182.9682 0.9993675
## mu[28]     1.1287409    1.2848984    1.5679803  6652.2435 0.9990872
## mu[29]     1.2656105    1.4334676    1.7583454  9277.7690 0.9996743
## mu[30]     1.1113598    1.2370597    1.4797347  8198.4863 0.9994936
## mu[31]     1.6423134    1.8077425    2.1074174  6060.8716 0.9993707
## mu[32]     1.3141220    1.4721831    1.8019702  8345.7373 0.9997944
## mu[33]     1.6213228    1.7891378    2.1261397  7155.2990 1.0001663
## mu[34]     1.2843425    1.4517979    1.7763304  8617.8708 0.9993220
## mu[35]     0.8997456    1.0470795    1.3225364  5089.3940 1.0010202
## mu[36]     1.6466252    1.8345607    2.1980887  5265.8091 1.0004946
## mu[37]     0.8092612    0.9367922    1.1934323  4880.9878 1.0002064
## mu[38]     1.4199477    1.5771672    1.8770837  8831.0680 0.9995758
## mu[39]     1.4628513    1.6200893    1.9402769  8169.4607 0.9994252
## mu[40]     1.6523191    1.8176921    2.1596890  6418.6055 0.9996533
## mu[41]     1.6420389    1.7854406    2.0709821  6231.7887 0.9993254
## mu[42]     1.3565849    1.5474653    1.9209223  7229.7651 0.9996136
## mu[43]     1.2949444    1.4269853    1.6748497  8091.8602 0.9993775
## mu[44]     1.1753598    1.3097298    1.5950901  7589.5151 0.9993226
## mu[45]     1.1928447    1.3099681    1.5225500  7726.3913 0.9998309
## mu[46]     1.2980083    1.4548427    1.7436223  7756.3712 0.9992997
## mu[47]     1.1802272    1.3529394    1.7077173  8040.1380 0.9994605
## mu[48]     1.2103853    1.3382149    1.5905475  9307.7116 0.9997337
## mu[49]     1.5280431    1.6460546    1.8728475  9662.7077 0.9993806
## mu[50]     1.5072001    1.6995948    2.1038509  8756.1267 0.9993610
## mu[51]     1.6671780    1.8296374    2.1668095  6393.2002 0.9997520
## mu[52]     1.5329855    1.7035805    2.0371242  7319.8468 0.9993024
## mu[53]     1.2550589    1.4174483    1.7428291  7098.6512 0.9996058
## mu[54]     1.2743815    1.3699784    1.5445140  8686.9495 0.9995465
## mu[55]     1.3669686    1.5083417    1.7799605  7831.3603 0.9992907
## mu[56]     1.1498922    1.3344582    1.6556087  7776.7101 0.9998806
## mu[57]     1.0439881    1.1920100    1.4581743  8162.9892 0.9995094
## mu[58]     1.4805049    1.6491533    1.9702421  7498.0140 0.9991861
## mu[59]     1.3694552    1.5169917    1.8427379  7927.3213 0.9995389
## mu[60]     1.3392361    1.5296180    1.9134666 10447.3132 0.9993162
## mu[61]     1.1681516    1.2493052    1.4115024  8885.6901 0.9996095
## mu[62]     1.5728904    1.7226016    2.0395881  7200.6593 0.9994111
## mu[63]     1.3862015    1.5658122    1.8948110  9035.7231 0.9992142
## mu[64]     1.6305440    1.7539010    2.0028515  6594.9281 0.9997190
## mu[65]     1.3462720    1.5139854    1.8828968  9169.5936 0.9992291
## mu[66]     1.3107814    1.4255655    1.6416546  6800.4364 0.9996596
## mu[67]     1.5225261    1.6428089    1.8759448  8206.2865 0.9993290
## mu[68]     1.2271781    1.3581812    1.6104177  9726.4745 0.9994652
## mu[69]     1.3201200    1.4784969    1.7934454  8347.8413 0.9994231
## mu[70]     0.8570901    0.9029779    0.9949332  7476.1662 0.9994037
## mu[71]     1.3983536    1.4920465    1.6721854  9077.5867 0.9992892
## mu[72]     1.5039051    1.6322885    1.8834759  8159.7239 0.9993921
## mu[73]     1.4623304    1.6448563    2.0120321  7349.4631 0.9995899
## mu[74]     1.2280951    1.3871312    1.6915879  8656.4627 0.9993487
## mu[75]     1.3976216    1.5551214    1.8941375  8840.8385 0.9991892
## mu[76]     1.5330760    1.6919286    2.0421158  6768.3518 1.0001668
## mu[77]     1.5479112    1.6972867    1.9623699  7206.5911 0.9993215
## mu[78]     1.2263972    1.3741112    1.6668108  8603.7671 0.9995464
## mu[79]     1.0440576    1.2010567    1.5009966  6867.2418 0.9996874
## mu[80]     1.2987245    1.3672508    1.4999565  7155.7890 0.9995775
## mu[81]     1.6235498    1.8002821    2.1420728  5481.4536 1.0001790
## mu[82]     1.4677632    1.6675195    2.0649620  7047.5319 0.9997944
## mu[83]     1.4447813    1.5663151    1.7939616  8697.3269 0.9991505
## mu[84]     1.5221791    1.6448752    1.8774427  9021.6987 0.9994987
## mu[85]     1.3197250    1.4950314    1.8196886  8076.6573 0.9999474
## mu_a       1.3508595    1.3803184    1.4409502  4292.7544 0.9994196
## sigma_y    0.7664086    0.7795749    0.8056477  6836.7692 0.9991387
## sigma_a    0.3014830    0.3334791    0.4038968  1211.8161 1.0044759
## lp__    -157.7176301 -151.4218874 -139.3209969   705.9151 1.0113196

### 68.2.5 对比三个模型

overall_mean <- broom.mixed::tidyMCMC(fit_pooling) %>%
filter(term == "mu") %>%
pull(estimate)

df_no_pooling <- fit_no_pooling %>%
tidybayes::gather_draws(mu[i]) %>%
tidybayes::mean_hdi() %>%
ungroup() %>%
mutate(
type = "no_pooling"
) %>%
select(type, .value) %>%
bind_cols(df_n_county)

df_partial_pooling <- fit_partial_pooling %>%
tidybayes::gather_draws(mu[i]) %>%
tidybayes::mean_hdi() %>%
ungroup() %>%
mutate(
type = "partial_pooling"
) %>%
select(type, .value) %>%
bind_cols(df_n_county)

bind_rows(df_no_pooling, df_partial_pooling) %>%
ggplot(
aes(x = n, y = .value, color = type)
) +
geom_point(size = 3) +
geom_hline(yintercept = overall_mean) +
scale_x_log10()
• 层级模型可以实现不同分组之间的信息交换
• 分组的均值向整体的均值靠拢（收缩）
• 分组的样本量越小，收缩效应越明显

## 68.3 增加预测变量

### 68.3.1 增加楼层floor作为预测变量

\begin{aligned} y_i &\sim N(\mu_i, \sigma^2) \\ \mu_i &= \alpha_{j[i]} + \beta~\mathtt{floor}_i \\ \alpha_j &\sim \operatorname{normal}(\gamma, \tau) \\ \beta &\sim \operatorname{normal}(0, 2.5)\\ \gamma &\sim \operatorname{normal}(0, 10) \\ \tau &\sim \operatorname{exp}(1) \\ \end{aligned} 不同的县有不同的截距，但有共同的$$\beta$$，因此被称为变化的截距

stan_program <- "
data {
int<lower=1> N;
int<lower=2> J;
int<lower=1, upper=J> county[N];
vector[N] x;
vector[N] y;
}
parameters {
vector[J] alpha;
real beta;
real gamma;
real<lower=0> sigma_y;
real<lower=0> sigma_a;
}
model {
vector[N] mu;
for(i in 1:N) {
mu[i] = alpha[county[i]] + beta * x[i];
}

for(i in 1:N) {
y[i] ~ normal(mu[i], sigma_y);
}

alpha ~ normal(gamma, sigma_a);
gamma ~ normal(0, 10);
beta ~ normal(0, 2.5);
sigma_a ~ exponential(1);
sigma_y ~ exponential(1);

}
"

stan_data <- list(
J      = length(unique(radon$county)), county = as.numeric(radon$county),
x      = radon$floor, y = radon$log_radon
)

fit_intercept_partial <- stan(model_code = stan_program, data = stan_data)
summary(fit_intercept_partial)summary ## mean se_mean sd 2.5% 25% ## alpha[1] 1.2341771 0.0031082316 0.24279128 0.7535863 1.0754394 ## alpha[2] 0.9838383 0.0013466167 0.09865125 0.7908418 0.9167684 ## alpha[3] 1.5085429 0.0034374507 0.25619266 0.9961306 1.3383977 ## alpha[4] 1.5378967 0.0028340506 0.21438214 1.1136958 1.3911780 ## alpha[5] 1.4709565 0.0029103138 0.24210303 1.0065934 1.3005174 ## alpha[6] 1.5119591 0.0030517888 0.25427073 1.0139909 1.3468809 ## alpha[7] 1.8733998 0.0022014215 0.17130372 1.5316554 1.7586038 ## alpha[8] 1.7039983 0.0032788793 0.25284739 1.2071369 1.5381718 ## alpha[9] 1.2023261 0.0022997228 0.18394253 0.8388158 1.0751469 ## alpha[10] 1.5242719 0.0026003080 0.21449469 1.1001360 1.3799134 ## alpha[11] 1.4670822 0.0026075931 0.22330607 1.0280239 1.3163855 ## alpha[12] 1.6025584 0.0029308648 0.24476709 1.1317711 1.4417562 ## alpha[13] 1.2765172 0.0028579877 0.21790068 0.8410490 1.1337229 ## alpha[14] 1.8591817 0.0022201183 0.16763367 1.5285440 1.7444400 ## alpha[15] 1.4311016 0.0028113780 0.24098741 0.9523492 1.2740916 ## alpha[16] 1.2756993 0.0034279498 0.27830032 0.7167610 1.0972018 ## alpha[17] 1.3890714 0.0027877742 0.23158174 0.9237427 1.2365600 ## alpha[18] 1.2611156 0.0021819683 0.17694959 0.9168994 1.1391662 ## alpha[19] 1.3801588 0.0009696178 0.08505835 1.2127625 1.3228117 ## alpha[20] 1.6091828 0.0030922758 0.25092479 1.1232125 1.4475746 ## alpha[21] 1.6517031 0.0023524592 0.19566942 1.2617338 1.5197683 ## alpha[22] 1.1193281 0.0029632106 0.22683875 0.6735621 0.9670613 ## alpha[23] 1.4725805 0.0032971510 0.27828079 0.9182043 1.2838504 ## alpha[24] 1.8777719 0.0027049126 0.19735472 1.4896719 1.7439812 ## alpha[25] 1.8345686 0.0023673259 0.16730683 1.5101676 1.7180730 ## alpha[26] 1.3946586 0.0008255136 0.06910588 1.2590302 1.3491100 ## alpha[27] 1.6428501 0.0030118036 0.22510492 1.2067128 1.4942903 ## alpha[28] 1.3828605 0.0027588306 0.22365415 0.9419528 1.2324503 ## alpha[29] 1.3505131 0.0028552468 0.24871558 0.8740902 1.1860678 ## alpha[30] 1.1408361 0.0023311308 0.18439092 0.7681148 1.0171588 ## alpha[31] 1.7633962 0.0029185178 0.22889557 1.3298168 1.6080559 ## alpha[32] 1.3971255 0.0028141848 0.24158286 0.9325936 1.2310258 ## alpha[33] 1.7422072 0.0032999402 0.24452122 1.2725307 1.5781832 ## alpha[34] 1.5311530 0.0033744460 0.26016671 1.0207198 1.3611445 ## alpha[35] 1.1319218 0.0028079473 0.21084867 0.7244647 0.9877906 ## alpha[36] 1.9008329 0.0043153405 0.28263531 1.3610572 1.7064411 ## alpha[37] 0.8625804 0.0030590776 0.21023827 0.4369244 0.7219994 ## alpha[38] 1.6569077 0.0030318669 0.24108030 1.2002431 1.4857043 ## alpha[39] 1.6261119 0.0027138131 0.22575064 1.1867030 1.4689241 ## alpha[40] 1.8488500 0.0033966950 0.24285433 1.3778842 1.6865921 ## alpha[41] 1.7795452 0.0027253082 0.20128026 1.3882330 1.6403105 ## alpha[42] 1.4787880 0.0034758718 0.29072208 0.9175392 1.2807412 ## alpha[43] 1.5774642 0.0023847391 0.19102984 1.2076431 1.4477501 ## alpha[44] 1.2740258 0.0028472195 0.20414634 0.8542849 1.1401377 ## alpha[45] 1.3650549 0.0020124697 0.17020376 1.0283513 1.2486172 ## alpha[46] 1.3727369 0.0028812830 0.23335735 0.9153409 1.2181685 ## alpha[47] 1.3426364 0.0034298053 0.27578988 0.7999980 1.1528151 ## alpha[48] 1.2934942 0.0022244532 0.19280109 0.9209228 1.1599354 ## alpha[49] 1.6546323 0.0020332892 0.16897088 1.3281295 1.5416668 ## alpha[50] 1.6578680 0.0039922796 0.29688761 1.0913495 1.4600105 ## alpha[51] 1.7879346 0.0034298594 0.24878312 1.3071472 1.6167029 ## alpha[52] 1.6644739 0.0034329996 0.25073202 1.1779788 1.4973778 ## alpha[53] 1.4148599 0.0031017003 0.25713690 0.9051383 1.2438256 ## alpha[54] 1.3681743 0.0016740272 0.13748955 1.0954831 1.2757907 ## alpha[55] 1.5764009 0.0024571055 0.20113826 1.1754492 1.4440119 ## alpha[56] 1.3773281 0.0034421183 0.25994476 0.8590428 1.2127669 ## alpha[57] 1.1235537 0.0030015804 0.22121929 0.6770065 0.9758431 ## alpha[58] 1.6538300 0.0032544230 0.24621729 1.1705652 1.4938870 ## alpha[59] 1.5939537 0.0029828800 0.23446837 1.1423512 1.4358356 ## alpha[60] 1.4382794 0.0031221133 0.28077623 0.9034553 1.2531193 ## alpha[61] 1.2355359 0.0013403435 0.12171103 0.9926576 1.1537035 ## alpha[62] 1.7343024 0.0029892932 0.23237285 1.2800817 1.5785489 ## alpha[63] 1.5620336 0.0031823411 0.25704096 1.0516074 1.3913950 ## alpha[64] 1.7428082 0.0019217328 0.17700592 1.4008936 1.6219951 ## alpha[65] 1.4502243 0.0035983177 0.27056699 0.9181711 1.2726624 ## alpha[66] 1.6213711 0.0021408975 0.17006838 1.2830556 1.5062310 ## alpha[67] 1.7177277 0.0021980179 0.17305161 1.3676931 1.6021960 ## alpha[68] 1.2689898 0.0026072252 0.19839689 0.8757977 1.1329047 ## alpha[69] 1.4009745 0.0027297794 0.23085882 0.9461544 1.2488287 ## alpha[70] 0.9466394 0.0009331736 0.06513651 0.8212172 0.9021656 ## alpha[71] 1.5110153 0.0015913921 0.13197267 1.2477667 1.4213682 ## alpha[72] 1.5638988 0.0023107714 0.19143513 1.2012276 1.4354749 ## alpha[73] 1.5805028 0.0034554312 0.26686866 1.0473999 1.4034845 ## alpha[74] 1.2880860 0.0029882980 0.24310421 0.8114095 1.1293767 ## alpha[75] 1.5806238 0.0030193519 0.25382404 1.0932004 1.4067153 ## alpha[76] 1.7183588 0.0031008160 0.24135703 1.2580231 1.5530815 ## alpha[77] 1.6896485 0.0025164861 0.21303536 1.2717048 1.5382971 ## alpha[78] 1.4058183 0.0027182064 0.22098209 0.9767842 1.2584847 ## alpha[79] 1.1470895 0.0032866557 0.23842744 0.6739538 0.9873502 ## alpha[80] 1.3753752 0.0012124056 0.10013406 1.1820727 1.3090826 ## alpha[81] 1.9245395 0.0039837714 0.26872435 1.4257995 1.7370430 ## alpha[82] 1.6177690 0.0032993520 0.29837481 1.0349770 1.4219464 ## alpha[83] 1.6044163 0.0020684568 0.16991217 1.2739508 1.4860786 ## alpha[84] 1.6137412 0.0020883924 0.17303118 1.2828360 1.4995805 ## alpha[85] 1.4149168 0.0034331127 0.27202398 0.8813020 1.2331781 ## beta -0.6636116 0.0010440044 0.06626257 -0.7936687 -0.7085433 ## gamma 1.4933699 0.0008340008 0.04870441 1.3967587 1.4610136 ## sigma_y 0.7268850 0.0002371290 0.01817082 0.6932983 0.7141963 ## sigma_a 0.3184676 0.0012553504 0.04405155 0.2397795 0.2874022 ## lp__ -112.4010460 0.2967100183 8.53067514 -129.5273262 -117.9979628 ## 50% 75% 97.5% n_eff Rhat ## alpha[1] 1.2331212 1.4000509 1.7090087 6101.5395 0.9994385 ## alpha[2] 0.9842524 1.0502752 1.1778507 5366.8221 0.9993058 ## alpha[3] 1.5055571 1.6726123 2.0141333 5554.6973 0.9993901 ## alpha[4] 1.5367637 1.6884978 1.9537798 5722.1866 0.9997065 ## alpha[5] 1.4653854 1.6381692 1.9410567 6920.2343 0.9997675 ## alpha[6] 1.5124288 1.6827284 2.0150175 6941.9870 0.9991148 ## alpha[7] 1.8732744 1.9899201 2.2110598 6055.1814 0.9996049 ## alpha[8] 1.7041258 1.8682744 2.2075534 5946.5640 0.9993162 ## alpha[9] 1.2035594 1.3280979 1.5566922 6397.5449 0.9994920 ## alpha[10] 1.5227416 1.6682964 1.9537904 6804.3004 0.9999289 ## alpha[11] 1.4664318 1.6193546 1.9144964 7333.6711 0.9993754 ## alpha[12] 1.6000753 1.7674605 2.0789784 6974.5225 0.9993098 ## alpha[13] 1.2786345 1.4192218 1.7056741 5812.9484 1.0000039 ## alpha[14] 1.8592097 1.9712809 2.1915199 5701.2521 1.0000576 ## alpha[15] 1.4304302 1.5871045 1.9097590 7347.6799 0.9999325 ## alpha[16] 1.2815765 1.4602587 1.8245511 6591.1091 0.9991034 ## alpha[17] 1.3923293 1.5454335 1.8396757 6900.7044 0.9991477 ## alpha[18] 1.2653554 1.3804229 1.5963723 6576.6119 0.9995124 ## alpha[19] 1.3798986 1.4375659 1.5479345 7695.4278 0.9991038 ## alpha[20] 1.6088904 1.7746145 2.1087569 6584.6197 0.9997220 ## alpha[21] 1.6517081 1.7847972 2.0325520 6918.3368 0.9996741 ## alpha[22] 1.1247192 1.2754756 1.5497925 5860.1597 0.9995082 ## alpha[23] 1.4750699 1.6618305 2.0123459 7123.4238 0.9994798 ## alpha[24] 1.8777284 2.0103108 2.2723030 5323.3934 0.9995632 ## alpha[25] 1.8369818 1.9457812 2.1666411 4994.7214 0.9998918 ## alpha[26] 1.3937170 1.4422362 1.5311756 7007.7968 0.9991012 ## alpha[27] 1.6388155 1.7954945 2.0844332 5586.2025 0.9993411 ## alpha[28] 1.3812237 1.5367809 1.8073521 6572.0951 1.0000726 ## alpha[29] 1.3527213 1.5119101 1.8307615 7587.8490 0.9995323 ## alpha[30] 1.1436843 1.2634944 1.4981343 6256.7063 1.0001648 ## alpha[31] 1.7600618 1.9132680 2.2218658 6151.0613 0.9995917 ## alpha[32] 1.3974235 1.5653441 1.8519678 7369.3131 0.9994361 ## alpha[33] 1.7435082 1.8976810 2.2319158 5490.6149 0.9998154 ## alpha[34] 1.5292303 1.6979349 2.0688322 5944.2697 0.9994575 ## alpha[35] 1.1332153 1.2828968 1.5329935 5638.5035 1.0002100 ## alpha[36] 1.8964360 2.0834845 2.4808808 4289.6585 1.0002155 ## alpha[37] 0.8641311 1.0049534 1.2604920 4723.2678 0.9998492 ## alpha[38] 1.6587978 1.8259539 2.1147352 6322.7086 0.9992978 ## alpha[39] 1.6258314 1.7787346 2.0701179 6919.8725 0.9995221 ## alpha[40] 1.8422603 2.0138317 2.3369804 5111.8560 0.9998795 ## alpha[41] 1.7824726 1.9161410 2.1717328 5454.7028 0.9999438 ## alpha[42] 1.4781008 1.6711749 2.0545345 6995.6578 0.9999712 ## alpha[43] 1.5760485 1.7069013 1.9483788 6416.8322 0.9994406 ## alpha[44] 1.2774254 1.4098381 1.6706790 5140.9251 0.9999165 ## alpha[45] 1.3666067 1.4822228 1.6912166 7152.8583 1.0000599 ## alpha[46] 1.3707863 1.5293081 1.8347486 6559.5061 0.9994298 ## alpha[47] 1.3411143 1.5283189 1.8754373 6465.7325 0.9992925 ## alpha[48] 1.2946463 1.4264631 1.6639195 7512.2914 0.9995128 ## alpha[49] 1.6526638 1.7650774 1.9788220 6905.9813 0.9996570 ## alpha[50] 1.6519106 1.8535046 2.2590925 5530.2178 0.9995980 ## alpha[51] 1.7860080 1.9542965 2.3002270 5261.2528 1.0006851 ## alpha[52] 1.6602781 1.8342629 2.1559763 5334.2342 1.0001562 ## alpha[53] 1.4190286 1.5872525 1.9117951 6872.7278 0.9994035 ## alpha[54] 1.3657728 1.4607707 1.6350977 6745.5036 1.0002918 ## alpha[55] 1.5764196 1.7123460 1.9723892 6701.0332 0.9997858 ## alpha[56] 1.3825726 1.5401232 1.8894196 5703.0941 0.9993746 ## alpha[57] 1.1253622 1.2700161 1.5609764 5431.8281 0.9991605 ## alpha[58] 1.6502837 1.8104771 2.1622035 5723.8614 1.0012880 ## alpha[59] 1.5889465 1.7519823 2.0573067 6178.6979 0.9994608 ## alpha[60] 1.4408127 1.6230764 1.9930203 8087.6688 0.9997020 ## alpha[61] 1.2345522 1.3176607 1.4704036 8245.7021 0.9991599 ## alpha[62] 1.7368800 1.8870550 2.1897934 6042.7376 0.9999751 ## alpha[63] 1.5659990 1.7385489 2.0689474 6523.9591 1.0003280 ## alpha[64] 1.7427766 1.8609954 2.0883033 8483.7843 1.0000881 ## alpha[65] 1.4492716 1.6289924 1.9784422 5653.9324 0.9995803 ## alpha[66] 1.6217200 1.7339206 1.9452554 6310.3787 1.0002613 ## alpha[67] 1.7177880 1.8302424 2.0654307 6198.5321 0.9998875 ## alpha[68] 1.2730311 1.4031207 1.6496155 5790.4543 0.9994630 ## alpha[69] 1.3986444 1.5537886 1.8534438 7152.1701 0.9996164 ## alpha[70] 0.9461263 0.9896974 1.0726619 4872.1881 1.0001475 ## alpha[71] 1.5125007 1.6012605 1.7622722 6877.2307 1.0002868 ## alpha[72] 1.5607890 1.6925710 1.9354295 6863.2418 0.9992212 ## alpha[73] 1.5805637 1.7588989 2.1099543 5964.7281 0.9998568 ## alpha[74] 1.2893997 1.4500669 1.7551057 6618.1583 0.9993402 ## alpha[75] 1.5805516 1.7532071 2.0713911 7067.0483 1.0000471 ## alpha[76] 1.7124312 1.8810068 2.2026189 6058.5387 0.9995450 ## alpha[77] 1.6888231 1.8393355 2.0949555 7166.6191 0.9992999 ## alpha[78] 1.4063669 1.5491743 1.8494659 6609.2060 0.9993618 ## alpha[79] 1.1467608 1.3075405 1.6079330 5262.6445 1.0000585 ## alpha[80] 1.3764424 1.4423446 1.5690641 6821.3100 0.9994182 ## alpha[81] 1.9157492 2.0999410 2.4736201 4550.1447 1.0003923 ## alpha[82] 1.6111457 1.8120464 2.2193480 8178.3750 0.9993475 ## alpha[83] 1.6041648 1.7175488 1.9383902 6747.7045 0.9994418 ## alpha[84] 1.6143557 1.7283508 1.9503691 6864.7468 0.9997444 ## alpha[85] 1.4200387 1.5992577 1.9339475 6278.2450 0.9994482 ## beta -0.6642821 -0.6188949 -0.5336899 4028.3937 1.0008453 ## gamma 1.4935239 1.5253940 1.5905826 3410.3875 1.0001835 ## sigma_y 0.7261399 0.7393328 0.7622820 5871.9175 0.9993105 ## sigma_a 0.3163937 0.3464567 0.4122320 1231.3808 1.0018482 ## lp__ -112.0614001 -106.4044557 -96.4620097 826.6133 1.0016620 ### 68.3.2 截距中增加预测因子 相当于在第二层参数中增加预测因子 \begin{aligned} y_i &\sim N(\mu_i, ~\sigma) \\ \mu_i &= \alpha_{j[i]} + \beta~\mathtt{floor}_i \\ \alpha_j &\sim \operatorname{normal}(\gamma_0 + \gamma_1~u_j, ~\tau) \\ \beta &\sim \operatorname{normal}(0, 1)\\ \gamma_0 &\sim \operatorname{normal}(0, 2.5)\\ \gamma_1 &\sim \operatorname{normal}(0, 2.5)\\ \tau &\sim \operatorname{exp}(1) \\ \end{aligned} stan_program <- " data { int<lower=0> N; vector[N] y; int<lower=0, upper=1> x[N]; int<lower=2> J; int<lower=1, upper=J> county[N]; vector[J] u; } parameters { vector[J] alpha; real beta; real gamma0; real gamma1; real<lower=0> sigma_a; real<lower=0> sigma_y; } model { vector[N] mu; for(i in 1:N) { mu[i] = alpha[county[i]] + x[i] * beta; } for(j in 1:J) { alpha[j] ~ normal(gamma0 + gamma1 * u[j], sigma_a); } y ~ normal(mu, sigma_y); beta ~ normal(0, 1); gamma0 ~ normal(0, 2.5); gamma1 ~ normal(0, 2.5); sigma_a ~ exponential(1); sigma_y ~ exponential(1); } " stan_data <- list( N = nrow(radon), J = length(unique(radoncounty)),
county = as.numeric(radon$county), x = radon$floor,
y      = radon$log_radon, u = unique(radon$log_uranium)
)

fit_intercept_partial_2 <- stan(model_code = stan_program, data = stan_data)
summary(fit_intercept_partial_2, c("beta", "gamma0", "gamma1", "sigma_y", "sigma_a"))summary ## mean se_mean sd 2.5% 25% 50% ## beta -0.6465663 0.0010213090 0.06806418 -0.7814113 -0.6939567 -0.6456922 ## gamma0 1.4926610 0.0008813975 0.04478036 1.4052806 1.4624673 1.4932624 ## gamma1 0.5892888 0.0018442793 0.10780197 0.3783845 0.5152805 0.5889562 ## sigma_y 0.7247127 0.0001833809 0.01768431 0.6904711 0.7131013 0.7242356 ## sigma_a 0.2438118 0.0012433887 0.03934467 0.1721244 0.2160493 0.2422651 ## 75% 97.5% n_eff Rhat ## beta -0.5996350 -0.5149011 4441.432 0.9999587 ## gamma0 1.5215209 1.5813333 2581.258 0.9995895 ## gamma1 0.6621449 0.7973865 3416.646 1.0024602 ## sigma_y 0.7362497 0.7595757 9299.681 0.9993431 ## sigma_a 0.2690141 0.3250065 1001.286 1.0024075 beta怎么解释? - 负号，说明楼上比楼下氡含量低 ### 68.3.3 变化的截距和斜率 之前模型假定，不管哪个县，所有的房屋一楼和二楼的氡含量的差别是一样的（beta系数是不变的），现在，我们将模型进一步扩展，假定一楼和二楼的氡含量的差别不是固定不变的，而是随县变化的，也就说不同县的房屋，一二楼氡含量差别是不同的。 写出变化的截距和斜率模型的数学表达式 \begin{aligned}[t] y_i &\sim \operatorname{Normal}(\mu_i, \sigma_y) \\ \mu_i &= \alpha_{j[i]} + \beta_{j[i]}~\mathtt{floor}_i \\ \begin{bmatrix} \alpha_j \\ \beta_j \end{bmatrix} & \sim \operatorname{MVNormal} \left( \begin{bmatrix} \gamma_0^{\alpha} + \gamma_1^{\alpha} ~ u_j \\ \gamma_0^{\beta} + \gamma_1^{\beta} ~ u_j \\ \end{bmatrix}, ~\mathbf S \right) \\ \mathbf S & = \begin{bmatrix} \sigma_\alpha & 0 \\ 0 & \sigma_\beta \end{bmatrix} \mathbf R \begin{bmatrix} \sigma_\alpha & 0 \\ 0 & \sigma_\beta \end{bmatrix} \\ & = \begin{bmatrix} \sigma_\alpha & 0 \\ 0 & \sigma_\beta \end{bmatrix} \begin{bmatrix} 1 & \rho \\ \rho & 1 \end{bmatrix} \begin{bmatrix} \sigma_\alpha & 0 \\ 0 & \sigma_\beta \end{bmatrix} \\ \gamma_a & \sim \operatorname{Normal}(0, 4) \\ \gamma_b & \sim \operatorname{Normal}(0, 4) \\ \sigma & \sim \operatorname{Exponential}(1) \\ \sigma_\alpha & \sim \operatorname{Exponential}(1) \\ \sigma_\beta & \sim \operatorname{Exponential}(1) \\ \mathbf R & \sim \operatorname{LKJcorr}(2) \end{aligned} • 模型表达式中 $$\alpha_j$$$$\beta_j$$ 不是直接给先验，而是给的层级先验。 • $$\alpha_j$$$$\beta_j$$ 也可能存在关联，常见的有，多元正态分布（Multivariate Gaussian Distribution） \begin{aligned}[t] \begin{bmatrix} \alpha_j \\ \beta_j \end{bmatrix} &\sim \operatorname{MVNormal}\left(\begin{bmatrix}\gamma_{\alpha} \\ \gamma_{\beta} \end{bmatrix}, \mathbf S\right) \\ \end{aligned} ### 68.3.4 协方差矩阵(covariance matrix) MASS::mvrnorm(n, mu, Sigma)产生多元高斯分布的随机数，每组随机变量高度相关。 比如，人的身高服从正态分布，人的体重也服从正态分布，同时身高和体重又存在强烈的关联。 • n: 随机样本的大小 • mu: 多元高斯分布的均值向量 • Sigma: 协方差矩阵，主要这里是大写的S (Sigma)，提醒我们它是一个矩阵，不是一个数值 a <- 3.5 b <- -1 sigma_a <- 1 sigma_b <- 0.5 rho <- -0.7 mu <- c(a, b) cov_ab <- sigma_a * sigma_b * rho sigma <- matrix(c(sigma_a^2, cov_ab, cov_ab, sigma_b^2), ncol = 2) sigma ## [,1] [,2] ## [1,] 1.00 -0.35 ## [2,] -0.35 0.25 d <- MASS::mvrnorm(1000, mu = mu, Sigma = sigma) %>% data.frame() %>% set_names("group_a", "group_b") head(d) ## group_a group_b ## 1 2.715244 -0.2723168 ## 2 3.021387 -0.9497089 ## 3 2.995002 -0.8270510 ## 4 2.826995 -1.0425705 ## 5 1.849620 -1.1043509 ## 6 3.606869 -0.6291369 d %>% ggplot(aes(x = group_a)) + geom_density( color = "transparent", fill = "dodgerblue3", alpha = 1 / 2 ) + stat_function( fun = dnorm, args = list(mean = 3.5, sd = 1), linetype = 2 ) d %>% ggplot(aes(x = group_b)) + geom_density( color = "transparent", fill = "dodgerblue3", alpha = 1 / 2 ) + stat_function( fun = dnorm, args = list(mean = -1, sd = 0.5), linetype = 2 ) d %>% ggplot(aes(x = group_a, y = group_b)) + geom_point() + stat_ellipse(type = "norm", level = 0.95) ### 68.3.5 回到模型 在stan中要给协方差矩阵指定一个先验，Priors for Covariances stan_program <- " data { int<lower=0> N; vector[N] y; int<lower=0, upper=1> x[N]; int<lower=2> J; int<lower=1, upper=J> county[N]; vector[J] u; } parameters { vector[J] alpha; vector[J] beta; vector[2] gamma_a; vector[2] gamma_b; real<lower=0> sigma; vector<lower=0>[2] tau; corr_matrix[2] Rho; } transformed parameters { vector[2] YY[J]; for (j in 1:J) { YY[j] = [alpha[j], beta[j]]'; } } model { vector[N] mu; vector[2] MU[J]; sigma ~ exponential(1); tau ~ exponential(1); Rho ~ lkj_corr(2); gamma_a ~ normal(0, 2); gamma_b ~ normal(0, 2); for(i in 1:N) { mu[i] = alpha[county[i]] + beta[county[i]] * x[i]; } for(j in 1:J) { MU[j, 1] = gamma_a[1] + gamma_a[2] * u[j]; MU[j, 2] = gamma_b[1] + gamma_b[2] * u[j]; } target += multi_normal_lpdf(YY | MU, quad_form_diag(Rho, tau)); y ~ normal(mu, sigma); } " stan_data <- list( N = nrow(radon), J = length(unique(radoncounty)),
county = as.numeric(radon$county), x = radon$floor,
y      = radon$log_radon, u = unique(radon$log_uranium)
)

fit_slope_partial <- stan(model_code = stan_program, data = stan_data)
summary(fit_slope_partial, c("alpha"))$summary ## mean se_mean sd 2.5% 25% 50% ## alpha[1] 0.9519317 0.003353654 0.21468785 0.5331852 0.8065040 0.9537085 ## alpha[2] 0.9213506 0.001520614 0.09297252 0.7445764 0.8583941 0.9206529 ## alpha[3] 1.4327532 0.003307994 0.22069738 1.0009574 1.2847138 1.4281543 ## alpha[4] 1.2307084 0.003544460 0.20498548 0.8505676 1.0908605 1.2258605 ## alpha[5] 1.4012124 0.002736854 0.20435606 1.0024084 1.2688080 1.3972693 ## alpha[6] 1.7006649 0.003069700 0.21971719 1.2582892 1.5586131 1.7037156 ## alpha[7] 1.8682765 0.002742384 0.15871713 1.5601888 1.7593660 1.8687053 ## alpha[8] 1.7839273 0.003117164 0.20637049 1.3879590 1.6467750 1.7816495 ## alpha[9] 1.1288098 0.002610434 0.16795887 0.8002425 1.0131178 1.1279613 ## alpha[10] 1.5784437 0.002905269 0.19507045 1.1998763 1.4443787 1.5778675 ## alpha[11] 1.2004181 0.002979086 0.20199305 0.8037032 1.0640679 1.2004750 ## alpha[12] 1.7024737 0.002629637 0.20405450 1.3050602 1.5652270 1.6995846 ## alpha[13] 1.0251240 0.002792856 0.19031646 0.6502916 0.9002770 1.0220134 ## alpha[14] 1.9189194 0.002530061 0.16226987 1.6033615 1.8091695 1.9167418 ## alpha[15] 1.4144309 0.002873039 0.21273116 0.9851256 1.2790922 1.4175438 ## alpha[16] 1.0645622 0.003452293 0.22491820 0.6074773 0.9165784 1.0695671 ## alpha[17] 1.6500046 0.003687618 0.22155579 1.2270210 1.4998423 1.6502365 ## alpha[18] 1.0525670 0.002652472 0.16403507 0.7284906 0.9446956 1.0543608 ## alpha[19] 1.3883093 0.001178226 0.08812721 1.2140297 1.3289647 1.3891252 ## alpha[20] 1.7128467 0.002897388 0.21225267 1.3113888 1.5667382 1.7088012 ## alpha[21] 1.6679869 0.002397118 0.17307648 1.3370031 1.5491531 1.6641465 ## alpha[22] 1.3355807 0.003620887 0.20240956 0.9227366 1.1981750 1.3406356 ## alpha[23] 1.7222808 0.003323876 0.23273001 1.2505402 1.5689641 1.7238414 ## alpha[24] 1.8808092 0.003070899 0.18119698 1.5388245 1.7551287 1.8747088 ## alpha[25] 1.8091645 0.002458036 0.15724280 1.5000183 1.7033750 1.8112576 ## alpha[26] 1.3961411 0.001031404 0.07040717 1.2613581 1.3485908 1.3952360 ## alpha[27] 1.8327158 0.003011070 0.19462635 1.4566815 1.7053590 1.8325327 ## alpha[28] 1.1850781 0.003468087 0.21114908 0.7779572 1.0469643 1.1836832 ## alpha[29] 1.0077382 0.003212421 0.22125759 0.5874808 0.8543263 1.0051908 ## alpha[30] 0.9952942 0.002399774 0.16835525 0.6678215 0.8873337 0.9959623 ## alpha[31] 1.8205261 0.002781380 0.20301114 1.4312303 1.6789819 1.8195778 ## alpha[32] 1.3967406 0.002575971 0.20249457 0.9969899 1.2593385 1.3977493 ## alpha[33] 1.7235691 0.003052286 0.20784215 1.3270668 1.5836191 1.7175826 ## alpha[34] 1.5132556 0.003088099 0.22089601 1.0886321 1.3639818 1.5097109 ## alpha[35] 0.7610688 0.003932438 0.20830745 0.3344719 0.6268445 0.7653319 ## alpha[36] 1.9272049 0.004115546 0.24632230 1.4731471 1.7584748 1.9148040 ## alpha[37] 0.7339738 0.002942820 0.17681842 0.3788598 0.6172423 0.7415420 ## alpha[38] 1.2148739 0.003601584 0.21835942 0.7955514 1.0695808 1.2060466 ## alpha[39] 1.6692999 0.003096599 0.19752040 1.2867499 1.5378543 1.6671692 ## alpha[40] 1.9687914 0.003428570 0.21495861 1.5664819 1.8215939 1.9646679 ## alpha[41] 1.8564128 0.002541474 0.17409119 1.5230290 1.7383874 1.8558836 ## alpha[42] 1.5626027 0.003064477 0.23234993 1.0999282 1.4148451 1.5643962 ## alpha[43] 1.7218205 0.005637101 0.19738626 1.3623538 1.5860971 1.7138082 ## alpha[44] 1.3402833 0.002684746 0.18593309 0.9727795 1.2170085 1.3440359 ## alpha[45] 1.4665663 0.002667160 0.16459785 1.1346443 1.3578059 1.4701169 ## alpha[46] 1.4120261 0.002584964 0.19135524 1.0338819 1.2883924 1.4126593 ## alpha[47] 1.2880182 0.003443675 0.22215974 0.8603349 1.1410978 1.2876299 ## alpha[48] 1.2921851 0.002494741 0.17408660 0.9443450 1.1756492 1.2934839 ## alpha[49] 1.7241471 0.002540136 0.15529069 1.4228538 1.6195810 1.7256671 ## alpha[50] 1.8372352 0.003503701 0.23995656 1.3705600 1.6760922 1.8367269 ## alpha[51] 1.8196693 0.003053724 0.20682477 1.4158252 1.6791080 1.8211672 ## alpha[52] 1.8066083 0.002935125 0.21162286 1.3927384 1.6670596 1.8043193 ## alpha[53] 1.5838625 0.003112178 0.21673020 1.1495365 1.4398343 1.5864813 ## alpha[54] 1.4548553 0.001812282 0.13323220 1.1920199 1.3660671 1.4545263 ## alpha[55] 1.4454911 0.002540107 0.18112401 1.0892453 1.3268496 1.4419640 ## alpha[56] 1.3896750 0.003539458 0.22305591 0.9640651 1.2420396 1.3896368 ## alpha[57] 1.1440631 0.002955152 0.19234800 0.7568794 1.0178469 1.1499908 ## alpha[58] 1.8436091 0.003135100 0.20717642 1.4370710 1.7049651 1.8426400 ## alpha[59] 1.7141568 0.003097634 0.20868751 1.3159720 1.5775359 1.7139989 ## alpha[60] 1.6148653 0.003085026 0.22414441 1.1787419 1.4616501 1.6156019 ## alpha[61] 1.1671926 0.001641145 0.11759923 0.9359935 1.0874309 1.1668885 ## alpha[62] 1.8149507 0.003161927 0.20197701 1.4022872 1.6832495 1.8184751 ## alpha[63] 1.7245416 0.003250193 0.21580664 1.2802520 1.5873794 1.7290552 ## alpha[64] 1.7613902 0.002060697 0.16079979 1.4564064 1.6516886 1.7609193 ## alpha[65] 1.7564018 0.003207661 0.22860426 1.2983539 1.6044767 1.7609477 ## alpha[66] 1.4796253 0.002579439 0.16782088 1.1479370 1.3684441 1.4768058 ## alpha[67] 1.4581322 0.003242883 0.17002073 1.1272241 1.3427318 1.4572282 ## alpha[68] 1.3400376 0.002421674 0.17783606 0.9895438 1.2179056 1.3431086 ## alpha[69] 1.1052663 0.002971051 0.21661274 0.6966168 0.9597750 1.0988825 ## alpha[70] 0.9757155 0.001295334 0.07382497 0.8323926 0.9279980 0.9758341 ## alpha[71] 1.5438858 0.001776335 0.12623121 1.2972565 1.4611862 1.5432967 ## alpha[72] 1.6409851 0.002083285 0.16596574 1.3114261 1.5311118 1.6395149 ## alpha[73] 1.8131499 0.003428889 0.22175330 1.3758959 1.6631683 1.8116511 ## alpha[74] 1.4937826 0.003430274 0.20909286 1.0709270 1.3552306 1.4975707 ## alpha[75] 1.5079348 0.003050620 0.20656003 1.1005149 1.3706130 1.5079433 ## alpha[76] 1.9041916 0.003575203 0.20310389 1.5150809 1.7700360 1.9037997 ## alpha[77] 1.7143489 0.002710865 0.18135671 1.3635311 1.5901476 1.7103102 ## alpha[78] 1.0962731 0.003262629 0.20613290 0.6967964 0.9581975 1.0895785 ## alpha[79] 1.3554009 0.003470343 0.20696385 0.9375743 1.2182870 1.3630556 ## alpha[80] 1.3720130 0.001415465 0.09791249 1.1794778 1.3063741 1.3724494 ## alpha[81] 1.8586083 0.004328592 0.23689050 1.4039156 1.7031916 1.8514036 ## alpha[82] 1.7071957 0.003915923 0.22770527 1.2747605 1.5537967 1.7019673 ## alpha[83] 1.7865354 0.002999872 0.16399051 1.4751124 1.6762375 1.7840108 ## alpha[84] 1.5660924 0.002129781 0.15587944 1.2766856 1.4580465 1.5620844 ## alpha[85] 1.6351601 0.002929707 0.22301609 1.1830134 1.4888412 1.6417432 ## 75% 97.5% n_eff Rhat ## alpha[1] 1.1003015 1.360342 4098.060 0.9997172 ## alpha[2] 0.9842125 1.106770 3738.276 0.9999053 ## alpha[3] 1.5774113 1.870244 4451.076 1.0004986 ## alpha[4] 1.3646823 1.664353 3344.613 1.0008200 ## alpha[5] 1.5341600 1.807129 5575.346 1.0001793 ## alpha[6] 1.8486566 2.129637 5123.140 0.9997305 ## alpha[7] 1.9733099 2.176808 3349.586 1.0002705 ## alpha[8] 1.9222286 2.194028 4383.044 0.9995557 ## alpha[9] 1.2470978 1.460232 4139.810 1.0004175 ## alpha[10] 1.7076384 1.982730 4508.274 1.0004635 ## alpha[11] 1.3345524 1.608036 4597.340 1.0001867 ## alpha[12] 1.8396405 2.089860 6021.444 1.0000293 ## alpha[13] 1.1501953 1.410773 4643.608 1.0004185 ## alpha[14] 2.0256995 2.235397 4113.521 1.0002933 ## alpha[15] 1.5569713 1.823673 5482.508 0.9993977 ## alpha[16] 1.2148245 1.495768 4244.571 0.9999769 ## alpha[17] 1.8011947 2.086203 3609.727 1.0027579 ## alpha[18] 1.1652075 1.355866 3824.474 1.0001771 ## alpha[19] 1.4470976 1.556684 5594.522 0.9998284 ## alpha[20] 1.8573444 2.136092 5366.521 0.9995045 ## alpha[21] 1.7797779 2.018619 5213.116 1.0009420 ## alpha[22] 1.4736449 1.717472 3124.871 1.0005473 ## alpha[23] 1.8762236 2.165036 4902.473 0.9991197 ## alpha[24] 2.0004046 2.253822 3481.535 1.0008662 ## alpha[25] 1.9153384 2.113069 4092.278 1.0013684 ## alpha[26] 1.4430359 1.535565 4659.893 1.0016308 ## alpha[27] 1.9587928 2.211046 4177.933 0.9996019 ## alpha[28] 1.3224614 1.612108 3706.793 1.0001495 ## alpha[29] 1.1510521 1.453448 4743.857 0.9998455 ## alpha[30] 1.1081339 1.331021 4921.671 0.9995717 ## alpha[31] 1.9580927 2.225042 5327.446 1.0001730 ## alpha[32] 1.5360485 1.796799 6179.377 0.9993134 ## alpha[33] 1.8552389 2.149746 4636.785 1.0002771 ## alpha[34] 1.6583388 1.959657 5116.740 1.0001739 ## alpha[35] 0.9017612 1.151721 2805.988 1.0011116 ## alpha[36] 2.0850028 2.437771 3582.222 1.0000540 ## alpha[37] 0.8509241 1.075149 3610.169 1.0009169 ## alpha[38] 1.3575566 1.665925 3675.842 1.0003793 ## alpha[39] 1.7995900 2.062082 4068.684 0.9991789 ## alpha[40] 2.1065268 2.403715 3930.826 0.9999035 ## alpha[41] 1.9720484 2.209405 4692.263 0.9996486 ## alpha[42] 1.7133396 2.021255 5748.735 1.0001209 ## alpha[43] 1.8458754 2.137788 1226.090 1.0024276 ## alpha[44] 1.4623153 1.700079 4796.308 1.0015063 ## alpha[45] 1.5759521 1.788291 3808.466 1.0008279 ## alpha[46] 1.5371528 1.774580 5479.888 0.9993782 ## alpha[47] 1.4331916 1.727210 4161.851 1.0004470 ## alpha[48] 1.4104354 1.625416 4869.450 0.9996094 ## alpha[49] 1.8243277 2.034269 3737.462 0.9999708 ## alpha[50] 1.9939146 2.332710 4690.413 0.9993716 ## alpha[51] 1.9575679 2.236414 4587.178 0.9992191 ## alpha[52] 1.9483241 2.235419 5198.428 0.9999447 ## alpha[53] 1.7300816 2.011675 4849.647 0.9995000 ## alpha[54] 1.5445952 1.720587 5404.640 0.9997539 ## alpha[55] 1.5685743 1.804953 5084.498 1.0008839 ## alpha[56] 1.5361079 1.833575 3971.495 0.9999883 ## alpha[57] 1.2717847 1.516737 4236.584 1.0000696 ## alpha[58] 1.9828200 2.262707 4366.947 0.9999132 ## alpha[59] 1.8491338 2.139414 4538.712 1.0007966 ## alpha[60] 1.7680276 2.053259 5278.837 0.9998648 ## alpha[61] 1.2482358 1.392249 5134.701 0.9995918 ## alpha[62] 1.9478640 2.201454 4080.376 1.0012090 ## alpha[63] 1.8673545 2.140254 4408.707 0.9991195 ## alpha[64] 1.8677874 2.075037 6088.952 0.9995091 ## alpha[65] 1.9062534 2.202483 5079.158 0.9998632 ## alpha[66] 1.5928385 1.818104 4232.934 0.9999891 ## alpha[67] 1.5698649 1.796656 2748.788 1.0013054 ## alpha[68] 1.4598779 1.699556 5392.724 0.9997470 ## alpha[69] 1.2501871 1.543298 5315.544 0.9999522 ## alpha[70] 1.0259323 1.120187 3248.201 1.0005520 ## alpha[71] 1.6280134 1.794891 5049.912 0.9993192 ## alpha[72] 1.7494469 1.966321 6346.575 0.9993569 ## alpha[73] 1.9656252 2.245212 4182.475 0.9994124 ## alpha[74] 1.6356340 1.886567 3715.530 0.9998144 ## alpha[75] 1.6430099 1.921257 4584.756 0.9998729 ## alpha[76] 2.0315432 2.317663 3227.269 0.9997366 ## alpha[77] 1.8349298 2.077528 4475.601 0.9994004 ## alpha[78] 1.2299953 1.505411 3991.713 0.9996280 ## alpha[79] 1.4977606 1.740977 3556.674 0.9997123 ## alpha[80] 1.4367455 1.560968 4784.957 0.9994886 ## alpha[81] 2.0130290 2.341839 2995.036 1.0009345 ## alpha[82] 1.8554026 2.161381 3381.255 1.0001061 ## alpha[83] 1.8940519 2.120908 2988.354 1.0031464 ## alpha[84] 1.6732702 1.875764 5356.830 0.9999885 ## alpha[85] 1.7842689 2.059926 5794.608 0.9997485 summary(fit_slope_partial, c("beta"))$summary
##                mean     se_mean        sd       2.5%        25%        50%
## beta[1]  -0.3030413 0.006720692 0.3126060 -0.9140722 -0.4940543 -0.3120472
## beta[2]  -0.4980363 0.013611312 0.2875532 -1.1154770 -0.6758638 -0.4788113
## beta[3]  -0.5883236 0.004386772 0.2570363 -1.1051184 -0.7430379 -0.5832167
## beta[4]  -0.4021724 0.005355640 0.2620278 -0.9336048 -0.5662986 -0.3977372
## beta[5]  -0.5384383 0.004604968 0.2819605 -1.1030659 -0.7014163 -0.5466950
## beta[6]  -0.8159568 0.006641223 0.3104158 -1.4482857 -1.0009603 -0.8184723
## beta[7]  -0.5221451 0.016142625 0.2988984 -1.0335387 -0.7274081 -0.5583546
## beta[8]  -0.7383255 0.004946105 0.2601781 -1.2586115 -0.9005770 -0.7428251
## beta[9]  -0.3465328 0.010091581 0.2899161 -0.8649025 -0.5381192 -0.3764453
## beta[10] -0.7616415 0.005179511 0.2506588 -1.2855322 -0.9095501 -0.7535025
## beta[11] -0.3825179 0.007206771 0.3333535 -1.0368771 -0.5805990 -0.3826561
## beta[12] -0.7709969 0.005734165 0.3072965 -1.4009586 -0.9445013 -0.7687419
## beta[13] -0.3238779 0.007647073 0.3419432 -1.0156753 -0.5246843 -0.3302553
## beta[14] -0.8396599 0.005003122 0.2413719 -1.3390137 -0.9858599 -0.8323510
## beta[15] -0.6153940 0.003896563 0.2581678 -1.1452472 -0.7656193 -0.6170301
## beta[16] -0.4134817 0.006224523 0.3172008 -1.0712782 -0.5944658 -0.4131444
## beta[17] -0.9476459 0.010790606 0.2703088 -1.5379111 -1.1068621 -0.9220920
## beta[18] -0.2735102 0.006228926 0.2622621 -0.7684646 -0.4425521 -0.2792567
## beta[19] -0.7250979 0.004798187 0.2183951 -1.1830943 -0.8609326 -0.7115620
## beta[20] -0.7677315 0.005523243 0.3135258 -1.3925103 -0.9493436 -0.7683732
## beta[21] -0.6705168 0.005356064 0.2803788 -1.1910896 -0.8429943 -0.6863102
## beta[22] -0.7887503 0.005963844 0.3000488 -1.4071099 -0.9654353 -0.7939567
## beta[23] -0.8218970 0.006076073 0.2899649 -1.3943003 -0.9987064 -0.8200531
## beta[24] -0.7261831 0.005195648 0.2632440 -1.2415006 -0.8938480 -0.7339934
## beta[25] -0.5077868 0.014834273 0.2909818 -0.9979299 -0.7123235 -0.5430667
## beta[26] -0.7107391 0.004193608 0.1825726 -1.0980543 -0.8231486 -0.7033650
## beta[27] -0.8146455 0.006288994 0.2838293 -1.3640494 -0.9988645 -0.8227987
## beta[28] -0.4527634 0.004803400 0.2541751 -0.9637185 -0.6048339 -0.4548247
## beta[29] -0.3161594 0.007449517 0.3459894 -1.0248022 -0.5268567 -0.3148994
## beta[30] -0.3460725 0.007119331 0.3274406 -1.0044489 -0.5531515 -0.3504414
## beta[31] -0.7940265 0.005755141 0.3145944 -1.4416483 -0.9734705 -0.7906300
## beta[32] -0.6169924 0.004928547 0.3027245 -1.2148826 -0.7964968 -0.6187311
## beta[33] -0.7074118 0.005834255 0.3170576 -1.3670052 -0.8801510 -0.7017518
## beta[34] -0.6677593 0.003994489 0.2571996 -1.2000831 -0.8205331 -0.6639891
## beta[35] -0.2237865 0.006621125 0.2749385 -0.7457459 -0.4041935 -0.2296301
## beta[36] -0.6269031 0.010623309 0.3159487 -1.1982220 -0.8334872 -0.6558471
## beta[37] -0.3236230 0.006688778 0.3120225 -0.9284546 -0.5225015 -0.3288592
## beta[38] -0.2554516 0.006687635 0.2834597 -0.8066718 -0.4372508 -0.2666320
## beta[39] -0.6684845 0.005954442 0.2894112 -1.2060467 -0.8512198 -0.6806734
## beta[40] -0.8353723 0.006262632 0.2931388 -1.4295812 -1.0169266 -0.8345612
## beta[41] -0.7123072 0.009499444 0.2927183 -1.2511662 -0.9045290 -0.7329133
## beta[42] -0.7082503 0.005149082 0.3084356 -1.3360289 -0.8805794 -0.7119100
## beta[43] -1.0457201 0.019253643 0.2830325 -1.6795114 -1.2158100 -1.0142153
## beta[44] -0.7993056 0.009716235 0.2911761 -1.4366340 -0.9674106 -0.7695560
## beta[45] -0.8350362 0.008276736 0.2382125 -1.3318285 -0.9835211 -0.8190592
## beta[46] -0.6478682 0.005726239 0.3058810 -1.2729869 -0.8257849 -0.6457934
## beta[47] -0.7226032 0.010815687 0.3015054 -1.4028746 -0.8933732 -0.6905117
## beta[48] -0.5405341 0.005304329 0.2697159 -1.0411369 -0.7014851 -0.5533612
## beta[49] -0.9255142 0.010683095 0.2756646 -1.5527112 -1.0872977 -0.9002967
## beta[50] -0.8397182 0.006834991 0.3205389 -1.5114593 -1.0246911 -0.8374269
## beta[51] -0.7676813 0.006103267 0.3120952 -1.3926615 -0.9483248 -0.7697585
## beta[52] -0.8276903 0.006507587 0.3240390 -1.4636376 -1.0127452 -0.8296644
## beta[53] -0.7967042 0.004906244 0.2775771 -1.3754808 -0.9585333 -0.7941758
## beta[54] -0.9094890 0.009996546 0.2545942 -1.4750582 -1.0600454 -0.8833766
## beta[55] -0.4764234 0.005330174 0.2554075 -0.9556680 -0.6394411 -0.4934966
## beta[56] -0.7441212 0.007248965 0.2711338 -1.3444772 -0.8948435 -0.7214473
## beta[57] -0.5961015 0.005121362 0.2819350 -1.1599240 -0.7625197 -0.5946360
## beta[58] -0.7908568 0.006168628 0.2959496 -1.3647272 -0.9762762 -0.8057767
## beta[59] -0.8291218 0.005433591 0.2636252 -1.3783127 -0.9861114 -0.8216350
## beta[60] -0.7680102 0.006238209 0.3172696 -1.4156311 -0.9512974 -0.7730598
## beta[61] -0.2776078 0.010094660 0.2601798 -0.7410178 -0.4537275 -0.3028755
## beta[62] -0.5346912 0.018491146 0.3402042 -1.0770543 -0.7727514 -0.5864294
## beta[63] -0.6972739 0.007888426 0.2979608 -1.2505420 -0.8890613 -0.7200443
## beta[64] -0.7539639 0.004801536 0.2739794 -1.3376980 -0.9132354 -0.7534081
## beta[65] -0.8756623 0.006653224 0.3264299 -1.5263907 -1.0786572 -0.8796967
## beta[66] -0.5001943 0.004542816 0.2092116 -0.9083963 -0.6330584 -0.5054298
## beta[67] -0.2184017 0.014313564 0.2700924 -0.7020678 -0.4078772 -0.2328044
## beta[68] -0.6628048 0.005359459 0.3055929 -1.2822973 -0.8409814 -0.6674304
## beta[69] -0.3437809 0.007418044 0.3418222 -1.0210306 -0.5482539 -0.3465923
## beta[70] -0.6431331 0.005234519 0.1742594 -0.9747187 -0.7625968 -0.6479965
## beta[71] -0.7822887 0.005616177 0.2302088 -1.2384447 -0.9258432 -0.7716008
## beta[72] -0.7619719 0.005343562 0.3103291 -1.4043833 -0.9420532 -0.7643868
## beta[73] -0.8621089 0.006679232 0.3213920 -1.5205982 -1.0466283 -0.8588473
## beta[74] -0.7663318 0.006283631 0.3270461 -1.4077400 -0.9572036 -0.7795805
## beta[75] -0.5015279 0.009723381 0.2900317 -1.0129398 -0.6809862 -0.5267676
## beta[76] -0.8673323 0.006176914 0.2806875 -1.4506170 -1.0399824 -0.8632977
## beta[77] -0.8321239 0.007475239 0.2865095 -1.4472824 -1.0019863 -0.8098555
## beta[78] -0.4128055 0.005950462 0.2870089 -1.0145391 -0.5893904 -0.4094492
## beta[79] -0.8000064 0.006271739 0.2909240 -1.4269699 -0.9685357 -0.7880590
## beta[80] -0.7321706 0.008382554 0.2294750 -1.2319209 -0.8683308 -0.7145151
## beta[81] -0.5395559 0.012883785 0.2925521 -1.0537814 -0.7280829 -0.5745713
## beta[82] -0.7612997 0.005331392 0.3101680 -1.4154587 -0.9372896 -0.7647274
## beta[83] -1.1431209 0.019381658 0.2975025 -1.7912397 -1.3268295 -1.1059823
## beta[84] -0.6276947 0.004805438 0.2762994 -1.2091163 -0.7860138 -0.6223734
## beta[85] -0.8019686 0.005568033 0.3136438 -1.4594796 -0.9897656 -0.8005862
##                  75%        97.5%     n_eff      Rhat
## beta[1]  -0.11912508  0.351010525 2163.5485 1.0013650
## beta[2]  -0.30057741  0.020061064  446.3098 1.0121605
## beta[3]  -0.44049841 -0.056782556 3433.1964 1.0008918
## beta[4]  -0.23563538  0.111292978 2393.7120 1.0016570
## beta[5]  -0.38490682  0.050641274 3749.0677 1.0002738
## beta[6]  -0.63737414 -0.172413312 2184.6993 1.0013362
## beta[7]  -0.33603076  0.151569000  342.8459 1.0114602
## beta[8]  -0.58673725 -0.184164834 2767.0371 1.0003627
## beta[9]  -0.18262043  0.299801499  825.3273 1.0059825
## beta[10] -0.60663571 -0.279568685 2342.0079 1.0019851
## beta[11] -0.18275615  0.297173151 2139.5798 1.0004640
## beta[12] -0.59968545 -0.135266685 2871.9365 0.9997418
## beta[13] -0.11946617  0.365191674 1999.4823 1.0002025
## beta[14] -0.67726377 -0.384023318 2327.5072 1.0018073
## beta[15] -0.46432270 -0.082495188 4389.7617 0.9996521
## beta[16] -0.23054840  0.243602840 2596.9079 1.0006262
## beta[17] -0.77406859 -0.451257594  627.5218 1.0053595
## beta[18] -0.10981851  0.281144450 1772.7388 1.0038056
## beta[19] -0.58449687 -0.310124910 2071.7220 1.0021092
## beta[20] -0.58230348 -0.147836169 3222.2425 1.0004023
## beta[21] -0.51076361 -0.051826722 2740.3044 1.0011318
## beta[22] -0.61266700 -0.175721500 2531.2284 0.9996334
## beta[23] -0.64808959 -0.236589536 2277.4297 1.0002088
## beta[24] -0.56496472 -0.163902252 2567.0684 1.0019776
## beta[25] -0.33320594  0.159170303  384.7682 1.0103853
## beta[26] -0.58554008 -0.374363418 1895.3767 1.0026909
## beta[27] -0.63974931 -0.220641578 2036.8173 1.0014487
## beta[28] -0.29247046  0.059357974 2800.0674 1.0013073
## beta[29] -0.10752871  0.376074618 2157.0956 1.0008307
## beta[30] -0.14767650  0.319960280 2115.3715 1.0010405
## beta[31] -0.61514988 -0.159609501 2988.0653 0.9996404
## beta[32] -0.45128138  0.018368911 3772.7428 1.0000598
## beta[33] -0.53454404 -0.054186815 2953.2870 1.0005211
## beta[34] -0.51097082 -0.149539318 4145.8927 0.9997209
## beta[35] -0.04500423  0.339145023 1724.2793 1.0021092
## beta[36] -0.44835118  0.100508416  884.5321 1.0061291
## beta[37] -0.13432195  0.324575336 2176.0975 1.0023461
## beta[38] -0.07915815  0.323632742 1796.5426 1.0023679
## beta[39] -0.50502242 -0.028683366 2362.3736 1.0013306
## beta[40] -0.65260323 -0.235814358 2190.9514 1.0024495
## beta[41] -0.54035886 -0.061512200  949.5180 1.0037489
## beta[42] -0.53019667 -0.076892808 3588.1408 0.9998515
## beta[43] -0.84115116 -0.586293013  216.0960 1.0191532
## beta[44] -0.61303106 -0.264492616  898.0806 1.0072343
## beta[45] -0.67746588 -0.384095675  828.3446 1.0048936
## beta[46] -0.47542431 -0.004782087 2853.4217 0.9997329
## beta[47] -0.52580992 -0.192019385  777.1092 1.0082638
## beta[48] -0.38910950  0.037311342 2585.5465 1.0004794
## beta[49] -0.73582274 -0.439279750  665.8368 1.0075882
## beta[50] -0.65654604 -0.178681877 2199.3059 1.0003204
## beta[51] -0.59155104 -0.132422338 2614.8658 1.0003848
## beta[52] -0.64477686 -0.125665892 2479.4453 1.0022709
## beta[53] -0.63662980 -0.213984233 3200.8763 1.0006439
## beta[54] -0.74335792 -0.444620177  648.6299 1.0066013
## beta[55] -0.32377037  0.062042204 2296.0673 1.0025998
## beta[56] -0.56696770 -0.274699262 1398.9925 1.0059094
## beta[57] -0.43000226 -0.027116399 3030.5878 1.0011166
## beta[58] -0.61209113 -0.173199482 2301.7507 1.0018637
## beta[59] -0.65987369 -0.307318874 2353.9636 1.0019660
## beta[60] -0.59231317 -0.076258232 2586.6458 1.0014369
## beta[61] -0.11610993  0.287447347  664.2995 1.0068440
## beta[62] -0.34472779  0.250036811  338.4946 1.0143482
## beta[63] -0.52679463 -0.053542807 1426.7159 1.0028267
## beta[64] -0.58936705 -0.187893514 3255.9335 1.0011178
## beta[65] -0.68282182 -0.211397920 2407.2187 0.9995663
## beta[66] -0.37645533 -0.065107681 2120.9054 1.0008409
## beta[67] -0.04859708  0.347004994  356.0648 1.0103891
## beta[68] -0.48811163 -0.021088296 3251.2076 0.9999984
## beta[69] -0.13453942  0.361258163 2123.3511 1.0008679
## beta[70] -0.52590149 -0.301162946 1108.2522 1.0038789
## beta[71] -0.63806985 -0.351301224 1680.2044 1.0036527
## beta[72] -0.58017919 -0.141279399 3372.7432 0.9999572
## beta[73] -0.67438725 -0.198143092 2315.3520 1.0007570
## beta[74] -0.58318193 -0.066150815 2708.9234 0.9995692
## beta[75] -0.34942255  0.141285715  889.7260 1.0053339
## beta[76] -0.68292910 -0.318243818 2064.9189 1.0002657
## beta[77] -0.64833029 -0.322031875 1469.0205 1.0034849
## beta[78] -0.22931408  0.155018694 2326.4269 1.0015869
## beta[79] -0.62224852 -0.234310472 2151.7074 1.0025285
## beta[80] -0.57606428 -0.320129129  749.4076 1.0081500
## beta[81] -0.37831808  0.121988216  515.6079 1.0099209
## beta[82] -0.57827585 -0.128848354 3384.6424 0.9996730
## beta[83] -0.93217154 -0.642387360  235.6130 1.0156904
## beta[84] -0.46318686 -0.072329950 3305.9310 0.9996514
## beta[85] -0.61145908 -0.163757628 3172.9996 1.0002582
summary(fit_slope_partial, c("sigma"))$summary ## mean se_mean sd 2.5% 25% 50% 75% ## sigma 0.7169821 0.000294179 0.01753899 0.6834949 0.7047496 0.7169355 0.7282565 ## 97.5% n_eff Rhat ## sigma 0.7519314 3554.561 1.001291 summary(fit_slope_partial, c("gamma_a", "gamma_b"))$summary
##                  mean     se_mean         sd       2.5%        25%        50%
## gamma_a[1]  1.4919256 0.001165342 0.04291215  1.4090995  1.4622673  1.4913780
## gamma_a[2]  0.6850737 0.002850866 0.11604210  0.4546167  0.6078951  0.6841795
## gamma_b[1] -0.6453958 0.002988174 0.08067028 -0.8086556 -0.6971753 -0.6447844
## gamma_b[2] -0.4466330 0.007599022 0.22231790 -0.8852762 -0.5939574 -0.4434967
##                   75%        97.5%     n_eff     Rhat
## gamma_a[1]  1.5207872  1.577032940 1355.9807 1.002477
## gamma_a[2]  0.7672601  0.912117610 1656.8291 1.001838
## gamma_b[1] -0.5919461 -0.488345518  728.8116 1.005086
## gamma_b[2] -0.3008174 -0.002157828  855.9206 1.002744
rstan::traceplot(fit_slope_partial, pars = c("sigma"))