Compute the pooled covariance or precision matrix estimate from a list
of covariance matrices or precision matrices.
A list
of length \(G\) of numeric
covariance
matrices of the same size.
A numeric
vector for length \(G\) giving the sample sizes
in the corresponding entries of Slist
logical
vector of the same length as Slist
giving
the classes to pool. Default is all classes.
logical
. If TRUE
, the (biased) MLE is given. If
FALSE
, the biased corrected estimate is given. Default is
TRUE
.
A list
of length \(G\) of invertible numeric
precision matrices of the same size.
pooledS
returns the pooled covariance matrix, that is a
numeric
matrix with the same size as the elements of Slist
.
Similarly, pooledP
returns the pooled precision matrix, i.e. a
numeric
matrix with the same size as the elements of Plist
.
When mle
is FALSE
the given covariance/precision matrices is
assumed to have been computed using the denominator ns[i] - 1
. Hence,
the sum of all ns
minus \(G\) is used a the denominator of the
pooled estimate. Conversely, when mle
is TRUE
the total sum of
the sample sizes ns
is used as the denominator in the pooled estimate.
The function pooledP
is equivalent to a wrapper for pooledS
.
That is, it inverts all the precision matrices in Plist
, applies
pooledS
, and inverts the resulting matrix.
ns <- c(4, 6, 8)
Slist <- createS(ns, p = 6)
pooledS(Slist, ns)
#> A B C D E F
#> A 0.86989140 -0.3297835 0.08920894 0.1366720 0.1869922 -0.1968171
#> B -0.32978352 0.9138706 -0.44135587 0.3090903 -0.1584364 0.2056258
#> C 0.08920894 -0.4413559 0.73697128 -0.1620565 -0.3563228 -0.1413516
#> D 0.13667202 0.3090903 -0.16205654 0.5613611 -0.1043477 -0.1102288
#> E 0.18699224 -0.1584364 -0.35632281 -0.1043477 0.8518057 -0.2399880
#> F -0.19681706 0.2056258 -0.14135163 -0.1102288 -0.2399880 0.8871244
pooledS(Slist, ns, mle = FALSE)
#> A B C D E F
#> A 0.8836116 -0.3458551 0.1007218 0.14137761 0.17893532 -0.2018550
#> B -0.3458551 0.9257781 -0.4365946 0.31924614 -0.16279716 0.2144874
#> C 0.1007218 -0.4365946 0.7294518 -0.17024071 -0.34716582 -0.1487366
#> D 0.1413776 0.3192461 -0.1702407 0.56104952 -0.09982845 -0.1134843
#> E 0.1789353 -0.1627972 -0.3471658 -0.09982845 0.83575132 -0.2403261
#> F -0.2018550 0.2144874 -0.1487366 -0.11348428 -0.24032610 0.9251927
# Pool the first two classes only, leave out the remaning
pooledS(Slist, ns, subset = c(TRUE, TRUE, FALSE))
#> A B C D E F
#> A 0.91739452 0.05219749 -0.21077840 0.32409531 0.39384577 -0.16884561
#> B 0.05219749 0.64598753 -0.44642461 0.22046003 -0.09114574 0.02270576
#> C -0.21077840 -0.44642461 0.85797324 -0.14352016 -0.49206156 -0.03951128
#> D 0.32409531 0.22046003 -0.14352016 0.57196653 -0.06943747 -0.05737787
#> E 0.39384577 -0.09114574 -0.49206156 -0.06943747 1.11414803 -0.27766912
#> F -0.16884561 0.02270576 -0.03951128 -0.05737787 -0.27766912 0.19461117
pooledS(Slist, ns, subset = ns > 5) # Pool studies with sample size > 5
#> A B C D E F
#> A 1.0632589 -0.3999969 0.1300936 0.26410935 0.15727963 -0.2516008
#> B -0.3999969 0.9712945 -0.3819496 0.40801200 -0.19047057 0.2542324
#> C 0.1300936 -0.3819496 0.6835067 -0.26066152 -0.28706825 -0.1999300
#> D 0.2641093 0.4080120 -0.2606615 0.56114329 -0.03377479 -0.1332098
#> E 0.1572796 -0.1904706 -0.2870682 -0.03377479 0.73908565 -0.2577921
#> F -0.2516008 0.2542324 -0.1999300 -0.13320984 -0.25779206 1.1292485
# Pooled precision matrices
ns <- c(7, 8, 9)
Plist <- lapply(createS(ns, p = 6), solve)
pooledS(Plist, ns)
#> A B C D E F
#> A 2.663008 -10.77858 6.236063 -4.329388 6.875685 11.82840
#> B -10.778583 219.25443 -127.640235 61.702027 -133.231662 -188.88071
#> C 6.236063 -127.64024 81.705584 -37.371541 78.943385 113.38607
#> D -4.329388 61.70203 -37.371541 22.965118 -37.562869 -57.35836
#> E 6.875685 -133.23166 78.943385 -37.562869 83.388285 115.98320
#> F 11.828401 -188.88071 113.386067 -57.358362 115.983201 175.66281