Skip to content

group interaction in a varying coeff. model (mgcv)

2 messages · Denes Toth, Simon Wood

#
After your code below you could add...

x1g <- X*(1-Group)
x2g <- X*Group

## different moderator effects in the different groups...
mgu <- gam(Y~s(M,by=x1g)+s(M,by=x2g))

## same moderator effects, but different intercepts in the groups...
mgc <- gam(Y~s(M,by=X)+Group)

## Alternative way of specifying different moderator effects
## in the 2 groups...
mgu.alt <- gam(Y~s(M,by=X)+s(M,by=x2g))

## compare alternatives via generalized AIC...
AIC(mgu,mgc,mgu.alt)

## ... in general you could use an approximate GLRT as well.
## e.g. anova(mgc, mgu), but in this case it makes no sense
## as mgc is estimated to have *higher* edf than mgu, clearly
## indicating that mgu is preferable by any sensible measure.

Note that mgu and mgu.alt will not generally give identical fitted
values, despite superficially appearing to be the same model
parameterized in two different ways. This is because the smoothing
penalties mean that the models are actually different (In mgu the
effects in the 2 groups are assumed to be smooth, but in mgu.alt the
difference in effects is assumed smooth, as is the overall effect...)

best,
Simon
On 27/06/11 13:53, Denes Toth wrote:
> # ------ # generate moderator variable (can the
> modvar<- c(1:1000)
> x1<- rnorm(1000)
 > y1<- scale(cbind(1,poly(modvar,2))%*%c(1,2,1)*x1 + rnorm(1000,0,0.3))
> y2<-scale(cbind(1,poly(modvar,2))%*%c(-1,0.5,-1)*x2 + rnorm(1000,0,0.3))
> mg1<- gam(y1~s(modvar,by=x1))
 > mg2<-gam(y2~s(modvar,by=x2))
> M<- c(modvar,modvar)