Created
October 7, 2019 19:11
-
-
Save monogenea/008024dbe281887268af50085c82a16a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
houses <- read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data", | |
header = F, na.string = "?") | |
colnames(houses) <- c("CRIM", "ZN", "INDUS","CHAS", | |
"NOX","RM","AGE","DIS","RAD", | |
"TAX","PTRATIO","B","LSTAT","MEDV") | |
# Perform PCA | |
pcaHouses <- prcomp(scale(houses[,-14])) | |
scoresHouses <- pcaHouses$x | |
# Fit lm using the first 3 PCs | |
modHouses <- lm(houses$MEDV ~ scoresHouses[,1:3]) | |
summary(modHouses) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment