You can perform the lack-of-fit test with the alr3
package.
> library(alr3)
> x1 <- c(1,1,1,2,3,3,4,4,4,4)
> x2 <- c(1,2,3,1,2,3,1,2,3,3)
> y <- rnorm(10, x1+x2)
> fit <- lm(y ~ x1+x2)
> pureErrorAnova(fit)
Analysis of Variance Table
Response: y
Df Sum Sq Mean Sq F value Pr(>F)
x1 1 8.6412 8.6412 53.857 0.08622 .
x2 1 11.9019 11.9019 74.180 0.07359 .
Residuals 7 10.8198 1.5457
Lack of fit 6 10.6593 1.7766 11.073 0.22608
Pure Error 1 0.1604 0.1604
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Note the equivalence here:
> xx1 <- factor(x1)
> xx2 <- factor(x2)
> fit1 <- lm(y ~ xx1*xx2)
> anova(fit, fit1)
Analysis of Variance Table
Model 1: y ~ x1 + x2
Model 2: y ~ xx1 * xx2
Res.Df RSS Df Sum of Sq F Pr(>F)
1 7 10.8198
2 1 0.1604 6 10.659 11.073 0.2261