if (FALSE) {
library(agridat)
data(thompson.cornsoy)
dat <- thompson.cornsoy
# The droughts of 1934/36 were severe in IA/MO. Less so in OH.
libs(lattice)
xyplot(corn+soy~year|state, dat,
type=c('p','l','r'), auto.key=list(columns=2),
main="thompson.cornsoy",
layout=c(5,1),ylab='yield')
# In 1954, only Missouri suffered very hot, dry weather
## xyplot(corn~year, dat,
## groups=state, type=c('p','l'),
## main="thompson.cornsoy",
## auto.key=list(columns=5), ylab='corn yield')
# Rain and temperature have negative correlation in each month.
# July is a critical month: temp and yield are negatively correlated,
# while rain and yield are positively correlated.
# splom(~dat[-1,-1], col=dat$state, cex=.5, main="thompson.cornsoy")
# Plots similar to those in Venables' Exegeses paper.
dat.ia <- subset(dat, state=="Iowa")
libs(splines)
m2 <- aov(corn ~ ns(rain0, 3) + ns(rain7, 3) +
ns(temp8, 3) + ns(year,3), dat.ia)
op <- par(mfrow=c(2,2))
termplot(m2, se=TRUE, rug=TRUE, partial=TRUE, main="thompson.cornsoy")
par(op)
# do NOT use gam package
libs(mgcv)
m1 <- gam(corn ~ s(year, k=5) + s(rain0, k=5) +
s(rain7, k=5) + s(temp8, k=5), data=dat.ia)
op <- par(mfrow=c(2,2))
plot.gam(m1, residuals=TRUE, se=TRUE, cex=2, main="thompson.cornsoy")
par(op)
}
Run the code above in your browser using DataLab