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
TRUEparameters will be mapped back to the cells of the experimental design using the design matrices. Otherwise the sampled parameters are returned. Only works forselection = muorselection = alpha.- add_recalculated
Boolean. If
TRUEwill 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
TRUEfor selections that include subject parameters (e.g.alpha), plot/stats are organized by subject, otherwise by parameter.- return_mcmc
Boolean. If
TRUEreturns an mcmc.list object, otherwise a matrix/array with the parameter type.- merge_chains
Boolean. If
TRUEreturns 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
FALSEfor 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
TRUEremoves duplicate values from the samples. Automatically set toTRUEifflatten = TRUE- remove_constants
Boolean. If
TRUEremoves 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 = TRUEand 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_parameterscan 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
plotfor 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_lMFALSE m_lMTRUE s t0
#> [1,] -0.6937074 -1.261873 0.5967690 0.2035805
#> [2,] -0.6837835 -1.208066 0.5806074 0.1929428
#> [3,] -0.7032869 -1.244045 0.5889311 0.1954557
#> [4,] -0.7156402 -1.268085 0.5947269 0.2023890
#> [5,] -0.7128273 -1.269819 0.6077364 0.2062804
#> [6,] -0.6752838 -1.202673 0.5720401 0.1855074
#> [7,] -0.6658296 -1.231175 0.5930388 0.1927474
#> [8,] -0.7068141 -1.234489 0.5942607 0.1931034
#> [9,] -0.7089803 -1.249469 0.5843531 0.2002257
#> [10,] -0.6534510 -1.188619 0.5721255 0.1821459
#> [11,] -0.6938596 -1.238013 0.5988642 0.1978446
#> [12,] -0.7024917 -1.253944 0.5820750 0.1936223
#> [13,] -0.7179961 -1.221744 0.5793001 0.1960401
#> [14,] -0.6968079 -1.226207 0.5746676 0.1911691
#> [15,] -0.6782162 -1.186353 0.5853018 0.1822496
#> [16,] -0.6881154 -1.179852 0.5640123 0.1820923
#> [17,] -0.6869742 -1.223431 0.6102557 0.1971488
#> [18,] -0.7016255 -1.215240 0.5815923 0.1887973
#> [19,] -0.6834792 -1.237660 0.5941110 0.1948877
#> [20,] -0.7211161 -1.229649 0.5893507 0.1948774
#> [21,] -0.7354103 -1.212540 0.6065229 0.1951934
#> [22,] -0.7034326 -1.237525 0.5816087 0.1940623
#> [23,] -0.7226265 -1.230618 0.5713501 0.1882809
#> [24,] -0.7092905 -1.174272 0.5583626 0.1831627
#> [25,] -0.6909877 -1.179852 0.5617443 0.1743750
#> [26,] -0.7314921 -1.249218 0.6000737 0.1986381
#> [27,] -0.7371862 -1.207763 0.5729587 0.1899698
#> [28,] -0.6851206 -1.258731 0.6006532 0.1956958
#> [29,] -0.7002711 -1.209433 0.5698207 0.1884210
#> [30,] -0.7158703 -1.239049 0.6107395 0.1980347
#> [31,] -0.7486052 -1.245834 0.5823222 0.2004337
#> [32,] -0.7449802 -1.213600 0.5731348 0.1944033
#> [33,] -0.7286414 -1.306997 0.6050682 0.2034429
#> [34,] -0.6777175 -1.218268 0.5915888 0.1954768
#> [35,] -0.6795627 -1.237744 0.5943980 0.1965913
#> [36,] -0.6961628 -1.261136 0.5983252 0.2005975
#> [37,] -0.7177071 -1.242914 0.6020886 0.1988354
#> [38,] -0.7101093 -1.222228 0.5711783 0.1886777
#> [39,] -0.6810068 -1.245589 0.6093494 0.1988327
#> [40,] -0.7514807 -1.239256 0.5963858 0.2011185
#> [41,] -0.7471643 -1.254590 0.5869238 0.1959565
#> [42,] -0.7235961 -1.267195 0.5831425 0.2003266
#> [43,] -0.6879244 -1.233251 0.6017389 0.1929547
#> [44,] -0.7451185 -1.238998 0.5855902 0.2006685
#> [45,] -0.7222584 -1.179668 0.5587499 0.1765217
#> [46,] -0.6976791 -1.238178 0.5874365 0.1900977
#> [47,] -0.7045851 -1.220465 0.5653750 0.1896306
#> [48,] -0.7650919 -1.263445 0.5942845 0.2053468
#> [49,] -0.6858591 -1.250131 0.6261243 0.2011719
#> [50,] -0.6902581 -1.218855 0.5472478 0.1803648
#>
#> [[2]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMFALSE m_lMTRUE s t0
#> [1,] -0.7108250 -1.272743 0.6065678 0.2006626
#> [2,] -0.7305644 -1.212768 0.5764193 0.1868570
#> [3,] -0.6861798 -1.200343 0.5554562 0.1822752
#> [4,] -0.6562984 -1.148537 0.5597145 0.1780572
#> [5,] -0.7242438 -1.247031 0.5907488 0.1944682
#> [6,] -0.6984970 -1.240390 0.6022001 0.1977499
#> [7,] -0.6984494 -1.235358 0.5861201 0.1938389
#> [8,] -0.6802532 -1.221167 0.5842821 0.1910767
#> [9,] -0.6952965 -1.194410 0.5693456 0.1886901
#> [10,] -0.7099271 -1.203537 0.5546907 0.1889772
#> [11,] -0.7139524 -1.205274 0.5406871 0.1865492
#> [12,] -0.7530878 -1.253714 0.6106048 0.2018113
#> [13,] -0.7143715 -1.259832 0.6166018 0.2044722
#> [14,] -0.7108664 -1.269340 0.6188859 0.2028187
#> [15,] -0.6737171 -1.212217 0.5777267 0.1819353
#> [16,] -0.6725689 -1.214488 0.5610210 0.1886513
#> [17,] -0.6751460 -1.181408 0.5722199 0.1833590
#> [18,] -0.6933819 -1.212669 0.5587832 0.1889791
#> [19,] -0.6964849 -1.211050 0.5527698 0.1801412
#> [20,] -0.7250139 -1.212226 0.5807470 0.1913505
#> [21,] -0.7137828 -1.232188 0.6099002 0.1963669
#> [22,] -0.7126522 -1.233609 0.5981594 0.2015839
#> [23,] -0.7173131 -1.214821 0.5693447 0.1885640
#> [24,] -0.6976412 -1.246633 0.5865030 0.1928977
#> [25,] -0.6855860 -1.212346 0.5663770 0.1792266
#> [26,] -0.6848367 -1.263591 0.6162259 0.1960655
#> [27,] -0.7000051 -1.201189 0.5666755 0.1856122
#> [28,] -0.7048056 -1.247993 0.5860899 0.1981103
#> [29,] -0.6735296 -1.219301 0.5783853 0.1918409
#> [30,] -0.7041821 -1.224739 0.5624781 0.1925944
#> [31,] -0.6879703 -1.176537 0.5922783 0.1829574
#> [32,] -0.7015596 -1.225985 0.6022888 0.1883082
#> [33,] -0.7113303 -1.186098 0.5684854 0.1813698
#> [34,] -0.6931098 -1.171785 0.5554645 0.1780372
#> [35,] -0.6784804 -1.259339 0.6152325 0.2034388
#> [36,] -0.7100140 -1.224787 0.6033962 0.1984401
#> [37,] -0.7210589 -1.260996 0.6062016 0.2014078
#> [38,] -0.6882450 -1.192611 0.5677018 0.1781674
#> [39,] -0.7116972 -1.244715 0.5834305 0.1958156
#> [40,] -0.7019193 -1.232307 0.5915866 0.1972216
#> [41,] -0.6920956 -1.147064 0.5551532 0.1791662
#> [42,] -0.6549979 -1.201924 0.5681591 0.1845000
#> [43,] -0.7346968 -1.245950 0.6208460 0.2004060
#> [44,] -0.6957814 -1.240569 0.5830975 0.1950392
#> [45,] -0.7175142 -1.268823 0.6203409 0.2019336
#> [46,] -0.6745873 -1.221676 0.5801757 0.1862511
#> [47,] -0.7087072 -1.241601 0.6011106 0.1999040
#> [48,] -0.7438918 -1.248331 0.5856863 0.2000360
#> [49,] -0.6932679 -1.212201 0.5709087 0.1870179
#> [50,] -0.6853319 -1.159803 0.5551370 0.1794044
#>
#> [[3]]
#> Markov Chain Monte Carlo (MCMC) output:
#> Start = 1
#> End = 50
#> Thinning interval = 1
#> m_lMFALSE m_lMTRUE s t0
#> [1,] -0.6980027 -1.193954 0.5578647 0.1848045
#> [2,] -0.6905133 -1.202994 0.5742652 0.1840583
#> [3,] -0.7176547 -1.199108 0.5588409 0.1853183
#> [4,] -0.7132144 -1.211761 0.5545588 0.1905521
#> [5,] -0.7277258 -1.206845 0.5845871 0.1935976
#> [6,] -0.6729147 -1.233556 0.6074722 0.1996313
#> [7,] -0.7134757 -1.239247 0.5674351 0.1920402
#> [8,] -0.6909631 -1.235491 0.6090291 0.1929363
#> [9,] -0.6973701 -1.193849 0.5784691 0.1816082
#> [10,] -0.7414503 -1.266162 0.6165291 0.2064437
#> [11,] -0.6877004 -1.206747 0.5586950 0.1864027
#> [12,] -0.6953645 -1.193286 0.5695796 0.1819363
#> [13,] -0.6863437 -1.198617 0.5616489 0.1826754
#> [14,] -0.7428372 -1.248149 0.5662471 0.1966820
#> [15,] -0.7259579 -1.259806 0.5972899 0.1973183
#> [16,] -0.6719086 -1.249133 0.6125440 0.2016624
#> [17,] -0.6782051 -1.198887 0.5701002 0.1891554
#> [18,] -0.6716843 -1.229755 0.5782770 0.1878326
#> [19,] -0.7062093 -1.169420 0.5592610 0.1810550
#> [20,] -0.6967348 -1.171796 0.5571947 0.1775232
#> [21,] -0.6906187 -1.209106 0.5809366 0.1886724
#> [22,] -0.7274479 -1.291071 0.6080417 0.2076627
#> [23,] -0.7064975 -1.247767 0.5688869 0.1969054
#> [24,] -0.6918072 -1.236992 0.5979697 0.1922560
#> [25,] -0.7001467 -1.248215 0.5843129 0.1971156
#> [26,] -0.7201511 -1.253556 0.5884043 0.1935452
#> [27,] -0.7190374 -1.199418 0.5616902 0.1890781
#> [28,] -0.7166702 -1.250776 0.5950026 0.2001735
#> [29,] -0.6903151 -1.217040 0.5849620 0.1797831
#> [30,] -0.7372599 -1.259630 0.5780547 0.2010400
#> [31,] -0.7195818 -1.258987 0.6072654 0.2009412
#> [32,] -0.7065699 -1.199504 0.5625187 0.1876239
#> [33,] -0.7142465 -1.215972 0.5796934 0.1923922
#> [34,] -0.7485838 -1.274720 0.6152537 0.2063058
#> [35,] -0.6844042 -1.195584 0.5633908 0.1894273
#> [36,] -0.6812509 -1.202937 0.5661957 0.1790764
#> [37,] -0.6933671 -1.231175 0.6005087 0.1887136
#> [38,] -0.6898210 -1.230119 0.5860407 0.1904618
#> [39,] -0.6961594 -1.210798 0.5850866 0.1920990
#> [40,] -0.7525775 -1.263783 0.5831080 0.2076248
#> [41,] -0.6774468 -1.198771 0.5643272 0.1859665
#> [42,] -0.7634064 -1.243282 0.5995616 0.2000908
#> [43,] -0.6639828 -1.133885 0.5336265 0.1663793
#> [44,] -0.7014677 -1.202657 0.5670398 0.1880572
#> [45,] -0.6766233 -1.173715 0.5609001 0.1761194
#> [46,] -0.6531246 -1.228800 0.6058790 0.1963162
#> [47,] -0.6480219 -1.189397 0.5737930 0.1799501
#> [48,] -0.6849164 -1.254128 0.5841736 0.1926244
#> [49,] -0.7409462 -1.261282 0.6200951 0.2070999
#> [50,] -0.6521973 -1.178427 0.5795901 0.1793761
#>
#> 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"
#>