Liviu Andronic
2011-Aug-19 18:50 UTC
[R] display only the top-right half of a correlation matrix?
Dear all Is there an easy way to display only one half (top-right or bottom-left) of a correlation matrix?> require(Hmisc) > rcorr(as.matrix(mtcars[ , 1:4]))mpg cyl disp hp mpg 1.00 -0.85 -0.85 -0.78 cyl -0.85 1.00 0.90 0.83 disp -0.85 0.90 1.00 0.79 hp -0.78 0.83 0.79 1.00 n= 32 P mpg cyl disp hp mpg 0 0 0 cyl 0 0 0 disp 0 0 0 hp 0 0 0 Since the two sides are identical, there is little value in having both displayed at the same time. Moreover, it considerably slows down the inspection of the results. Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
Peter Langfelder
2011-Aug-19 19:02 UTC
[R] display only the top-right half of a correlation matrix?
On Fri, Aug 19, 2011 at 11:50 AM, Liviu Andronic <landronimirc at gmail.com> wrote:> Dear all > Is there an easy way to display only one half (top-right or > bottom-left) of a correlation matrix? > >> require(Hmisc) >> rcorr(as.matrix(mtcars[ , 1:4])) > ? ? ? mpg ? cyl ?disp ? ?hp > mpg ? 1.00 -0.85 -0.85 -0.78 > cyl ?-0.85 ?1.00 ?0.90 ?0.83 > disp -0.85 ?0.90 ?1.00 ?0.79 > hp ? -0.78 ?0.83 ?0.79 ?1.00 >Use as.dist: here's an example.> x = matrix(rnorm(5*100), 100, 5) > as.dist(cor(x))1 2 3 4 2 -2.892981e-06 3 2.873711e-02 1.002969e-02 4 -5.803705e-02 4.022733e-02 -6.154211e-02 5 1.137083e-01 -8.065676e-02 -9.279316e-02 -8.201583e-02
Jean V Adams
2011-Aug-19 19:03 UTC
[R] display only the top-right half of a correlation matrix?
r-help-bounces@r-project.org wrote on 08/19/2011 01:50:48 PM:> [image removed] > > [R] display only the top-right half of a correlation matrix? > > Liviu Andronic > > to: > > r-help@r-project.org Help > > 08/19/2011 01:55 PM > > Sent by: > > r-help-bounces@r-project.org > > Dear all > Is there an easy way to display only one half (top-right or > bottom-left) of a correlation matrix?See ?lower.tri> > > require(Hmisc) > > rcorr(as.matrix(mtcars[ , 1:4])) > mpg cyl disp hp > mpg 1.00 -0.85 -0.85 -0.78 > cyl -0.85 1.00 0.90 0.83 > disp -0.85 0.90 1.00 0.79 > hp -0.78 0.83 0.79 1.00 > > n= 32 > > > P > mpg cyl disp hp > mpg 0 0 0 > cyl 0 0 0 > disp 0 0 0 > hp 0 0 0 > > > Since the two sides are identical, there is little value in having > both displayed at the same time. Moreover, it considerably slows down > the inspection of the results. > > Thank you > Liviu >Jean `·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º> Jean V. Adams Statistician U.S. Geological Survey Great Lakes Science Center 223 East Steinfest Road Antigo, WI 54409 USA [[alternative HTML version deleted]]