Skip to content

Instantly share code, notes, and snippets.

@DonatasD
Created November 20, 2015 14:35
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 DonatasD/a6bf20151c4483c3fe04 to your computer and use it in GitHub Desktop.
Save DonatasD/a6bf20151c4483c3fe04 to your computer and use it in GitHub Desktop.
plotSubset = function(regfit.summary) {
#Plot RSS
op = par(mfrow = c(2,2))
plot(regfit.summary$rss, xlab = "Number of variables", ylab="RSS", type="l")
#Plot adjusted RS^2 and mark its maximum
plot(regfit.summary$adjr2, xlab = "Number of variables", ylab="Adjusted RS^2", type="l")
max = which.max(regfit.summary$adjr2)
points(max, regfit.summary$adjr2[max], col="red", cex=2, pch=20)
#Plot CP and mark its minimum point
plot(regfit.summary$cp, xlab= "Number of variables", ylab="CP", type="l")
min = which.min(regfit.summary$cp)
points(min, regfit.summary$cp[min], col="red", cex=2,pch=20)
#Plot BIC and mark its minimum
plot(regfit.summary$bic, xlab="Number of variables", ylab="BIC", type="l")
min = which.min(regfit.summary$bic)
points(min, regfit.summary$bic[min], col="red", cex=2,pch=20)
par(op)
}
plotSubsetWithPredictors = function(reg) {
op = par(mfrow=c(2,2))
plot(reg, scale ="r2")
plot(reg, scale ="adjr2")
plot(reg, scale ="Cp")
plot(reg, scale ="bic")
par(op)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment