Created
November 7, 2014 21:27
-
-
Save avansp/d3bcb6da7da98d47e71b to your computer and use it in GitHub Desktop.
Comparison plot between AIC and BIC penalty terms
This file contains 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
# AIC vs BIC comparison | |
# | |
# AIC = -2*log(L) + 2*k | |
# BIC = -2*log(L) + k*log(n) | |
# | |
# Since the first term is equal, we only compute the penalized term | |
k <- seq(1,50) | |
n <- seq(1,20) | |
grid.aic <- outer(k,n,function(x,y) 2*x) | |
grid.bic <- outer(k,n,function(x,y) x*log(y)) | |
par(mar=c(5,4,2,2)) | |
contour(x=k, y=n, grid.aic, | |
xlab="number of parameters (k)", ylab="sample size (n)", | |
col="dodgerblue3", method="flattest", levels=seq(10,100,by=10)) | |
contour(x=k, y=n, grid.bic, | |
add=TRUE, col="firebrick3", levels=seq(10,100,by=10)) | |
abline(h=exp(2),lty=2) | |
legend( "topright", col=c("dodgerblue3", "firebrick3"), | |
legend=c("AIC", "BIC"), lty=1, bg="white") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment