Simple linear regression is a model which estimates the relationship between one dependent variable and one independent variable. \[ y = \alpha + \beta x \]
where \(\beta\) represents slope and \(\alpha\) represents y-intercept
2025-04-14
Simple linear regression is a model which estimates the relationship between one dependent variable and one independent variable. \[ y = \alpha + \beta x \]
where \(\beta\) represents slope and \(\alpha\) represents y-intercept
If mean of x (\(\bar x\)) and mean of y (\(\bar y\)) are known at time of calculation where n is number of elements: \[\hat\beta\ = \frac{\sum_{i=1}^{n}(x_i - \bar x)(y_i - \bar y)} {\sum_{i=1}^{n}(x_i - \bar x)^2}\] \[\hat\alpha\ = \bar y - \hat\beta\ \bar x\]
plot_ly(x=longley$Population, y=longley$GNP,
type="scatter", mode="markers",
name="data") %>%
add_lines(x=longley$Population,
y=fitted(lm(longley$GNP ~ longley$Population)),
name="fitted") %>%
layout(title="GNP by Population",
xaxis=list(title="Population"),
yaxis=list(title="GNP"))
plot_ly(x=longley$Population, y=longley$GNP.deflator,
type="scatter", mode="markers",
name="data") %>%
add_lines(x=longley$Population,
y=fitted(lm(longley$GNP.deflator ~ longley$Population)),
name="fitted") %>%
layout(title="GNP Deflator by Population",
xaxis=list(title="Population"), yaxis=list(title="GNP Deflator"))
ggplot(data=mtcars, aes(x=wt,y=mpg)) + geom_point() +
geom_smooth(method="lm", se=FALSE) +
ggtitle("Miles per Gallon by Weight of Car") + xlab("Weight") + ylab("MPG")
ggplot(data=mtcars, aes(x=hp,y=mpg)) + geom_point() +
geom_smooth(method="lm", se=FALSE) +
ggtitle("Miles per Gallon by HP of Car") + xlab("HP") + ylab("MPG")