David Emmerth
2011-Sep-29 07:11 UTC
[R] create loops in the explanatory variables using lm
Hi everyone I am new to the list and read all the instructions, hope i get it right. I have the following linear model: model_sqrt<-lm(sqrt(mortality)~richness +Acer_davidii+Ailanthus_altissima+Alniphyllum_fortunei +Betula_luminifera+Castanea_henryi+Castanopsis_carlesii +Castanopsis_eyrei+Castanopsis_fargesii+Castanopsis_sclerophylla +Celtis_biondii+Choerospondias_axillaris+Cinamomum_camphora +Cyclobalanopsis_glauca+Cyclobalanopsis_myrsinifolia+Diospyros_glaucifolia +Elaeocarpus_chinensis+Elaeocarpus_glabripetalus+Elaeocarpus_japonicus +Idesia_polycarpa+Koelreuteria_bipinnata+Liquidambar_formosana +Lithocarpus_glaber+Machilus_grijsii+Machilus_leptophylla +Machilus_thunbergii+Manglietia_yuyuanensis+Melia_azedarach+Meliosma_flexuosa +Nyssa_sinensis+Phoebe_bournei+Quercus_acutissima+Quercus_fabri +Quercus_phillyreoides+Quercus_serrata+Rhus_chinensis+Sapindus_mukorossi +Sapium_discolor+Sapium_sebiferum+Schima_superba +community ,weights=wei) Where everything from Acer_davidii to Schima_superba are plant species. Since the order of the plant species matters in my case, I want to repeatedly fit the model so that every species is in the first place, that is after the richness term, once. I am looking for a way so that I don't have to do this by hand. I already checked combn with as.formula and paste, but I couldn't get it right. I'd be very grateful for any help. Thanks David [[alternative HTML version deleted]]
Petr PIKAL
2011-Sep-29 09:57 UTC
[R] Odp: create loops in the explanatory variables using lm
Hi Well, are those names (Acer_davidii, ...) columns in data frame? If not and you want them as factors of species you shall reformat your input so as you get data frame with columns mortality, richness, species, community. Column species shall have your plant species names in each respective row. Your lm call shall be lm(sqrt(mortality)~richness+species+community, data=your.data.frame) see then ?relevel for setting reference level of your factor. Regards Petr> > Hi everyone > > I am new to the list and read all the instructions, hope i get it right. > > I have the following linear model: > > > model_sqrt<-lm(sqrt(mortality)~richness > +Acer_davidii+Ailanthus_altissima+Alniphyllum_fortunei > +Betula_luminifera+Castanea_henryi+Castanopsis_carlesii > +Castanopsis_eyrei+Castanopsis_fargesii+Castanopsis_sclerophylla > +Celtis_biondii+Choerospondias_axillaris+Cinamomum_camphora > +Cyclobalanopsis_glauca+Cyclobalanopsis_myrsinifolia > +Diospyros_glaucifolia > +Elaeocarpus_chinensis+Elaeocarpus_glabripetalus > +Elaeocarpus_japonicus > +Idesia_polycarpa+Koelreuteria_bipinnata+Liquidambar_formosana > +Lithocarpus_glaber+Machilus_grijsii+Machilus_leptophylla > +Machilus_thunbergii+Manglietia_yuyuanensis+Melia_azedarach > +Meliosma_flexuosa > +Nyssa_sinensis+Phoebe_bournei+Quercus_acutissima+Quercus_fabri > +Quercus_phillyreoides+Quercus_serrata+Rhus_chinensis > +Sapindus_mukorossi > +Sapium_discolor+Sapium_sebiferum+Schima_superba > +community > ,weights=wei) > > > > > Where everything from Acer_davidii to Schima_superba are plant species. > Since the order of the plant species matters in my case, I want to > repeatedly fit the model so that every species is in the first place,that> is after the richness term, once. > > I am looking for a way so that I don't have to do this by hand. Ialready> checked combn with as.formula and paste, but I couldn't get it right. > > I'd be very grateful for any help. > > > Thanks > > > David > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.