Underlying function used in most plotting and object handling functions in
EMC2. Can for example be used to filter/thin a parameter type
(i.e, group-level means mu
) and convert to an mcmc.list.
Usage
get_pars(
emc,
selection = "mu",
stage = get_last_stage(emc),
thin = 1,
filter = 0,
map = FALSE,
add_recalculated = FALSE,
length.out = NULL,
by_subject = FALSE,
return_mcmc = TRUE,
merge_chains = FALSE,
subject = NULL,
flatten = FALSE,
remove_dup = FALSE,
remove_constants = TRUE,
use_par = NULL,
type = NULL,
true_pars = NULL,
chain = NULL,
covariates = NULL
)
Arguments
- emc
an emc object.
- selection
A Character string. Indicates which parameter type to select (e.g.,
alpha
,mu
,sigma2
,correlation
).- stage
A character string. Indicates from which sampling stage(s) to take the samples from (i.e.
preburn
,burn
,adapt
,sample
)- thin
An integer. By how much to thin the chains
- filter
Integer or numeric vector. If an integer is supplied, iterations up until that integer are removed. If a vector is supplied, the iterations within the range are kept.
- map
Boolean. If
TRUE
parameters will be mapped back to the cells of the experimental design using the design matrices. Otherwise the sampled parameters are returned. Only works forselection = mu
orselection = alpha
.- add_recalculated
Boolean. If
TRUE
will also add recalculated parameters, such as b in the LBA (b = B + A; see?LBA
), or z in the DDM z = Z*A (see?DDM
) only works whenmap = TRUE
- length.out
Integer. Alternatively to thinning, you can also select a desired length of the MCMC chains, which will be thinned appropriately.
- by_subject
Boolean. If
TRUE
for selections that include subject parameters (e.g.alpha
), plot/stats are organized by subject, otherwise by parameter.- return_mcmc
Boolean. If
TRUE
returns an mcmc.list object, otherwise a matrix/array with the parameter type.- merge_chains
Boolean. If
TRUE
returns parameter type merged across chains.- subject
Integer (vector) or character (vector). If an integer will select the 'x'th subject(s), if a character it should match subject names in the data which will be selected.
- flatten
Boolean. If
FALSE
for 3-dimensional samples (e.g., correlations: n-pars x n-pars x iterations). organizes by the dimension containing parameter names, otherwise collapses names across the first and second dimension. Does not apply forselection = "alpha"
- remove_dup
Boolean. If
TRUE
removes duplicate values from the samples. Automatically set toTRUE
ifflatten = TRUE
- remove_constants
Boolean. If
TRUE
removes constant values from the samples (e.g. 0s in the covariance matrix).- use_par
Character (vector). If specified, only these parameters are returned. Should match the parameter names (i.e. these are collapsed when
flatten = TRUE
and use_par should also be collapsed names).- type
Character indicating the group-level model selected. Only necessary if sampler isn't specified.
- true_pars
Set of
true_parameters
can be specified to apply flatten or use_par on a set of true parameters- chain
Integer. Which of the chain(s) to return
- covariates
Only needed with
plot
for priors and covariates in the design
Examples
# E.g. get the group-level mean parameters mapped back to the design
get_pars(samples_LNR, stage = "sample", map = TRUE, selection = "mu")
#> $mu
#> [[1]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.1071199 -0.7220976 0.5147673 0.1509100
#> [2,] -1.1163682 -0.8718823 1.4502697 0.2007689
#> [3,] -1.3256591 -0.5727143 0.6483144 0.2219049
#> [4,] -1.2519621 -0.7164368 0.5765470 0.1771225
#> [5,] -1.2962281 -0.6390243 0.4349689 0.1714742
#> [6,] -1.2352215 -0.6721022 0.6145338 0.2344133
#> [7,] -1.1011875 -0.7369250 0.4845878 0.1512651
#> [8,] -1.4000472 -0.6921902 0.9672897 0.2375900
#> [9,] -1.2677786 -0.6352720 0.5630492 0.1954891
#> [10,] -1.1193087 -0.7361534 0.6318139 0.1669678
#> [11,] -1.1870954 -0.7156723 0.6183504 0.1816539
#> [12,] -1.2963633 -0.6335718 0.4455817 0.1806443
#> [13,] -1.1693209 -0.5452283 0.6467498 0.2157353
#> [14,] -1.2838212 -0.6883959 0.8090042 0.1640947
#> [15,] -1.1438136 -0.7162684 0.5611150 0.1663250
#> [16,] -1.2369173 -0.7452483 0.5075017 0.1679524
#> [17,] -1.2760378 -0.6630577 0.7136102 0.2039214
#> [18,] -0.9569555 -0.6714145 0.3944418 0.1058011
#> [19,] -1.2958004 -0.7126064 0.5978612 0.1956022
#> [20,] -1.3266943 -0.7121075 0.5459786 0.2024320
#> [21,] -1.2916290 -0.6500968 0.4065917 0.1600773
#> [22,] -1.3082923 -0.7377160 0.6492396 0.1970477
#> [23,] -1.2334494 -0.7824171 0.5460141 0.1751200
#> [24,] -1.2307418 -0.7320717 0.4832905 0.1799636
#> [25,] -1.3745211 -0.6769474 0.6940851 0.2245997
#> [26,] -1.4237386 -0.7851848 0.5756534 0.2124725
#> [27,] -1.2741901 -0.6492443 0.5877968 0.1956832
#> [28,] -1.1180005 -0.6948921 0.6159922 0.1655834
#> [29,] -1.1435519 -0.6949538 0.5886766 0.1736435
#> [30,] -1.2999704 -0.6463263 0.4407454 0.1799873
#> [31,] -1.5277075 -0.6700489 0.7693353 0.2056187
#> [32,] -1.3583006 -0.7350555 0.7128378 0.2155958
#> [33,] -1.1253326 -0.7076415 0.5413434 0.1597984
#> [34,] -1.2076533 -0.7524936 0.4572553 0.1591182
#> [35,] -1.2932183 -0.6774493 0.7094676 0.2081379
#> [36,] -1.0114748 -0.9907262 0.5407341 0.1841633
#> [37,] -1.2759996 -0.5827415 0.6088163 0.2126526
#> [38,] -1.0650256 -0.6824697 0.5067497 0.1632599
#> [39,] -1.1647805 -0.6637146 0.5640144 0.2124185
#> [40,] -1.1610729 -0.6623362 0.5706719 0.2245656
#> [41,] -1.2932356 -0.6536455 0.6335321 0.2173542
#> [42,] -1.3098143 -0.6216076 0.7472250 0.2325364
#> [43,] -1.1264320 -0.6732470 0.5402224 0.1809871
#> [44,] -1.2865447 -0.7653235 0.9983763 0.3237331
#> [45,] -1.4360782 -0.7085184 0.7584256 0.2547333
#> [46,] -1.1186826 -0.6065196 0.5079966 0.1482779
#> [47,] -1.0823467 -0.5732527 0.5428531 0.1985621
#> [48,] -1.1597812 -0.5891118 0.6151728 0.1809847
#> [49,] -1.4135610 -0.6692559 0.7684605 0.2688995
#> [50,] -1.3255023 -0.6029758 0.6523020 0.2224729
#>
#> [[2]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.166620 -0.6436965 0.5483156 0.1824958
#> [2,] -1.129361 -0.6940353 0.6504419 0.2238207
#> [3,] -1.035410 -0.5220367 0.4486110 0.1761931
#> [4,] -1.174329 -0.6579760 0.4496510 0.1692996
#> [5,] -1.346630 -0.8100170 0.8129067 0.1533285
#> [6,] -1.216599 -0.6074362 1.0612011 0.2011152
#> [7,] -1.167284 -0.8010020 0.5345502 0.2214807
#> [8,] -1.402791 -0.5764342 0.9103967 0.1948459
#> [9,] -1.155260 -0.7111675 0.6130229 0.2068978
#> [10,] -1.219703 -0.6077669 0.6361968 0.1736355
#> [11,] -1.138964 -0.9726752 0.5748449 0.1874014
#> [12,] -1.196334 -0.6423007 0.6124782 0.1683968
#> [13,] -1.308103 -0.7940534 0.4838400 0.1941362
#> [14,] -1.180130 -0.7931882 0.5255716 0.2093412
#> [15,] -1.206589 -0.8055788 0.4399331 0.1688123
#> [16,] -1.344950 -0.7079971 1.7433605 0.2657071
#> [17,] -1.274149 -0.7389293 0.6353651 0.2072035
#> [18,] -1.372032 -0.7443061 0.5059275 0.1946451
#> [19,] -1.138607 -0.7215356 0.4221424 0.1325161
#> [20,] -1.049668 -0.6572624 0.4629125 0.1250820
#> [21,] -1.237615 -0.6646893 0.5007629 0.1593965
#> [22,] -1.241572 -0.7703325 0.5805802 0.1705039
#> [23,] -1.073517 -0.6427730 0.5112735 0.1885735
#> [24,] -1.175376 -0.3144181 0.6528783 0.2560266
#> [25,] -1.297612 -0.6796154 0.5986907 0.2379454
#> [26,] -1.326655 -0.7546058 0.6085117 0.3510918
#> [27,] -1.529888 -0.6562680 0.7458121 0.2505685
#> [28,] -1.136565 -0.6996505 0.5880211 0.1793332
#> [29,] -1.228315 -0.7178054 0.6961524 0.2305281
#> [30,] -1.055710 -0.6861501 0.4216104 0.1720014
#> [31,] -1.033535 -0.6214487 0.5059544 0.1780939
#> [32,] -1.174620 -0.3461413 0.6293584 0.2530105
#> [33,] -1.281433 -0.7059498 0.5736847 0.2348974
#> [34,] -1.333515 -0.7361447 0.5846070 0.3017878
#> [35,] -1.111562 -0.7181569 0.5614534 0.1930306
#> [36,] -1.240188 -0.6678870 0.6529873 0.2018294
#> [37,] -1.034334 -0.6747510 0.4440856 0.1359399
#> [38,] -1.231319 -0.5082971 0.8640634 0.2534823
#> [39,] -1.292363 -0.7232922 0.5362257 0.1578257
#> [40,] -1.257335 -0.6700340 0.6330931 0.2132559
#> [41,] -1.104252 -0.6512645 0.5862228 0.1881040
#> [42,] -1.279697 -0.5904236 0.8222898 0.2395956
#> [43,] -1.175070 -0.7673987 0.6112281 0.2124924
#> [44,] -1.146769 -0.8066323 0.7578018 0.2559919
#> [45,] -1.185470 -0.7871866 0.5933441 0.2033400
#> [46,] -1.177755 -0.7978748 0.7010437 0.1901041
#> [47,] -1.224404 -0.7391781 0.4714232 0.1833023
#> [48,] -1.172331 -0.7891516 0.5212959 0.2088208
#> [49,] -1.254364 -0.7580256 0.5511295 0.2170247
#> [50,] -1.233781 -0.6687595 0.4517207 0.1818752
#>
#> [[3]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.2731368 -0.7367828 0.5393966 0.1800588
#> [2,] -1.3547698 -0.7719067 0.6059274 0.2881173
#> [3,] -1.3701245 -0.6620441 2.7777240 0.4623419
#> [4,] -1.1465094 -0.6569767 0.4442653 0.1291673
#> [5,] -1.0888582 -0.6709700 0.2082840 0.1033847
#> [6,] -1.2349771 -0.6354421 0.6250958 0.1939795
#> [7,] -1.1523360 -0.7822882 0.6859788 0.2243507
#> [8,] -1.3376190 -0.7546565 0.7115331 0.2670506
#> [9,] -1.2858631 -0.9768512 0.4181991 0.1834650
#> [10,] -1.2834923 -0.7982710 0.5883589 0.1472735
#> [11,] -1.1955012 -0.6417108 1.0376509 0.2171665
#> [12,] -1.1194535 -0.6951976 0.5678184 0.1623017
#> [13,] -1.1484230 -0.8477156 0.5793230 0.1933313
#> [14,] -1.2353492 -0.7570164 0.6617036 0.2107478
#> [15,] -1.1855666 -0.6520351 0.7334752 0.1885796
#> [16,] -1.1831243 -0.7281809 0.5583322 0.1703373
#> [17,] -1.0674854 -0.6679383 0.4584398 0.1523974
#> [18,] -1.2724749 -0.8762560 0.5456309 0.1527952
#> [19,] -1.1304785 -0.6893755 0.4995961 0.1958766
#> [20,] -1.0947456 -0.7048952 0.6343532 0.2193115
#> [21,] -1.2312652 -0.6429199 0.5504249 0.2216558
#> [22,] -1.4128707 -0.8997997 0.5558181 0.2086801
#> [23,] -1.2010679 -0.6450097 0.4907052 0.1719908
#> [24,] -1.1176069 -0.7338291 0.5083830 0.2072398
#> [25,] -1.3255316 -0.6706068 0.8447773 0.2276562
#> [26,] -1.0486168 -0.6810839 0.5353877 0.1562091
#> [27,] -0.8296912 -0.7193978 0.6417813 0.1579394
#> [28,] -1.2717467 -0.6130800 0.5481344 0.1610885
#> [29,] -1.2628152 -0.7604565 0.5347309 0.1774062
#> [30,] -1.3068111 -0.7883407 0.5718342 0.2668543
#> [31,] -1.1065581 -0.6636373 0.4740449 0.1510734
#> [32,] -1.1168221 -0.6886473 0.4178538 0.1256710
#> [33,] -1.0812587 -0.6756990 0.2210258 0.1146578
#> [34,] -1.2672277 -0.6632880 0.6523421 0.2014930
#> [35,] -1.1825662 -0.7913080 0.7002053 0.2286720
#> [36,] -1.3015904 -0.6492433 0.6958241 0.2219591
#> [37,] -1.3076069 -0.7501126 0.5436814 0.1909402
#> [38,] -1.0704925 -0.7269100 0.2879609 0.1635738
#> [39,] -1.1477846 -0.6633830 0.7088244 0.1990619
#> [40,] -1.1472460 -0.7918392 0.5490609 0.1871133
#> [41,] -1.1453784 -0.6645891 0.3568385 0.1800180
#> [42,] -1.3768269 -0.6947874 0.7504402 0.3000593
#> [43,] -1.3988054 -0.8169032 0.6983234 0.2417897
#> [44,] -1.3060989 -0.6910173 0.5587477 0.2193387
#> [45,] -1.0728021 -0.7139964 0.3883413 0.1484307
#> [46,] -1.2396330 -0.7091984 0.4215551 0.1729264
#> [47,] -1.2875998 -0.7001954 0.5944964 0.1935024
#> [48,] -1.2233096 -0.7419060 0.6584175 0.2039052
#> [49,] -1.3139851 -0.7484463 0.7817506 0.2293535
#> [50,] -1.4367052 -0.5442389 0.8974026 0.3102700
#>
#> attr(,"class")
#> [1] "mcmc.list"
#>
# Or return the flattened correlation, with 10 iterations per chain
get_pars(samples_LNR, stage = "sample", selection = "correlation", flatten = TRUE, length.out = 10)
#> $correlation
#> [[1]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 10
#> Thinning interval = 1
#> m_lMd.m s.m t0.m s.m_lMd t0.m_lMd t0.s
#> [1,] 0.7401921 -0.27379473 -0.158828346 -0.3413920 -0.2905146 0.3927959
#> [2,] 0.3346316 -0.61304302 -0.558801927 -0.7336282 -0.7844260 0.7683781
#> [3,] 0.1188370 0.28776638 0.006526124 0.2388786 -0.7250749 0.2238313
#> [4,] 0.9124463 -0.87236300 -0.862231024 -0.8900886 -0.9426745 0.7851931
#> [5,] 0.3590428 -0.46676771 -0.647839026 -0.4795519 -0.5353959 0.4606919
#> [6,] 0.9406204 -0.44714862 -0.838808838 -0.5896045 -0.9159409 0.6256583
#> [7,] 0.1690634 -0.14484130 -0.158384599 -0.8944778 -0.9089595 0.9449304
#> [8,] -0.3839514 -0.09195571 -0.344437397 -0.6433593 -0.3622843 0.6928654
#> [9,] -0.3522426 -0.36777592 -0.601305576 -0.3882730 -0.3524715 0.6658014
#> [10,] 0.9090930 -0.86711946 -0.891770905 -0.9659576 -0.9780690 0.9817928
#>
#> [[2]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 10
#> Thinning interval = 1
#> m_lMd.m s.m t0.m s.m_lMd t0.m_lMd t0.s
#> [1,] -0.1591950 -0.22621326 -0.64850124 -0.19525322 -0.1859843 0.5945697
#> [2,] 0.8947240 -0.75283218 -0.91877790 -0.87442420 -0.9392924 0.8901573
#> [3,] 0.7461567 -0.54518329 -0.80057319 -0.77988063 -0.5758995 0.2534077
#> [4,] -0.0601351 -0.51358367 -0.71679722 -0.19411829 0.3429105 0.5453731
#> [5,] 0.5415741 -0.05014657 -0.36095284 -0.67795467 -0.9334796 0.7978296
#> [6,] 0.3359781 -0.07350043 -0.36210841 -0.20195811 -0.8030213 0.5572776
#> [7,] 0.6836957 -0.37213531 -0.51927771 -0.48830478 -0.4964144 0.2420130
#> [8,] -0.1372217 -0.37339802 0.03223619 0.43744387 0.1653675 0.4329614
#> [9,] 0.1722723 -0.87588245 -0.79607169 -0.36240819 -0.5211272 0.9324336
#> [10,] 0.7667364 0.25789323 -0.65464871 0.07559904 -0.7871726 0.1661282
#>
#> [[3]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 10
#> Thinning interval = 1
#> m_lMd.m s.m t0.m s.m_lMd t0.m_lMd t0.s
#> [1,] 0.779671663 -0.3930359 -0.8195756 -0.6519761 -0.7700062 0.3427482
#> [2,] 0.820108180 -0.7745469 -0.9282492 -0.9152567 -0.8654701 0.8250528
#> [3,] 0.826708155 -0.8783329 -0.7513702 -0.8713940 -0.6829756 0.8669153
#> [4,] -0.117791279 -0.3631814 -0.4674088 -0.6545253 -0.3532025 0.6896687
#> [5,] -0.224668284 -0.8187805 -0.7430029 0.0489364 -0.3700873 0.7957690
#> [6,] 0.939392730 -0.9175202 -0.9202362 -0.8404066 -0.9018581 0.9174461
#> [7,] 0.789599745 -0.7219735 -0.9141796 -0.8960489 -0.8141610 0.7474581
#> [8,] -0.004242966 -0.1978745 -0.2696838 -0.8897465 -0.8507771 0.9709818
#> [9,] 0.968739231 -0.7048245 -0.8805625 -0.8272502 -0.9545817 0.9266628
#> [10,] 0.765479769 -0.7338619 -0.6491893 -0.8594702 -0.9449381 0.7832226
#>
#> attr(,"class")
#> [1] "mcmc.list"
#>