Hi, I need to raise a correlation matrix; R; to the negative one half power. i.e. I need to find R^(-1/2) eg: if R=[{1,.4},{.4,1}], then R^(-1/2)=[{1.0681,-.2229}, {-.2229,1.0681}]where matrix=[{row1},{row2}] And are there any built in functions to do this? mtx.exp doesn't work because it's not raised to a positive integer Thank you so much. -- View this message in context: http://www.nabble.com/Raising-a-matrix-to-the-%28-1-2%29-power.-tp16923522p16923522.html Sent from the R help mailing list archive at Nabble.com.
On Sun, 27 Apr 2008, jmrossbach wrote:> > Hi, I need to raise a correlation matrix; R; to the negative one half power. > i.e. I need to find R^(-1/2) > > eg: if R=[{1,.4},{.4,1}], then R^(-1/2)=[{1.0681,-.2229}, > {-.2229,1.0681}]where matrix=[{row1},{row2}] > > > And are there any built in functions to do this? mtx.exp doesn't work > because it's not raised to a positive integer?eigen as in emat <- eigen( R ) emat$vectors %*%diag(emat$values^(-1/2)) %*% t(emat$vectors) Or if you do not need a symmetric result ?chol ?backsolve The usual advice given to a question along these lines (inverting a matrix) is to be sure you really needed to do it explicitly. If you are solving a system of equations there are often better methods to do it involving matrix decompositions. HTH, Chuck> > Thank you so much. > -- > View this message in context: http://www.nabble.com/Raising-a-matrix-to-the-%28-1-2%29-power.-tp16923522p16923522.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
This is probably as good a way as any way for this kind of problem. First define a binary operator:> "%^%" <- function(x, n)with(eigen(x), vectors %*% (values^n * t(vectors))) Your toy example then becomes> m <- matrix(c(1, 0.4, 0.4, 1), nrow = 2) > m[,1] [,2] [1,] 1.0 0.4 [2,] 0.4 1.0> m %^% (-0.5)[,1] [,2] [1,] 1.0680744 -0.2229201 [2,] -0.2229201 1.0680744 Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:Bill.Venables at csiro.au http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of jmrossbach Sent: Sunday, 27 April 2008 11:05 PM To: r-help at r-project.org Subject: [R] Raising a matrix to the (-1/2) power. Hi, I need to raise a correlation matrix; R; to the negative one half power. i.e. I need to find R^(-1/2) eg: if R=[{1,.4},{.4,1}], then R^(-1/2)=[{1.0681,-.2229}, {-.2229,1.0681}]where matrix=[{row1},{row2}] And are there any built in functions to do this? mtx.exp doesn't work because it's not raised to a positive integer Thank you so much. -- View this message in context: http://www.nabble.com/Raising-a-matrix-to-the-%28-1-2%29-power.-tp169235 22p16923522.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.