coob.hyperh.test <- function(x, p){
start_time <- Sys.time()
res<-data.frame(SP1=character(),
SP2=character(),
N1=integer(),
N2=integer(),
N1N2=integer(),
N1N2.scaled=integer(),
p.lt=double(),
p.gt=double(),
stringsAsFactors=FALSE)
for(i in 1:(s-1)){
for(j in (i+1):s){
q<-length(which(x[i,]>0 & x[j,]>0))
m<-min(length(x[i, which(x[i,]>0)]), length(x[j, which(x[j,]>0)]))
n<-ncol(x)-m
k<-max(length(x[i, which(x[i,]>0)]), length(x[j, which(x[j,]>0)]))
dh1<-phyper(q, m, n, k, lower.tail=TRUE)
dh2<-phyper(q-1, m, n, k, lower.tail=FALSE)
if (dh1<p | dh2<p) {
res[nrow(res)+1,]<-list(row.names(x[i,]),
row.names(x[j,]),
m,
k,
q,
round(2*q/sum(colSums(x[c(i,j),] != 0, na.rm=TRUE)), 2),
round(dh1, 5),
round(dh2, 5))
}
}
}
end_time <- Sys.time()
print(end_time - start_time)
return(res)
}
x<-read.table('khoper_n_by_lake.csv', header=TRUE, sep=";")
