Entering edit mode
OSAT seems to be a very nice package which allow sample assignment to batches to minimize batch effect.
Unfortunately I did not find an easy way how to correct for multiple potential batch effects. E.g., plate and row number.
library(OSAT)
set.seed(1)
samples <- data.frame(ID=1:64, group=factor(rep(1:8, each=8)))
myChip <- new("BeadChip", nRows=1L, nColumns=8L, byrow=FALSE,
comment='8 wells chip')
myPlate <- new("BeadPlate", chip=myChip, nRows=1L, nColumns=1L,
comment="one chip")
gs <- setup.sample(samples, optimal=c("group"))
gc <- setup.container(myPlate, 8, batch='plates')
gSetup <- create.optimized.setup(
sample = gs,
container = gc,
nSim = 10000
)
assignment <- get.experiment.setup(gSetup)
with(assignment, table(group, columns))
# columns
# group 1 2 3 4 5 6 7 8
# 1 2 1 0 1 1 1 0 2
# 2 0 1 1 3 0 1 0 2
# 3 2 3 1 0 0 0 1 1
# 4 1 3 0 0 2 1 1 0
# 5 1 0 1 0 2 1 2 1
# 6 1 0 2 3 0 0 2 0
# 7 0 0 2 1 1 1 1 2
# 8 1 0 1 0 2 3 1 0
What I managed to far, is to create a custom optimization function. Just by copying optimal.shuffle, and adding a custom weight to the objective function:
my.optmial.shuffle <- function (x, nSim = 100, k = 2) {
# ...
bestDiff <- sum((oCountObs - oCount)^2) + custom.score(con, link)
# ...
optValue[i] <- sum((oCountObs - oCount)^2) + custom.score(con, newlink)
# ...
}
But this does not always work as expected.
I was wondering if there is a more elegant solution to the problem.