- Linear Regression models the relationship between a dependent and an independent variable.
- Equation of a simple linear regression model:
\[ y = \beta_0 + \beta_1 x + \epsilon\]
\[ y = \beta_0 + \beta_1 x + \epsilon\]
trees Dataset is Good for Linear Regressiong <- ggplot(trees, aes(x = Girth, y = Volume)) + geom_point() +
labs(title="Tree Girth vs Volume", x="Girth", y="Volume")
g
g + geom_smooth(method="lm", se=FALSE, color="blue")
## `geom_smooth()` using formula = 'y ~ x'
\[ \sum_{i=1}^{n} (y_i - (\beta_0 + \beta_1 x_i))^2 \]
\[ \hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]
\[ \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]
mod <- lm(Volume ~ Girth, data=trees) print(summary(mod))
Call: lm(formula = Volume ~ Girth, data = trees)
Residuals: Min 1Q Median 3Q Max -8.065 -3.107 0.152 3.495 9.587
Coefficients: Estimate Std. Error t value Pr(>|t|)
(Intercept) -36.9435 3.3651 -10.98 7.62e-12 Girth 5.0659 0.2474 20.48 < 2e-16 — Signif. codes: 0 ‘’ 0.001 ’’ 0.01 ’’ 0.05 ‘.’ 0.1 ’ ’ 1
Residual standard error: 4.252 on 29 degrees of freedom Multiple R-squared: 0.9353, Adjusted R-squared: 0.9331 F-statistic: 419.4 on 1 and 29 DF, p-value: < 2.2e-16