The ethanol dataframe contains 88 sets of measurements for variables from an experiment in which ethanol was burned in a single cylinder automobile test engine. The response variable, NOx, is the concentration of nitric oxide (NO) and nitrogen dioxide (NO2) in engine exhaust, normalized by the work done by the engine, and the two continuous explanatory variables are C (the compression ratio of the engine), and E (the equivalence ratio at which the engine was run, which is a measure of the richness of the air–ethanol mix).
install.packages("SemiPar") library(SemiPar) data(ethanol) attach(ethanol) names(ethanol)  "Nox" "C" "E"
Because NOx is such a strongly humped function of the equivalence ratio, E, we start with a model, NOx ~ s(E) + C, that fits this as a smoothed term and estimates a parametric term for the compression ratio:
model<-gam(NOx~s(E)+C) par(mfrow=c(1,2)) plot.gam(model,residuals=T,pch=16,all.terms=T)
The coplot function is helpful in showing where the effect of C on NOx was most marked:
There is a pronounced positive effect of C on NOx only in panel 2 (ethanol 0.7 < E < 0.9 from the shingles ...