[R] create loops in the explanatory variables using lm

David Emmerth david.emmerth at ieu.uzh.ch
Thu Sep 29 14:11:37 CEST 2011


Hey Petr

thanks for the answer

I guess I was a bit unclear about the nature of my data

the species terms are columns in the data frame, and they are coded 0/1, depending whether the species is present in a plot or not. 


No I want to repeatedly fit the linear model with all the species presence absence term in a hierarchical model, so that every species is in the first place, after the richness term once. I hope this is possible with data like this.


thanks a lot

david
Am 29.09.2011 um 11:57 schrieb Petr PIKAL:

> 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. 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]]
>> 
>> ______________________________________________
>> 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.
> 



More information about the R-help mailing list