Using Boston dataset in MASS library, I'm trying to find correlation of all columns against the column medv.

For each column, I'm doing similar to below:

 cor(Boston$crim, Boston$medv)

The correlation between crim and medv as calculated above is a negative value. I understand negative values means they are not related closely and therefore the values in crim column is not suitable to use to predict the values in medv column. Which means the Crime Rate (crim) data is not sufficient to predict the Median house pricing (medv).

Did I get that right?

Also, do I have to check each column against medv for correlation? Is there a way to check all columns against medv at once?

Is it ok to say that the highest correlation value would mean that the column is best predictor for medv?


In fact the correlation (-0.338) is strong (large magnitude) and statistically significant, so medv would be a useful predictor. Non-useful predictors would have small absolute values, whether negative or positive.


    Pearson's product-moment correlation

data:  crim and medv
t = -9.4597, df = 504, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.4599064 -0.3116859
sample estimates:

You might be looking for

      crim         zn      indus       chas        nox         rm        age 
-0.3883046  0.3604453 -0.4837252  0.1752602 -0.4273208  0.6953599 -0.3769546 
       dis        rad        tax    ptratio      black      lstat       medv 
 0.2499287 -0.3816262 -0.4685359 -0.5077867  0.3334608 -0.7376627  1.0000000 
| cite | improve this answer | |
  • $\begingroup$ Thank you. Nice code on finding correlation with all. I used cor(Boston[,], Boston$medv) but your looks pretty. So, in the result, correlation of medv and rm is 0.6953599 which is the highest. Does that mean rm is best predictor of medv? Also I am a bit confused on why negative value would make a good predictor. $\endgroup$ – caroline Mar 16 '15 at 2:01
  • $\begingroup$ Understood. The positive correlation value indicates that increase of predictor value also increases the output. Negative means the response value decreases as predictor increases. The absolute value indicates the measure. $\endgroup$ – caroline Mar 16 '15 at 7:25

Concerning your question: "Does higher value of correlation between two values indicate it is good predictor?"

In general I would be very cautious because one of the most important facts in statistics is that correlation does not imply causation: http://en.wikipedia.org/wiki/Correlation_does_not_imply_causation

See this great site which illustrates spurious correlation very effectively: http://www.tylervigen.com/

In practice I would create at least a training set and a test set so that you can build your model first (= in sample) and then test it (= out of sample). Many models work in sample but lose their forecasting ability "mysteriously" out of sample.

See also this question and answers here: What is the difference between test set and validation set?

| cite | improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.