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.3724278 -0.58981139 0.5764218 0.2080038
#> [2,] -1.4380903 -0.49417229 0.6879095 0.1938321
#> [3,] -1.1985992 -0.72040448 0.5897593 0.1722501
#> [4,] -1.2122172 -0.75312032 0.6356574 0.2123582
#> [5,] -1.2001971 -0.61804095 0.5581922 0.1961481
#> [6,] -1.2430005 -0.70074757 0.6405943 0.2095871
#> [7,] -0.4390734 -0.03051267 0.7275988 0.1608097
#> [8,] -1.2060253 -0.72007007 0.4267749 0.1584079
#> [9,] -1.1232320 -0.82611126 0.4706202 0.2106787
#> [10,] -1.2096670 -0.64832340 0.5687333 0.1793606
#> [11,] -1.1847205 -0.74017212 0.6746322 0.2051977
#> [12,] -1.1936277 -0.66364232 0.4544391 0.2829153
#> [13,] -1.1604312 -0.74489876 0.5587398 0.1823236
#> [14,] -1.3132219 -0.59758805 0.6956217 0.2420677
#> [15,] -1.2250089 -0.71074020 0.6203497 0.1791960
#> [16,] -0.9471587 -0.68103563 0.4635536 0.1832709
#> [17,] -1.2992975 -0.64081311 0.6360427 0.2018553
#> [18,] -1.1116161 -0.78469993 0.4708712 0.1490390
#> [19,] -1.2570860 -0.56964708 0.3350269 0.1733079
#> [20,] -1.2185306 -0.71685779 0.4745038 0.1788060
#> [21,] -1.2271193 -0.71941211 0.4719644 0.1961247
#> [22,] -1.2054916 -0.65548425 0.6554753 0.3003477
#> [23,] -1.1694250 -0.82627834 0.6595367 0.1920978
#> [24,] -1.1991012 -0.70956265 0.6353297 0.2043464
#> [25,] -1.0384773 -0.72561104 0.3484726 0.1506471
#> [26,] -1.3649195 -0.80185759 0.7231538 0.2460836
#> [27,] -1.1947683 -0.75472039 0.5402294 0.1675914
#> [28,] -1.2691990 -0.54112729 0.5449802 0.1996636
#> [29,] -1.1604201 -0.70056229 0.7140801 0.2119681
#> [30,] -1.3902229 -0.77727206 0.7266797 0.1910823
#> [31,] -0.9968339 -0.48411860 0.5925160 0.1903998
#> [32,] -1.2724450 -0.76511303 0.6712795 0.2169163
#> [33,] -1.4244347 -0.69881799 0.7729153 0.2252262
#> [34,] -1.2180871 -0.71540526 1.2449302 0.1742438
#> [35,] -1.2216050 -0.69488317 0.6078121 0.1864412
#> [36,] -1.2882258 -0.66887986 0.2775274 0.1559498
#> [37,] -1.2016389 -0.71084942 0.6464914 0.2150593
#> [38,] -1.2191901 -0.71358065 0.4877644 0.2071221
#> [39,] -1.2304000 -0.71128937 0.6606686 0.1960196
#> [40,] -1.4008366 -0.72698482 0.7304964 0.2278025
#> [41,] -1.3072914 -0.73753966 0.5470727 0.2501924
#> [42,] -1.2545036 -0.73425851 0.5597240 0.2033896
#> [43,] -1.2700849 -0.72641190 0.6119168 0.1826255
#> [44,] -1.2750785 -0.70561014 0.4924746 0.1940834
#> [45,] -1.1307109 -0.72712958 0.9730560 0.5067519
#> [46,] -1.3663470 -0.68400812 0.5744444 0.1834742
#> [47,] -1.5076094 -0.75074651 0.7799396 0.2180042
#> [48,] -1.4053897 -0.65873264 0.7220433 0.2090458
#> [49,] -1.2880984 -0.67129046 0.5376537 0.1919354
#> [50,] -1.0675718 -0.55521713 0.4999791 0.1662000
#>
#> [[2]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.7066522 -0.7335021 0.7425789 0.2978328
#> [2,] -1.2062376 -0.6340021 0.7717840 0.2015730
#> [3,] -1.8532897 -1.0268290 1.1011453 0.5193080
#> [4,] -1.1630268 -0.6654120 0.7391780 0.2065239
#> [5,] -1.1652105 -0.7581018 0.5858381 0.1754007
#> [6,] -1.3131661 -0.6474179 0.7899601 0.2477474
#> [7,] -1.2261216 -0.6723682 0.6615136 0.2138730
#> [8,] -1.1891323 -0.7897444 0.5052698 0.1363019
#> [9,] -1.2333542 -0.6200472 0.5975226 0.2706106
#> [10,] -1.1406123 -0.6207648 0.5635681 0.2383060
#> [11,] -1.1773953 -0.7585084 0.4549549 0.1459030
#> [12,] -1.1616748 -0.6628213 0.6379687 0.1350229
#> [13,] -1.2278392 -0.8118670 0.5548704 0.1971553
#> [14,] -1.2992306 -0.8624486 0.6253085 0.1971859
#> [15,] -1.2468343 -0.7317623 0.5028325 0.1597956
#> [16,] -1.1387384 -0.7179837 0.5301410 0.1729046
#> [17,] -1.4061649 -0.8791198 0.6069638 0.2194458
#> [18,] -1.1715826 -0.7069557 0.5767978 0.1864654
#> [19,] -1.6344531 -0.9690069 0.7151377 0.2882214
#> [20,] -1.2133031 -0.7369664 0.6792409 0.1949177
#> [21,] -1.2323295 -0.7814825 0.4951901 0.2359922
#> [22,] -1.1853473 -0.6830994 0.5374353 0.1922523
#> [23,] -1.2252488 -0.7719440 0.5323672 0.2094968
#> [24,] -1.2861226 -0.7197872 0.5363692 0.1897593
#> [25,] -1.1914202 -0.6717554 0.6276431 0.1760473
#> [26,] -1.4329612 -0.5411416 0.8946306 0.2299379
#> [27,] -1.1870407 -0.7499283 0.4959408 0.2583758
#> [28,] -1.1939417 -0.6398973 0.7024145 0.2114183
#> [29,] -1.1501511 -0.6071143 0.7070541 0.2218332
#> [30,] -1.4200054 -0.7053841 0.6487644 0.2346741
#> [31,] -1.2557691 -0.6398114 0.5729651 0.3058167
#> [32,] -1.1792559 -0.7760680 0.5879837 0.2731472
#> [33,] -1.2065856 -0.7487174 0.5802422 0.1826778
#> [34,] -1.0028307 -0.6841219 0.4540112 0.1337158
#> [35,] -1.1615908 -0.6623436 0.7455004 0.2025464
#> [36,] -1.4952345 -0.7221891 0.6938113 0.1764792
#> [37,] -1.2648483 -0.7605931 0.6376705 0.2194761
#> [38,] -0.8995442 -0.5711582 0.4408398 0.1230782
#> [39,] -1.3929097 -0.7716277 0.6177276 0.2115297
#> [40,] -1.3145986 -0.6253537 0.6158837 0.2193275
#> [41,] -0.9910219 -0.9135109 0.6164150 0.1925811
#> [42,] -1.4600108 -0.9941648 0.3543312 0.1802639
#> [43,] -1.3388105 -0.7347232 0.5900058 0.2405685
#> [44,] -1.7807451 -0.8461076 0.9926297 0.2494845
#> [45,] -0.9345299 -0.9725452 0.4455336 0.1697540
#> [46,] -1.3268410 -0.6797518 0.5406862 0.1758003
#> [47,] -1.1343156 -0.7012167 0.6302116 0.2011703
#> [48,] -1.1826979 -0.7356426 0.4809055 0.1949308
#> [49,] -1.3897375 -0.6647682 0.9718724 0.1510047
#> [50,] -0.9658377 -0.5998396 0.4115150 0.1480975
#>
#> [[3]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMTRUE m_lMFALSE s t0
#> [1,] -1.2419278 -0.7366802 0.5365374 0.1762834
#> [2,] -1.1704017 -0.7374785 0.4924509 0.1461412
#> [3,] -1.1541713 -0.7225171 0.4428245 0.1491237
#> [4,] -0.9866940 -0.5889673 0.5809155 0.2007662
#> [5,] -1.3462420 -0.6527309 0.6666695 0.3635851
#> [6,] -1.2865374 -0.6677391 0.6482955 0.2197081
#> [7,] -1.3008633 -0.7986848 0.6219896 0.1341615
#> [8,] -1.2393178 -0.7886387 0.5157595 0.1217838
#> [9,] -0.9069586 -0.8265073 0.4195059 0.1134687
#> [10,] -1.3743695 -0.8283496 0.6632102 0.2180341
#> [11,] -1.0826683 -0.7209474 0.4433116 0.1524675
#> [12,] -1.1965874 -0.7110922 0.5064005 0.1634736
#> [13,] -1.1653809 -0.6316533 0.5967630 0.1831747
#> [14,] -1.2851988 -0.7042907 0.5630934 0.1953278
#> [15,] -1.2232061 -0.5332136 0.5968088 0.2359579
#> [16,] -1.1010417 -0.8131786 0.5771499 0.2016344
#> [17,] -1.1972235 -0.7306677 0.5844672 0.1810120
#> [18,] -1.3355031 -0.5995687 0.7733850 0.2569567
#> [19,] -0.9757394 -0.8389068 0.6324588 0.2773707
#> [20,] -1.0308375 -0.6148552 0.4057794 0.1576273
#> [21,] -1.3656953 -0.7402062 0.7050822 0.1880759
#> [22,] -1.2395553 -0.7248289 0.5483877 0.1829960
#> [23,] -1.2571655 -0.5517818 0.4442635 0.2335629
#> [24,] -1.2969971 -0.6777725 0.5671395 0.1878737
#> [25,] -1.0451909 -0.4605133 0.4777929 0.5082269
#> [26,] -1.3405134 -0.7659396 0.7068849 0.2653337
#> [27,] -1.1540591 -0.7901460 0.5425312 0.1484085
#> [28,] -1.2425942 -0.8120465 0.5346816 0.2041381
#> [29,] -1.3648310 -0.6337240 0.5940525 0.1663622
#> [30,] -1.3886808 -0.8806812 0.6685164 0.2320133
#> [31,] -1.4188472 -0.6737641 0.8926227 0.2938776
#> [32,] -1.0014827 -0.9557428 0.5852081 0.1707953
#> [33,] -1.1991161 -0.7405013 0.5744487 0.1797826
#> [34,] -1.2651053 -0.7074703 0.5893590 0.2168348
#> [35,] -1.0469770 -0.7304838 0.5281582 0.1967735
#> [36,] -1.0099733 -0.7991372 0.6263155 0.1442377
#> [37,] -1.1859977 -0.6309630 0.5026211 0.1559885
#> [38,] -1.1677112 -0.6949069 0.4811965 0.1640457
#> [39,] -1.1854109 -0.7729649 0.5252460 0.1486289
#> [40,] -1.2451804 -0.7558021 0.5466379 0.2053815
#> [41,] -1.1984830 -0.6512481 0.7398044 0.2314513
#> [42,] -1.3023619 -0.7621082 0.6706248 0.2144148
#> [43,] -1.1109036 -0.6417184 0.5218675 0.2390494
#> [44,] -1.1000904 -0.6915079 0.5458579 0.1725235
#> [45,] -1.2099536 -0.6913656 0.5523182 0.1823926
#> [46,] -1.2568096 -0.6707152 0.5517627 0.2906323
#> [47,] -1.3567533 -0.6367235 0.7391204 0.2531294
#> [48,] -1.2527009 -0.6745579 0.5972477 0.2145675
#> [49,] -1.2778999 -0.7279223 0.5937542 0.2005637
#> [50,] -1.2323263 -0.6423523 0.5287097 0.1380517
#>
#> 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.72735394 -0.4578625 -0.76409000 -0.37823117 -0.5852285 0.79087227
#> [2,] 0.22693752 -0.6397855 -0.70807797 -0.49223538 -0.5896884 0.72802145
#> [3,] -0.39351510 -0.2673523 -0.06575863 -0.18370527 0.1592195 -0.01171389
#> [4,] -0.01510057 -0.6204652 -0.45053126 -0.07012914 0.4890723 0.38976026
#> [5,] -0.69043851 -0.9309520 -0.87311587 0.86966844 0.7365236 0.92795192
#> [6,] -0.64036939 -0.8882950 -0.43398441 0.42511015 0.1677180 0.38932301
#> [7,] 0.55300713 -0.7069990 -0.36464760 0.01352493 -0.5315699 -0.02246001
#> [8,] 0.55479795 -0.6465398 -0.85876258 -0.57531700 -0.6518818 0.71023829
#> [9,] 0.65281131 -0.5720061 -0.58424406 -0.37149026 -0.4383711 0.72149969
#> [10,] 0.78964286 -0.8189555 -0.72716848 -0.83205179 -0.9060374 0.81455129
#>
#> [[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.97031139 -0.8079006 -0.9771206 -0.8464584 -0.9879185 0.8665682
#> [2,] 0.67348203 -0.8660952 -0.9317913 -0.8257367 -0.7985455 0.9460790
#> [3,] 0.85472077 -0.7931412 -0.6899291 -0.8604698 -0.5012591 0.6572865
#> [4,] -0.37164713 0.4600520 0.1673918 -0.8769380 -0.8917049 0.8486130
#> [5,] 0.77728849 -0.7535827 -0.9051840 -0.6902513 -0.8793569 0.8321535
#> [6,] 0.04186919 0.4360326 0.3283499 -0.6963570 -0.3611567 0.5037661
#> [7,] 0.87458526 -0.9567106 -0.8479342 -0.8733797 -0.9148460 0.8936307
#> [8,] 0.44714126 0.1006944 -0.1276430 -0.5583383 -0.6390361 0.9068056
#> [9,] 0.35116922 -0.5983315 -0.5687663 -0.3453492 -0.4107975 0.8542013
#> [10,] 0.32716393 -0.6744286 -0.2681621 -0.8036969 -0.7895631 0.7249065
#>
#> [[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.14149655 -0.7679618 -0.69969452 -0.3548290 -0.2939959 0.87890378
#> [2,] -0.29477027 -0.2604345 -0.09957154 -0.2631221 -0.6933381 0.43984673
#> [3,] 0.63332782 -0.3069405 -0.42021756 -0.5493297 -0.5730417 0.85165506
#> [4,] 0.90468051 -0.9012129 0.55535228 -0.8640272 0.5413524 -0.51718608
#> [5,] -0.45313984 -0.5711340 0.41615918 0.7657926 -0.8370803 -0.62156235
#> [6,] -0.13198317 0.4763816 0.26704604 -0.7106730 -0.6216942 0.74921520
#> [7,] 0.50623368 -0.8364985 -0.51178749 -0.8050010 -0.7853851 0.84240905
#> [8,] 0.01935597 -0.8213585 0.22229574 -0.2520593 -0.6491122 -0.02492421
#> [9,] 0.88781055 -0.8753648 -0.64517393 -0.9252473 -0.5562392 0.44160347
#> [10,] 0.88816282 -0.1381982 -0.24510683 -0.3008385 -0.4074488 0.58953572
#>
#> attr(,"class")
#> [1] "mcmc.list"
#>