[R] Bug in stepAIC?

Martin C. Martin martin at martincmartin.com
Wed Oct 11 18:30:56 CEST 2006


Hi,

First of all, thanks for the great work on R in general, and MASS in 
particular.  It's been a life saver for me many times.

However, I think I've discovered a bug.  It seems that, when I use 
weights during an initial least-squares regression fit, and later try to 
add terms using stepAIC(), it uses the weights when looking to remove 
terms, but not when looking to add them:

hills.lm <- lm(time ~ dist + climb, data = hills, weights = 1/dist2)
small.hills.lm <- stepAIC(hills.lm)
stepAIC(small.hills.lm, time ~ dist + climb)

In the first stepAIC(), it says that the AIC for the full "time ~ dist + 
climb" is 94.41.  Yet, during the second stepAIC, it says adding climb 
would produce an AIC of 212.1 (and an RSS of 12633.3).  Is this a bug?

Best,
Martin



More information about the R-help mailing list