Re: [R] Correlation question

2015-02-22 Thread David L Carlson
David L. Carlson Department of Anthropology Texas AM University -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Thayn Sent: Sunday, February 22, 2015 12:01 AM To: Kehl Dániel Cc: r-help@r-project.org Subject: Re: [R] Correlation question Of course

[R] Correlation question

2015-02-21 Thread Jonathan Thayn
I recently compared two different approaches to calculating the correlation of two variables, and I cannot explain the different results: data(cars) model - lm(dist~speed,data=cars) coef(model) fitted.right - model$fitted fitted.wrong - -17+5*cars$speed When using the OLS fitted values, the

Re: [R] Correlation question

2015-02-21 Thread Kehl Dániel
#243;: Jonathan Thayn [jth...@ilstu.edu] Küldve: 2015. február 21. 22:42 To: r-help@r-project.org Tárgy: [R] Correlation question I recently compared two different approaches to calculating the correlation of two variables, and I cannot explain the different results: data(cars) model - lm(dist

Re: [R] Correlation question

2015-02-21 Thread Jonathan Thayn
-project.org Tárgy: [R] Correlation question I recently compared two different approaches to calculating the correlation of two variables, and I cannot explain the different results: data(cars) model - lm(dist~speed,data=cars) coef(model) fitted.right - model$fitted fitted.wrong - -17+5*cars

Re: [R] Correlation question

2010-09-09 Thread Dennis Murphy
Did you try taking out P7, which is text? Moreover, if you get a message saying ' the standard deviation is zero', it means that the entire column is constant. By definition, the covariance of a constant with a random variable is 0, but your data consists of values, so cor() understandably throws

Re: [R] Correlation question

2010-09-09 Thread Stephane Vaucher
Thank you Dennis, You identified a factor (text column) that I was concerned with. I simplified my example to try and factor out possible causes. I eliminated the recurring values in columns (which were not the columns that caused problems). I produced three examples with simple data sets.

Re: [R] Correlation question

2010-09-09 Thread Joshua Wiley
Hi Stephane, When I use your sample data (e.g., test, test.number), cor() throws an error that x must be numeric (because of the factor or character data). Are you not getting any errors when trying to calculate the correlation on these data? If you are not, I wonder what version of R are you

Re: [R] Correlation question

2010-09-09 Thread Stephane Vaucher
Hi Josh, Initially, I was expecting R to simply ignore non-numeric data. I guess I was wrong... I copy-pasted what I observe, and I do not get an error when calculating correlations with text data. I can also do cor(test.n$P3, test$P7) without an error. If you have a function to select only

Re: [R] Correlation question

2010-09-09 Thread Joshua Wiley
Hi Stephane, According to the NEWS file, as of 2.11.0: cor() and cov() now test for misuse with non-numeric arguments, such as the non-bug report PR#14207 so there is no need for a new bug report. Here is a simple way to select only numeric columns: # Sample data dat - data.frame(a = 1:10L, b =

Re: [R] Correlation question

2010-09-09 Thread Peter Ehlers
On 2010-09-09 11:53, Stephane Vaucher wrote: Hi Josh, Initially, I was expecting R to simply ignore non-numeric data. I guess I was wrong... I copy-pasted what I observe, and I do not get an error when The first thing to do when you get results that you don't expect is to check the help page.

Re: [R] Correlation question

2010-09-09 Thread Stephane Vaucher
Hi everyone, Thanks for the help. On Thu, 9 Sep 2010, Peter Ehlers wrote: The first thing to do when you get results that you don't expect is to check the help page. The page for cor clearly states that its input is to a *numeric* vector, matrix or data frame (my emphasis). I would not be

[R] Correlation question

2010-09-08 Thread Stephane Vaucher
Hi everyone, I'm observing what I believe is weird behaviour when attempting to do something very simple. I want a correlation matrix, but my matrix seems to contain correlation values that are not found when executed on pairs: test2$P2 [1] 2 2 4 4 1 3 2 4 3 3 2 3 4 1 2 2 4 3 4 1 2 3 2 1

Re: [R] Correlation question

2010-09-08 Thread Joshua Wiley
Hi, Does your data have missing values? I am not sure it would change anything, but perhaps try adding: cor(test2, method = spearman, use = pairwise.complete.obs) or something of the like. I am not sure what R does by default. My reasoning stems from this particular passage in the

Re: [R] Correlation question

2010-09-08 Thread Stephane Vaucher
Hi everyone, First of all, thanks for the quick responses. I appreciate the help. Before answering questions, I wanted to mention that I tested this behaviour on 2.3.1 and 2.10.1 on a x86_64 linux arch, and on version 2.9.0 on a 32 bit arch. Now for the answers (batch version): 1/ I

Re: [R] Correlation question (from a newbie)

2009-07-15 Thread Santosh
Dear R-users please ignore my most recent posting.. Found the solution.. Thanks to David Winsemius.. Thanks, Santosh On Tue, Jul 14, 2009 at 9:14 PM, Santosh santosh2...@gmail.com wrote: Dear R-users.. I hope the following scenario is more explanatory of my question.. Continuous

[R] Correlation question (from a newbie)

2009-07-14 Thread Santosh
Hi R-users, Was wondering if there is a way to quickly compute correlations between continuous variables grouped by some categorical variables? What function do I use? Thanks much in advance. Regards, Santosh [[alternative HTML version deleted]]

Re: [R] Correlation question (from a newbie)

2009-07-14 Thread David Winsemius
On Jul 14, 2009, at 10:34 PM, Santosh wrote: Hi R-users, Was wondering if there is a way to quickly compute correlations between continuous variables grouped by some categorical variables? What function do I use? ?tapply ?by Thanks much in advance. Regards, Santosh

Re: [R] Correlation question (from a newbie)

2009-07-14 Thread Santosh
Dear R-users.. I hope the following scenario is more explanatory of my question.. Continuous variables: AGE, WEIGHT, HEIGHT Categorical variables: Group, Sex, Race I would like to find a correlation between WEIGHT and AGE, grouped by Group,Sex, and Race. Is the following formula correct?