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
lmgives me just so much useless stuff, while the formula for the information just requires the number of parameters (which I have without calculating the model), the MLE (which you get easily by the methods described above) and the loglikelihood, which is just one of the long list of stuff that calculating the model gives me. I am looking for a way to avoid computing the stuff which isn't strictly necessary. Do you really think that this is not possible? Thanks anyway for the answer – Gisalbur Sep 16 '17 at 17:18