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.98781558 -0.5534824 0.08334546 0.19148061 0.1375382 -0.11094620
#> B -0.55348242 0.9686563 -0.14299572 0.18787699 -0.1219701 0.23746372
#> C 0.08334546 -0.1429957 0.67967548 -0.18595532 -0.2826511 -0.14953181
#> D 0.19148061 0.1878770 -0.18595532 0.56012316 -0.1795982 -0.07988064
#> E 0.13753823 -0.1219701 -0.28265113 -0.17959817 0.8398531 -0.10484129
#> F -0.11094620 0.2374637 -0.14953181 -0.07988064 -0.1048413 0.81940281
pooledS(Slist, ns, mle = FALSE)
#> A B C D E F
#> A 0.98043162 -0.5545315 0.09896553 0.18275436 0.1238815 -0.11460308
#> B -0.55453145 0.9833678 -0.15149003 0.20111246 -0.1243012 0.24633170
#> C 0.09896553 -0.1514900 0.67986660 -0.18536884 -0.2717182 -0.15816782
#> D 0.18275436 0.2011125 -0.18536884 0.55428072 -0.1774696 -0.08502704
#> E 0.12388147 -0.1243012 -0.27171820 -0.17746963 0.8223110 -0.10327135
#> F -0.11460308 0.2463317 -0.15816782 -0.08502704 -0.1032713 0.85615571
# 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 1.12907163 -0.35809039 -0.19077364 0.42570103 0.30955619 -0.06042531
#> B -0.35809039 0.76352623 0.05681732 0.00666387 -0.04464695 0.13971259
#> C -0.19077364 0.05681732 0.73698155 -0.21618970 -0.31144257 -0.05882939
#> D 0.42570103 0.00666387 -0.21618970 0.56467476 -0.20547428 0.03953855
#> E 0.30955619 -0.04464695 -0.31144257 -0.20547428 1.10955272 -0.11280566
#> F -0.06042531 0.13971259 -0.05882939 0.03953855 -0.11280566 0.12794560
pooledS(Slist, ns, subset = ns > 5) # Pool studies with sample size > 5
#> A B C D E F
#> A 0.94332756 -0.4971871 0.1862752 0.1629362 0.02338639 -0.13992002
#> B -0.49718708 1.0845425 -0.1808464 0.2933283 -0.12432596 0.31656942
#> C 0.18627523 -0.1808464 0.7025991 -0.1892130 -0.15236753 -0.22817257
#> D 0.16293615 0.2933283 -0.1892130 0.4866317 -0.16147267 -0.10339891
#> E 0.02338639 -0.1243260 -0.1523675 -0.1614727 0.71063248 -0.08750066
#> F -0.13992002 0.3165694 -0.2281726 -0.1033989 -0.08750066 1.04499118
# 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 7.961655 -23.09424 23.29697 -20.84027 25.14375 31.62838
#> B -23.094241 102.98163 -108.08421 93.12652 -105.18271 -141.81541
#> C 23.296973 -108.08421 126.33231 -102.39062 113.25876 156.35703
#> D -20.840271 93.12652 -102.39062 89.41119 -95.31064 -133.61916
#> E 25.143753 -105.18271 113.25876 -95.31064 112.92850 145.07936
#> F 31.628381 -141.81541 156.35703 -133.61916 145.07936 210.64266