2023-11-09

Correlation

Correlation tests aim to see if a relationship exists within a data set and its variables.

The indicator is the “correlation coefficient” which is expressed on a scale of -1 to 1.

A result close to -1 represents a strong negative relationship, a result close to 1 represents a strong positive relationship, and a result close to 0 represent little to no correlation.

Formula for Correlation

The following is the formula used to calculate the correlation coefficient “r”.

\[ r = \frac{n(\sum xy) - (\sum x)(\sum y)}{\sqrt{[n\sum x^2 - (\sum x)^2][n\sum y^2 - (\sum y)^2]}} \]

Introducing the Data Set

The data used for the correlation testing is the “ChickWeight” set in R Studio.

This data set has information of 50 different newborn chicks on four different diets and their weight over a short period of time. Their weights were measured from the day they were born, then every two days, and concluded on the 21st day.

For the purposes of this test, weights taken on the final day (day 21) will be used. To get this information, the data set will first be filtered using the code below.

data(ChickWeight)
FinalChickWeight <- dplyr::filter(ChickWeight, Time == 21)

Chicks and Their Diets

The following shows the amount of chicks that were on each diet:

Weight vs Diet

The following graph shows the distribution of the chicks’ weight based on the diet they were on.

Weight Gain Over Time

The following graph displays the chicks’ weight gain over the first 21 days with colors separating each diet.

Calculating Correlation

Using the previously mentioned formula:
\[ r = \frac{n(\sum xy) - (\sum x)(\sum y)}{\sqrt{[n\sum x^2 - (\sum x)^2][n\sum y^2 - (\sum y)^2]}} \]
The strongest contributing factor to the chicks’ weight gain was time in general. The resulting correlation coefficient is close to 1, indicating a relatively strong relationship between the two variables.

cor(ChickWeight$Time, ChickWeight$weight)
## [1] 0.8371017