This report aims to explore the relationship between the number of Calories and the Sugar content (in grams) of 36 different breakfast cereals. Both frequentist and Bayesian methods will be employed to assess the correlation between these two variables.
## Cereal Calories Sugar Fiber
## 1 Common Sense Oat Bran 100 6 3
## 2 Product 19 100 3 1
## 3 All Bran Xtra Fiber 50 0 14
## 4 Just Right 140 9 2
## 5 Original Oat Bran 70 5 10
## 6 Heartwise 90 5 6
We begin by examining the relationship between Calories and Sugar through a scatterplot. Additionally, we will calculate the correlation coefficient.
## [1] 0.5154008
We will conduct a hypothesis test to determine whether there is a significant correlation between Calories and Sugar. The null hypothesis is that there is no correlation in the population of all breakfast cereals.
##
## Pearson's product-moment correlation
##
## data: cereal_data$Sugar and cereal_data$Calories
## t = 3.5069, df = 34, p-value = 0.001296
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2249563 0.7217280
## sample estimates:
## cor
## 0.5154008
## [1] 0.001295907
## [1] 0.2249563 0.7217280
## attr(,"conf.level")
## [1] 0.95
Using the bayes.cortest function from the BayesianFirstAid package, we will perform a Bayesian analysis to estimate the population correlation coefficient. This approach provides a 95% credible interval and the probability that the correlation is positive.
##
## Bayesian First Aid Pearson's Correlation Coefficient Test
##
## data: cereal_data$Sugar and cereal_data$Calories (n = 36)
## Estimated correlation:
## 0.49
## 95% credible interval:
## 0.20 0.72
## The correlation is more than 0 by a probability of 0.999
## and less than 0 by a probability of 0.001
We will now compare the p-value from the frequentist test with the Bayesian probability that the true correlation is negative, and compare the frequentist 95% confidence interval with the Bayesian 95% credible interval.
## P-value from frequentist approach: 0.001295907
## Bayesian probability that true correlation is negative:
## 95% Confidence Interval (Frequentist): 0.2249563 0.721728
## 95% Credible Interval (Bayesian):