s-news
[Top] [All Lists]

Re: question on cor function

To: "Data Analytics Corp." <dataanalytics@earthlink.net>
Subject: Re: question on cor function
From: David L Lorenz <lorenz@usgs.gov>
Date: Thu, 7 May 2009 10:38:39 -0500
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <4A02FB1C.2080303@earthlink.net>
References: <4A02FB1C.2080303@earthlink.net>

Walt,
  My guess is that there are missing values elsewhere in each data set, so you are getting different rows when you select only the first column in each data set.
  Try cor(na.omit(pat)[,1], na.omit(att)[,1])
Dave


From: "Data Analytics Corp." <dataanalytics@earthlink.net>
To: s-news@lists.biostat.wustl.edu
Date: 05/07/2009 10:15 AM
Subject: [S] question on cor function
Sent by: s-news-owner@lists.biostat.wustl.edu





Hi,

I'm confused about what the cor function is producing.  I have two data
frames: pat and att.  Each has 417 rows with missing data.  The first,
pat, has 4 columns; att has 30.  I want the correlations between each
column of pat with each column of att.  My results should be a 30 by 4
matrix.  I used at first

t(cor(pat, att, na.method = "omit"))

and got my 30X4 matrix.  The first cell, which should be for the
correlation between pat[, 1] and att[, 1] is -0.24399252  But then, just
for a check, I did cor(pat[, 1], att[, 1], na.method = "omit") and got a
different answer!  I got 0.001174417.  What's going on???  According to
the Help file, the answer for my first statement with the transpose
should be "a matrix such that the [i,j] element is the covariance
(correlation) of x[,i] and either y[,j] or x[,j]. "  So the [1,1] answer
should be the correlation between pat[, 1] and att[, 1] - but it's not.  
What am I missing?? Am I just not seeing the obvious??   I'm using S+8.0
on a Vista machine.

Thanks,

Walt



--
________________________

Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536
________________________
(V) 609-936-8999
(F) 609-936-3733
dataanalytics@earthlink.net
www.dataanalyticscorp.com

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news


<Prev in Thread] Current Thread [Next in Thread>