data(zmat)
## Each feature in each study has three association states, negative, null, or positive:
# The z-scores are binned and priors are given to each hypothesis state:
input.to.repfdr3 <- ztobins(zmat, 3, plot = TRUE, df = 15)
pbz <- input.to.repfdr3$pdf.binned.z
bz <- input.to.repfdr3$binned.z.mat
# load the prior probabilities for each association status vector.
# (this vector is computed with piem())
data(Pi)
round(Pi,6)
# Fdr calculation for replicablity analysis:
output3 <- repfdr(pbz, bz, "replication",Pi.previous.result=Pi,
control = em.control(nr.threads = 2))
# converge after 209 iterations.
# Set nr.threads = 0 to optimal use of threads.
BayesFdr <- output3$mat[,"Fdr"]
sum(BayesFdr <= 0.05) # 119
# The posterior probabilities for the features with Bayes FDR at most 0.05:
post <- ldr(pbz,bz[order(BayesFdr)[1:5],],Pi)
round(post,4)
# posteriors for a subset of the association status vectors can also be reported:
H <- hconfigs( dim(zmat)[2], 3)
h.replicability = apply(H, 1, function(y) {sum(y == 1)> 1 | sum(y == -1) >1})
post <- ldr(pbz,bz[order(BayesFdr)[1:5],],Pi,h.vecs= which(h.replicability==1))
round(post,4)
# Fdr calculation for meta-analysis:
output3.a <- repfdr(pbz, bz, "meta-analysis", Pi.previous.result = Pi)
BayesFdr.a <- output3.a$mat[,"Fdr"]
sum(BayesFdr.a <= 0.05) # 239
## manhattan plot (ploting can take a while):
# code for manhattan plot by Stephen Turner (see copyrights at the source code manhattan.r)
data(SNPlocations)
par(mfrow=c(2,1))
# Replication
manhattan(dataframe=cbind(SNPlocations,P=BayesFdr),ymax=10.5,pch=20,
limitchromosomes=1:4,suggestiveline=-log(0.05,10),genomewideline=F,cex=0.25,
annotate=SNPlocations$SNP[BayesFdr<=0.05],main="Replication")
# Association
manhattan(dataframe=cbind(SNPlocations,P=BayesFdr.a),ymax=10.5,cex=0.25,
limitchromosomes=1:4,suggestiveline=-log(0.05,10),genomewideline=F,pch=20,
annotate=SNPlocations$SNP[BayesFdr<=0.05],main="Meta-analysis")
par(mfrow=c(1,1))
## Each feature in each study has two association states:
data(simzmat)
input.to.repfdr <- ztobins(simzmat, 2, plot = TRUE, df = 15)
pbz <- input.to.repfdr$pdf.binned.z
bz <- input.to.repfdr$binned.z.mat
# which of the tests are true replication\\association (know this since the data was simulated!)?
true.rep <- apply(Hmat,1,function(y){ sum(y==1)>1 | sum(y==-1)>1 })
true.assoc <- rowSums(abs(Hmat)) >= 1
output <- repfdr(pbz, bz, "replication",control = em.control(nr.threads = 2))
# converge after 68 iterations.
# Set nr.threads = 0 to optimal use of threads.
BayesFdr <- output$mat[,"Fdr"]
Rej <- (BayesFdr <= 0.05)
sum(Rej) # = 839
# Check whether the Fdr controlled:
sum(Rej * !true.rep) / sum(true.rep) # FDP = 0.0388
Pi <- output$Pi
round(Pi,6) # close to the true proportions in the data, see help(simzmat)
outputa <- repfdr(pbz, bz, "meta-analysis", Pi.previous.result = Pi)
BayesFdr <- outputa$mat[,"Fdr"]
Rej <- (BayesFdr <= 0.05)
sum(Rej) # = 964
# Check whether the Fdr controlled:
sum(Rej * !true.assoc) / sum(true.assoc) # FDP = 0.0466
Run the code above in your browser using DataLab