## First example: one-factor analysis with sPLS-DA, selecting a subset of variables
# as in the paper Liquet et al.
#--------------------------------------------------------------
data(vac18)
X <- vac18$genes
Y <- vac18$stimulation
# sample indicates the repeated measurements
design <- data.frame(sample = vac18$sample,
stimul = vac18$stimulation)
# multilevel sPLS-DA model
res.1level <- multilevel(X, ncomp = 3, design = design,
method = "splsda", keepX = c(30, 137, 123))
# set up colors for plotIndiv
col.stim <- c("darkblue", "purple", "green4","red3")
col.stim <- col.stim[as.numeric(Y)]
plotIndiv(res.1level, ind.names = Y, col = col.stim)
## Second example: two-factor analysis with sPLS-DA, selecting a subset of variables
# as in the paper Liquet et al.
#--------------------------------------------------------------
data(vac18.simulated) # simulated data
X <- vac18.simulated$genes
design <- data.frame(sample = vac18.simulated$sample,
stimu = vac18.simulated$stimulation,
time = vac18.simulated$time)
res.2level <- multilevel(X, ncomp = 2, design = design,
keepX = c(200, 200), method = 'splsda')
# set up colors and pch for plotIndiv
col.stimu <- as.numeric(design$stimu)
pch.time <- c(20, 4)[as.numeric(design$time)]
plotIndiv(res.2level, col = col.stimu, ind.names = FALSE,
pch = pch.time)
legend('bottomright', legend = levels(design$stimu),
col = unique(col.stimu), pch = 20, cex = 0.8,
title = "Stimulation")
legend('topright', col = 'black', legend = levels(design$time),
pch = unique(pch.time), cex = 0.8, title = "Time")
## Third example: one-factor analysis with sPLS, selecting a subset of variables
#--------------------------------------------------------------
data(liver.toxicity)
# note: we made up those data, pretending they are repeated measurements
repeat.indiv <- c(1, 2, 1, 2, 1, 2, 1, 2, 3, 3, 4, 3, 4, 3, 4, 4, 5, 6, 5, 5,
6, 5, 6, 7, 7, 8, 6, 7, 8, 7, 8, 8, 9, 10, 9, 10, 11, 9, 9,
10, 11, 12, 12, 10, 11, 12, 11, 12, 13, 14, 13, 14, 13, 14,
13, 14, 15, 16, 15, 16, 15, 16, 15, 16)
summary(as.factor(repeat.indiv)) # 16 rats, 4 measurements each
# this is a spls (unsupervised analysis) so no need to mention any factor in design
# we only perform a one level variation split
design <- data.frame(sample = repeat.indiv)
res.spls.1level <- multilevel(X = liver.toxicity$gene,
Y=liver.toxicity$clinic,
design = design,
ncomp = 3,
keepX = c(50, 50, 50), keepY = c(5, 5, 5),
method = 'spls', mode = 'canonical')
# set up colors and pch for plotIndiv
col.stimu <- as.numeric(as.factor(design$stimu))
plotIndiv(res.spls.1level, rep.space = 'X-variate', ind.names = FALSE,
col = col.stimu, pch = 20)
title(main = 'Gene expression space')
plotIndiv(res.spls.1level, rep.space = 'Y-variate', ind.names = FALSE,
col = col.stimu, pch = 20)
title(main = 'Clinical measurements space')
legend('bottomright', legend = levels(as.factor(design$stimu)),
col = unique(col.stimu), pch = 20, cex = 0.8,
title = "Dose")
Run the code above in your browser using DataLab