Solved – F-test for lack of fit using R

rregression

How do I test for Lack Of Fit (F-test) using R? I've seen a similar question, but that was for SPSS and it was just said that is can be easily done in R, but not how.

I know in simple linear regression I would use anova(fm1,fm2), fm1 being my model, fm2 being the same model with x as a factor (if there are several y for x).
How do I do it in multiple linear regression?

Best Answer

As @gung says in the comment, your question title and text conflict. The F-test for joint significance of all parameters in a model is on a single model fit; it is displayed each time you do summary().

Comparisons of models is a whole different ball game -- as the models need to be nested for inference to be valid.

The lmtest adds a number of common econometrics tests for linear models. As an illustration, here is the beginning of examples(lrtest) for using a likelihood-ratio test to compare two nested models:

R>      ## with data from Greene (1993):
R>      data("USDistLag")
R>      usdl <- na.contiguous(cbind(USDistLag, lag(USDistLag, k = -1)))
R>      colnames(usdl) <- c("con", "gnp", "con1", "gnp1")
R>      fm1 <- lm(con ~ gnp + gnp1, data = usdl)
R>      fm2 <- lm(con ~ gnp + con1 + gnp1, data = usdl)
R>      lrtest(fm2, fm1)
Likelihood ratio test

Model 1: con ~ gnp + con1 + gnp1
Model 2: con ~ gnp + gnp1
  #Df LogLik Df Chisq Pr(>Chisq)    
1   5 -56.07                        
2   4 -65.87 -1 19.61   9.52e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
R> 
Related Question