[R] Raising a matrix to the (-1/2) power.
Charles C. Berry
cberry at tajo.ucsd.edu
Sun Apr 27 19:00:34 CEST 2008
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
More information about the R-help
mailing list