attach(irrigation)
names(irrigation)

plot(Irrigation,Yield)

lines(lowess(Irrigation,Yield))

ord<-order(Irrigation)
par(mfrow=c(1,2))

plot(Irrigation,Yield)
abline(lm(Yield~Irrigation))

plot(Irrigation,Yield)
lines(Irrigation[ord],Yield[ord])

par(mfrow=c(1,1))
plot(Irrigation,Yield)
lines(smooth.spline(Irrigation,Yield,df=3),lty=1)

attach(ethanol)
names(ethanol)

xyplot(NOx~E|C,
                 panel = function(x, y) {
                 panel.grid(h = 2)
                 panel.xyplot(x, y, col = 1, pch = 16)
                 panel.loess(x, y, span = 2/3,degree=1)        })

attach(lodata)
names(lodata)

model<-loess(z~x*y)
summary(model)

plot(model)

fit<-predict(model)
wireframe(fit~x+y)

contourplot(fit~x+y)

levelplot(fit~x+y)

image(interp(x,y,fit))

attach(ozone.data)
names(ozone.data)

pairs(ozone.data, panel=function(x,y) { points(x,y); lines(lowess(x,y))} )

model<-gam(ozone~s(rad)+s(temp)+s(wind))
summary(model)

model2<-gam(ozone~s(temp)+s(wind))
anova(model,model2,test="F")

wt<-wind*temp

model3<-gam(ozone~s(temp)+s(wind)+s(rad)+s(wt))
summary(model3)

anova(model,model3,test="F")

par(mfrow=c(2,2))
plot.gam(model3,resid=T,rugplot=F)

model<-tree(ozone~.,ozone.data)
plot(model,type="u")
text(model)


