2024-02-04
plot_ly(Seatbelts2, x=Seatbelts2$Month, y=Seatbelts2$PetrolPrice,
z=Seatbelts2$DriversKilled, type='scatter3d', mode='markers',
color=as.factor(Seatbelts2$SeatbeltsLaw)) %>%
layout(title = 'Drivers Killed vs Gas Price (w and w/o seatbelt law)
between 1969 and 1984',
scene=list(xaxis=xax, yaxis=zax, zaxis=yax))
ggplot(Seatbelts, aes(x=PetrolPrice, y=DriversKilled))+
geom_point() +
geom_smooth(method='lm') +
labs(title='Drivers Killed vs Gas Price (w and w/o seatbelt law)
between 1969 and 1984')
Equation for Simple Linear Regression line
\(\hat{y}=a+bx\)
where:
\(\hat{y} \text{ is the predicted value of y}\)
\(a = \overline{y}-b\overline{x}\)
\(\overline{x} = \frac{\sum x}{n}\)
\(\overline{y} = \frac{\sum y}{n}\)
\(b = \frac{Sxy}{Sxx} = \frac{\sum (x_{i}-\overline{x})(y_{i}-\overline{y})}{\sum (x_{i}-\overline{x})^{2}} = \frac{\sum (xy)-\frac{\sum x\sum y}{n}}{\sum {x}^{2}-\frac{({\sum {x})^{2}}}{n}}\)
Sum of the squares
\(SS = \sum x^2 - \frac{(\sum x)^2}{n}\)
Variance
\(s^{2} = \frac{\sum {x^{2}-\frac{(\sum x)^{2}}{n}}}{n-1}\)
Standard deviation
\(s = \sqrt {\frac{\sum x^2-\frac{(\sum x)^2}{n}}{n-1}}\)
Z scroes
\(Z = \frac{x-M}{s} = \frac{deiviation}{\text stand. dev.}\)