set.seed(123)
# Define the function to calculate the z-scores
meta.def <- function(logicalVec, SNP.list, arg.beta, arg.sigma) {
# Get the snps and subset to use
beta <- as.matrix(arg.beta[SNP.list, logicalVec])
se <- as.matrix(arg.sigma[SNP.list, logicalVec])
test <- (beta/se)^2
ret <- apply(test, 1, max)
list(z=ret)
}
# Define the function to determine which subsets to consider
sub.def <- function(logicalVec, args) {
# Only allow the cummulative subsets:
# TRUE FALSE FALSE FALSE ...
# TRUE TRUE FALSE FALSE ...
# TRUE TRUE TRUE FALSE ...
# etc
sum <- sum(logicalVec)
ret <- all(logicalVec[1:sum])
ret
}
# Assume there are 10 subtypes and 3 SNPs
k <- 10
snp.vars <- 1:3
# Generate some data
nsnp <- length(snp.vars)
beta <- matrix(-0.5 + runif(k*nsnp), nrow=nsnp)
sigma <- matrix(runif(k*nsnp)^2, nrow=nsnp)
meta.args <- list(arg.beta=beta, arg.sigma=sigma)
z.max(k, snp.vars, 2, meta.def, meta.args, sub.def=sub.def)
Run the code above in your browser using DataLab