From 2675b757c491a0304b9ef49abe02123fbdd912e8 Mon Sep 17 00:00:00 2001 From: Lubomir Chorbadjiev Date: Wed, 1 Dec 2021 16:51:23 +0200 Subject: [PATCH] SCP-76 additional fixes to simfisher from Alex --- R/simfisher.R | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/R/simfisher.R b/R/simfisher.R index 4816797..7032957 100644 --- a/R/simfisher.R +++ b/R/simfisher.R @@ -7,14 +7,10 @@ library("parallel") fast_fisher<-function(i,yy,ny,nn){ ftp <- rep(1,nrow(yy)) for(j in i:nrow(yy)) { - - if(j==i)ftp[j]<-10e-8 - else{ - ftp[j]<-fisher.test( + ftp[j]<-fisher.test( matrix(nrow=2,ncol=2, - data=c(yy[i,j],ny[i,j],ny[j,i],nn[i,j])),alternative="greater")$p.value - if(ftp[j]==0)print(c(i,j,yy[i,j],ny[i,j],ny[j,i],nn[i,j])) - } + data=c(yy[i,j],ny[i,j],ny[j,i],nn[i,j])),alternative="greater")$p.value + if(ftp[j]==0)ftp[j]<-2*.Machine$double.xmin } return(ftp) } @@ -23,7 +19,7 @@ fast_fisher<-function(i,yy,ny,nn){ # occupancy probabilities, keeping the sum of x fixed. If there are more 0s # than 1s in x, a subset of vacant positions is chosen at random, and 1s are # moved to these positions with Metropolis transition probability. If there -# are more 1s than 0s, the roles of 0s and 1s are inetrchanged +# are more 1s than 0s, the roles of 0s and 1s are interchanged metro<-function(x,p,sweeps){ for(i in 1:sweeps){ occ<-which(x==1&p<1)