Uploaded by 183043391

文章中用建模代码

advertisement
library(ggplot2)
library(ggpmisc)
library(GGally)
#Relationship between 8 characters in Pteromalidae and Eulophidae
P2<-PESMEAN[,c(5,10,11,12,13,14,17,19)]
ggpairs(P2)+scale_fill_manual(values=c("black","gray"))+scale_color_manual(name
="",values=c("black","gray"))
ggpairs(P2,aes(color=Sex),upper=list(continuous=wrap('cor',method="spearman")))+t
heme_bw()
E1<-EUMEAN[,c(5,10,11,12,13,14,17,19)]
ggpairs(E1)+scale_fill_manual(values=c("black","gray"))+scale_color_manual(name
="",values=c("black","gray"))
ggpairs(E1,aes(color=Sex),upper=list(continuous=wrap('cor',method="spearman")))+t
heme_bw()
#Relationship between FL/HTL and BL in Pteromalidae and Eulophidae
p<-ggplot(PESMEAN,aes(x=BL,y=HTL,group=Sex,color=Sex))+
geom_point(shape=19)+theme_bw()+
geom_smooth(method="glm",fullrange=T)+
scale_linetype_manual(values
=
c('solid',
'dashed'))+theme(panel.grid
=element_blank())
p1<-p+labs(x="Body
length(mm)",y="Hind
tibia
length
of
Pteromalidae")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..,se
p = "~~~~")),formula = y~x,parse=T,size=4)
p1
pf<-ggplot(PESMEAN,aes(x=BL,y=FL,group=Sex,color=Sex))+
geom_point(shape=19)+theme_bw()+
geom_smooth(method="glm",fullrange=T)+
scale_linetype_manual(values
=
c('solid',
'dashed'))+theme(panel.grid
=element_blank())
pf1<-pf+labs(x="Body
length(mm)",y="Forewing
length
of
Pteromalidae")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..,se
p = "~~~~")),formula = y~x,parse=T,size=4)
pf1
e<-ggplot(EUMEAN,aes(x=BL,y=HTL,group=Sex,color=Sex))+
geom_point(shape=19)+theme_bw()+
geom_smooth(method="glm",fullrange=T)+
scale_linetype_manual(values
=
c('solid',
'dashed'))+theme(panel.grid
=element_blank())
e1<-e+labs(x="Body
length(mm)",y="Hind
tibia
length
of
Eulophidae(mm)")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..
,sep = "~~~~")),formula = y~x,parse=T,size=4)
e1
ef<-ggplot(PESMEAN,aes(x=BL,y=FL,group=Sex,color=Sex))+
geom_point(shape=19)+theme_bw()+
geom_smooth(method="glm",fullrange=T)+
scale_linetype_manual(values
=
c('solid',
'dashed'))+theme(panel.grid
=element_blank())
ef1<-ef+labs(x="Body
length(mm)",y="Forewing
length
of
Eulophidae")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..,sep
= "~~~~")),formula = y~x,parse=T,size=4)
ef1
Relationship between altitude and HTL(WL)
p<-ggplot(NEO,aes(x=AL,y=HTL(WL),group=Sex,color=Sex))+theme_bw()+
geom_smooth(method="glm",fullrange=F)+geom_point(shape=19)+
scale_linetype_manual(values = c('solid', 'dashed'))+
theme(panel.grid =element_blank())
p1<-p+labs(x="Altitude(m)",y="Hind
tibia
length(mm)")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..,sep
= "~~~~")),formula = y~x,parse=T,size=4)
p1
E<-ggplot(EU,aes(x=AL,y=HTL(WL),group=Sex,color=Sex))+
geom_point(shape=19)+theme_bw()+
geom_smooth(method="glm",fullrange=T)+
scale_linetype_manual(values = c('solid', 'dashed'))+
theme(panel.grid =element_blank())
E1<-E+labs(x="Altitude(m)",y="Hind
tibia
length
of
Eulophidae(mm)")+stat_poly_eq(aes(label=paste(..eq.label..,..rr.label..,..p.value.label..
,sep = "~~~~")),formula = y~x,parse=T,size=4)
E1
Gls model to verify Bergmann’s rule:
PF<-PE[PE$Sex=="F" ,]
PM<-PE[PE$Sex=="M" ,]
MD1<-gls(HTL~AL+LA+LO,data=PF,
correlation=corAR1(form=~1|GE),
method="ML",na.action = na.omit)#Bestfit AIC=-1054.632
MD2<-update(MD1, correlation=corARMA(p=1))#AIC=-972.4825
MD3<- update(MD1, correlation=corARMA(p=3))#AIC= -1017.439
MD4<- update(MD1, correlation=NULL)
anova(MD1, MD3, MD4,MD2)
anova(MD1)
MDPM<-gls(HTL~AL+LA+LO,data=PM,
correlation=corAR1(form=~1|GE),
method="ML",na.action = na.omit)
MDPM1<-update(MDPM, correlation=corARMA(p=1))
MDPM2<-update(MDPM, correlation=corARMA(p=3))#Best fit,AIC=-798.9105
MDPM3<-update(MDPM, correlation=NULL)
anova(MDPM,MDPM1,MDPM2,MDPM3)
EF<-EU[EU$Sex=="F",]
EM<-EU[EU$Sex=="M",]
EFGLS<-gls(HTL~AL+LA+LO,data=EF,
correlation=corAR1(form=~1|GE),
method="ML",na.action = na.omit)#best fit,AIC=-1467.201
EFGLS1<-update(EFGLS, correlation=corARMA(p=1))
EFGLS2<-update(EFGLS, correlation=corARMA(p=3))
EFGLS3<-update(EFGLS, correlation=NULL)
anova(EFGLS,EFGLS1,EFGLS2,EFGLS3)
EMGLS<-gls(HTL~AL+LA+LO,data=EM1,
correlation=corAR1(form=~1|GE),
method="ML",na.action = na.omit)
EMGLS1<-update(EMGLS, correlation=corARMA(p=1))
EMGLS2<-update(EMGLS, correlation=corARMA(p=3))#BEST FIT,AIC=-971.4220
EMGLS3<-update(EMGLS, correlation=NULL)
Anova(EMGLS2)
Stepwise model to verify the influence of environmental factors on HTL:
library(MASS)
HTL_data<-PE[,c(6,15,23,24,25,26)]
HTLLM<-lm(HTL~.,data = HTL_data)
HTLLM_stepwise<-stepAIC(HTLLM,direction = "both")
HTLLM_stepwise$anova
PEHTL<-glm(HTL~Sex + AMSR + AMWS + APRE+ AMTEM,data=HTL_data)
summary(PEHTL)
anova(PEHTL)
vif(PEHTL,digits=3)
Download