Skip to content

Instantly share code, notes, and snippets.

@Laurae2
Created February 24, 2017 19:55
Show Gist options
  • Save Laurae2/38176eed780e2833a9ecd8d701e4b916 to your computer and use it in GitHub Desktop.
Save Laurae2/38176eed780e2833a9ecd8d701e4b916 to your computer and use it in GitHub Desktop.
Akaike Information Criterion and Bayesian Information Criterion
lm_model <- lm(preds ~ ., data = data)
my_AIC <- AIC(lm_model)
my_AIC <- nrow(data) * (log(2 * pi) + 1 + log((sum(lm_model$residuals ^ 2) / nrow(data)))) + ((length(lm_model$coefficients) + 1) * 2)
my_BIC <- AIC(lm_model, k = log(nrow(data)))
my_BIC <- nrow(data) * (log(2 * pi) + 1 + log((sum(lm_model$residuals ^ 2) / nrow(data)))) + ((length(lm_model$coefficients) + 1) * log(nrow(data)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment