Skip to content

Instantly share code, notes, and snippets.

@monogenea
Created October 7, 2019 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monogenea/66dff559969502f0c995dcf6184e52ca to your computer and use it in GitHub Desktop.
Save monogenea/66dff559969502f0c995dcf6184e52ca to your computer and use it in GitHub Desktop.
# Fit lm using all 14 vars
modHousesFull <- lm(MEDV ~ ., data = houses)
summary(modHousesFull) # R2 = 0.741
# Compare obs. vs. pred. plots
par(mfrow = c(1,2))
plot(houses$MEDV, predict(modHouses),
xlab = "Observed MEDV", ylab = "Predicted MEDV",
main = "PCR", abline(a = 0, b = 1, col = "red"))
plot(houses$MEDV, predict(modHousesFull),
xlab = "Observed MEDV", ylab = "Predicted MEDV",
main = "Full model", abline(a = 0, b = 1, col = "red"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment