Skip to content
Prev 58278 / 398498 Next

Obtaining fitted model information

On Sun, 31 Oct 2004, Prof Brian Ripley wrote:

            
But only better, as it looks like it has fallen into the first trap.
AFAICS, if 'fit' is an lm fit, then

n = df.residual(fit) + fit$rank


Quick check:

x <- rnorm(10); x[2] <- NA
y <- rnorm(10); y[1] <- NA
w <- c(rep(1,9), 0)
fit <- lm(y ~x, weights = w, na.action=na.exclude)
df.residual(fit) + fit$rank  # 7, correct
attributes(logLik(fit)) # nall 9 nobs 9 df 3
# but AIC fails
length(resid(fit)) # 10

fit <- lm(y ~x, weights = w, na.action=na.omit)
df.residual(fit) + fit$rank  # 7, correct
attributes(logLik(fit)) # nall 7 nobs 7 df 3
length(resid(fit)) # 8