Obviously the easiest way to get the AIC of a linear model is by using the lm
function and then the AIC
command. However, this simple method can be very time consuming, as actually with the lm
function R computes a lot of stuff which isn't strictly needed to calculate the AIC of the model. When this is done for thousands of different models that time quickly adds up.
As I am just interested in the AIC and don't care about anything else in the model, is there any easy way of getting just that without having to calculate the full lm
object?
I was thinking about using lm.fit
(which takes only 1/10 of the time of lm
) - or even better solve(crossprod(X), t(X) %*% y)
- to get the coefficients but then I am not really sure on how to get the loglikelihood function in a general way. Do you have any ideas or maybe some different approaches on how to get the AIC?
Many thanks in advance