tree<-read.nexus("C:/Users/feder/Desktop/MASTER UPO/_TFM/ANALISIS/bats_fixedMCC.tre") plot(tree) traits<- read.csv("MATRIXDATA.csv", sep="\t",header=T,row.names = "Cod2") head(traits) ## check tree and traits match up name.check(tree, traits) rownames(traits)==tree$tip.label traits<-traits[tree$tip.label,] rownames(traits)==tree$tip.label traits1 <- comparative.data(phy = tree, data = traits, names.col = Cod, vcv = TRUE, na.omit = FALSE, warn.dropped = TRUE) phylo.d(data=traits1, binvar = Presencia, permut = 1000) tree$edge.length <- tree$edge.length * 100 fit6 <- binaryPGLMM(Presencia~ log10(Group_size) + log10(Forearm) + as.factor(swarming) + as.factor(migration) + as.factor(Inter_species2) + as.factor(refuge),data=traits, phy=tree) tip<- c("Malc", "Mbra", "Mdas", "Mcfn", "Rmeh") tree2<-drop.tip(phy=tree, tip) plot(tree2) traits3<- read.csv("MATRIXDATAn2.csv",sep=";", row.names = "Cod") head(traits3) phylosig(tree2, traits3$Perc_trans, method="lambda", test=TRUE) phylosig(tree2, traits3$Perc_trans, nsim=1000,method="K", test=TRUE) name.check(tree2, traits3) rownames(traits3)==tree2$tip.label traits3<-traits3[tree2$tip.label,] rownames(traits3)==tree2$tip.label fit.bm<-phylolm(Perc_trans ~log10(as.numeric(Group_size)) + log10(as.numeric(Forearm)) + as.factor(swarming) + as.factor(migration) + as.factor(Inter_species2) + as.factor(refuge),data=traits3, phy=tree2, model=c("BM")) summary(fit.bm) fit.lam<-phylolm(Perc_trans ~log10(as.numeric(Group_size)) + log10(as.numeric(Forearm)) + as.factor(swarming) + as.factor(migration) + as.factor(Inter_species2) + as.factor(refuge),data=traits3, phy=tree2, model=c("lambda")) summary(fit.lam) fit.ou<-phylolm(Perc_trans ~log10(as.numeric(Group_size)) + log10(as.numeric(Forearm)) + as.factor(swarming) + as.factor(migration) + as.factor(Inter_species2) + as.factor(refuge),data=traits3, phy=tree2, model=c("OUfixedRoot")) summary(fit.ou) # compare aic fit.bm$aic fit.lam$aic fit.ou$aic ### bm seems to be best # perform model dredging (stepwise aic) str(summary(fit.bm)) fit.dredge<-dredge(fit.bm, rank = "AICc") subset(fit.dredge, delta<4) # show all models with AICc>=4 fit.dredge<-dredge(fit.lam, rank = "AICc") subset(fit.dredge, delta<4) # show all models with AICc>=4 fit.dredge<-dredge(fit.ou, rank = "AICc") subset(fit.dredge, delta<4) # show all models with AICc>=4 # visualize importance of variables par(mar = c(2,5,14,4)) plot(fit.dredge, labAsExpr = TRUE, col = "green", col2="yellow") # here, each row is a model, with the best one on the top. coloured boxes are the variables included in the model #get 'Best' model summary(get.models(fit.dredge, 1)[[1]]) summary(get.models(fit.dredge, 2)[[1]]) summary(get.models(fit.dredge, 3)[[1]]) ###variables correlations nylas2<-read.csv("Nlas2.csv",header=T,sep=";") nylas2[] <- lapply(nylas2,as.integer) sjp.corr(nylas2[,c(2,4,10,11)],show.legend = TRUE) ppyg2<-read.csv("Ppyg2.csv",header=T,sep="\t") ppyg2[] <- lapply(ppyg2,as.integer) sjp.corr(ppyg2[,c(2,4,9,10)],show.legend = TRUE) pkuh2<-read.csv("Pkuh3.csv",header=T,sep=";") pkuh2[] <- lapply(pkuh2,as.integer) sjp.corr(pkuh2[,c(2,5,10,11)],show.legend = TRUE) nl4<-glmer(Presencia ~ Sexo2 + Av + (1|LOCALIDAD),data = nylas2, family="binomial") pp4<-glmer(Presencia ~ Sexo2 + Av2 + (1|LOCALIDAD),data = ppyg2, family="binomial") pk4<-glmer(Presencia ~ Sexo2 + Av2 + (1|LOCALIDAD),data = pkuh2, family="binomial") ggplot(pkuh2, aes(x=as.factor(Presencia), y=Av)) + geom_boxplot(fill="slateblue", alpha=0.3) + xlab("Presence AdV") + ylab("Forearm (mm)") ##MANTEL### disloc_nl<-(dist(cbind(nylas_mant$Longitude, nylas_mant$Latitude))) distpor_nl<-(dist(nylas_mant$Perc)) disloc_nl as.matrix(disloc_nl) as.matrix(distpor_nl) mantel.rtest(disloc_nl,distpor_nl, nrepet=999)รน p1<-plot(distpor_nl~disloc_nl, xlab="geographic distance", ylab="percentage difference (%)",ylim=c(0,40),xlim=c(0,7), bty="n") nl<-lm(distpor_nl~disloc_nl) abline(nl,col="black", lwd=2) ppyg_mant<-read.csv("Ppyg_mantel510.csv",header=T,sep=";") head(ppyg_mant) disloc_pp<-dist(cbind(ppyg_mant$Longitude, ppyg_mant$Latitude)) distpor_pp<-dist(ppyg_mant$Perc) disloc_pp as.matrix(disloc_pp) as.matrix(distpor_pp) mantel.rtest(disloc_pp,distpor_pp, nrep=999) p1<-plot(distpor_pp~disloc_pp, xlab="geographic distance", ylab="percentage difference (%)",ylim=c(0,40), xlim=c(0,4), bty="n") abline(mod_man, col="black", lwd=2) disloc_pk<-dist(cbind(pkuh_mant$Longitude, pkuh_mant$Latitude)) distpor_pk<-dist(pkuh_mant$Perc) as.matrix(disloc_pk) as.matrix(distpor_pk) mpk<-mantel.rtest(disloc_pk,distpor_pk) mpk mantel.randtest(disloc_pk,distpor_pk) pk<-plot(distpor_pk~disloc_pk, xlab="geographic distance", ylab="percentage difference (%)",ylim=c(0,40),xlim=c(0,5) ,bty="n") pk<-lm(distpor_pk~disloc_pk) summary(pk) abline(pk,col="black", lwd=2)