Is there a function that will allow me to run all model iterations if I specify a full model? I am using information criteria to choose between possible candidate models. I have been writing out all possible model combinations by hand, and I am always worried that I am missing models or have made a mistake somewhere. It is also difficult to alter models if I want to change a term. For example, below are the set of models I would like to run. Is there a way to specify the full model and have R generate the rest? I.e. specify m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) and have R run all the other models. library(MASS) #Intercept only m0<-glm.convert(glm.nb(mantas~1,data=mydata)) #One term - 7 models #Manta abundance is greater at one of the two sites m1<-glm.convert(glm.nb(mantas~site,data=mydata)) #Manta abundance increases each year as the population increases in size due to births or immigration being greater than deaths and emmigration m2<-glm.convert(glm.nb(mantas~year,data=mydata)) #Manta abundances increases during part of the year due to seasonal cycles in resources (mates, food) m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) #Manta abundance decreases with increased lunar phase m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) #Manta abundance increases with increased levels of plankton m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) #Two terms - 21 models m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) #Interaction term to account for hotel being closed at Keauhou for some years m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this have an interaction term? Plankton may varry by site m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) #Interaction term? Plankton may vary by season m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) #Interaction term? Plankton may vary by season m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) #Interaction term? Plankton may have lunar cycles #Three terms - 35 models m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) #Four terms - 34 models m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, data=mydata)) m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, data=mydata)) m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, data=mydata)) m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, data=mydata)) m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, data=mydata)) m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, data=mydata)) m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, data=mydata)) m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, data=mydata)) m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, data=mydata)) m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, data=mydata)) m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) #Five terms - 21 models m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, data=mydata)) m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, data=mydata)) m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, data=mydata)) m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, data=mydata)) m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, data=mydata)) m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, data=mydata)) m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, data=mydata)) m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, data=mydata)) m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, data=mydata)) m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, data=mydata)) m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, data=mydata)) m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, data=mydata)) m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, data=mydata)) m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) #Six terms - 7 models m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) #Seven terms - 1 model m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) Tim Clark Department of Zoology University of Hawaii
Do you mean only all of the FIRST order models (that is, without interactions) ? ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Wed, May 19, 2010 at 7:38 AM, Tim Clark <mudiver1200@yahoo.com> wrote:> Is there a function that will allow me to run all model iterations if I > specify a full model? I am using information criteria to choose between > possible candidate models. I have been writing out all possible model > combinations by hand, and I am always worried that I am missing models or > have made a mistake somewhere. It is also difficult to alter models if I > want to change a term. For example, below are the set of models I would > like to run. Is there a way to specify the full model and have R generate > the rest? I.e. specify > > m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > and have R run all the other models. > > > library(MASS) > > #Intercept only > m0<-glm.convert(glm.nb(mantas~1,data=mydata)) > > #One term - 7 models > #Manta abundance is greater at one of the two sites > m1<-glm.convert(glm.nb(mantas~site,data=mydata)) > #Manta abundance increases each year as the population increases in size > due to births or immigration being greater than deaths and emmigration > m2<-glm.convert(glm.nb(mantas~year,data=mydata)) > #Manta abundances increases during part of the year due to seasonal cycles > in resources (mates, food) > m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) > m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) > #Manta abundance decreases with increased lunar phase > m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) > m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) > #Manta abundance increases with increased levels of plankton > m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) > > #Two terms - 21 models > m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) #Interaction > term to account for hotel being closed at Keauhou for some years > m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) > m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) > m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) > m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) > m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this > have an interaction term? Plankton may varry by site > > m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) > m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) > m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) > m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) > m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) > > m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) > m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) > m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) > m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) > #Interaction term? Plankton may vary by season > > m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) > m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) > m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) > #Interaction term? Plankton may vary by season > > m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) > m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) > > m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) > #Interaction term? Plankton may have lunar cycles > > #Three terms - 35 models > m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) > m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) > m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) > m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) > m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) > > m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) > m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) > m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) > m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) > > m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) > m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) > m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) > > m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) > m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) > > m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) > > m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) > m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) > m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) > m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) > > m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) > m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) > m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) > > m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) > m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) > > m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) > > m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) > m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) > m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) > > m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) > m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) > > m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) > > m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) > m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) > > m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) > > m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) > > #Four terms - 34 models > m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, > data=mydata)) > m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, > data=mydata)) > m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, > data=mydata)) > m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, > data=mydata)) > > m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, > data=mydata)) > m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, > data=mydata)) > m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, > data=mydata)) > > m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, > data=mydata)) > m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, > data=mydata)) > > m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, > data=mydata)) > > > m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) > > m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) > > m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) > > > m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) > > m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) > > > m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) > > > m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) > > m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) > > > m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) > > > m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) > > > m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) > > m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) > > m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) > > > m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) > > m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) > > > m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) > > > m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) > > m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) > > > m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) > > > m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) > > > m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) > > m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) > > > m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) > > > m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) > > #Five terms - 21 models > m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, > data=mydata)) > m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, > data=mydata)) > m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, > data=mydata)) > > m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, > data=mydata)) > m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, > data=mydata)) > > m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, > data=mydata)) > > m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, > data=mydata)) > m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, > data=mydata)) > > m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, > data=mydata)) > > m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, > data=mydata)) > > m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, > data=mydata)) > m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, > data=mydata)) > > m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, > data=mydata)) > > m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, > data=mydata)) > m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, > data=mydata)) > > m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, > data=mydata)) > > m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > #Six terms - 7 models > m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, > data=mydata)) > m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, > data=mydata)) > > m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, > data=mydata)) > > m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > #Seven terms - 1 model > m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, > data=mydata)) > > > Tim Clark > Department of Zoology > University of Hawaii > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Hi Tim, So if I understand you correctly, you are talking about 7! models, that's hell of alot, are you considering model-selection/multiple-comparisons issues when you are picking your models ? If you are hoping to do cross validation on such a variaty of models, you might find out it wouldn't scale for larger problems. There is the regsubsets from the {leaps} package. Which can also work with biglm and bigglm objects. I am not sure what alternative exists for other glm objects, but it's worth checking. I can imagine you can write a function that will create all the variable combinations using a combo of the functions combn (to create all the combinations) with eval+parse. But asI wrote, I think you're issue here is the model selection, not just the creation of all the models. Best, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Wed, May 19, 2010 at 2:00 PM, Tim Clark <mudiver1200@yahoo.com> wrote:> Not necessarily. In the example I included: > > manta~year*site > > in the model, which includes both first order terms and interactions: > > manta~year+site+year:site > > I am just wanting to know if there is an easier way than writing out all > the possible models long-hand given a full model with all desired terms, > where some terms may have interactions and others don't. > > > > > > > Tim Clark > Department of Zoology > University of Hawaii > > --- On *Tue, 5/18/10, Tal Galili <tal.galili@gmail.com>* wrote: > > > From: Tal Galili <tal.galili@gmail.com> > Subject: Re: [R] Generating all possible models from full model > To: "Tim Clark" <mudiver1200@yahoo.com> > Cc: r-help@r-project.org > Date: Tuesday, May 18, 2010, 9:40 PM > > > Do you mean only all of the FIRST order models (that is, without > interactions) ? > > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili@gmail.com<http://mc/compose?to=Tal.Galili@gmail.com>| 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > > > > On Wed, May 19, 2010 at 7:38 AM, Tim Clark <mudiver1200@yahoo.com<http://mc/compose?to=mudiver1200@yahoo.com> > > wrote: > >> Is there a function that will allow me to run all model iterations if I >> specify a full model? I am using information criteria to choose between >> possible candidate models. I have been writing out all possible model >> combinations by hand, and I am always worried that I am missing models or >> have made a mistake somewhere. It is also difficult to alter models if I >> want to change a term. For example, below are the set of models I would >> like to run. Is there a way to specify the full model and have R generate >> the rest? I.e. specify >> >> m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> and have R run all the other models. >> >> >> library(MASS) >> >> #Intercept only >> m0<-glm.convert(glm.nb(mantas~1,data=mydata)) >> >> #One term - 7 models >> #Manta abundance is greater at one of the two sites >> m1<-glm.convert(glm.nb(mantas~site,data=mydata)) >> #Manta abundance increases each year as the population increases in size >> due to births or immigration being greater than deaths and emmigration >> m2<-glm.convert(glm.nb(mantas~year,data=mydata)) >> #Manta abundances increases during part of the year due to seasonal >> cycles in resources (mates, food) >> m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) >> m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) >> #Manta abundance decreases with increased lunar phase >> m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) >> m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) >> #Manta abundance increases with increased levels of plankton >> m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) >> >> #Two terms - 21 models >> m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) #Interaction >> term to account for hotel being closed at Keauhou for some years >> m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) >> m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) >> m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) >> m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) >> m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this >> have an interaction term? Plankton may varry by site >> >> m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) >> m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) >> m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) >> m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) >> m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) >> >> m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) >> m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) >> m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) >> m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) >> #Interaction term? Plankton may vary by season >> >> m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) >> m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) >> m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) >> #Interaction term? Plankton may vary by season >> >> m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) >> m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) >> >> m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) >> #Interaction term? Plankton may have lunar cycles >> >> #Three terms - 35 models >> m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) >> m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) >> m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) >> m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) >> m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) >> >> m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) >> m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) >> m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) >> m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) >> >> m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) >> m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) >> m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) >> >> m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) >> m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) >> >> m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) >> >> m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) >> m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) >> m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) >> m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) >> >> m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) >> m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) >> m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) >> >> m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) >> m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) >> >> m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) >> >> m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) >> m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) >> m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) >> >> m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) >> m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) >> >> m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) >> >> m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) >> m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) >> >> m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) >> >> m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) >> >> #Four terms - 34 models >> m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, >> data=mydata)) >> m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, >> data=mydata)) >> m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, >> data=mydata)) >> m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, >> data=mydata)) >> >> m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, >> data=mydata)) >> m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, >> data=mydata)) >> m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, >> data=mydata)) >> >> m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, >> data=mydata)) >> m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, >> data=mydata)) >> >> m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, >> data=mydata)) >> >> >> m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) >> >> m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) >> >> m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) >> >> >> m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) >> >> m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) >> >> >> m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) >> >> >> m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) >> >> m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) >> >> >> m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) >> >> >> m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) >> >> >> m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) >> >> m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) >> >> m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) >> >> >> m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) >> >> m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) >> >> >> m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) >> >> >> m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) >> >> m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) >> >> >> m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) >> >> >> m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) >> >> >> m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) >> >> m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) >> >> >> m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) >> >> >> m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) >> >> #Five terms - 21 models >> m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, >> data=mydata)) >> m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, >> data=mydata)) >> m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, >> data=mydata)) >> >> m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, >> data=mydata)) >> m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, >> data=mydata)) >> >> m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, >> data=mydata)) >> >> m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, >> data=mydata)) >> m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, >> data=mydata)) >> >> m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, >> data=mydata)) >> >> m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, >> data=mydata)) >> m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, >> data=mydata)) >> >> m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, >> data=mydata)) >> >> m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, >> data=mydata)) >> m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, >> data=mydata)) >> >> m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, >> data=mydata)) >> >> m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> #Six terms - 7 models >> m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, >> data=mydata)) >> m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, >> data=mydata)) >> >> m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, >> data=mydata)) >> >> m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> #Seven terms - 1 model >> m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >> data=mydata)) >> >> >> Tim Clark >> Department of Zoology >> University of Hawaii >> >> ______________________________________________ >> R-help@r-project.org <http://mc/compose?to=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. >> > > >[[alternative HTML version deleted]]
Frank E Harrell Jr
2010-May-19 12:43 UTC
[R] Generating all possible models from full model
On 05/18/2010 11:38 PM, Tim Clark wrote:> Is there a function that will allow me to run all model iterations if I specify a full model? I am using information criteria to choose between possible candidate models. I have been writing out all possible model combinations by hand, and I am always worried that I am missing models or have made a mistake somewhere. It is also difficult to alter models if I want to change a term. For example, below are the set of models I would like to run. Is there a way to specify the full model and have R generate the rest? I.e. specify > > m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > and have R run all the other models. > > > library(MASS) > > #Intercept only > m0<-glm.convert(glm.nb(mantas~1,data=mydata)) > > #One term - 7 models > #Manta abundance is greater at one of the two sites > m1<-glm.convert(glm.nb(mantas~site,data=mydata)) > #Manta abundance increases each year as the population increases in size due to births or immigration being greater than deaths and emmigration > m2<-glm.convert(glm.nb(mantas~year,data=mydata)) > #Manta abundances increases during part of the year due to seasonal cycles in resources (mates, food) > m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) > m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) > #Manta abundance decreases with increased lunar phase > m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) > m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) > #Manta abundance increases with increased levels of plankton > m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) > > #Two terms - 21 models > m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) #Interaction term to account for hotel being closed at Keauhou for some years > m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) > m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) > m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) > m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) > m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this have an interaction term? Plankton may varry by site > > m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) > m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) > m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) > m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) > m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) > > m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) > m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) > m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) > m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) #Interaction term? Plankton may vary by season > > m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) > m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) > m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) #Interaction term? Plankton may vary by season > > m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) > m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) > > m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) #Interaction term? Plankton may have lunar cycles > > #Three terms - 35 models > m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) > m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) > m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) > m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) > m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) > > m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) > m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) > m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) > m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) > > m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) > m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) > m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) > > m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) > m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) > > m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) > > m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) > m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) > m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) > m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) > > m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) > m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) > m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) > > m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) > m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) > > m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) > > m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) > m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) > m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) > > m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) > m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) > > m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) > > m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) > m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) > > m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) > > m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) > > #Four terms - 34 models > m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, data=mydata)) > m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, data=mydata)) > m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, data=mydata)) > m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, data=mydata)) > > m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, data=mydata)) > m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, data=mydata)) > m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, data=mydata)) > > m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, data=mydata)) > m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, data=mydata)) > > m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, data=mydata)) > > m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) > m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) > m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) > > m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) > m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) > > m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) > > m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) > m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) > > m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) > > m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) > > m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) > m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) > m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) > > m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) > m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) > > m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) > > m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) > m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) > > m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) > > m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) > > m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) > m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) > > m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) > > m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) > > #Five terms - 21 models > m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, data=mydata)) > m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, data=mydata)) > m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, data=mydata)) > > m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, data=mydata)) > m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, data=mydata)) > > m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, data=mydata)) > > m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, data=mydata)) > m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, data=mydata)) > > m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, data=mydata)) > > m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, data=mydata)) > > m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Six terms - 7 models > m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Seven terms - 1 model > m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > > Tim Clark > Department of Zoology > University of HawaiiPlease read the large number of notes in the e-mail archive about the invalidity of such modeling procedures. Frank -- Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
Try the MuMIn package from r-forge. Ben Bolker
Hi Tim, Here is a rather clumsy way of going about your task: # ---------- example code --------- func.getY.getX.return.lm <- function(Y, X.matrix , lm.id.vec) { # gets a Y, a vec of T/F and a X.matrix # performs lm # and returns output potential.X.size <- length(lm.id.vec) + 1 lm.data <- data.frame(Y, X.matrix[,lm.id.vec]) lm1 <- lm(Y ~ . ,data = lm.data) return(lm1) } data(mtcars) X <- mtcars[, -1] Y <- mtcars[, 1] X.toUse <- sample(c(T,F), 10, T) func.getY.getX.return.lm(Y, X , X.toUse ) # ---------- example code --------- Now what you will need to do is: 1) Create an X matrix that includes the vectors of all the interactions you will be interested in. 2) make a matrix of TRUE/FALSE id's for the variables you would like to use. 3) go through that matrix and build the models (using, for example, the function I gave above) 4) insert the output to a big list(), and on that list perform the checks that interest you for finding your model. As Frank Harrell and the others have mentioned, you are walking on VERY shaky grounds (in terms of the stability of your models predictive/explanatory power). In case you develop the code more, I'd be curious to see how you did it. Good luck, Tal ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Wed, May 19, 2010 at 8:48 PM, Tim Clark <mudiver1200@yahoo.com> wrote:> Tal, > > No, I am definitely not wanting to generate 7! models. At least not with > my current dataset. That would only be if I was running all first order > terms and all possible interactions. In this example I am only wanting to > run interactions for the variables year:site, which should give 2^7+32=160 > possible models. What I am really asking is if everyone writes out all of > their models of interest by hand, or if there is some function that has been > written that makes it easier to generate all the models. I keep making > mistakes when writing out lots of models, and was hoping for something that > would automate the process so that I was sure I didn't screw up in the > formulas. This may just require more practice on my part, but it seems like > such a common problem that someone would have written a function to do it. > It looks like a function could be written using combn() with different > number of elements. I will see if I can come up with something. > > I am using AIC values to pick the best models and the function modavg() in > the package AICcmodavg to generate model averages. I have read a lot about > the problems of stepwise selection, so I am trying to find something besides > regsubsets() from leaps package. > > Thanks, > > Tim > > > Tim Clark > Department of Zoology > University of Hawaii > > --- On *Wed, 5/19/10, Tal Galili <tal.galili@gmail.com>* wrote: > > > From: Tal Galili <tal.galili@gmail.com> > Subject: Re: [R] Generating all possible models from full model > To: "Tim Clark" <mudiver1200@yahoo.com> > Cc: r-help@r-project.org > Date: Wednesday, May 19, 2010, 12:47 AM > > Hi Tim, > So if I understand you correctly, you are talking about 7! models, that's > hell of alot, are you considering model-selection/multiple-comparisons > issues when you are picking your models ? > If you are hoping to do cross validation on such a variaty of models, you > might find out it wouldn't scale for larger problems. > > There is the > regsubsets from the {leaps} package. > Which can also work with biglm and bigglm objects. I am not sure what > alternative exists for other glm objects, but it's worth checking. > > I can imagine you can write a function that will create all the variable > combinations using a combo of the functions combn (to create all the > combinations) with eval+parse. > But asI wrote, I think you're issue here is the model selection, not just > the creation of all the models. > > Best, > Tal > > > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili@gmail.com<http://us.mc361.mail.yahoo.com/mc/compose?to=Tal.Galili@gmail.com>| 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > > > > On Wed, May 19, 2010 at 2:00 PM, Tim Clark <mudiver1200@yahoo.com<http://us.mc361.mail.yahoo.com/mc/compose?to=mudiver1200@yahoo.com> > > wrote: > >> Not necessarily. In the example I included: >> >> manta~year*site >> >> in the model, which includes both first order terms and interactions: >> >> manta~year+site+year:site >> >> I am just wanting to know if there is an easier way than writing out all >> the possible models long-hand given a full model with all desired terms, >> where some terms may have interactions and others don't. >> >> >> >> >> >> >> Tim Clark >> Department of Zoology >> University of Hawaii >> >> --- On *Tue, 5/18/10, Tal Galili <tal.galili@gmail.com<http://us.mc361.mail.yahoo.com/mc/compose?to=tal.galili@gmail.com> >> >* wrote: >> >> >> From: Tal Galili <tal.galili@gmail.com<http://us.mc361.mail.yahoo.com/mc/compose?to=tal.galili@gmail.com> >> > >> Subject: Re: [R] Generating all possible models from full model >> To: "Tim Clark" <mudiver1200@yahoo.com<http://us.mc361.mail.yahoo.com/mc/compose?to=mudiver1200@yahoo.com> >> > >> Cc: r-help@r-project.org<http://us.mc361.mail.yahoo.com/mc/compose?to=r-help@r-project.org> >> Date: Tuesday, May 18, 2010, 9:40 PM >> >> >> Do you mean only all of the FIRST order models (that is, without >> interactions) ? >> >> >> >> >> ----------------Contact >> Details:------------------------------------------------------- >> Contact me: Tal.Galili@gmail.com<http://mc/compose?to=Tal.Galili@gmail.com>| 972-52-7275845 >> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | >> www.r-statistics.com (English) >> >> ---------------------------------------------------------------------------------------------- >> >> >> >> >> On Wed, May 19, 2010 at 7:38 AM, Tim Clark <mudiver1200@yahoo.com<http://mc/compose?to=mudiver1200@yahoo.com> >> > wrote: >> >>> Is there a function that will allow me to run all model iterations if I >>> specify a full model? I am using information criteria to choose between >>> possible candidate models. I have been writing out all possible model >>> combinations by hand, and I am always worried that I am missing models or >>> have made a mistake somewhere. It is also difficult to alter models if I >>> want to change a term. For example, below are the set of models I would >>> like to run. Is there a way to specify the full model and have R generate >>> the rest? I.e. specify >>> >>> m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> and have R run all the other models. >>> >>> >>> library(MASS) >>> >>> #Intercept only >>> m0<-glm.convert(glm.nb(mantas~1,data=mydata)) >>> >>> #One term - 7 models >>> #Manta abundance is greater at one of the two sites >>> m1<-glm.convert(glm.nb(mantas~site,data=mydata)) >>> #Manta abundance increases each year as the population increases in size >>> due to births or immigration being greater than deaths and emmigration >>> m2<-glm.convert(glm.nb(mantas~year,data=mydata)) >>> #Manta abundances increases during part of the year due to seasonal >>> cycles in resources (mates, food) >>> m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) >>> m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) >>> #Manta abundance decreases with increased lunar phase >>> m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) >>> m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) >>> #Manta abundance increases with increased levels of plankton >>> m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) >>> >>> #Two terms - 21 models >>> m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) #Interaction >>> term to account for hotel being closed at Keauhou for some years >>> m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) >>> m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) >>> m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) >>> m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) >>> m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this >>> have an interaction term? Plankton may varry by site >>> >>> m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) >>> m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) >>> m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) >>> m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) >>> m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) >>> >>> m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) >>> m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) >>> m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) >>> m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) >>> #Interaction term? Plankton may vary by season >>> >>> m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) >>> m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) >>> m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) >>> #Interaction term? Plankton may vary by season >>> >>> m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) >>> m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) >>> >>> m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) >>> #Interaction term? Plankton may have lunar cycles >>> >>> #Three terms - 35 models >>> m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) >>> m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) >>> m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) >>> m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) >>> m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) >>> >>> m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) >>> m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) >>> m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) >>> m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) >>> >>> m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) >>> m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) >>> m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) >>> >>> m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) >>> m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) >>> >>> m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) >>> >>> m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) >>> m235<-glm.convert(glm.nb(mant as~year+cosmonth+coslunar,data=mydata)) >>> >>> m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) >>> m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) >>> >>> m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) >>> m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) >>> m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) >>> >>> m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) >>> m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) >>> >>> m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) >>> >>> m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) >>> m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) >>> m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) >>> >>> & >>> nbsp;m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) >>> >>> m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) >>> >>> m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) >>> >>> m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) >>> m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) >>> >>> m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) >>> >>> m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) >>> >>> #Four terms - 34 models >>> m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, >>> data=mydata)) >>> m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, >>> data=mydata)) >>> m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, >>> data=mydata)) >>> m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, >>> data=mydata)) >>> >>> m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, >>> data=mydata)) >>> m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, >>> data=mydata)) >>> m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, >>> data=mydata)) >>> >>> m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, >>> data=mydata)) >>> m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, >>> data=mydata)) >>> >>> m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, >>> data=mydata)) >>> >>> >>> m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) >>> >>> m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) >>> >>> m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) >>> >>> >>> m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) >>> >>> m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) >>> >>> >>> m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) >>> >>> >>> m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) >>> >>> m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) >>> >>> >>> m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) >>> >>> >>> m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) >>> >>> m2345 >>> <-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) >>> >>> m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) >>> >>> m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) >>> >>> >>> m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) >>> >>> m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) >>> >>> >>> m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) >>> >>> >>> m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) >>> >>> m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) >>> >>> >>> m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) >>> >>> >>> m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) >>> >>> m3456<-glm.convert(glm.nb(mantas~co >>> smonth+sinmonth+coslunar+sinlunar,data=mydata)) >>> >>> >>> m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) >>> >>> >>> m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) >>> >>> >>> m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) >>> >>> #Five terms - 21 models >>> m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, >>> data=mydata)) >>> m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, >>> data=mydata)) >>> m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, >>> data=mydata)) >>> >>> m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, >>> data=mydata)) >>> m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, >>> data=mydata)) >>> >>> m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, >>> data=mydata)) >>> >>> m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, >>> data=mydata)) >>> m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, >>> data=mydata)) >>> >>> m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, >>> data=mydata)) >>> >>> m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, >>> data=mydata)) >>> m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, >>> data=mydata)) >>> >>> m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, >>> data=mydata)) >>> >>> m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, >>> data=mydata)) >>> m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, >>> data=mydata)) >>> >>> m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, >>> data=mydata)) >>> >>> m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> #Six terms - 7 models >>> m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, >>> data=mydata)) >>> m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, >>> data=mydata)) >>> >>> m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, >>> data=mydata)) >>> >>> m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> #Seven terms - 1 model >>> m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, >>> data=mydata)) >>> >>> >>> Tim Clark >>> Department of Zoology >>> University of Hawaii >>> >>> ______________________________________________ >>> R-help@r-project.org <http://mc/compose?to=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<http://www.r-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> > >[[alternative HTML version deleted]]
A couple of years ago, I wrote a function for doing this. It can be found in the following file: http://pegasus.cc.ucf.edu/~xsu/CLASS/STA4164/mt4-2009.doc I also pasted a copy below. Hope you find it useful. -XG # =======================# ALL POSSIBLE REGRESSIONS # =======================# The parameter k is the total number of predictors. To apply the function, # you need to prepare the data so that all predictors for selection are named # as x1, x2, ..., and the response is called y. all.possible.regressions <- function(dat, k){ n <- nrow(dat) regressors <- paste("x", 1:k, sep="") lst <- rep(list(c(T, F)), k) regMat <- expand.grid(lst); names(regMat) <- regressors formular <- apply(regMat, 1, function(x) as.character(paste(c("y ~ 1", regressors[x]), collapse="+"))) allModelsList <- apply(regMat, 1, function(x) as.formula(paste(c("y ~ 1", regressors[x]),collapse=" + ")) ) allModelsResults <- lapply(allModelsList, function(x, data) lm(x, data=data), data=dat) n.models <- length(allModelsResults) extract <- function(fit) { df.sse <- fit$df.residual p <- n - df.sse -1 sigma <- summary(fit)$sigma MSE <- sigma^2 R2 <- summary(fit)$r.squared R2.adj <- summary(fit)$adj.r.squared sse <- MSE*df.sse aic <- n*log(sse) + 2*(p+2) bic <- n*log(sse) + log(n)*(p+2) out <- data.frame(df.sse=df.sse, p=p, SSE=sse, MSE=MSE, R2=R2, R2.adj=R2.adj, AIC=aic, BIC=bic) return(out) } result <- lapply(allModelsResults, extract) result <- as.data.frame(matrix(unlist(result), nrow=n.models, byrow=T)) result <- cbind(formular, result) rownames(result) <- NULL colnames(result) <- c("model", "df.sse", "p", "SSE", "MSE", "R2", "R2.adj", "AIC", "BIC") return(result) } all.possible.regressions(dat=quasar, k=5) On Tue, May 18, 2010 at 11:38 PM, Tim Clark <mudiver1200 at yahoo.com> wrote:> Is there a function that will allow me to run all model iterations if I specify a full model? ?I am using information criteria to choose between possible candidate models. ?I have been writing out all possible model combinations by hand, and I am always worried that I am missing models or have made a mistake somewhere. ?It is also difficult to alter models if I want to change a term. ?For example, below are the set of models I would like to run. ?Is there a way to specify the full model and have R generate the rest? ?I.e. specify > > ?m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > and have R run all the other models. > > > library(MASS) > > #Intercept only > ?m0<-glm.convert(glm.nb(mantas~1,data=mydata)) > > #One term - 7 models > ?#Manta abundance is greater at one of the two sites > ?m1<-glm.convert(glm.nb(mantas~site,data=mydata)) > ?#Manta abundance increases each year as the population increases in size due to births or immigration being greater than deaths and emmigration > ?m2<-glm.convert(glm.nb(mantas~year,data=mydata)) > ?#Manta abundances increases during part of the year due to seasonal cycles in resources (mates, food) > ?m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) > ?m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) > ?#Manta abundance decreases with increased lunar phase > ?m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) > ?m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) > ?#Manta abundance increases with increased levels of plankton > ?m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) > > #Two terms - 21 models > ?m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) ? #Interaction term to account for hotel being closed at Keauhou for some years > ?m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) > ?m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) > ?m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) > ?m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) > ?m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this have an interaction term? ?Plankton may varry by site > > ?m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) > ?m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) > ?m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) > ?m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) > ?m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) > > ?m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) > ?m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) > ?m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) > ?m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) ?#Interaction term? ?Plankton may vary by season > > ?m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) > ?m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) > ?m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) #Interaction term? ?Plankton may vary by season > > ?m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) > ?m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) > > ?m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) #Interaction term? ?Plankton may have lunar cycles > > #Three terms - 35 models > ?m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) > ?m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) > ?m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) > ?m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) > ?m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) > > ?m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) > ?m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) > ?m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) > ?m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) > > ?m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) > ?m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) > ?m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) > > ?m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) > ?m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) > > ?m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) > > ?m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) > ?m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) > ?m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) > ?m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) > > ?m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) > ?m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) > ?m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) > > ?m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) > ?m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) > > ?m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) > > ?m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) > ?m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) > ?m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) > > ?m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) > ?m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) > > ?m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) > > ?m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) > ?m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) > > ?m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) > > ?m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) > > #Four terms - 34 models > ?m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, data=mydata)) > ?m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, data=mydata)) > ?m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, data=mydata)) > ?m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, data=mydata)) > > ?m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, data=mydata)) > ?m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, data=mydata)) > ?m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, data=mydata)) > > ?m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, data=mydata)) > ?m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, data=mydata)) > > ?m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, data=mydata)) > > ?m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) > ?m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) > ?m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) > > ?m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) > ?m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) > > ?m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) > > ?m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) > ?m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) > > ?m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) > > ?m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) > > ?m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) > ?m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) > ?m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) > > ?m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) > ?m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) > > ?m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) > > ?m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) > ?m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) > > ?m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) > > ?m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) > > ?m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) > ?m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) > > ?m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) > > ?m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) > > #Five terms - 21 models > ?m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, data=mydata)) > ?m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, data=mydata)) > ?m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, data=mydata)) > > ?m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, data=mydata)) > ?m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, data=mydata)) > > ?m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, data=mydata)) > > ?m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, data=mydata)) > ?m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, data=mydata)) > > ?m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, data=mydata)) > > ?m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, data=mydata)) > > ?m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Six terms - 7 models > ?m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Seven terms - 1 model > ?m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > > Tim Clark > Department of Zoology > University of Hawaii > > ______________________________________________ > R-help at 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. >-- =============================Xiaogang Su, Ph.D. Associate Professor, Biostatistician SON, University of Alabama Birmingham, AL 35294-1210 (205) 934-2355 [Office] xgsu at uab.edu xiaogangsu at gmail.com
Hi, one approach is document below. The function should work with any regression function that follows the syntax of lm (others will need adjustments). Note that you would have to create the interactions terms by hand (which is no big deal if there are just few). Note also that this approach can be highly problematic if you are scrounging for significant relationships (this depends on the field and the specific intention with which these analyses are performed). #simulate data #predictor variables data=data.frame(d=rnorm(100),e=rnorm(100),f=rnorm(100)) #error term u=rnorm(100) #dependent variable y=data$d-data$e+2*data$f+u #create a present/absent list for the regressors grits=list() for(i in 1:length(data)){ grits[[i]]=c(0,1) } #expand the above list to a grid that contains all combinations of regressors selection=expand.grid(grits) #given the above grid, which regressor should I pick (get the indices for which variable(s) should be included) one=function(x){which(x==1)} selection.id=apply(selection,1,one) #what are the names of the included variables vnames=function(x){names(data)[x]} var.names=lapply(selection.id,vnames) #Dependent variable (unnecessary step if y is a vector or matrix anyway) y=as.matrix(y) #Select the data for each regression and store them in a list select.data=function(x){as.matrix(data[,x],row.names=T)} Xs=lapply(selection.id,select.data) #get the column names for each element of Xs right (workaround) #this is necessary because R does not get the column names right if there is only one column in the list element for(i in 1:length(Xs)){dimnames(Xs[[i]])=list(NULL,var.names[[i]])} #remove the first element because it's empty (otherwise the regression function returns an error #when it tries to run the first regression) Xs[[1]]=NULL #Define a function that regresses y on x and shows us the summary regress=function(x){summary(lm(y~x))} #Apply regress over all elements of Xs, i.e., #regress y on all possible subsets of regressors lapply(Xs,regress) HTH, Daniel -- View this message in context: http://r.789695.n4.nabble.com/Generating-all-possible-models-from-full-model-tp2222377p2223550.html Sent from the R help mailing list archive at Nabble.com.
Thanks to everyone for the replies and functions.? For some reason?my emails are not going to the thread.? I just switched to the newer mail version for?my yahoo account, so hopefully this one will get posted. Aloha, Tim ?Tim Clark Department of Zoology University of Hawaii ----- Original Message ---- From: Xiaogang Su <xiaogangsu at gmail.com> To: Tim Clark <mudiver1200 at yahoo.com> Cc: r-help at r-project.org Sent: Wed, May 19, 2010 9:42:40 AM Subject: Re: [R] Generating all possible models from full model A couple of years ago, I wrote a function for doing this. It can be found in the following file: http://pegasus.cc.ucf.edu/~xsu/CLASS/STA4164/mt4-2009.doc I also pasted a copy below. Hope you find it useful.? -XG # =======================# ALL POSSIBLE REGRESSIONS # =======================# The parameter k is the total number of predictors. To apply the function, # you need to prepare the data so that all predictors for selection are named # as x1, x2, ..., and the response is called y. all.possible.regressions <- function(dat, k){ ? ? n <- nrow(dat) ? ? regressors <- paste("x", 1:k, sep="") ? ? lst <- rep(list(c(T, F)), k) ? ? regMat <- expand.grid(lst); ? ? names(regMat) <- regressors ? ? formular <- apply(regMat, 1, function(x) ? ? ? ? ? ? as.character(paste(c("y ~ 1", regressors[x]), collapse="+"))) ? ? allModelsList <- apply(regMat, 1, function(x) ? ? ? ? ? ? as.formula(paste(c("y ~ 1", regressors[x]),collapse=" + ")) ) ? ? allModelsResults <- lapply(allModelsList, ? ? ? ? ? ? function(x, data) lm(x, data=data), data=dat) ? ? n.models <- length(allModelsResults) ? ? extract <- function(fit) { ? ? ? ? df.sse <- fit$df.residual ? ? ? ? p <- n - df.sse -1 ? ? ? ? sigma <- summary(fit)$sigma ? ? ? ? MSE <- sigma^2 ? ? ? ? R2 <- summary(fit)$r.squared ? ? ? ? R2.adj <- summary(fit)$adj.r.squared ? ? ? ? sse <- MSE*df.sse ? ? ? ? aic <- n*log(sse) + 2*(p+2) ? ? ? ? bic <- n*log(sse) + log(n)*(p+2) ? ? ? ? out <- data.frame(df.sse=df.sse, p=p, SSE=sse, MSE=MSE, ? ? ? ? ? ? R2=R2, R2.adj=R2.adj, AIC=aic, BIC=bic) ? ? ? ? return(out) ? ? } ? ? result <- lapply(allModelsResults, extract) ? ? result <- as.data.frame(matrix(unlist(result), nrow=n.models, byrow=T)) ? ? result <- cbind(formular, result) rownames(result) <- NULL colnames(result) <- c("model", "df.sse", "p", "SSE", "MSE", "R2", "R2.adj", "AIC", "BIC") ? ? return(result) } all.possible.regressions(dat=quasar, k=5) On Tue, May 18, 2010 at 11:38 PM, Tim Clark <mudiver1200 at yahoo.com> wrote:> Is there a function that will allow me to run all model iterations if I specify a full model? ?I am using information criteria to choose between possible candidate models. ?I have been writing out all possible model combinations by hand, and I am always worried that I am missing models or have made a mistake somewhere. ?It is also difficult to alter models if I want to change a term. ?For example, below are the set of models I would like to run. ?Is there a way to specify the full model and have R generate the rest? ?I.e. specify > > ?m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > and have R run all the other models. > > > library(MASS) > > #Intercept only > ?m0<-glm.convert(glm.nb(mantas~1,data=mydata)) > > #One term - 7 models > ?#Manta abundance is greater at one of the two sites > ?m1<-glm.convert(glm.nb(mantas~site,data=mydata)) > ?#Manta abundance increases each year as the population increases in size due to births or immigration being greater than deaths and emmigration > ?m2<-glm.convert(glm.nb(mantas~year,data=mydata)) > ?#Manta abundances increases during part of the year due to seasonal cycles in resources (mates, food) > ?m3<-glm.convert(glm.nb(mantas~cosmonth,data=mydata)) > ?m4<-glm.convert(glm.nb(mantas~sinmonth,data=mydata)) > ?#Manta abundance decreases with increased lunar phase > ?m5<-glm.convert(glm.nb(mantas~coslunar, data=mydata)) > ?m6<-glm.convert(glm.nb(mantas~sinlunar, data=mydata)) > ?#Manta abundance increases with increased levels of plankton > ?m7<-glm.convert(glm.nb(mantas~plankton,data=mydata)) > > #Two terms - 21 models > ?m12<-glm.convert(glm.nb(mantas~site*year, data=mydata)) ? #Interaction term to account for hotel being closed at Keauhou for some years > ?m13<-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata)) > ?m14<-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata)) > ?m15<-glm.convert(glm.nb(mantas~site+coslunar,data=mydata)) > ?m16<-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata)) > ?m17<-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this have an interaction term? ?Plankton may varry by site > > ?m23<-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata)) > ?m24<-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata)) > ?m25<-glm.convert(glm.nb(mantas~year+coslunar,data=mydata)) > ?m26<-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata)) > ?m27<-glm.convert(glm.nb(mantas~year+plankton,data=mydata)) > > ?m34<-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata)) > ?m35<-glm.convert(glm.nb(mantas~cosmonth+coslunar,data=mydata)) > ?m36<-glm.convert(glm.nb(mantas~cosmonth+sinlunar,data=mydata)) > ?m37<-glm.convert(glm.nb(mantas~cosmonth+plankton,data=mydata)) ?#Interaction term? ?Plankton may vary by season > > ?m45<-glm.convert(glm.nb(mantas~sinmonth+coslunar, data=mydata)) > ?m46<-glm.convert(glm.nb(mantas~sinmonth+sinlunar, data=mydata)) > ?m47<-glm.convert(glm.nb(mantas~sinmonth+plankton, data=mydata)) #Interaction term? ?Plankton may vary by season > > ?m56<-glm.convert(glm.nb(mantas~coslunar+sinlunar, data=mydata)) > ?m57<-glm.convert(glm.nb(mantas~coslunar+plankton, data=mydata)) > > ?m67<-glm.convert(glm.nb(mantas~sinlunar+plankton, data=mydata)) #Interaction term? ?Plankton may have lunar cycles > > #Three terms - 35 models > ?m123<-glm.convert(glm.nb(mantas~site*year+cosmonth, data=mydata)) > ?m124<-glm.convert(glm.nb(mantas~site*year+sinmonth, data=mydata)) > ?m125<-glm.convert(glm.nb(mantas~site*year+coslunar, data=mydata)) > ?m126<-glm.convert(glm.nb(mantas~site*year+sinlunar, data=mydata)) > ?m127<-glm.convert(glm.nb(mantas~site*year+plankton, data=mydata)) > > ?m134<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth,data=mydata)) > ?m135<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar,data=mydata)) > ?m136<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar,data=mydata)) > ?m137<-glm.convert(glm.nb(mantas~site+cosmonth+plankton,data=mydata)) > > ?m145<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar,data=mydata)) > ?m146<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar,data=mydata)) > ?m147<-glm.convert(glm.nb(mantas~site+sinmonth+plankton,data=mydata)) > > ?m156<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar,data=mydata)) > ?m157<-glm.convert(glm.nb(mantas~site+coslunar+plankton,data=mydata)) > > ?m167<-glm.convert(glm.nb(mantas~site+sinlunar+plankton,data=mydata)) > > ?m234<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth,data=mydata)) > ?m235<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar,data=mydata)) > ?m236<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar,data=mydata)) > ?m237<-glm.convert(glm.nb(mantas~year+cosmonth+plankton,data=mydata)) > > ?m245<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar,data=mydata)) > ?m246<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar,data=mydata)) > ?m247<-glm.convert(glm.nb(mantas~year+sinmonth+plankton,data=mydata)) > > ?m256<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar,data=mydata)) > ?m257<-glm.convert(glm.nb(mantas~year+coslunar+plankton,data=mydata)) > > ?m267<-glm.convert(glm.nb(mantas~year+sinlunar+plankton,data=mydata)) > > ?m345<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar,data=mydata)) > ?m346<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+sinlunar,data=mydata)) > ?m347<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+plankton,data=mydata)) > > ?m356<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar,data=mydata)) > ?m357<-glm.convert(glm.nb(mantas~cosmonth+coslunar+plankton,data=mydata)) > > ?m367<-glm.convert(glm.nb(mantas~cosmonth+sinlunar+plankton,data=mydata)) > > ?m456<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar,data=mydata)) > ?m457<-glm.convert(glm.nb(mantas~sinmonth+coslunar+plankton,data=mydata)) > > ?m467<-glm.convert(glm.nb(mantas~sinmonth+sinlunar+plankton,data=mydata)) > > ?m567<-glm.convert(glm.nb(mantas~coslunar+sinlunar+plankton,data=mydata)) > > #Four terms - 34 models > ?m1234<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth, data=mydata)) > ?m1235<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar, data=mydata)) > ?m1236<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar, data=mydata)) > ?m1237<-glm.convert(glm.nb(mantas~site*year+cosmonth+plankton, data=mydata)) > > ?m1245<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar, data=mydata)) > ?m1246<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar, data=mydata)) > ?m1247<-glm.convert(glm.nb(mantas~site*year+sinmonth+plankton, data=mydata)) > > ?m1256<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar, data=mydata)) > ?m1257<-glm.convert(glm.nb(mantas~site*year+coslunar+plankton, data=mydata)) > > ?m1267<-glm.convert(glm.nb(mantas~site*year+sinlunar+plankton, data=mydata)) > > ?m1345<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar,data=mydata)) > ?m1346<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar,data=mydata)) > ?m1347<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+plankton,data=mydata)) > > ?m1356<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar,data=mydata)) > ?m1357<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+plankton,data=mydata)) > > ?m1367<-glm.convert(glm.nb(mantas~site+cosmonth+sinlunar+plankton,data=mydata)) > > ?m1456<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar,data=mydata)) > ?m1457<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+plankton,data=mydata)) > > ?m1467<-glm.convert(glm.nb(mantas~site+sinmonth+sinlunar+plankton,data=mydata)) > > ?m1567<-glm.convert(glm.nb(mantas~site+coslunar+sinlunar+plankton,data=mydata)) > > ?m2345<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar,data=mydata)) > ?m2346<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar,data=mydata)) > ?m2347<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+plankton,data=mydata)) > > ?m2356<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar,data=mydata)) > ?m2357<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+plankton,data=mydata)) > > ?m2367<-glm.convert(glm.nb(mantas~year+cosmonth+sinlunar+plankton,data=mydata)) > > ?m2456<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar,data=mydata)) > ?m2457<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+plankton,data=mydata)) > > ?m2467<-glm.convert(glm.nb(mantas~year+sinmonth+sinlunar+plankton,data=mydata)) > > ?m2567<-glm.convert(glm.nb(mantas~year+coslunar+sinlunar+plankton,data=mydata)) > > ?m3456<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar,data=mydata)) > ?m3457<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+plankton,data=mydata)) > > ?m3567<-glm.convert(glm.nb(mantas~cosmonth+coslunar+sinlunar+plankton,data=mydata)) > > ?m4567<-glm.convert(glm.nb(mantas~sinmonth+coslunar+sinlunar+plankton,data=mydata)) > > #Five terms - 21 models > ?m12345<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar, data=mydata)) > ?m12346<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar, data=mydata)) > ?m12347<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+plankton, data=mydata)) > > ?m12356<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar, data=mydata)) > ?m12357<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+plankton, data=mydata)) > > ?m12367<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinlunar+plankton, data=mydata)) > > ?m12456<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar, data=mydata)) > ?m12457<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+plankton, data=mydata)) > > ?m12467<-glm.convert(glm.nb(mantas~site*year+sinmonth+sinlunar+plankton, data=mydata)) > > ?m12567<-glm.convert(glm.nb(mantas~site*year+coslunar+sinlunar+plankton, data=mydata)) > > ?m13456<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m13457<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m13467<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m13567<-glm.convert(glm.nb(mantas~site+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m14567<-glm.convert(glm.nb(mantas~site+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m23456<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m23457<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m23467<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m23567<-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m24567<-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m34567<-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Six terms - 7 models > ?m123456<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar, data=mydata)) > ?m123457<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton, data=mydata)) > > ?m123467<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton, data=mydata)) > > ?m123567<-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m124567<-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m134567<-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > ?m234567<-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > #Seven terms - 1 model > ?m1234567<-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton, data=mydata)) > > > Tim Clark > Department of Zoology > University of Hawaii > > ______________________________________________ > R-help at 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. >-- =============================Xiaogang Su, Ph.D. Associate Professor, Biostatistician SON, University of Alabama Birmingham, AL 35294-1210 (205) 934-2355 [Office] xgsu at uab.edu xiaogangsu at gmail.com