[R] 12th Root of a Square (Transition) Matrix
David Winsemius
dwinsemius at comcast.net
Fri Nov 4 20:32:46 CET 2011
On Nov 4, 2011, at 6:34 AM, clangkamp wrote:
> I have tried this method, but the result is not working, at least
> not as I
> expect:
> I used the CreditMetrics package transition matrix
> rc <- c("AAA", "AA", "A", "BBB", "BB", "B", "CCC", "D")
> M <- matrix(c(90.81, 8.33, 0.68, 0.06, 0.08, 0.02, 0.01, 0.01,
> 0.70, 90.65, 7.79, 0.64, 0.06, 0.13, 0.02, 0.01,
> 0.09, 2.27, 91.05, 5.52, 0.74, 0.26, 0.01, 0.06,
> 0.02, 0.33, 5.95, 85.93, 5.30, 1.17, 1.12, 0.18,
> 0.03, 0.14, 0.67, 7.73, 80.53, 8.84, 1.00, 1.06,
> 0.01, 0.11, 0.24, 0.43, 6.48, 83.46, 4.07, 5.20,
> 0.21, 0, 0.22, 1.30, 2.38, 11.24, 64.86, 19.79,
> 0, 0, 0, 0, 0, 0, 0, 100
> )/100, 8, 8, dimnames = list(rc, rc), byrow = TRUE)
>
> then followed through with the steps:
>
> nth_root <- X %*% L_star %*% X_inv
Despite my (distant) physics training, I am no matrix mechanic, so I
cannot comment on that method. I would instead search for an nth-root
matrix function ::::
http://search.r-project.org/cgi-bin/namazu.cgi?query=nth+root+of+matrix&max=100&result=normal&sort=score&idxname=functions&idxname=vignettes&idxname=views
And finding one in package 'pracma', see if it succeeds:
> nthroot(M, 12)
AAA AA A BBB BB B
CCC D
AAA 0.9919988 0.8129311 0.6597444 0.5389055 0.5519810 0.4917592
0.4641589 0.4641589
AA 0.6613401 0.9918530 0.8084034 0.6564198 0.5389055 0.5747716
0.4917592 0.4641589
A 0.5574256 0.7294611 0.9922170 0.7855279 0.6644097 0.6089493
0.4641589 0.5389055
BBB 0.4917592 0.6211686 0.7904537 0.9874431 0.7828700 0.6902644
0.6877567 0.5905718
BB 0.5086590 0.5783322 0.6589304 0.8078827 0.9821168 0.8169667
0.6812921 0.6846083
B 0.4641589 0.5668255 0.6049010 0.6350224 0.7960944 0.9850460
0.7658309 0.7816283
CCC 0.5982072 0.0000000 0.6005307 0.6963517 0.7323434 0.8334839
0.9645648 0.8737164
D 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
0.0000000 1.0000000
> nthroot(M, 12)^12
AAA AA A BBB BB B CCC D
AAA 0.9081 0.0833 0.0068 0.0006 0.0008 0.0002 0.0001 0.0001
AA 0.0070 0.9065 0.0779 0.0064 0.0006 0.0013 0.0002 0.0001
A 0.0009 0.0227 0.9105 0.0552 0.0074 0.0026 0.0001 0.0006
BBB 0.0002 0.0033 0.0595 0.8593 0.0530 0.0117 0.0112 0.0018
BB 0.0003 0.0014 0.0067 0.0773 0.8053 0.0884 0.0100 0.0106
B 0.0001 0.0011 0.0024 0.0043 0.0648 0.8346 0.0407 0.0520
CCC 0.0021 0.0000 0.0022 0.0130 0.0238 0.1124 0.6486 0.1979
D 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000
> all.equal(M , nthroot(M, 12)^12)
[1] TRUE
Success!
--
David.
>
> But the check (going back 12 to the power again) doesn't yield the
> original
> matrix. Now some rounding errors can be expected, but I didn't
> expect a
> perfectly diagonal matrix, when the initial matrix isn't diagonal at
> all.
>> round(nth_root^12,4)
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
> [1,] 0.9078 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0
> [2,] 0.0000 0.9053 0.0000 0.0000 0.0000 0.0000 0.0000 0
> [3,] 0.0000 0.0000 0.9079 0.0000 0.0000 0.0000 0.0000 0
> [4,] 0.0000 0.0000 0.0000 0.8553 0.0000 0.0000 0.0000 0
> [5,] 0.0000 0.0000 0.0000 0.0000 0.7998 0.0000 0.0000 0
> [6,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.8285 0.0000 0
> [7,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.6457 0
> [8,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1
>
> Any takers
>
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list