Why does the mgcv::gam.vcomp
show two variance components for interactions made with mgcv::ti
?¨
I can't seem to find the explanation or the between-the-lines explanation anywhere. Is is perhaps variance attributed to each components in the interaction?
require(mgcv)
test1 <- function(x,z,sx=0.3,sz=0.4) {
x <- x*20
(pi**sx*sz)*(1.2*exp(-(x-0.2)^2/sx^2-(z-0.3)^2/sz^2)+
0.8*exp(-(x-0.7)^2/sx^2-(z-0.8)^2/sz^2))
}
n <- 500
old.par <- par(mfrow=c(2,2))
x <- runif(n)/20;z <- runif(n);
xs <- seq(0,1,length=30)/20;zs <- seq(0,1,length=30)
pr <- data.frame(x=rep(xs,30),z=rep(zs,rep(30,30)))
truth <- matrix(test1(pr$x,pr$z),30,30)
f <- test1(x,z)
y <- f + rnorm(n)*0.2
b3 <- gam(y~ ti(x) + ti(z) + ti(x,z))
b3s <- gam(y~ ti(x) + ti(z) + s(x,z)) # describing the itneraction with s().
I know we're sort of mixing apples and oranges here.
gam.vcomp(b3)
ti(x) ti(z) ti(x,z)1 ti(x,z)2
0.06609731 0.01476070 0.08834218 0.05700322
gam.vcomp(b3s)
ti(x) ti(z) s(x,z)
0.1623056 2.4870344 7.7484987
You'll see the same behaviour with te(x, z)
> b <- gam(y ~ te(x,z))
> gam.vcomp(b)
te(x,z)1 te(x,z)2
0.08668107 0.04596708
and arises because tensor product smooths are defined by two, in this case, marginal bases, each of which have a smoothness parameter. Hence there are two variance components, one per smoothness parameter/marginal basis.
ti(x,z)1
is the variance component for the marginal basis of x
,ti(x,z)2
is the variance component for the marginal basis of z
.As these tensor product interactions smooth have had the main effects removed from them, physical interpretation is complicated, but in a practical sense, the values are the variance component interpretation of the smoothness parameters of the marginal bases.
The reason s(x, z)
has just one variance component is that it is a 2-d thinplate spline basis. This basis is isotropic; there is the same smoothness in the to dimensions and hence a single smoothness parameter is required for the basis. Hence there is a single variance component.