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 = "sample",
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_prior
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.1920924 -0.6809216 0.6604494 0.2651123
#> [2,] -1.1757901 -0.7395519 0.2720634 0.2224151
#> [3,] -1.2123114 -0.6898549 0.5541135 0.2484732
#> [4,] -1.1954771 -0.6762847 0.5447346 0.1970971
#> [5,] -1.2362388 -0.6394192 0.6237535 0.2096733
#> [6,] -1.1215688 -0.7176369 0.4758425 0.1616310
#> [7,] -1.2996047 -0.7754258 0.5720885 0.2020359
#> [8,] -1.2970967 -0.6815042 0.6492037 0.2230304
#> [9,] -1.0726048 -0.7034601 0.4366363 0.1462328
#> [10,] -1.4515919 -0.8515052 0.5396432 0.1096103
#> [11,] -1.2612356 -0.7122519 0.5969090 0.1948246
#> [12,] -1.3442766 -0.7563897 0.6952948 0.2316453
#> [13,] -1.2774815 -0.7466007 0.6385198 0.2199084
#> [14,] -1.1593737 -0.6937867 0.4582658 0.1617241
#> [15,] -1.3366380 -0.6543866 0.5993636 0.2086989
#> [16,] -1.2939252 -0.6136663 0.7916026 0.2460659
#> [17,] -1.2008918 -0.7259295 0.6111249 0.1997995
#> [18,] -1.2477707 -0.5970814 0.5226730 0.1889922
#> [19,] -1.2045829 -0.6958584 0.5814007 0.1876382
#> [20,] -1.0591428 -0.7508324 0.4106376 0.1908981
#> [21,] -1.4780744 -0.6319482 0.7713129 0.2934900
#> [22,] -0.9497168 -0.7565709 0.4150196 0.1066652
#> [23,] -1.1434682 -0.8183133 0.5438682 0.1776610
#> [24,] -1.2639046 -0.7591947 0.4564527 0.1857802
#> [25,] -1.1873879 -0.6762365 0.4414869 0.1966494
#> [26,] -1.2750700 -0.5970024 0.7554563 0.2835544
#> [27,] -1.0707260 -0.6033494 0.6097751 0.2039506
#> [28,] -1.4331083 -0.8173170 0.7163503 0.2219129
#> [29,] -1.2168231 -0.6316163 1.0074731 0.1898737
#> [30,] -1.4871952 -0.7604884 0.7891218 0.2141996
#> [31,] -1.2395259 -0.6661198 0.7236153 0.1968053
#> [32,] -1.1448358 -0.7675980 0.7720474 0.1956714
#> [33,] -1.1834311 -0.9232632 0.8696167 0.1985600
#> [34,] -1.1418132 -0.7287812 0.5099218 0.1693109
#> [35,] -1.2647551 -0.6365577 0.7365540 0.2152349
#> [36,] -1.3066424 -0.7050625 0.6038484 0.2111324
#> [37,] -1.3506842 -0.6834220 0.6518795 0.2052281
#> [38,] -1.4847642 -0.5553439 0.8414987 0.2304558
#> [39,] -1.3402707 -0.6406965 0.4875574 0.2019986
#> [40,] -1.2829468 -0.6682817 0.4943084 0.1773156
#> [41,] -1.1530293 -0.6887993 0.6774977 0.1780029
#> [42,] -1.2452478 -0.6791583 0.6441185 0.1956835
#> [43,] -1.1263970 -0.6049137 0.6064294 0.1938780
#> [44,] -1.1256120 -0.6935153 0.6380753 0.2126334
#> [45,] -1.2708226 -0.5840467 0.5663583 0.2085726
#> [46,] -1.1361407 -0.6144855 0.5985695 0.1869545
#> [47,] -1.6770298 -0.9382264 0.7546737 0.2265821
#> [48,] -1.1901487 -0.6382173 0.6637652 0.2638690
#> [49,] -1.2953280 -0.7189685 0.6040354 0.2449891
#> [50,] -0.9347495 -0.5026462 0.4395758 0.1310129
#>
#> [[2]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.231779 -0.7051322 0.5424936 0.2678836
#> [2,] -1.053080 -0.7313593 0.3932500 0.2096421
#> [3,] -1.138662 -0.6522221 0.5002147 0.1776996
#> [4,] -1.295980 -0.7278642 0.6059163 0.2147054
#> [5,] -1.283500 -0.5204109 0.9861930 0.2455106
#> [6,] -1.468244 -0.8730374 0.4414587 0.2762443
#> [7,] -1.181485 -0.7543682 0.5500385 0.2460739
#> [8,] -1.224092 -0.6991040 0.6099010 0.1987255
#> [9,] -1.257650 -0.7090712 0.7728024 0.2552177
#> [10,] -1.274503 -0.7079087 0.5957354 0.2108119
#> [11,] -1.223605 -0.7666614 0.4650659 0.2058799
#> [12,] -1.275549 -0.7312570 0.5565925 0.2002538
#> [13,] -1.243499 -0.7547148 0.7158540 0.1898466
#> [14,] -1.273127 -0.7251139 0.6206787 0.1883382
#> [15,] -1.255377 -0.7406829 0.6029538 0.1982640
#> [16,] -1.231695 -0.7640299 0.5572062 0.1927043
#> [17,] -1.379568 -0.6225881 0.6612891 0.2210106
#> [18,] -1.213572 -0.7845654 0.6330077 0.1913032
#> [19,] -1.297656 -0.7019892 0.6102527 0.2033506
#> [20,] -1.231487 -0.7455866 0.5166158 0.2024808
#> [21,] -1.274819 -0.6527395 0.5305315 0.1866189
#> [22,] -1.317250 -0.5668717 0.5151540 0.2113019
#> [23,] -1.322553 -0.7035489 0.4965762 0.2247801
#> [24,] -1.281774 -0.5898852 0.5251848 0.1744173
#> [25,] -1.219040 -0.7162943 0.6080580 0.2176056
#> [26,] -1.094497 -0.7136422 0.4536940 0.1326454
#> [27,] -1.250709 -0.7063833 0.5964513 0.1935783
#> [28,] -1.232375 -0.6531303 0.5819782 0.2002087
#> [29,] -1.679494 -0.6786174 1.1720190 0.4008867
#> [30,] -1.271059 -0.6878048 0.6254777 0.2011596
#> [31,] -1.297251 -0.7811351 0.5297242 0.1735854
#> [32,] -1.243670 -0.8383700 0.6456202 0.2055509
#> [33,] -1.238690 -0.6247802 0.5949236 0.1672777
#> [34,] -1.372255 -0.6769841 0.8198382 0.1983006
#> [35,] -1.272935 -0.5827113 0.5474637 0.2091681
#> [36,] -1.151066 -0.6011843 0.4657399 0.1956647
#> [37,] -1.204262 -0.5825676 0.8639464 0.2739012
#> [38,] -1.327062 -0.6362256 0.6862855 0.2116947
#> [39,] -1.259571 -0.6859095 0.4576179 0.2401605
#> [40,] -1.372819 -0.8076699 0.5153701 0.3053534
#> [41,] -1.396066 -0.6791213 0.6296598 0.2415830
#> [42,] -1.180984 -0.7288405 0.5901554 0.1823600
#> [43,] -1.303471 -0.6215640 0.7260234 0.2471794
#> [44,] -1.165494 -0.7642515 0.4926795 0.1862872
#> [45,] -1.216408 -0.7174346 0.6971196 0.2165391
#> [46,] -1.162512 -0.7826961 0.4557066 0.1806881
#> [47,] -1.289946 -0.6577004 1.0180593 0.3120207
#> [48,] -1.275500 -0.6850336 0.6798758 0.2722158
#> [49,] -1.465880 -0.5489986 0.7037287 0.2706573
#> [50,] -1.172132 -0.7816744 0.4441473 0.1631845
#>
#> [[3]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.3779562 -0.6537067 0.6975120 0.2151056
#> [2,] -1.2578764 -0.7706126 0.7071788 0.2081969
#> [3,] -1.4913232 -0.5869754 0.7920330 0.2331730
#> [4,] -1.3509312 -0.6864458 0.6241563 0.2131383
#> [5,] -1.3672584 -0.6539830 0.7903058 0.2274617
#> [6,] -1.2642376 -0.7692119 0.3871163 0.2014690
#> [7,] -1.1178269 -0.9225495 0.4628911 0.1999846
#> [8,] -1.3060877 -0.7664543 0.7178458 0.2203287
#> [9,] -1.1600876 -0.6675774 0.9143382 0.2241095
#> [10,] -1.0557119 -0.8848330 0.4712680 0.1467519
#> [11,] -1.3952108 -0.6910641 0.6529364 0.2352537
#> [12,] -1.3379641 -0.6507158 0.8206602 0.2167237
#> [13,] -1.3713054 -0.6029987 0.5909167 0.2358092
#> [14,] -1.2395316 -0.6762416 0.5957505 0.1972560
#> [15,] -1.2099198 -0.7463735 0.5172726 0.1690587
#> [16,] -1.1660298 -0.6999998 0.5082607 0.1546705
#> [17,] -1.1982459 -0.6886732 0.4857607 0.1723107
#> [18,] -1.1084198 -0.6819424 0.4525926 0.1436432
#> [19,] -1.2650655 -0.8155321 0.4987935 0.2032893
#> [20,] -1.3875001 -0.6927166 0.6648349 0.2144398
#> [21,] -1.3201731 -0.5641296 0.6881136 0.2357804
#> [22,] -1.3073586 -0.6443296 0.5150883 0.1885417
#> [23,] -1.2858976 -0.7066907 0.5583213 0.1999040
#> [24,] -1.1082654 -0.7923914 0.5272049 0.1981756
#> [25,] -1.1923896 -0.7037801 0.5872294 0.1767263
#> [26,] -1.0453512 -0.8235067 0.4239175 0.2910261
#> [27,] -1.1811366 -0.7655223 0.5895681 0.1650112
#> [28,] -1.2753562 -0.6967752 0.5974773 0.1933016
#> [29,] -1.2340416 -0.5788672 0.7556593 0.1685145
#> [30,] -1.0130066 -0.5535399 0.4961625 0.1888387
#> [31,] -1.2865730 -0.7333881 0.5956655 0.2106269
#> [32,] -1.2175287 -0.7302854 0.5722834 0.1634218
#> [33,] -1.1242358 -0.6620005 0.4491883 0.1326018
#> [34,] -1.1619379 -0.6600945 0.5909084 0.1749821
#> [35,] -1.2319359 -0.7430304 0.5668122 0.1817159
#> [36,] -1.2962195 -0.7026321 0.6266842 0.1928500
#> [37,] -1.2323205 -0.6886936 0.7831787 0.2151430
#> [38,] -1.1863135 -0.7693131 0.5683690 0.1917683
#> [39,] -1.2408820 -0.6862107 0.4995583 0.2089834
#> [40,] -1.2517841 -0.7721452 0.6586921 0.2055099
#> [41,] -1.3648569 -0.6672994 0.6708135 0.2056277
#> [42,] -1.3062083 -0.8020254 0.7094450 0.2299180
#> [43,] -1.1574713 -0.7757509 0.5992594 0.2682575
#> [44,] -1.3155249 -0.6496178 0.6143657 0.2081420
#> [45,] -1.3478975 -0.7865393 0.5615905 0.1934034
#> [46,] -1.2219161 -0.6977170 0.7517153 0.1820479
#> [47,] -0.9733468 -0.4196035 0.6273231 0.2293625
#> [48,] -1.3649918 -0.7388624 0.6056969 0.2332632
#> [49,] -1.2941953 -0.6369562 0.7558910 0.2029876
#> [50,] -1.2545747 -0.7328641 1.0740808 0.2057475
#>
#> 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.4161710 -0.6259101 -0.7718499 -0.35553290 -0.6256956 0.6667611
#> [2,] 0.2501842 -0.9145107 -0.7955403 -0.44346196 -0.6067699 0.8940067
#> [3,] 0.9380206 -0.7432630 -0.6485934 -0.80325567 -0.7607187 0.8958959
#> [4,] 0.9012393 -0.8598360 -0.9070840 -0.81564785 -0.7857671 0.8023191
#> [5,] -0.3318392 -0.6172538 -0.3607328 -0.01709717 -0.4680233 0.7224332
#> [6,] 0.3632546 -0.5779674 -0.6217344 -0.33415065 -0.6140923 0.5190850
#> [7,] 0.9089677 -0.4972707 -0.3765058 -0.67796702 -0.5270201 0.8069139
#> [8,] 0.7921812 -0.6232306 -0.7189267 -0.26017151 -0.4338810 0.5790486
#> [9,] -0.5027539 0.3108699 0.2131788 -0.57969274 -0.2809811 0.6623240
#> [10,] 0.9050753 -0.9158997 -0.9183176 -0.96503892 -0.9310012 0.9170239
#>
#> [[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.72380800 0.3632221 0.3824542 0.01009507 0.1217113 0.10199593
#> [2,] 0.63967736 -0.0872879 -0.3767488 0.26465814 -0.5279094 0.08677739
#> [3,] 0.66764646 -0.1298830 0.2244160 -0.72193329 -0.2378108 0.29716339
#> [4,] 0.50860601 0.3215838 0.1365122 -0.28725407 -0.2814896 0.72706995
#> [5,] 0.97202375 -0.8540369 -0.9202158 -0.90616284 -0.9437163 0.86288112
#> [6,] 0.71747092 -0.7931026 -0.8820200 -0.61464123 -0.8418412 0.75485969
#> [7,] 0.32358089 -0.8265526 -0.8194899 -0.11420503 -0.1080113 0.98079341
#> [8,] 0.09362899 -0.4534869 -0.1398391 0.05341269 -0.5076566 0.28797526
#> [9,] -0.67982519 0.3466001 -0.1773134 -0.45229919 0.2681004 0.49333839
#> [10,] 0.50179387 -0.5953184 -0.4790218 -0.90900744 -0.9234997 0.83370013
#>
#> [[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.8671442 -0.41315331 -0.67095310 -0.52884700 -0.72228925 0.5592671
#> [2,] 0.7313510 -0.60859329 -0.51751044 -0.59550307 -0.85142037 0.5012968
#> [3,] 0.7947831 -0.73853832 -0.17845371 -0.78742059 -0.27699367 0.5972722
#> [4,] 0.6870603 -0.48150737 -0.54228968 -0.59407139 -0.82447241 0.8811392
#> [5,] 0.6160009 -0.27463906 -0.41870063 -0.50370139 -0.73793340 0.6593811
#> [6,] -0.1148367 -0.02781127 0.04183441 -0.88253651 -0.66663829 0.6022866
#> [7,] 0.7717988 -0.81631346 -0.80039250 -0.45855096 -0.69259725 0.5922351
#> [8,] 0.8803450 -0.05208476 -0.88156786 -0.19539243 -0.96658182 0.1106099
#> [9,] 0.1273639 0.40332163 0.17323633 -0.55190424 -0.78948670 0.7809628
#> [10,] 0.1032909 -0.92818684 -0.92789494 0.03446882 -0.01983142 0.9086741
#>
#> attr(,"class")
#> [1] "mcmc.list"
#>