[R] Submodel selection using dredge and gam (mgcv)

Arnaud Mosnier a.mosnier at gmail.com
Mon Nov 10 21:26:43 CET 2014


Hi,

I want to use dredge to test several gam submodels including interactions.
I tried to find a way in order to keep models with interaction only if the
single variables occurring in the interaction are also included.

i.e.: for
 y~s(x0)+s(x1)+ti(x0, x1)

I want to keep
y ~ s(x0)
y ~ s(x1)
y ~ s(x0) + s(x1)
y ~ s(x0) + s(x1) + ti(x0,x1)

and I want to remove

y ~ s(x0) + ti(x0,x1)
y ~ s(x1) + ti(x0,x1)
y ~ ti(x0,x1)


I know that I should use the "subset" option of the dredge function.
However, I can not find the correct matrix / expression to obtain what I
need !


Here a small example.

################

# Create some data (use mgcv example)
library(mgcv)
set.seed(2)
dat <- gamSim(1,n=400,dist="normal",scale=2)

# Create the global gam model
# Here a model with interaction. Note the use of ti()
bt <- gam(y~s(x0)+s(x1)+s(x2)+s(x3)+ti(x1,x2), data=dat,method="ML")

# Use dredge to test sub-models
library(MuMIn)
print(modstab <- dredge(bt))

# Here the 11th model include the interaction but do not include the single
variables x1 and x2
# ... I want to avoid that kind of model.
get.models(modstab, subset = 11)

################


Any help would be appreciated !

Arnaud

	[[alternative HTML version deleted]]



More information about the R-help mailing list