[R] Raising a matrix to the (-1/2) power.

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Apr 28 01:56:01 CEST 2008


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.



More information about the R-help mailing list