I'm running cor()
on a data.frame
with 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 NA
s showing up instead of valid correlations?
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.
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.
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.
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.
Tell the correlation to ignore the NAs with use
argument, e.g.:
cor(data$price, data$exprice, use = "complete.obs")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With