[R] Submodel selection using dredge and gam (mgcv)
a.mosnier at gmail.com
Wed Nov 12 15:19:39 CET 2014
Thanks for your answer. In fact, I already tried something with operators
in such a way you advise, but it seems more complicated due to the use of
the s() and ti() operators.
Can you provide a solution for the following example ?
dat <- gamSim(1,n=400,dist="normal",scale=2)
bt <- gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method="ML")
# this does not work
dredge(bt, subset = (!(x0,x1) | (x0 & x1)))
dredge(bt, subset = (!ti(x0,x1) | (s(x0) & s(x1))))
2014-11-11 4:11 GMT-05:00 Kamil Bartoń <kamil.barton at o2.pl>:
> 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")
> On 2014-11-10 21:26, Arnaud Mosnier wrote:
>> 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)
>> 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
>> 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 !
[[alternative HTML version deleted]]
More information about the R-help