- Linear regression is a method used to model the relationship between a dependent variable and one or more independent variables.
2024-10-18
car_data <- data.frame ( speed = c(50,55,60,65,70,75,80,85,90), weight = c(200,205,210,215,220, 225, 230, 235, 240) ) print(car_data)
## speed weight ## 1 50 200 ## 2 55 205 ## 3 60 210 ## 4 65 215 ## 5 70 220 ## 6 75 225 ## 7 80 230 ## 8 85 235 ## 9 90 240
library(ggplot2) ggplot(car_data, aes(x=speed)) + geom_histogram(binwidth = 8, fill = “yellow”, color = “black”) + labs(title = “Histogram of Speed”, x = “speed(mph)”, y = “frequency”)
\(y = \beta_0 + \beta_1 x\)
Where:
\(y\) is the dependent variable (weight)
\(x\) is the independent variable (speed)
\(\beta_0\) is the intercept
\(\beta_1\) is the slope.
model <- lm(weight ~ speed, data=car_data)
\(\beta_0\) = This represents the expected value of y when x is zero
\(\beta_1\) = This shows what y is going to change to while x is also growing