-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutlier-detection.R
More file actions
69 lines (55 loc) · 2.01 KB
/
Copy pathoutlier-detection.R
File metadata and controls
69 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
source("load-cancer.R")
# ---------------------------------------------------------------------------
#
# 1. Outlier detection
#
# ---------------------------------------------------------------------------
# The spectra length is the number of peaks that it holds.
spectraLengths <- sapply(data$spectra, length)
# Calculate the mean intensity of the peaks in the spectra.
intensityMeans <-
sapply(data$spectra, function(spectra)
mean(intensity(spectra)))
# Data is grouped in a data frame, so that it can be used in the boxplot function.
dataFrame <- data.frame(
"spectra" = data$spectraNames,
"samples" = data$sampleNames,
"spectraLengths" = spectraLengths,
"intensityMeans" = intensityMeans,
stringsAsFactors = FALSE
)
# This graphical configuration allows including two plots in the same window.
par(mfrow = c(1, 2))
# Generation of the boxplot for the spectra lengths.
bpLength = boxplot(
spectraLengths ~ samples,
data = dataFrame,
main = "Spectra Size",
ylab = "Number of peaks",
xlab = "Sample",
col = data$samplesColors
)
# Generation of the boxplot for the mean peak intensity.
bpIntensity = boxplot(
intensityMeans ~ samples,
data = dataFrame,
main = "Intensities",
ylab = "Mean Intensity",
xlab = "Sample",
col = data$samplesColors
)
# The boxplot result includes the "out" attribute, a vector with the outlier values.
# The spectra with outlier values in the characteristics analyzed are extracted here.
dataFrame[dataFrame$spectraLengths %in% bpLength$out, ]
dataFrame[dataFrame$intensityMeans %in% bpIntensity$out, ]
# ---------------------------------------------------------------------------
#
# 2. Spectra comparison
#
# ---------------------------------------------------------------------------
source("multiple-sample-visualization-functions.R")
par(mfrow = c(2, 2))
compareSpectra(data$spectra[[7]], data$spectra[[6]])
compareSpectra(data$spectra[[7]], data$spectra[[8]])
compareSpectra(data$spectra[[7]], data$spectra[[9]])
compareSpectra(data$spectra[[7]], data$spectra[[10]])