Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cor shows only NA or 1 for correlations - Why?

Tags:

r

correlation

I'm running cor() on a data.framewith all numeric values and I'm getting this as the result:

       price exprice... price      1      NA exprice   NA       1 ... 

So it's either 1 or NA for each value in the resulting table. Why are the NAs showing up instead of valid correlations?

like image 747
Dave Avatar asked Sep 26 '10 17:09

Dave


People also ask

Why is COR () returning na?

The NA can actually be due to 2 reasons. One is that there is a NA in your data. Another one is due to there being one of the values being constant. This results in standard deviation being equal to zero and hence the cor function returns NA.

What does A and or +1 correlation coefficient mean?

This measures the strength and direction of a linear relationship between two variables. Values always range between -1 (strong negative relationship) and +1 (strong positive relationship). Values at or close to zero imply a weak or no linear relationship.

Why is the correlation coefficient less than 1?

The Correlation Coefficient cannot be greater then the absolute value of 1 because it is a measure of fit between two variables that are not affected by units of measurement. A correlation coefficient is a measure of how well the data points of a given set of data fall on a straight line.

Should we interpret a correlation coefficient of 1?

Graphs for Different Correlation Coefficients Correlation Coefficient = +1: A perfect positive relationship. Correlation Coefficient = 0.8: A fairly strong positive relationship. Correlation Coefficient = 0.6: A moderate positive relationship. Correlation Coefficient = 0: No relationship.


1 Answers

Tell the correlation to ignore the NAs with use argument, e.g.:

cor(data$price, data$exprice, use = "complete.obs") 
like image 196
dmt Avatar answered Oct 12 '22 02:10

dmt