Section 7 Geometric constaints
+First, we tested for an association between raw elevational shift and the breadth of elevational distribution (elevational range) of the species, in which we calculated elevational range by subtracting the summer lower elevation limit from the summer upper elevational limit. To test whether elevational shifts are smaller for species with a broad elevational distribution.
+7.1 Calculations across multiple levels of sampling effort
+## Eastern Himalayas
+
+## An example with high effort is shown here (this can be repeated for medium and low effort as well for both Eastern and Western Himalayas)
+
+## (files available for replication in the results/ folder)
+
+## read in phylogenetic tree
+
+tree <- read.nexus("data/birdtree.nex")
+tree <- mcc(tree) ## maximum clade credibility tree
+x <- read.csv("results/East_ele_range_higheffort.csv") # read in high effort data
+
+## subset tree to match species
+pruned.tree <- drop.tip(tree,tree$tip.label[-match(x$Tree.name, tree$tip.label)])
+pruned.tree
+
+## Match tree tips to species name
+glsdata <- x[match(pruned.tree$tip.label, x$Tree.name),]
+
+# PGLS analysis
+pgls1 <- gls(Median_diff_upper~Summer_range,correlation=corPagel(1,pruned.tree),data=glsdata)
+j<-summary(pgls1)
+j
+
+pgls2<- gls(Median_diff_median~Summer_range,correlation=corPagel(1,pruned.tree),data=glsdata)
+k<-summary(pgls2)
+k
+
+pgls3 <- gls(Median_diff_lower~Summer_range,correlation=corPagel(1,pruned.tree),data=glsdata)
+l<-summary(pgls3)
+l
+
+outputj <- as.data.frame(j$tTable)
+outputj$Lambda <- j$modelStruct
+outputj <- as.matrix(outputj)
+outputk <- as.data.frame(k$tTable)
+outputk$Lambda <- k$modelStruct
+outputk <- as.matrix(outputk)
+outputl <- as.data.frame(l$tTable)
+outputl$Lambda <- l$modelStruct
+outputl <- as.matrix(outputl)
+
+# write .csv files
+write.csv(outputj,file="East_shift_upper~Summer_range_higheffort.csv",row.names=FALSE)
+write.csv(outputk,file="East_shift_median~Summer_range_higheffort.csv",row.names=FALSE)
+write.csv(outputl,file="East_shift_lower~Summer_range_higheffort.csv",row.names=FALSE)
+
+### East_ele_range_higheffort was used to produce Figure 3A with Median_diff_median ~ Summer_range
7.2 Absolute shift ~ Summer Elevational Distribution
+Now we test for an association between absolute elevational shift and the estimated summer elevation of the species. To test whether elevational shifts are greater for high or low elevation birds simply because they have more elevation to potentially shift (upslope or downslope), we calculated absolute relative elevational shift as the elevational shift at each elevational limit (upper, median, lower) divided by the predicted elevation for the respective limit (i.e., elevational shift at upper limit / elevational upper limit)
+
+## the below analysis should be repeated across other levels of sampling effort
+
+x <- read.csv("results/East_ele_range_higheffort.csv")
+
+x$absrelshift_upper <- abs(x$Diff_ratio_upper)
+x$absrelshift_median <- abs(x$Diff_ratio_median)
+x$absrelshift_lower <- abs(x$Diff_ratio_lower)
+
+pruned.tree <- drop.tip(tree1,tree1$tip.label[-match(x$Tree.name, tree1$tip.label)])
+pruned.tree
+
+glsdata <- x[match(pruned.tree$tip.label, x$Tree.name),]
+pgls1 <- gls(absrelshift_upper~Median_S_upper,correlation=corPagel(1,pruned.tree),data=glsdata)
+j<-summary(pgls1)
+j
+
+pgls2 <-gls(absrelshift_median~Median_S_median,correlation=corPagel(1,pruned.tree),data=glsdata)
+k<-summary(pgls2)
+k
+
+pgls3 <-gls(absrelshift_lower~Median_S_lower,correlation=corPagel(1,pruned.tree),data=glsdata)
+l <- summary(pgls3)
+l
+
+outputj<-as.data.frame(j$tTable)
+outputj$Lambda<-j$modelStruct
+outputj<-as.matrix(outputj)
+outputk<-as.data.frame(k$tTable)
+outputk$Lambda<-k$modelStruct
+outputk<-as.matrix(outputk)
+outputl<-as.data.frame(l$tTable)
+outputl$Lambda<-l$modelStruct
+outputl<-as.matrix(outputl)
+
+write.csv(outputj,file="East_absrelshift_upper~Median_S_upper_higheffort.csv",row.names=FALSE)
+write.csv(outputk,file="East_absrelshift_median~Median_S_median_higheffort.csv",row.names=FALSE)
+write.csv(outputl,file="East_absrelshift_lower~Median_S_lower_higheffort.csv.csv",row.names=FALSE)
+
+## East_ele_range_higheffort was used to produce figure 3C with absrelshift_median ~ Median_S_median