Skip to content

Instantly share code, notes, and snippets.

@Puriney
Created March 9, 2013 17:19
Show Gist options
  • Save Puriney/5124888 to your computer and use it in GitHub Desktop.
Save Puriney/5124888 to your computer and use it in GitHub Desktop.
R: DEG Poisson Fisher.test
set.seed(1026)
Cond1<-rpois(n=1000,lambda=5) #虽然用泊松分布模拟数据已经被吐槽了
Cond2<-rpois(n=1000,lambda=10)
df<-as.data.frame(cbind(cond1=Cond1,cond2=Cond2))
row.names(df)=paste("g",1:1000,sep="")
cond1Sum<-sum(df$cond1)
cond2Sum<-sum(df$cond2)
df$cond1Other<--df$cond1+cond1Sum
df$cond2Other<--df$cond2+cond2Sum
head (df)
df$pVals<-apply(df,1,fishtable)
df$WaltVals<-apply(df,1,Wald.test)
plot(density(df$WaltVals))
fishtable<-function(x){
cond1<-x[1]
cond2<-x[2]
cond1oth<-x[3]
cond2oth<-x[4]
testFisher<-data.frame(gene=c(cond1,cond2),not.gene=c(cond1oth,cond2oth))
row.names(testFisher)=c("cond1","cond2")
f<-fisher.test(testFisher)
return(f$p.value)
}
Wald.test<-function(x){
cond1<-x[1]
cond2<-x[2]
wald.value<-(cond1-cond2)/(sqrt(cond1+cond2))
return(wald.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment