2025-11-08
“)
Formula below shows how relationship between temperature and mood could be represent in a Linear model:
\[ \text{Mood} = \beta_0 + \beta_1 \times \text{Temperature} + \varepsilon \]
Where:
To measure the strength of the relationship, we can compute the correlation coefficient:
\[ r = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})} {\sqrt{\sum (x_i - \bar{x})^2 \sum (y_i - \bar{y})^2}} \]
If \(r\) is close to \(1\) means a strong positive relationship. If \(r\) is close to \(-1\) means a strong negative relationship.
R code below shows the relationship between temperature and mood using linear model.
ggplot(data, aes(x = temperature, y = mood)) +
geom_point(color = "#1A237E", alpha = 0.6, size = 3) +
geom_smooth(method = "lm", se = TRUE, color = "#D32F2F") +
labs(
title = "Mood Levels vs Temperature",
x = "Temperature (°F)",
y = "Mood Level (1–10)"
) +
theme_minimal(base_family = "Verdana") +
theme(
plot.title = element_text(face = "bold", hjust = 0.5, size = 18, color = "#1A237E")
)
The linear model provides a basic trend, however the residual pattern appears to be a curved (nonlinear) relationship. Below shows quadratic model. Mood rises as the temperature increase, peaks around 70 degree, and decreases as it gets hotter.