
###########################################################################
######## This is the file to reproduce the analysis of the ALL data #######
###########################################################################

#################
# Load packages #
#################

library(globalboosttest)
library(globaltest)


################################
# Load and preprocess ALL data #
################################

library(ALL)
data(ALL)
X<-t(exprs(ALL))
X<-data.frame(X)
pheno<-pData(ALL)
Y<-as.factor(pheno$remission)
levels(Y)<-c("0","1")

Z<-data.frame(pheno$sex,pheno$age,pheno$BT)
names(Z)<-c("sex","age","BT")

# sex
levels(Z[,1])<-c("0","1")
# BT
Z[is.element(Z[,3],c("B1","B2","B3","B4")),3]<-"B"
Z[is.element(Z[,3],c("T1","T2","T3","T4")),3]<-"T"
Z[,3]<-as.factor(as.character(Z[,3]))
levels(Z[,3])<-c("0","1")

whichNA<-c()
for (i in 1:nrow(Z))
 {
 if (any(is.na(Z[i,])))
  {
  whichNA<-c(whichNA,i)
  }
 }

whichNA<-union(whichNA,which(is.na(Y)))

X<-X[-whichNA,]
Y<-Y[-whichNA]
Z<-Z[-whichNA,]


########################################################################
# Perform the test with and without adjustment for clinical covariates #
########################################################################

result2ALL_noadj<-globalboosttest(X,Y,Z=NULL,nperm=1000,mstop=c(100,500,1000),mstopAIC=TRUE,pvalueonly=FALSE)
result2ALL<-globalboosttest(X,Y,Z=Z,nperm=1000,mstop=c(100,500,1000),mstopAIC=TRUE,pvalueonly=FALSE)


############################
# Run Goeman's global test #
############################

goeman<-function(X,Y,Z)
{
globaltest(X=t(X),Y=Y,adjust=Z)
}
result1ALL<-globaltest(t(X),Y,adjust=Z)
result1ALL_noadj<-globaltest(t(X),Y)



