I?m confused by the difference in the fit of a gam model (in package mgcv) 
when I specify an interaction in different ways.  I would appreciate it if 
someone could explain the cause of these differences.

For example:

x <- c(105, 124, 124, 124, 144, 144, 150, 176, 178, 178, 
        206, 206, 212, 215, 215, 227, 229, 229, 229, 234, 
        234, 254, 254, 290, 290, 303, 334, 334, 334, 344, 
        345, 345)
y <- c(0.31, 1.41, 2.87, 1.92, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 
        0.31, 0.31, 0.31, 1.92, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 
        0.31, 2.08, 2.28, 1.59, 2.13, 2.77, 3.97, 4.54, 4.35, 3.6, 
        5.2, 4.6)
loc <- c("S", "N", "S", "S", "N", "N", "S", "S", "N", "N", 
        "N", "N", "S", "N", "S", "S", "N", "S", "S", "N", 
        "N", "N", "N", "N", "N", "S", "N", "S", "S", "N", 
        "S", "S")
locf <- as.factor(loc)
locN <- as.numeric(loc=="N")
locS <- as.numeric(loc=="S")

# fit the model with a separate smooth for loc = N and loc = S
fit1 <- gam(y ~ locf + s(x, by=locN) + s(x, by=locS))

# fit the model with a separate smooth for each level of the factor loc (N 
and S)
fit2 <- gam(y ~ locf + s(x, by=locf))

# The shape of the relations are similar, but the vertical locations are 
different,
# and the size of the standard errors of the smooth are different
windows()
par(mfrow=c(2, 2), mar=c(4, 4, 2, 1))
plot(fit1)
plot(fit2)

# The R-sq., deviance explained, GCV score, and scale est. are the same,
# but the estimates and degrees of freedom are different
summary(fit1)
summary(fit2)

I'm using R version 2.13.0 (2011-04-13) and mgcv version 1.7-6 on Windows 
XP.

Thanks for your help.

Jean


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
http://www.glsc.usgs.gov  (GLSC web site)
jvadams@usgs.gov  (E-mail)
	[[alternative HTML version deleted]]

