PNG_butterflies<-c(1, 1, 56, 53, 1, 1, 2, 8, 4, 1, 15, 7, 2, 22, 6, 9, 1, 16, 28, 49, 2, 5, 562, 30, 63, 7, 1922, 321, 231, 59, 4, 1, 1, 6, 2, 2, 5, 2, 3, 4, 3, 163, 3, 61, 2, 58, 6, 5, 15, 22, 85, 50, 8, 6, 97, 3, 140, 37, 4, 3, 17, 2, 1, 41, 1, 1, 45, 3, 4, 45, 14, 5, 17, 11, 1, 2, 1, 17, 48, 24, 100, 2, 4, 2, 52, 17, 1, 1, 1, 12, 4, 9, 9, 21, 11, 4, 7, 37, 51, 7, 9, 66, 1, 4, 8, 51, 39, 2, 19, 15, 1, 3, 16, 75, 10, 141, 26, 21, 2, 3, 689, 15, 9, 9, 3, 2, 6, 3, 149, 1, 5, 79, 1, 1, 2, 18, 154, 10, 113, 3, 3, 3, 1, 1, 142, 2, 9, 1, 9, 16) par(mfrow=c(2,2)) # setting the plot area to be 2 x 2 graphs hist(PNG_butterflies, col= "grey50") length(which(PNG_butterflies==1)) s<-seq(0:11)-1 s2<-2^s s3<-s2-0.5 hist(PNG_butterflies, breaks=s3, col= "grey50") log_butterflies<-log(PNG_butterflies,2) hist(log_butterflies, col= "grey50") install.packages("vegan") # only if you have not already installed it library(vegan) fisherfit(PNG_butterflies) plot(fisherfit(PNG_butterflies)) ############## data<-read.table(file="PNG_transects.txt",header=TRUE) head(data) PA<-replace(PA<-data,PA>1,1) species_recorded <- NULL hold_temp<-NULL for (i in 1:ncol(PA)){ temp<- grep(1,PA[,i]) hold_temp<-c(hold_temp,temp) species_recorded<-c(species_recorded,length(unique(hold_temp))) } plot(species_recorded, xlab= "Transect number", ylab="Total number of species") N<-100 M<- matrix(NA,nrow=N, ncol=ncol(PA)) for (i in 1:N){ to_add_seq<-sample (1:50, 50, replace=FALSE) species_recorded <- NULL hold_temp<-NULL for (j in to_add_seq){ temp<- grep(1,PA[,j]) hold_temp<-c(hold_temp,temp) species_recorded<-c(species_recorded,length(unique(hold_temp))) } M[i,]<- species_recorded } head(M) plot(NULL, xlim=c(1,50),ylim=c(1,93), xlab= "Transect number", ylab="Total number of species") for (i in 1:100){ points(c(1:50),M[i,],pch= 15,cex=0.2)} points(c(1:50),colMeans(M), col="red", pch=16) lines(smooth.spline(c(1:50),colMeans(M), spar=0.4, all.knots=F), lwd=2, lty=1,col="blue") propPNGbutts<-PNG_butterflies/sum(PNG_butterflies) Simpson <- 1 - sum(propPNGbutts^2) Simpson ShannonH<- -sum(propPNGbutts * log(propPNGbutts,2)) ShannonH# species_observed<-NULL Simpson_transect<-NULL Shannon_transect<-NULL for (i in 1:length(data)){ temp<-data[which(data[,i]>0),i] species_observed<-c(species_observed,length(temp)) Simpson_transect<-c(Simpson_transect,1-sum((temp/sum(temp))^2)) Shannon_transect<-c(Shannon_transect,-sum(sum((temp/sum(temp)) * log(temp/sum(temp),2)))) } par(mfrow=c(2,2)) plot(species_observed,Simpson_transect,xlab="Number of butterflies spp in transect",ylab="Simpson's Index") plot(species_observed,Shannon_transect,xlab="Number of butterflies spp in transect",ylab="Shannon's Index") plot(Shannon_transect,Simpson_transect,xlab="Shannon",ylab="Simpson",col="red") library('vegan') SW<-diversity(propPNGbutts, index = "shannon", MARGIN = 1, base = exp(1)) SW ShannonH<- -sum(propPNGbutts*log(propPNGbutts)) #log(propPNGbutts, 2.718281828459)) ShannonH