For this discussion board I will be using the women dataset to predict the height using the weight.
df <- women
head(df)
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
You can also embed plots, for example:
lm <- lm(weight ~ height, data = df)
print(lm)
##
## Call:
## lm(formula = weight ~ height, data = df)
##
## Coefficients:
## (Intercept) height
## -87.52 3.45
plot( weight ~ height, data = df)
abline(lm)
summary(lm)
##
## Call:
## lm(formula = weight ~ height, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.7333 -1.1333 -0.3833 0.7417 3.1167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -87.51667 5.93694 -14.74 1.71e-09 ***
## height 3.45000 0.09114 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.525 on 13 degrees of freedom
## Multiple R-squared: 0.991, Adjusted R-squared: 0.9903
## F-statistic: 1433 on 1 and 13 DF, p-value: 1.091e-14
plot(fitted(lm),resid(lm))
qqnorm(resid(lm))
qqline(resid(lm))
par(mfrow=c(2,2))
plot(lm)
There is a curved pattern in the residuals so a linear model might not
be a great fit for the data