suppressPackageStartupMessages(library(UsingR))
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(tidyr))
suppressPackageStartupMessages(library(knitr))
homes <- as.data.frame(homedata)
head(homes)
hp <-
ggplot(homes, aes(x = y1970, y = y2000)) +
geom_point(size = 1, color = "purple2") +
geom_smooth(method = lm, se = FALSE, color = "black") +
xlab("Home Value in 1970") +
ylab("Home Value in 2000")
hp
## `geom_smooth()` using formula 'y ~ x'

modelh <- lm(y2000 ~ y1970, data = homes)
summary(modelh)
##
## Call:
## lm(formula = y2000 ~ y1970, data = homes)
##
## Residuals:
## Min 1Q Median 3Q Max
## -416665 -36308 809 34372 536605
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.040e+05 2.337e+03 -44.51 <2e-16 ***
## y1970 5.258e+00 3.147e-02 167.07 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 58000 on 6839 degrees of freedom
## Multiple R-squared: 0.8032, Adjusted R-squared: 0.8032
## F-statistic: 2.791e+04 on 1 and 6839 DF, p-value: < 2.2e-16
### With every increase in year, home value increases by 5.258e+00 (%).
### The equation is: Home value in 2000 = -1.040e+05 + 5.258e+00 * home value in 1970
predict(modelh, data.frame(y1970 = c(55000, 60000, 65000)))
## 1 2 3
## 185183.8 211473.6 237763.5
### According to 'modelh', a home valued at $55,000 in 1970 would be worth $185,183.80 in 2000, a home valued at $60,000 would be worth $211,473.60 in 2000, and a home valued at $65,000 in 1970 would be worth $237,763.50 in 2000.