Activity

You have been told that there is a correlation between coffee consumption and blood pressure. In order to statistically test the relationship you have collected data from 48 coffee drinkers, including the number of cups of coffee they have consumed and their blood pressures. Now you want to run a linear regression to see if there is any relationship between coffee consumption and blood pressure.

Tasks

1.    Find the estimated regression line.

2.     Find the correlation between coffee consumption and blood pressure.

3.     Describe the relationship between coffee consumption and blood pressure and explain what someone should do if their doctor says that their blood pressure is a concern.

coffee_data <- read.csv("C://Users//Gurvinder//Desktop//Data Analytics//Assignments//Predictive Analytics//Linear Regression//To be uploaded on the Brightspace//Part1//Coffee_BloodPressure_Datasheet.csv")

# Running linear regression
lm_result <- lm(BloodPressure ~ CupsOfCoffee, data = coffee_data)

# Summary of the linear regression model
summary(lm_result)
## 
## Call:
## lm(formula = BloodPressure ~ CupsOfCoffee, data = coffee_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -27.125  -8.321   1.957   9.916  24.563 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  138.2239     4.0101  34.469   <2e-16 ***
## CupsOfCoffee   1.7376     0.8505   2.043   0.0468 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.77 on 46 degrees of freedom
## Multiple R-squared:  0.08318,    Adjusted R-squared:  0.06325 
## F-statistic: 4.174 on 1 and 46 DF,  p-value: 0.04681
# Calculating correlation
correlation <- cor(coffee_data$CupsOfCoffee, coffee_data$BloodPressure)
correlation
## [1] 0.2884135
# Print the estimated regression line equation
cat("Estimated Regression Line: BloodPressure =", round(coef(lm_result)[1], 2), "+", round(coef(lm_result)[2], 2), "* CupsOfCoffee\n")
## Estimated Regression Line: BloodPressure = 138.22 + 1.74 * CupsOfCoffee
# Description of the relationship based on correlation
if (correlation > 0.8) {
  cat("There is a strong correlation between coffee consumption and blood pressure.\n")
} else if (correlation < 0.8) {
  cat("There is a weak correlation between coffee consumption and blood pressure.\n")
} 
## There is a weak correlation between coffee consumption and blood pressure.
# Plotting the scatterplot with the regression line
library(ggplot2)
ggplot(coffee_data, aes(x = CupsOfCoffee, y = BloodPressure)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Coffee Consumption vs Blood Pressure",
       x = "Cups of Coffee",
       y = "Blood Pressure")