[R] Submodel selection using dredge and gam (mgcv)
Kamil Bartoń
kamil.barton at o2.pl
Tue Nov 11 10:11:50 CET 2014
Hi Arnaud,
your question has in fact nothing to do with gam or model selection.
What you are asking is: what is the logical expression that yields True
when AB is False or both A and B are True. Now replace the words with
operators (!AB | (A & B)) and voilà.
See also:
help("Logic", "base")
fortunes::fortune(350)
best,
kamil
On 2014-11-10 21:26, Arnaud Mosnier wrote:
> 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
More information about the R-help
mailing list