Skip to contents

Process samples to a list that can be included to a dataframe

Usage

samples_to_list(object, par_name = "y_pred", n_samples = NULL)

Arguments

object

Stanfit object containing variable par_name or matrix with rows representing samples, columns representing variables.

par_name

Name of variable to extract when object is a stanfit object. Default to "y_pred" (variable containing predictions).

n_samples

How many samples to return. Default (=NULL) to all samples.

Value

List of vector of samples

Examples

samples_to_list(matrix(rnorm(1e3), nrow = 1e2))
#> [[1]]
#>   [1] -1.885182210  1.485105629 -1.409276775 -1.264273327 -1.116836503
#>   [6] -0.606148294  1.052341793  2.703803826 -1.231752234  0.574650154
#>  [11] -0.867083875  1.294509378 -0.277401449 -0.423005668 -0.444667479
#>  [16]  0.698511833 -1.220886545  0.417633585  2.653131735  1.443847730
#>  [21]  0.292958229  0.415582028 -0.480793381  0.611136834 -1.354127091
#>  [26]  0.008165982  0.063951847 -0.678440573 -0.894198702  0.996269585
#>  [31] -0.228075754  1.046937379 -0.729782153  0.421128342  1.023689672
#>  [36]  0.663597986 -0.065235086 -1.379501641  0.406370310 -0.671915292
#>  [41]  0.570893481 -0.190722809 -1.382687907 -0.417600275 -1.836224625
#>  [46] -0.776087496  1.212265977 -0.328009862  0.290032097  0.609304700
#>  [51] -1.263316070 -1.608600694 -2.252128727 -0.557479608 -1.170584092
#>  [56]  0.090016290  1.083716601 -0.767988597 -0.389547599  1.295696961
#>  [61]  0.997376046  0.039803670  0.712188498  0.493212825 -0.900669061
#>  [66]  0.040815423  0.734572468  1.980806312  0.275609400 -0.987717454
#>  [71] -0.913698036 -0.731226916  0.051657911  1.017777398 -0.558320053
#>  [76]  0.417023692 -0.077186503 -0.403291076  0.314777374  0.740077907
#>  [81]  1.368782011  1.169922394  2.510816011 -1.135979048 -1.035556492
#>  [86] -0.633043971  0.927324201  0.382202717  2.048867130 -0.786858525
#>  [91]  1.542581014  0.099938762  0.356749480 -0.914530830  0.594297097
#>  [96] -0.567070551 -2.385654854  0.794389081  0.691848129  0.755027049
#> 
#> [[2]]
#>   [1] -0.079569075 -0.357340899 -0.005912703  0.260379148  1.040858241
#>   [6] -1.189013786  0.853000565 -0.266470528 -0.359544340  0.460420773
#>  [11]  1.009677687 -0.732564657  0.039160230  1.838926035  1.583506067
#>  [16]  1.350733405 -0.676214270 -1.886787252  0.228617389  1.033223751
#>  [21] -1.192859948 -1.128250471 -0.089524133 -0.090524225  0.189735394
#>  [26] -0.714459653  1.237599744 -2.003873208  1.241366481 -0.196531104
#>  [31] -0.524328733 -1.237618905  1.661563505  0.771291699 -1.029744501
#>  [36]  0.047775816 -0.590238675  0.494290809 -0.351905633 -0.635511153
#>  [41] -0.390074926  1.244012102 -0.028429389  0.329241560 -0.858507647
#>  [46] -1.656271456  0.649955424  1.274596015 -1.785577716  0.623895080
#>  [51]  0.444014002  0.350660781 -0.807652159 -0.605021692  0.697781599
#>  [56] -0.031141958  0.247677475  0.600882066  0.439687697 -0.836108168
#>  [61]  0.316780657  0.444698007  0.004971021 -1.207579309  0.432889114
#>  [66]  1.298635205  0.611055229  2.546062895  0.758101927  0.344185388
#>  [71] -1.156977123 -0.384422508  1.119530546 -0.608891649  0.466645346
#>  [76] -0.139423348  0.264246422  0.788224799 -1.706713389 -1.876012604
#>  [81]  0.325638995 -0.625151913 -1.441009137  2.621596253  0.434057591
#>  [86]  1.300752250  0.970186169  0.542455909 -1.169924554  1.600069698
#>  [91] -0.845653584 -0.554268732  0.689870631  0.192119935  0.808481629
#>  [96]  0.871194191 -2.411271022 -1.061411448  2.092406721  0.294674823
#> 
#> [[3]]
#>   [1] -0.70022267  0.73920842  0.45318641 -1.46165997 -0.16419907 -0.60340079
#>   [7]  0.80006592 -1.57763840  1.59642912  0.68955281 -0.55477906  0.65221753
#>  [13]  1.04899717 -0.86231466  1.85930896  0.15371554 -1.23707155 -1.54220997
#>  [19] -1.52653228 -0.30696845 -0.47466047  0.03917443 -0.66133654 -0.42859914
#>  [25]  1.42768151  0.85754397  1.29908716 -2.16486793  0.81835090 -0.26274494
#>  [31]  0.45022697  0.10515939 -0.23074925 -0.62950216  1.13286042  0.49975901
#>  [37] -0.83832600 -0.96057558  0.40600496  0.98271214  1.62902751  0.30594422
#>  [43] -0.93197288 -0.30972745 -0.26536897 -0.05596398  1.32663592 -1.05085954
#>  [49]  0.13800123  2.20205347 -0.03470886  1.13161017 -1.01291708 -1.58138542
#>  [55]  1.29294792  0.12734320 -1.60284719 -0.66075517  0.85036568  0.36241109
#>  [61] -0.05875674  1.95357644 -0.04062259  1.01101108 -0.06566995  0.52427448
#>  [67]  0.55956117  0.81802062  1.66279832  1.53185481 -0.93657454  0.15133578
#>  [73] -0.69663494  0.65645164 -0.79550805 -1.08189505 -0.47826561  0.97378726
#>  [79]  1.05856173 -0.33791268  1.25657327 -0.34675041 -1.08670773 -0.56801224
#>  [85]  0.21511185 -0.49592932  0.68928334  0.33877736 -0.76979331 -1.04958441
#>  [91] -0.74481945 -0.19531328  1.27199989 -0.32259585 -0.12063043 -0.02544976
#>  [97]  0.15553939  0.96873271  1.00349685 -2.08212558
#> 
#> [[4]]
#>   [1]  0.64585281  0.34602423  0.26857316 -0.09970610 -0.50137944 -0.62120538
#>   [7] -1.26875484  0.17900096  0.07804341  0.23067173  0.68900028  0.95525708
#>  [13] -2.14835191  0.53057603 -0.06678455  0.12570083 -0.28682257  0.47131915
#>  [19] -1.79689020  0.08535018  1.46847025  1.02469389 -2.70108694  0.27185985
#>  [25] -0.33438377 -1.65623074 -0.05527014 -0.38699272 -0.39998556 -0.38380616
#>  [31] -1.66614632  0.01511392  0.97585784  0.34593748 -0.84958935  0.57138192
#>  [37] -1.18892661  1.25698354  0.27402202 -0.37438611  0.97570634 -1.82770901
#>  [43] -0.52157040  0.88496492 -0.43743027 -0.20434397 -0.43577216  0.48519445
#>  [49] -0.14143107 -0.39534904  1.58067706  0.86032206  0.55404556  0.13718514
#>  [55] -0.71796052  1.61253865  0.24786470 -0.87294116 -1.03067565  1.48527591
#>  [61]  1.36583998  0.88339244 -0.90761500  0.35475204 -0.80623503  0.46025516
#>  [67] -0.13247367  1.36656879 -1.50903090 -0.93240515 -1.03975938  0.57843068
#>  [73] -0.88461775  0.02805359  0.76261731  1.47735930  0.03287525  0.70378889
#>  [79]  1.14170332 -0.01035263 -0.83896767 -1.38182287  0.49380602  1.34441430
#>  [85]  1.02662218  0.37495700  0.49899591 -2.18476523  1.24611269 -1.12259640
#>  [91]  0.10581760 -1.14064360  0.24539688 -1.99551426  0.81935467  0.14382902
#>  [97]  0.21778939  0.06851911  2.90911575  0.04372531
#> 
#> [[5]]
#>   [1] -2.03435460  1.22187780  0.41352832 -0.74435114  1.49982101  2.63006841
#>   [7]  2.34025844  1.00818135 -0.22858542  0.71226621 -0.48273615  0.09478431
#>  [13] -0.15878734  1.07128093  0.11236398  1.93707352 -1.60300480 -1.83244963
#>  [19] -0.06934179  0.90733976 -0.74827256  1.71954846 -1.98166990  0.81408961
#>  [25]  0.34367086 -0.28736719 -0.96758373 -2.76192283 -0.82892680 -0.92627071
#>  [31] -2.80229907 -0.50536198 -0.34303890 -0.62494203  0.47913881  0.39288860
#>  [37]  1.04944303  1.50262445  0.25465166 -1.48050594  0.62418032  0.99160197
#>  [43]  0.47319546 -0.21030071 -0.91924223  0.15502744  1.62080324 -0.18033604
#>  [49]  0.15280566 -0.67742608 -0.16566342  0.28986639  1.04008158 -0.27458659
#>  [55]  0.71446511 -0.32770891  2.57926739  0.51784090 -0.81237376  2.24004318
#>  [61]  0.57392446 -0.24419747  0.36469388  0.47848639 -0.74741509 -0.58580498
#>  [67]  0.81984989 -0.68913350  0.67861801  0.63313145 -1.26938774 -0.43311584
#>  [73]  1.05673363  2.17221597  0.38924272  0.24855281 -1.37060954 -1.13953214
#>  [79]  0.29004423  0.18658272 -1.07630010 -0.43726629  0.38338733  0.59828260
#>  [85]  0.20830616  1.40212242 -1.19585221 -1.43146305  0.55635863 -0.83940300
#>  [91]  0.57388077  0.78154562  0.84100003 -0.01878956  0.79153663  1.16131117
#>  [97] -2.10546294 -0.24957478  0.82966382 -0.62701578
#> 
#> [[6]]
#>   [1]  0.879523511  0.545333630 -0.019001299 -0.945680689 -0.576730396
#>   [6] -0.207042581  0.336817925  0.298815255  0.108870259  1.598633821
#>  [11] -0.831500086 -0.936120220 -0.892454622  0.763323551  0.485710112
#>  [16]  0.353483964  0.979249607 -1.253620802 -1.781204648 -0.241597305
#>  [21]  0.366877697 -0.981608482 -2.133639750  0.565177869  0.356414560
#>  [26]  0.941147432 -0.706161599  1.036431170 -0.503635040  0.160716009
#>  [31] -0.792661186 -1.451544063  2.209182665  0.913431821  0.267468854
#>  [36] -1.091500624  1.187091207  0.313880515 -1.016363889 -0.683341213
#>  [41]  0.277859440  1.017499482 -0.148002370  0.152928961  1.478002812
#>  [46] -0.545550192  0.406422378  2.000152894  0.346622456 -0.203976399
#>  [51]  0.908102663 -1.067338448 -0.129707548 -0.079325698  0.470661758
#>  [56]  0.258019081 -0.600750361 -1.818119025 -0.961900162  0.080790497
#>  [61] -0.616233616 -0.660061788 -1.274224168  1.203963447  1.215426163
#>  [66]  0.197249018 -0.912645937 -0.672906874  0.835836155 -0.757759067
#>  [71]  1.091721424  0.171217647 -0.643920002 -0.141601494  0.566006803
#>  [76] -0.997968658 -0.945871928 -1.333327537  1.422882148 -2.144413148
#>  [81] -0.157713459  0.208864019  0.398735412  0.254721293  0.603076925
#>  [86] -1.957453144  1.336658775 -0.292231777 -0.949667512 -0.725664483
#>  [91] -0.964688224  0.407766795  0.230652561 -0.002481081  0.163327006
#>  [96] -0.531545759 -1.150778455 -0.839336863  0.047613558 -0.623317847
#> 
#> [[7]]
#>   [1]  0.564940697  1.870197677 -0.903672639  0.569737515  1.342271978
#>   [6] -1.695259958  0.878230142  1.538807622 -0.218224055  0.021311855
#>  [11] -0.261843203 -0.773387544 -1.034177314  0.239601944  0.436251248
#>  [16]  0.946562330  0.566989690 -0.683188133 -2.120194934  0.392399537
#>  [21]  0.488346226 -0.643152393  0.366685188 -0.349584368  1.811511491
#>  [26]  0.393995928 -1.669623364 -0.209687367  0.607540693 -2.442213660
#>  [31] -0.805658553 -0.487432382 -0.897161781  0.881141938 -0.725634256
#>  [36]  0.140559749  1.774539240  0.658900095 -0.188181089  0.123445719
#>  [41]  0.742210635  0.012199201  0.650342159  0.804621820 -0.966893835
#>  [46] -1.789950834 -2.285816677  0.598471966 -0.271087890 -0.861005884
#>  [51]  0.436631716 -1.678770784 -0.903780822  2.039974325  0.191768154
#>  [56]  0.422037205  1.425104590 -0.017557913  0.417568168 -0.053184152
#>  [61] -1.586748363  0.073071469  0.475058812  2.426402951 -0.325803092
#>  [66] -0.188479727 -2.413689381  0.960841194 -1.787189053  0.591219171
#>  [71]  0.292244219  1.353687996 -1.520739268 -0.463780281 -2.025791111
#>  [76] -0.419603495 -0.181850664  0.891754322 -0.100053621 -0.031201893
#>  [81]  0.198322759 -2.421440561  0.727534559  0.312976583 -0.826169454
#>  [86] -0.014622325  0.112393451  0.265332731 -0.300193340 -0.005004081
#>  [91]  1.675171431 -2.205185337 -1.827085941 -0.142974952 -0.825564089
#>  [96] -0.860903872 -0.898814062 -0.735604073 -0.072757355 -0.918872963
#> 
#> [[8]]
#>   [1] -0.22173494 -0.02754112 -1.66895864  0.73250240  0.14242400  2.03653985
#>   [7] -0.47332138 -0.14071364  0.17711375 -0.72550574  0.72479654  0.09554315
#>  [13] -0.62988079 -1.16235121 -0.46730166  2.19778896 -0.02471908  1.40222789
#>  [19]  1.23910645  1.18630829  1.58123794  0.48236966  1.59533335 -0.40371451
#>  [25]  0.20994043  0.38356497  0.13491488 -0.46903500 -0.99382491 -0.10698836
#>  [31] -1.93762832 -0.33836235  1.23881989 -0.81765733  1.14633687  0.42427250
#>  [37] -0.20783742 -0.13062761 -0.87668355  0.52088069  1.75113462 -0.14483898
#>  [43] -0.56127748  0.01921659 -3.03553722 -0.30233090 -0.54617002 -0.43411019
#>  [49]  0.94111873 -0.35410199  0.81961618 -0.35340102  0.65801836 -0.31289560
#>  [55] -0.44623718 -0.71042634  1.35424596 -0.86773765  0.28505023 -0.27796537
#>  [61]  1.50830628  0.13615927 -1.37686683 -0.25690785 -0.17857491  1.08615165
#>  [67]  0.78906536  0.13355519 -0.19135911  1.44391378 -0.59015169 -0.12058176
#>  [73]  0.61983000 -1.43810370  0.36712627  0.34588068 -2.03642093 -1.56410927
#>  [79] -0.32017508  2.02194998  0.51166897  1.04765877  0.23914818  1.53216967
#>  [85]  0.62830540  0.40941735 -0.07610928 -1.03404306 -0.08620944  0.15598272
#>  [91]  0.19767442 -0.63487460  1.62210313  0.74848509 -0.90447760 -0.82251136
#>  [97] -1.80200134  1.12813425 -0.33608343  0.18396453
#> 
#> [[9]]
#>   [1] -0.430358149  0.067115160  1.066261334 -0.513929737 -0.442503802
#>   [6]  1.423342676 -1.110745460 -1.460603316 -1.104862706  1.543810991
#>  [11]  0.075517566  1.364027545  1.165429895 -0.738057756  0.639732143
#>  [16]  1.065551700  0.078646671  0.471813129  0.505330085 -0.945990526
#>  [21]  0.509230957 -0.305771856  1.088550786 -0.570355446 -1.214357573
#>  [26] -0.102892876 -0.014228219  1.460418538  0.561713902 -0.228537291
#>  [31]  1.316174414 -0.368246287  0.690790457 -0.087100285 -1.899492929
#>  [36]  0.252593800 -0.309752623  0.158315387  0.924046946  0.753585453
#>  [41] -0.485395666  0.359642318 -0.431370317 -0.205457263 -1.518699120
#>  [46] -1.211109525  0.287891608 -2.238908768 -1.540904940  2.108437245
#>  [51]  0.251262514 -0.900152629 -0.319146951 -0.437684745  0.110136732
#>  [56]  0.512480900 -2.006250883  0.002062205 -0.058008295  0.855118266
#>  [61]  0.579701319 -1.718023419  0.673652500  0.208317584  0.410008945
#>  [66]  0.889257244 -0.341292755 -0.821948038 -0.587377854 -0.154391876
#>  [71]  0.011907158 -3.818226503 -1.225663959  0.289908563 -0.304752707
#>  [76]  0.803623695 -0.383241046 -0.151244278  1.260709741 -1.021518755
#>  [81]  0.318245580  0.114133408  1.048249767  0.664555363  1.003005242
#>  [86] -0.624877065 -0.249388611 -0.332908030 -0.329281459 -1.462578483
#>  [91] -1.327308076 -0.482600203 -0.438577428  0.249063791 -0.688772346
#>  [96]  0.698595638 -0.824830541 -0.385536317 -0.678549382 -0.127472943
#> 
#> [[10]]
#>   [1]  0.572242340  0.225426410 -0.111652316  1.038766304 -1.466892749
#>   [6]  0.124148121 -0.262233190  0.913772707 -0.775964879 -1.129281916
#>  [11] -1.154179655 -0.609612940 -0.814947310  0.961700663 -0.226345613
#>  [16]  0.586481422  0.704025800  0.154287797 -1.435837325 -1.174066080
#>  [21] -0.957994124 -0.644200596  0.182096221 -0.126896221  2.217299043
#>  [26] -0.618023279 -0.891732843  0.733735810 -1.238245665  0.204431211
#>  [31] -0.293852734 -1.417239224  1.613021742 -1.132934488 -0.479075780
#>  [36] -1.219403075 -0.385326305 -0.389775233  0.277285977  1.241678046
#>  [41]  1.026919591  0.003394658 -0.339272378  1.412783243  1.271441293
#>  [46]  2.335385593 -0.896087555  0.769887213  1.016389930  0.560748449
#>  [51] -2.975959115  1.133730972 -0.140103733 -0.676420319 -0.356788035
#>  [56]  1.876413735  1.312576995 -0.302971145  0.825505656  0.570664669
#>  [61]  1.815765648  0.003291955 -0.716833898 -0.468821391  2.552609838
#>  [66]  1.569221987 -0.154383930 -0.295184085  0.864414651  0.938340156
#>  [71] -0.937839280  2.632410087  2.067485792  2.120436673  1.307755508
#>  [76] -1.339179109  0.849612943  0.021527915 -0.341157148 -0.948062934
#>  [81]  0.152846422 -0.665904151 -0.903053563  0.926736233  0.923703275
#>  [86] -2.185556916  0.329298719  0.449028925  0.783230092 -1.028181035
#>  [91]  0.662845829  0.412419165 -0.785187936  0.142948349 -1.685319253
#>  [96] -0.143000718  0.692051770  0.811635611  0.577751854  1.444913627
#>