Hi Kamil, 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 ? library(mgcv) set.seed(2) dat <- gamSim(1,n=400,dist="normal",scale=2) bt <- gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method="ML") library(MuMIn) # this does not work dredge(bt, subset = (!(x0,x1) | (x0 & x1))) dredge(bt, subset = (!ti(x0,x1) | (s(x0) & s(x1)))) Cheers, Arnaud 2014-11-11 4:11 GMT-05:00 Kamil Bartoń <kamil.bar...@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") > 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 >> > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.