# NOT RUN {
data(autism)
# Random subset of 150 variables:
set.seed(1234)
Xsub <- X[,sample(1:ncol(X), size=150)]
# In cases of batches with more than 20 observations
# select 20 observations at random:
subinds <- unlist(sapply(1:length(levels(batch)), function(x) {
indbatch <- which(batch==x)
if(length(indbatch) > 20)
indbatch <- sort(sample(indbatch, size=20))
indbatch
}))
Xsub <- Xsub[subinds,]
batchsub <- batch[subinds]
ysub <- y[subinds]
trainind <- which(batchsub %in% c(1,2))
Xsubtrain <- Xsub[trainind,]
ysubtrain <- ysub[trainind]
batchsubtrain <- factor(as.numeric(batchsub[trainind]), levels=c(1,2))
testind <- which(batchsub %in% c(3,4))
Xsubtest <- Xsub[testind,]
ysubtest <- ysub[testind]
batchsubtest <- as.numeric(batchsub[testind])
batchsubtest[batchsubtest==3] <- 1
batchsubtest[batchsubtest==4] <- 2
batchsubtest <- factor(batchsubtest, levels=c(1,2))
somemethods <- c("fabatch", "combat", "meancenter", "none")
adjustedtestdata <- list()
for(i in seq(along=somemethods)) {
cat(paste("Adjusting training data using method = \"", somemethods[i],
"\"", sep=""), "\n")
paramstemp <- ba(x=Xsubtrain, y=ysubtrain, batch=batchsubtrain,
method = somemethods[i])
cat(paste("Addon adjusting test data using method = \"",
somemethods[i], "\"", sep=""), "\n")
adjustedtestdata[[i]] <- baaddon(params=paramstemp, x=Xsubtest,
batch=batchsubtest)
}
# }
Run the code above in your browser using DataLab