Created
January 2, 2016 05:50
-
-
Save PhillRob/87e56a9c683dff5236ac to your computer and use it in GitHub Desktop.
test the distance between two strata within a species.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ha <- function(x){ | |
x$Lat<-(as.numeric(paste(x$Lat))) | |
x$Lon<-(as.numeric(paste(x$Lon))) | |
pre<-x[(x[,17]==0),] | |
post<-x[(x[,17]==1),] | |
if(nrow(pre)<2| nrow(post)<2){results<-paste("not enought records per phase")}else{ | |
early <- x[(which.min(x$Year)),] | |
e1 <- early[1,] | |
predist<-apply(pre, 1, function(x) distHaversine(as.numeric(e1[4:3]),as.numeric(x[4:3]), r=6378137)) | |
postdist<-apply(post, 1, function(x) distHaversine(as.numeric(e1[4:3]),as.numeric(x[4:3]), r=6378137)) | |
mean.predist<-mean(predist) | |
mean.postdist<-mean(postdist) | |
ttest<-t.test(predist, postdist) | |
sig <- ifelse(ttest$p.value <= 0.05, c(1), c(0)) | |
ks.test<-ks.test(predist, postdist) | |
ks.sig<-ifelse(ks.test$p.value <= 0.05, c(1), c(0)) | |
results<-t(c(paste(unique(x$Species)),mean.predist,mean.postdist,ttest$p.value,sig,ks.sig )) | |
#colnames(results)<-c("Species", "mean.lag.dist", "mean.postlag.dist", "p.value", "sig", "ks.test.sig") | |
return(results)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment