mpower: Compute the Power of a Real Symmetric Matrix

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/mpower.R

Description

mpower computes m^alpha, i.e. the alpha-th power of the real symmetric matrix m.

Usage

1
mpower(m, alpha, pseudo=FALSE, tol)

Arguments

m

a real-valued symmetric matrix.

alpha

exponent.

pseudo

if pseudo=TRUE then all zero eigenvalues are dropped (e.g. for computing the pseudoinverse). The default is to use all eigenvalues.

tol

tolerance - eigenvalues with absolute value smaller or equal to tol are considered identically zero (default: tol = max(dim(m))*max(abs(eval))*.Machine$double.eps).

Details

The matrix power of m is obtained by first computing the spectral decomposition of m, and subsequent modification of the resulting eigenvalues.

Note that m is assumed to by symmetric, and only its lower triangle (diagonal included) is used in eigen.

For computing the matrix power of cor.shrink use the vastly more efficient function powcor.shrink.

Value

mpower returns a matrix of the same dimensions as m.

Author(s)

Korbinian Strimmer (https://strimmerlab.github.io).

See Also

powcor.shrink, eigen.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# load corpcor library
library("corpcor")

# generate symmetric matrix
p = 10
n = 20
X = matrix(rnorm(n*p), nrow = n, ncol = p)
m = cor(X)

m %*% m
mpower(m, 2)

solve(m)
mpower(m, -1)

msq = mpower(m, 0.5)
msq %*% msq
m

mpower(m, 1.234)

Example output

             [,1]       [,2]       [,3]        [,4]       [,5]        [,6]
 [1,]  1.40352992  0.9932183 -0.2656967 -0.36188771 -0.6488742 -0.31097499
 [2,]  0.99321828  1.8093366 -0.6693219 -0.60294304 -0.6099213 -0.54080690
 [3,] -0.26569666 -0.6693219  1.6183805  1.23991928 -0.4199607 -0.12644279
 [4,] -0.36188771 -0.6029430  1.2399193  1.49405920 -0.1272488  0.09793054
 [5,] -0.64887424 -0.6099213 -0.4199607 -0.12724878  1.3514692 -0.19440061
 [6,] -0.31097499 -0.5408069 -0.1264428  0.09793054 -0.1944006  1.34477836
 [7,]  0.02265809  0.9978720 -0.8292401 -0.78687673 -0.3972817  0.23814360
 [8,]  0.04404609  0.5836150  0.1312320 -0.37071764 -0.3960206 -0.63898830
 [9,] -0.11542231  0.4742612 -0.1574868 -0.03130882 -0.2243596 -0.55105859
[10,] -0.32047972 -1.1396375 -0.1290195  0.09604356  0.4253231  0.54058729
             [,7]        [,8]        [,9]       [,10]
 [1,]  0.02265809  0.04404609 -0.11542231 -0.32047972
 [2,]  0.99787197  0.58361496  0.47426116 -1.13963748
 [3,] -0.82924012  0.13123201 -0.15748678 -0.12901950
 [4,] -0.78687673 -0.37071764 -0.03130882  0.09604356
 [5,] -0.39728165 -0.39602061 -0.22435961  0.42532314
 [6,]  0.23814360 -0.63898830 -0.55105859  0.54058729
 [7,]  1.53523567  0.32666012  0.45381655 -0.67778368
 [8,]  0.32666012  1.28767604  0.46516620 -0.66846279
 [9,]  0.45381655  0.46516620  1.20454996 -0.27887359
[10,] -0.67778368 -0.66846279 -0.27887359  1.43231473
             [,1]       [,2]       [,3]        [,4]       [,5]        [,6]
 [1,]  1.40352992  0.9932183 -0.2656967 -0.36188771 -0.6488742 -0.31097499
 [2,]  0.99321828  1.8093366 -0.6693219 -0.60294304 -0.6099213 -0.54080690
 [3,] -0.26569666 -0.6693219  1.6183805  1.23991928 -0.4199607 -0.12644279
 [4,] -0.36188771 -0.6029430  1.2399193  1.49405920 -0.1272488  0.09793054
 [5,] -0.64887424 -0.6099213 -0.4199607 -0.12724878  1.3514692 -0.19440061
 [6,] -0.31097499 -0.5408069 -0.1264428  0.09793054 -0.1944006  1.34477836
 [7,]  0.02265809  0.9978720 -0.8292401 -0.78687673 -0.3972817  0.23814360
 [8,]  0.04404609  0.5836150  0.1312320 -0.37071764 -0.3960206 -0.63898830
 [9,] -0.11542231  0.4742612 -0.1574868 -0.03130882 -0.2243596 -0.55105859
[10,] -0.32047972 -1.1396375 -0.1290195  0.09604356  0.4253231  0.54058729
             [,7]        [,8]        [,9]       [,10]
 [1,]  0.02265809  0.04404609 -0.11542231 -0.32047972
 [2,]  0.99787197  0.58361496  0.47426116 -1.13963748
 [3,] -0.82924012  0.13123201 -0.15748678 -0.12901950
 [4,] -0.78687673 -0.37071764 -0.03130882  0.09604356
 [5,] -0.39728165 -0.39602061 -0.22435961  0.42532314
 [6,]  0.23814360 -0.63898830 -0.55105859  0.54058729
 [7,]  1.53523567  0.32666012  0.45381655 -0.67778368
 [8,]  0.32666012  1.28767604  0.46516620 -0.66846279
 [9,]  0.45381655  0.46516620  1.20454996 -0.27887359
[10,] -0.67778368 -0.66846279 -0.27887359  1.43231473
             [,1]        [,2]        [,3]        [,4]        [,5]       [,6]
 [1,]  2.15362678 -1.26787668 -0.08445574  0.63341006  0.84636349  0.3137123
 [2,] -1.26787668  2.81657406  1.23129505 -0.94286805  0.16085694  0.4380385
 [3,] -0.08445574  1.23129505  2.59608459 -1.37989210  0.85334177  0.5967004
 [4,]  0.63341006 -0.94286805 -1.37989210  2.16689788 -0.06715141 -0.4153257
 [5,]  0.84636349  0.16085694  0.85334177 -0.06715141  1.84506308  0.7123221
 [6,]  0.31371232  0.43803851  0.59670042 -0.41532565  0.71232212  1.7368730
 [7,]  0.82972760 -0.89424967  0.05555347  0.73923339  0.39889118 -0.4742407
 [8,]  0.59486183 -0.51564943 -0.42500556  0.68301622  0.37001742  0.2663466
 [9,]  0.31572604  0.01490004  0.45786373 -0.41628070  0.43041330  0.6529230
[10,] -0.25450270  0.93011149  0.62810133 -0.12291011  0.10256346 -0.1918883
             [,7]        [,8]        [,9]       [,10]
 [1,]  0.82972760  0.59486183  0.31572604 -0.25450270
 [2,] -0.89424967 -0.51564943  0.01490004  0.93011149
 [3,]  0.05555347 -0.42500556  0.45786373  0.62810133
 [4,]  0.73923339  0.68301622 -0.41628070 -0.12291011
 [5,]  0.39889118  0.37001742  0.43041330  0.10256346
 [6,] -0.47424067  0.26634661  0.65292297 -0.19188830
 [7,]  1.97064510  0.29924794 -0.31141671  0.30853807
 [8,]  0.29924794  1.47985073 -0.11573731  0.07335763
 [9,] -0.31141671 -0.11573731  1.40473365 -0.17178753
[10,]  0.30853807  0.07335763 -0.17178753  1.63485763
             [,1]        [,2]        [,3]        [,4]        [,5]       [,6]
 [1,]  2.15362678 -1.26787668 -0.08445574  0.63341006  0.84636349  0.3137123
 [2,] -1.26787668  2.81657406  1.23129505 -0.94286805  0.16085694  0.4380385
 [3,] -0.08445574  1.23129505  2.59608459 -1.37989210  0.85334177  0.5967004
 [4,]  0.63341006 -0.94286805 -1.37989210  2.16689788 -0.06715141 -0.4153257
 [5,]  0.84636349  0.16085694  0.85334177 -0.06715141  1.84506308  0.7123221
 [6,]  0.31371232  0.43803851  0.59670042 -0.41532565  0.71232212  1.7368730
 [7,]  0.82972760 -0.89424967  0.05555347  0.73923339  0.39889118 -0.4742407
 [8,]  0.59486183 -0.51564943 -0.42500556  0.68301622  0.37001742  0.2663466
 [9,]  0.31572604  0.01490004  0.45786373 -0.41628070  0.43041330  0.6529230
[10,] -0.25450270  0.93011149  0.62810133 -0.12291011  0.10256346 -0.1918883
             [,7]        [,8]        [,9]       [,10]
 [1,]  0.82972760  0.59486183  0.31572604 -0.25450270
 [2,] -0.89424967 -0.51564943  0.01490004  0.93011149
 [3,]  0.05555347 -0.42500556  0.45786373  0.62810133
 [4,]  0.73923339  0.68301622 -0.41628070 -0.12291011
 [5,]  0.39889118  0.37001742  0.43041330  0.10256346
 [6,] -0.47424067  0.26634661  0.65292297 -0.19188830
 [7,]  1.97064510  0.29924794 -0.31141671  0.30853807
 [8,]  0.29924794  1.47985073 -0.11573731  0.07335763
 [9,] -0.31141671 -0.11573731  1.40473365 -0.17178753
[10,]  0.30853807  0.07335763 -0.17178753  1.63485763
             [,1]       [,2]        [,3]        [,4]        [,5]        [,6]
 [1,]  1.00000000  0.4486604 -0.09686933 -0.15800400 -0.33070739 -0.14807855
 [2,]  0.44866041  1.0000000 -0.29611204 -0.11528113 -0.20834267 -0.20804491
 [3,] -0.09686933 -0.2961120  1.00000000  0.55513930 -0.26292910 -0.09444219
 [4,] -0.15800400 -0.1152811  0.55513930  1.00000000 -0.06522868  0.05670680
 [5,] -0.33070739 -0.2083427 -0.26292910 -0.06522868  1.00000000 -0.18861338
 [6,] -0.14807855 -0.2080449 -0.09444219  0.05670680 -0.18861338  1.00000000
 [7,] -0.12237467  0.3781663 -0.30860331 -0.30715549 -0.17939375  0.19214896
 [8,] -0.07260952  0.1845497  0.11189448 -0.20528156 -0.17939276 -0.27015689
 [9,] -0.11463995  0.1531420 -0.08834331  0.05916911 -0.11718240 -0.27770084
[10,] -0.05657012 -0.4688904 -0.13972443 -0.01296606  0.10787963  0.21174203
             [,7]        [,8]        [,9]       [,10]
 [1,] -0.12237467 -0.07260952 -0.11463995 -0.05657012
 [2,]  0.37816629  0.18454970  0.15314196 -0.46889039
 [3,] -0.30860331  0.11189448 -0.08834331 -0.13972443
 [4,] -0.30715549 -0.20528156  0.05916911 -0.01296606
 [5,] -0.17939375 -0.17939276 -0.11718240  0.10787963
 [6,]  0.19214896 -0.27015689 -0.27770084  0.21174203
 [7,]  1.00000000  0.07091623  0.19242019 -0.27660781
 [8,]  0.07091623  1.00000000  0.16685729 -0.23589709
 [9,]  0.19242019  0.16685729  1.00000000 -0.03054996
[10,] -0.27660781 -0.23589709 -0.03054996  1.00000000
             [,1]       [,2]        [,3]        [,4]        [,5]        [,6]
 [1,]  1.00000000  0.4486604 -0.09686933 -0.15800400 -0.33070739 -0.14807855
 [2,]  0.44866041  1.0000000 -0.29611204 -0.11528113 -0.20834267 -0.20804491
 [3,] -0.09686933 -0.2961120  1.00000000  0.55513930 -0.26292910 -0.09444219
 [4,] -0.15800400 -0.1152811  0.55513930  1.00000000 -0.06522868  0.05670680
 [5,] -0.33070739 -0.2083427 -0.26292910 -0.06522868  1.00000000 -0.18861338
 [6,] -0.14807855 -0.2080449 -0.09444219  0.05670680 -0.18861338  1.00000000
 [7,] -0.12237467  0.3781663 -0.30860331 -0.30715549 -0.17939375  0.19214896
 [8,] -0.07260952  0.1845497  0.11189448 -0.20528156 -0.17939276 -0.27015689
 [9,] -0.11463995  0.1531420 -0.08834331  0.05916911 -0.11718240 -0.27770084
[10,] -0.05657012 -0.4688904 -0.13972443 -0.01296606  0.10787963  0.21174203
             [,7]        [,8]        [,9]       [,10]
 [1,] -0.12237467 -0.07260952 -0.11463995 -0.05657012
 [2,]  0.37816629  0.18454970  0.15314196 -0.46889039
 [3,] -0.30860331  0.11189448 -0.08834331 -0.13972443
 [4,] -0.30715549 -0.20528156  0.05916911 -0.01296606
 [5,] -0.17939375 -0.17939276 -0.11718240  0.10787963
 [6,]  0.19214896 -0.27015689 -0.27770084  0.21174203
 [7,]  1.00000000  0.07091623  0.19242019 -0.27660781
 [8,]  0.07091623  1.00000000  0.16685729 -0.23589709
 [9,]  0.19242019  0.16685729  1.00000000 -0.03054996
[10,] -0.27660781 -0.23589709 -0.03054996  1.00000000
             [,1]       [,2]       [,3]         [,4]        [,5]       [,6]
 [1,]  1.06431917  0.5509593 -0.1270353 -0.193329903 -0.39632452 -0.1796502
 [2,]  0.55095930  1.1154684 -0.3605890 -0.195101046 -0.27857182 -0.2668626
 [3,] -0.12703530 -0.3605890  1.0945737  0.687109000 -0.30308941 -0.1034272
 [4,] -0.19332990 -0.1951010  0.6871090  1.073006073 -0.08250179  0.0628060
 [5,] -0.39632452 -0.2785718 -0.3030894 -0.082501793  1.05509573 -0.2032888
 [6,] -0.17965023 -0.2668626 -0.1034272  0.062805998 -0.20328877  1.0533149
 [7,] -0.11110048  0.4847251 -0.4042246 -0.391210784 -0.22047722  0.2157920
 [8,] -0.06123765  0.2472957  0.1240850 -0.239705551 -0.22054219 -0.3426074
 [9,] -0.12511833  0.2076670 -0.1006925  0.050826482 -0.13731876 -0.3345636
[10,] -0.09667476 -0.5910715 -0.1489316 -0.003598428  0.15987622  0.2724613
            [,7]        [,8]        [,9]        [,10]
 [1,] -0.1111005 -0.06123765 -0.12511833 -0.096674759
 [2,]  0.4847251  0.24729572  0.20766699 -0.591071459
 [3,] -0.4042246  0.12408498 -0.10069254 -0.148931555
 [4,] -0.3912108 -0.23970555  0.05082648 -0.003598428
 [5,] -0.2204772 -0.22054219 -0.13731876  0.159876221
 [6,]  0.2157920 -0.34260737 -0.33456355  0.272461252
 [7,]  1.0769815  0.11219130  0.24158384 -0.350474406
 [8,]  0.1121913  1.04072756  0.22127679 -0.313638544
 [9,]  0.2415838  0.22127679  1.03066184 -0.066646101
[10,] -0.3504744 -0.31363854 -0.06664610  1.060220351

corpcor documentation built on Sept. 16, 2021, 5:12 p.m.

Related to mpower in corpcor...