#### Example 1: a simulation; each feature in each study has two association states,
#### null and positive:
# a) Replicablity analysis:
data(binned_zmat_sim) # this loads the binned z-scores as well as the (estimated) probabilities
# in each bin for each state
output.rep <- repfdr(pbz_sim, bz_sim, "replication")
BayesFdr.rep <- output.rep$mat[,"Fdr"]
Rej <- (BayesFdr.rep <= 0.05)
sum(Rej)
# which of the tests are true replicability findings? (we know this since the data was simulated)
data(hmat_sim)
true.rep <- apply(hmat_sim,1,function(y){ sum(y==1)>1 })
# Compute the false discovery proportion (FDP) for replicability:
sum(Rej * !true.rep) / sum(true.rep)
# we can use the previously calculated Pi for further computations (e.g meta-analysis):
Pi_sim <- output.rep$Pi
# b) meta-analysis:
output.meta <- repfdr(pbz_sim, bz_sim, "meta-analysis", Pi.previous.result = Pi_sim)
BayesFdr.meta <- output.meta$mat[,"Fdr"]
Rej <- (BayesFdr.meta <= 0.05)
sum(Rej)
# which of the tests are true association findings? (we know this since the data was simulated)
true.assoc <- rowSums(hmat_sim) >= 1
# Compute the false discovery proportion (FDP) for association:
sum(Rej * !true.assoc) / sum(true.assoc)
## Not run:
# #### Example 2: SNPs data; each SNP in each study has three association states,
# #### negative, null, or positive:
#
# # load the bins of the z-scores and their probabilities.
# data(binned_zmat)
#
# # load the prior probabilities for each association status vector.
# data(Pi)
# Pi # the proportions vector was computed using piem()
# # with the following command: Pi <- piem(pbz, bz)$last.iteration
#
# # a) replicablity analysis:
# output.rep <- repfdr(pbz, bz, "replication",Pi.previous.result=Pi)
# BayesFdr.rep <- output.rep$mat[,"Fdr"]
# Rej <- sum(BayesFdr.rep <= 0.05)
# sum(Rej)
#
# # The posterior probabilities for the first five features with Bayes FDR at most 0.05:
# post <- ldr(pbz,bz[order(BayesFdr.rep)[1:5],],Pi)
# round(post,4)
#
# # posteriors for a subset of the association status vectors can also be reported:
# H <- hconfigs( dim(bz)[2], 3)
# h.replicability = apply(H, 1, function(y) {sum(y == 1)> 1 | sum(y == -1) >1})
# post <- ldr(pbz,bz[order(BayesFdr.rep)[1:5],],Pi,h.vecs= which(h.replicability==1))
# round(post,4)
#
# # b) meta-analysis:
# output.meta <- repfdr(pbz, bz, "meta-analysis", Pi.previous.result = Pi)
# BayesFdr.meta <- output.meta$mat[,"Fdr"]
# Rej <- sum(BayesFdr.meta <= 0.05)
# sum(Rej)
# ## End(Not run)
## manhattan plot (ploting can take a while):
# code for manhattan plot by Stephen Turner (see copyrights at the source code manhattan.r)
## Not run:
# data(SNPlocations)
# par(mfrow=c(2,1))
# # Replication
# manhattan(dataframe=cbind(SNPlocations,P=BayesFdr.rep),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.meta),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))
# ## End(Not run)
Run the code above in your browser using DataLab