2025-10-14

Correlation and Regression

Statistical Relationships Between Variables

  • Measures how variables relate to each other
  • Predicts outcomes based on relations

Correlation

This is Pearson Correlation Coefficient (r): \[ 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}} \]

Simple Linear Regression

Regression Equation: \[ Y = \beta_0+\beta_1X+\epsilon \]

Linear Regression Code

n <- 50
study_hours <- runif(n, 1, 10)
exam_score <- 50 + 5 * study_hours + rnorm(n, 0, 8)

study_data <- data.frame(study_hours, exam_score)

ggplot(study_data, aes(x = study_hours, y = exam_score)) + 
  geom_point(color = "darkblue", alpha = 0.7, size = 2) + 
  geom_smooth(method = "lm", color = "red", se = TRUE, fill = "lightpink") +
  labs(title = "Linear Regression: Study Hours vs Exam Score",
       x = "Study Hours", y = "Exam Score") +
  theme_minimal() 
## `geom_smooth()` using formula = 'y ~ x'

Linear Regression Plot

## `geom_smooth()` using formula = 'y ~ x'

Another Linear Regression Example

## `geom_smooth()` using formula = 'y ~ x'

3D Regression