# # File name: lec04.R # # # data example: LOF # # create data frame purerr = data.frame(matrix(0, 16, 2)) names(purerr) = c("x","y") purerr$x = c(4.1,5.1,5.1,5.1,6.3,6.3,7.0,7.9,7.9,7.9,8.6,9.4,9.4,9.4,10.2,10.2) purerr$y = c(6.3,7.3,7.4,7.4,7.8,7.7,8.4,10.8,10.6,10.9,11.0,11.1,10.9,11.0,12.6,12.8) plot(purerr) # simple linear regression inner.lm = lm(y ~ x, data=purerr) # ANOVA outer.lm = lm(y ~ factor(x), data=purerr) # LOF test anova(inner.lm, outer.lm) # Analysis of Variance Table # Model 1: y ~ x # Model 2: y ~ factor(x) # Res.Df RSS Df Sum of Sq F Pr(>F) # 1 14 4.4196 # 2 8 0.0983 6 4.3213 58.594 3.546e-06 *** plot(purerr$x, purerr$y, main="Example: LOF") lines(purerr$x, inner.lm$fitted)