Day 5: Introduction to Correlation

Resources
In Statistics, dependence is any statistical relationship between 2 random variables or two sets of data. Correlation refers to any of a broad class of statistical relationships involving dependence; however, in common usage it generally refers to the extent to which 2 variables have a linear relationship with each other. Familiar examples of dependent phenomena include the correlation between the physical statures of parents and their offspring, and the correlation between the demand for a product and its price.

Correlations are useful because they can indicate a predictive relationship that can be exploited in practice. For example, an electric utility may produce less power on a mild day based on the correlation between electricity demand and weather. In this example, there is a causal relationship because extreme weather causing people to use more electricity for heating or cooling; however, statistical dependence is not sufficient to demonstrate the presence of such a causal relationship. Correlation does not imply causation.

Formally, dependence refers to any situation in which random variables do not satisfy a mathematical condition of probabilistic independence. Loosely, correlation can refer to any departure of two or more random variables from independence. Technically, it refers to any of several more specialized types of relationships between mean values. There are several correlation coefficients, often denoted as ρ or r, measuring the degree of correlation. The most common of these is the Pearson correlation coefficient, which is sensitive only to a linear relationship between two variables. This may exist even if one is a nonlinear function of the other. Other correlation coefficients have been developed to be more robust than the Pearson correlation—that is, more sensitive to nonlinear relationships.

Here are 2 popular coefficients of correlation:

  1. Pearson's Product Moment Coefficient
  2. Spearman Rank Correlation

Source: Wikipedia

Here are 2 hypothetical examples of variable pairs that are positively and negatively correlated:

Positive Correlation
Positive Correlation Source: Mathwarehouse.com

Negative Correlation
Negative Correlation Source: uwsp.edu


  1. Challenge Walkthrough
    Let's walk through this sample challenge and explore the features of the code editor.1 of 6
  2. Review the problem statement
    Each challenge has a problem statement that includes sample inputs and outputs. Some challenges include additional information to help you out.2 of 6
  3. Choose a language
    Select the language you wish to use to solve this challenge.3 of 6
  4. Enter your code
    Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
  5. Test your code
    You can compile your code and test it for errors and accuracy before submitting.5 of 6
  6. Submit to see results
    When you're ready, submit your solution! Remember, you can go back and refine your code anytime.6 of 6
  1. Check your score