Skip to content

Instantly share code, notes, and snippets.

@mnarayan
Last active October 6, 2022 00:28
Show Gist options
  • Save mnarayan/868826ded05045def926f19d31552688 to your computer and use it in GitHub Desktop.
Save mnarayan/868826ded05045def926f19d31552688 to your computer and use it in GitHub Desktop.
Kendall Tau correction for zero-inflation

Pimental's correction for kendall's tau correlation coefficient is given by

Pimental:Proposition 1

tau_T<-function(x,y){
data=cbind(x,y)
nz=which(apply(data,1,function(row) all(row[1]>0 & row[2]>0)))
p_11=length(nz)/dim(data)[1]
nz_data=data[nz,]
if (length(nz)>1){
if (length(which(!duplicated(nz_data[,1])))==1 | length(which(!duplicated(nz_data[,2])))==1) {t_11=0}
else {t_11= cor(nz_data[,1],nz_data[,2],method="kendall")}
}
else {t_11=0}
p_01= (length(which(apply(data,1,function(row) all(row[1]==0 & row[2]>0)))))/dim(data)[1]
p_10= (length(which(apply(data,1,function(row) all(row[2]==0 & row[1]>0)))))/dim(data)[1]
p_00= (length(which(apply(data,1,function(row) all(row==0)))))/dim(data)[1]
return (p_11^2*t_11+2*(p_00*p_11-p_01*p_10))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment