2026-10-17

Correlation

Correlation is a statistical measure that describes the extent to which two variables are related. This method only looks at the two variables being explored and describes the relationship quantified by r, the strength of the relationship.

There are multiple types of correlation.

  • Positive: Both variables are moving in the same direction. As one increases, the other also increases.

  • Negative: Both variables are move in opposite direction. As one increases, the other decreases.

  • No correlation: There is no linear relationship between the variables.

Correlation Real Life Examples

Here are some examples of correlation relationships:

  • Positive: Study Hours and Exam Scores, As students spend more hours studying, their test scores typically go up.

  • Negative: TV Time and Exam Scores, The more hours a student spends watching television, the lower their exam scores tend to be.

  • No correlation: Outdoor Temperature and Exam Scores, The temperature outdoors does not affect the score students get on their exams.

Now Let’s Write the Mathematics

Pearson Correlation Coefficient (\(r\))

Measures the linear relationship between two continuous variables (\(X\) and \(Y\)).

\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2} \sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \]

Mathematics Continued

Spearman’s Rank Correlation Coefficient (\(r_{s}\) or \(\rho\))

Measures the strength and direction of a monotonic relationship between two ranked variables.

\[r_s = 1 - \frac{6 \sum d_i^2}{n(n^2 - 1)}\]

Chick Weight Boxplot by Diet

data(ChickWeight)

ggplot(ChickWeight) +
  geom_boxplot(
    aes(
      y = weight,
      x = factor(Diet),
      fill = factor(Diet)
    )
  ) +
  labs(
    y = "Weight",
    x = "Diet"
  ) +
  scale_fill_brewer(
    palette = "Set1"
  ) +
  theme_minimal()

Chick Weight Density Distribution by Diet

Plotly Scatterplot

Data Findings

From the graphs I created, I was able to learn much more about the relationship between chicks and the 4 types of diets they part took in. We initially went in trying to find the correlation between what the chicks were given to eat and the amount they weighed in grams. The scientists were tracking for changes every day.

Correlation analysis is important because we are able to figure out how two things are related to each other. We are able to quantify the relationship between two variables.

The first graph uses a boxplot in order to show the relationship between the 4 different diets that the Chicks consumed. Diet 1 shows the lowest median weight therefore, it has a lower correlation values. Diet 3 and 4 show the highest median weight therefore, they have higher correlation values.

The second graph uses a density distribution to show the range of chick weights. Diet 1 shows a left skewed graph whereas diet 4 shows a bit more of an even distribution.

Lastly, the plotly graph shows a way to interact with the scatter plot. You are able to see exact coordinates and how the diets compare to each other and ultimately the correlation relationship for each type of diet.