Estimate how well a fit predicts each observation when that observation is left out, by Pareto-smoothed importance-sampling leave-one-out cross-validation (PSIS-LOO; Vehtari et al. 2017).
Usage
# S3 method for class 'kb_fit'
loo(x, ...)Arguments
- x
A
kb_fitobject.- ...
Passed to
loo::loo(), for examplecores.
Value
A psis_loo object from loo::loo().
Details
The pointwise results ($pointwise and loo::pareto_k_values()) have one
row per observation, in the order of the fitted data. elpd_loo and the
Pareto k diagnostic are described in kb_influence(), which adds them to the
data. A Pareto k above the threshold in the printed result also marks the
PSIS-LOO estimate as unreliable.
Use loo::loo_compare() to compare fits to the same data.
References
Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing, 27, 1413-1432.
See also
log_lik() for the pointwise log-likelihood.
Other diagnostics:
kb_converged(),
kb_influence(),
kb_plot_trace(),
kb_sensitivity(),
pp_check.kb_fit()
Examples
loo_weight <- loo(fit_weight_sim_nereo)
loo_weight
#>
#> Computed from 1500 by 660 log-likelihood matrix.
#>
#> Estimate SE
#> elpd_loo -242.5 32.5
#> p_loo 30.3 1.8
#> looic 485.0 65.1
#> ------
#> MCSE of elpd_loo is 0.2.
#> MCSE and ESS estimates assume MCMC draws (r_eff in [0.7, 1.2]).
#>
#> All Pareto k estimates are good (k < 0.69).
#> See help('pareto-k-diagnostic') for details.
loo::pareto_k_values(loo_weight)
#> [1] 0.1310108127 -0.1061674771 0.1228431911 0.0329470805 0.1428002225
#> [6] 0.2169303234 0.2115496550 0.1306153147 0.0282848695 0.1836998576
#> [11] 0.0209237553 -0.0010689207 0.1513777705 -0.0303252747 0.0629120711
#> [16] 0.0422939158 0.2983739417 0.0341302859 -0.0035071803 -0.0725528921
#> [21] 0.0530693466 0.1175709641 0.0869619012 -0.1100670551 0.1292870003
#> [26] 0.1847556918 0.1289166520 0.0348315225 0.1631239902 0.1261515125
#> [31] 0.0867302611 0.0946857297 0.0413633715 0.0450071033 0.1144217326
#> [36] 0.0943200271 0.1830994501 0.0663458136 0.2368732665 0.0689457487
#> [41] -0.0146353646 -0.0085919899 0.0191372979 0.0058767912 0.0271366398
#> [46] -0.0063078403 0.0886465945 0.0109010983 0.0533423910 0.0573556700
#> [51] 0.0136893860 -0.0134612510 0.0677347042 0.0191569311 0.0948478563
#> [56] 0.0423056928 0.0509127572 0.2304786554 0.0171896985 0.0170128808
#> [61] 0.1943239938 0.2635635101 0.0573514247 0.1553812334 0.2058479626
#> [66] 0.1231578133 0.0850722866 0.1025678388 0.0918621473 0.2978984393
#> [71] 0.1836501855 0.1015777592 0.1088976192 0.1790759831 0.0390703215
#> [76] 0.0673309688 0.4215303277 0.2038378389 0.0773338732 0.0104169300
#> [81] 0.3491159785 0.0493180634 0.1046944630 0.0963193334 -0.0041212982
#> [86] 0.1048559902 0.2333642898 0.1831117499 0.0628762835 0.1053266480
#> [91] 0.2138179851 0.1731919213 0.1571773909 0.0689375602 0.1437225344
#> [96] -0.0190963019 0.0587251115 -0.0097090207 0.0839088375 0.2107158175
#> [101] 0.2132450608 -0.0246647766 0.0600660035 0.0857155266 -0.0703707994
#> [106] -0.0581893217 0.2328862946 0.1020978620 0.1566733576 -0.0329566387
#> [111] -0.1139934504 -0.0905095044 0.2340466361 0.2649989018 0.0064647286
#> [116] 0.1137319617 -0.0345007056 0.1598583289 -0.0652039983 0.1259623776
#> [121] 0.1000670012 0.0541791305 0.0790267942 0.0838125568 0.1400200923
#> [126] 0.1288991401 0.1137802854 0.1022167373 0.0496016189 0.1175626775
#> [131] 0.0983441993 0.1053682470 0.0361303042 0.1454931557 0.2088430685
#> [136] 0.2364995537 0.0405553400 0.0859262758 0.2256623633 0.0933887948
#> [141] 0.3097145599 0.0700323619 0.0753454946 0.3082152340 0.0918971495
#> [146] 0.0702592281 0.1910277397 0.1134471605 0.1181123403 0.0757189388
#> [151] 0.2177102835 0.1705599574 0.1397144091 0.2374821846 0.2186902791
#> [156] 0.3098392107 0.1517518042 0.1882869393 0.1670844658 0.0899476679
#> [161] 0.1593006714 0.0048166868 -0.1443141579 -0.2285337228 0.0144960190
#> [166] -0.0320259318 0.0311976639 -0.0428624001 0.0853903928 -0.0552747136
#> [171] -0.0734961644 -0.1271555781 0.0392842411 -0.1251031900 0.0468021938
#> [176] -0.0721267816 -0.1025386893 -0.0751608384 0.1265890040 0.0020664798
#> [181] 0.0186389928 0.0341272115 -0.0389425371 0.0356896158 0.0107143742
#> [186] 0.0198833705 0.0629645301 -0.0009932104 0.0642297288 0.0524509211
#> [191] 0.0707634049 -0.0893240334 0.0377338357 0.0561584511 0.0154346349
#> [196] 0.0465705496 0.0592727978 0.0433934621 0.0283376757 0.0700560346
#> [201] -0.0524923022 -0.0709008774 0.0893105971 -0.0172052065 0.0302185676
#> [206] -0.1859839838 -0.1065347298 -0.0175836499 -0.1315179005 -0.0555121281
#> [211] -0.0603824729 0.1488711489 0.1678728937 0.0238463414 -0.0075366946
#> [216] -0.0208206731 0.0556518076 0.1252884510 -0.1683371663 0.0146233233
#> [221] 0.0567483190 -0.0389402093 0.1198598597 -0.0330104269 0.1452354590
#> [226] 0.0272544052 0.0536560362 0.1009006142 0.1662276795 -0.1698848196
#> [231] 0.0704871507 0.0208756041 -0.1512271807 0.0942277557 -0.2124444934
#> [236] 0.0543284682 -0.0127116092 -0.1602888770 0.1064822575 0.1121098235
#> [241] 0.1541179989 0.0842273910 0.0843005490 -0.0487213684 0.0401028645
#> [246] 0.0985985009 0.0840708022 -0.1217203171 0.0376782957 -0.0688566441
#> [251] 0.1070912182 0.1640887589 0.0116181004 0.0327889649 -0.0446943825
#> [256] 0.2713939316 -0.0232237733 0.0470811579 0.1704522571 0.0850807953
#> [261] 0.3988341374 0.1141776611 0.1009207289 0.1854518611 0.1184925515
#> [266] 0.1037551136 0.1721833658 0.2557561307 0.1530320565 0.1253178636
#> [271] -0.0537881045 0.1054281069 0.1321708808 0.1141002668 0.1331931688
#> [276] 0.1906474909 0.1679426678 0.1059216778 0.1253720185 0.2371160597
#> [281] 0.2822547413 0.2525313824 0.2406677223 0.1766731292 0.1581534329
#> [286] 0.1216507851 0.0681771222 0.0562486436 0.1360284904 0.2031756440
#> [291] -0.0607639374 0.1976040543 0.1939792346 0.1156602708 0.2726660544
#> [296] 0.0059592062 0.1657547153 -0.1886967843 -0.0699304086 0.2185791787
#> [301] 0.1552339371 0.0814843159 0.1886730073 0.1768442259 -0.0271877667
#> [306] 0.2082427813 0.1612657702 0.1209791877 0.1619936075 -0.0613218781
#> [311] 0.1514562371 0.1184399374 0.1625941361 -0.0290780050 0.0534252090
#> [316] 0.1624571681 0.1458022733 0.0489890181 0.1341892447 0.0791817342
#> [321] 0.1697544829 0.1976963052 0.0700146423 0.0985828675 0.0705066876
#> [326] -0.1266028300 -0.0414603813 0.1183463277 0.0011470814 -0.0124611391
#> [331] 0.0571006437 0.1142086109 -0.0358990715 -0.0148539461 0.1559548559
#> [336] 0.1750845274 0.0172476932 0.0332514843 0.0862927994 0.1123772063
#> [341] 0.0058218874 0.0560056335 0.0021016904 0.0845719282 0.1098311986
#> [346] 0.0984581936 -0.0107925254 -0.1161030734 -0.0941177453 0.0191170696
#> [351] 0.2706821263 -0.0046992233 0.1217950535 0.0735532413 0.1494277554
#> [356] -0.0038811712 0.2996612795 0.1287651903 0.1033927891 0.1076205383
#> [361] -0.0492297937 0.1047884355 0.0885834155 -0.0101712089 0.1159302226
#> [366] 0.2429063604 0.0793246550 0.1284829592 0.1226675957 0.2344078978
#> [371] 0.1793998469 0.1835655281 0.1426299308 0.1535702716 0.2611278342
#> [376] 0.1045202071 0.0563380354 0.0936012423 0.0095754696 -0.0395404433
#> [381] 0.2310654038 0.0529874564 0.0198974637 0.1583806540 0.1429509474
#> [386] 0.2096520390 0.1575787862 0.1689541204 0.0584097265 0.0265079416
#> [391] 0.1505952512 0.0265751464 0.2326326048 0.1702477154 0.1879715352
#> [396] 0.0894667907 -0.0018109298 0.0847474307 0.0099769326 0.1899185958
#> [401] -0.0185194893 0.2469414370 0.1426393669 0.1170666639 -0.0136796900
#> [406] 0.0678426636 0.1342207069 0.0571098138 0.0849710023 0.1165178149
#> [411] 0.1985234418 0.0727954750 0.1171095709 0.1486913038 0.0813828309
#> [416] 0.0346955849 0.1179305251 0.0802336684 0.1731256200 0.0424007073
#> [421] 0.1955183751 0.0606556300 0.1276973221 0.0802718898 0.1190639208
#> [426] 0.0617073944 0.1769727849 0.0329985449 0.1312673286 0.0669646436
#> [431] 0.0612427920 0.0283951295 0.1462718862 0.0870869195 0.1532242376
#> [436] 0.1052248491 0.1500665907 0.0795575966 0.1534054549 0.2185506316
#> [441] 0.1431075854 0.0114777891 0.0414061336 0.0043084351 0.0910880646
#> [446] 0.0892914093 0.1497364478 0.1846269901 0.0354071967 0.1717349452
#> [451] -0.0218228329 0.0269856227 -0.0473540789 0.1615154001 0.1598393368
#> [456] -0.0258722952 0.1369269099 0.2610004824 0.0413419234 0.1533709430
#> [461] 0.0243986143 0.1329705720 0.2287810143 0.1879980887 0.1318642324
#> [466] -0.0270066209 0.1450700103 0.0361753238 0.0682545310 0.2005267155
#> [471] 0.0374282452 0.0739621713 0.2922876770 0.0354493015 -0.1350780554
#> [476] 0.0188927282 0.2295211116 -0.0041128348 0.0892758399 -0.0044485731
#> [481] 0.1034052546 0.0893777256 -0.0665984278 0.1447846424 0.0594320292
#> [486] 0.1118553387 0.1289074370 0.1409559209 0.1047174810 0.0604989502
#> [491] 0.2439021924 -0.0122372304 0.0868304599 0.0877766940 0.0888574861
#> [496] 0.2086490010 0.0198681384 -0.0593538742 0.1513191303 -0.0356575116
#> [501] 0.1009482783 0.0131663075 0.0124765478 0.1217718396 0.0115013187
#> [506] 0.2277958290 0.0957557946 -0.0064684159 0.0106926965 0.2798673191
#> [511] 0.1052330217 -0.1117995492 0.1148492473 0.0802006689 0.1793868955
#> [516] -0.0433625903 -0.0357750435 -0.0058947795 -0.0463035012 0.1698208075
#> [521] 0.0933934633 0.0229391417 -0.0165373467 -0.0170374134 -0.0343951123
#> [526] 0.0132338658 -0.0397560021 0.2083810430 0.0682932991 -0.0111899017
#> [531] -0.0040503498 -0.1593952878 0.0988738547 0.0093348334 0.0628073528
#> [536] 0.0579122475 -0.1162268403 0.0590417966 0.0706001816 -0.0343571322
#> [541] 0.0938552847 0.2534579200 0.1951064485 0.0022024166 0.1214664845
#> [546] 0.0405823584 0.0484792155 0.0930389598 0.0690967725 -0.0429581272
#> [551] 0.0407883235 0.0594423670 0.0237187423 0.1757650107 0.1234539966
#> [556] 0.2100406948 0.0708696354 0.1332012549 -0.0439607130 0.1173807515
#> [561] 0.0238478410 0.1363752601 0.0724876451 0.1492579125 0.1958723845
#> [566] 0.0010467143 0.0814287972 0.0527379809 0.1301372562 0.1472261230
#> [571] -0.0374489380 0.1735963718 0.1260088038 0.1012987615 0.2207437697
#> [576] 0.0591522399 0.1650104769 -0.0057978315 0.0780219625 0.1665734566
#> [581] 0.2122592833 0.2451166329 -0.0122328453 0.1940226424 -0.0133483451
#> [586] 0.0474494089 0.0872885705 0.0807318613 0.0759259308 0.0768165011
#> [591] 0.1722627569 -0.0663544731 0.1741907291 0.2905663134 0.0863014732
#> [596] 0.0710235138 0.1588857841 0.0879266321 0.1369329700 0.2490630650
#> [601] -0.0615748261 0.0358711875 0.0659658276 -0.0804468269 0.1332207680
#> [606] -0.0201506076 0.1460960090 0.1235758479 -0.1065846186 0.0967890364
#> [611] 0.1576362709 0.0800088380 0.0622629784 0.1132092090 0.0894338421
#> [616] 0.0770202830 0.1019777770 0.0028472523 0.0683909322 0.1572695394
#> [621] 0.1341782530 -0.1246758578 -0.0206903468 -0.1756528420 -0.0504622100
#> [626] 0.0402193951 0.0406775527 0.1335438181 -0.0719033859 -0.1313113657
#> [631] 0.0057958392 -0.1242073248 0.0150815579 0.0180657815 -0.0838824651
#> [636] 0.0107935489 -0.1734439300 -0.1386247956 -0.0853938094 -0.0856046943
#> [641] 0.0150930396 -0.1073297367 -0.0755143334 0.1309656626 0.0802645210
#> [646] 0.2138690894 0.2888782841 0.2079368898 0.1678167342 0.1442517493
#> [651] 0.2368604132 0.1999170170 0.2139336269 -0.0108760660 0.1442797532
#> [656] 0.2400364934 0.1654686443 -0.0808419421 0.2089577417 0.2528379451
# Compare the two forms of the Nereocystis weight model on the same data
loo_compare(loo_weight, loo(fit_weight_sim_nereo_power))
#> model elpd_diff se_diff p_worse diag_diff diag_elpd
#> model1 0.0 0.0 NA
#> model2 -67.7 12.3 1.00