# NOT RUN {
## Create small simulated dataset, A, with embeded batch effects
set.seed(2731)
kRid <- 20
p <- 100
n <- 200
W <- matrix(rnorm(p*kRid), kRid)
S <- matrix(rnorm(n*kRid), n)
z <- sample(1:3, rep = TRUE, size = n)
Z <- model.matrix( ~ -1 + as.factor(z))
l <- matrix(rnorm(kRid*NCOL(Z)), kRid)
A <- (S - Z %*% t(l) ) %*% W
## Scale A to give input, X
X <- scale(A)
resUnadj <- Rtsne::Rtsne(X) ## Standard t-SNE
resAdj <- bctsne(X = X, Z = Z, k = 10) ## Batch-corrected t-SNE
## Plot results, no true effects were included in the simulated data, so
## we expect all batches to overlap with bcTSNE; batch membership indicated
## by color
plot(resUnadj$Y, col = z)
plot(resAdj$Y, col = z)
# }
Run the code above in your browser using DataLab