Introduction to linear regression
1.Choose another traditional variable from mlb11 that you think might be a good predictor
of runs. Produce a scatterplot of the two variables and fit a linear model. At a glance, does there
seem to be a linear relationship?
CODE:
predict_runs <- lm(runs ~ hits, data = mlb11)
predict_runs
plot(mlb11$runs ~ mlb11$hits)
abline(predict_runs)
plot(predict_runs$residuals ~ mlb11$hits)
abline(h = 0, lty = 3)
OUTPUT:
> predict_runs <- lm(runs ~ hits, data = mlb11)
> predict_runs
Call:
lm(formula = runs ~ hits, data = mlb11)
Coefficients:
(Intercept) hits
-375.5600 0.7589
> plot(mlb11$runs ~ mlb11$hits)
> abline(predict_runs)
SCREENSHOT: