# Chapter 11 rm(ozone) ozone.pollution<-read.table("c:\\temp\\ozone.data.txt",header=T) attach(ozone.pollution) names(ozone.pollution) pairs(ozone.pollution,panel=panel.smooth) library(mgcv) par(mfrow=c(2,2)) model<-gam(ozone~s(rad)+s(temp)+s(wind)) plot(model) par(mfrow=c(1,1)) # make sure that you have down-loaded the tree library from CRAN library(tree) model<-tree(ozone~.,data=ozone.pollution) plot(model) text(model) model1<-lm(ozone~temp*wind*rad+I(rad^2)+I(temp^2)+I(wind^2)) summary(model1) model2<-update(model1,~. – temp:wind:rad) summary(model2) model3<-update(model2,~. - wind:rad) summary(model3) model4<-update(model3,~. - temp:wind) summary(model4) model5<-update(model4,~. - I(rad^2)) summary(model5) model6<-update(model5,~. - temp:rad) summary(model6) model7<-lm(log(ozone) ~ temp + wind + rad + I(temp^2) + I(wind^2)) summary(model7) model8<-update(model7,~. - I(temp^2)) summary(model8) plot(model8) model9<-lm(log(ozone) ~ temp + wind + rad + I(wind^2),subset=(1:length(ozone)!=17)) summary(model9) pollute<-read.table("c:\\temp\\sulphur.dioxide.txt",header=T) attach(pollute) names(pollute) pairs(pollute,panel=panel.smooth) # make sure that you have down-loaded the tree library from CRAN library(tree) model<-tree(Pollution~.,data=pollute) plot(model) text(model) model1<-lm(Pollution~Temp+I(Temp^2)+Industry+I(Industry^2)+Population+I(Population^2)+Wind+I(Wind^2)+Rain+I(Rain^2)+Wet.days+I(Wet.days^2)) summary(model1) interactions<-c("ti","tp","tw","tr","td","ip","iw","ir","id","pw","pr","pd","wr","wd","rd") sample(interactions) model2<-lm(Pollution~Temp+Industry+Population+Wind+Rain+Wet.days+Wind:Rain+Wind:Wet.days+Industry:Wet.days+Industry:Rain+Rain:Wet.days) model3<-lm(Pollution~Temp+Industry+Population+Wind+Rain+Wet.days+Population:Rain+Temp:Population+Population:Wind+Temp:Industry+Industry:Wind) model4<-lm(Pollution~Temp+Industry+Population+Wind+Rain+Wet.days+Temp:Wind+Population:Wet.days+Temp:Rain+Temp:Wet.days+Industry:Population) model5<-lm(Pollution~Temp+Industry+Population+Wind+Rain+Wet.days+Wind:Rain+Wind:Wet.days+Population:Wind+Temp:Rain) summary(model5) model6<-update(model5,~. – Temp:Rain) model7<-update(model6,~. – Population:Wind) plot(model7) model8<-update(model7,~. + Wind:Rain:Wet.days) summary(model8)