# R example of lack of fit test # The data are from the bank example discussed in class. # deposit will be our predictor variable (X). # accounts will be our response variable (Y). # Reading the data into R: my.datafile <- tempfile() cat(file=my.datafile, " 125 160 100 112 200 124 75 28 150 152 175 156 75 42 175 124 125 150 200 104 100 136 ", sep=" ") options(scipen=999) # suppressing scientific notation banks <- read.table(my.datafile, header=FALSE, col.names=c("deposit","accounts")) attach(banks) ######### ######### ## Initial scatterplot of data: plot(deposit, accounts) # Not a linear trend? # Reduced (linear) model reduced_model_37 <- lm(accounts ~ deposit, data = banks) # Full (categorical/factor) model full_model_37 <- lm(accounts ~ factor(deposit), data = banks) # Compare models with ANOVA (general linear test) anova(reduced_model_37, full_model_37) # Find the results of the lack-of-fit F-test in the R output. # Compare the results in the R output to the results in the # book (Sec. 3.7) for the banks example.