-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-Liechti_28-experiments.Rmd
More file actions
668 lines (591 loc) · 22.2 KB
/
02-Liechti_28-experiments.Rmd
File metadata and controls
668 lines (591 loc) · 22.2 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
---
title: "Liechti_28-experiments"
output: html_document
date: "2025-09-01"
---
# Setup
## Setup libraries
```{r, message = FALSE, warning = FALSE}
library(CytoScan)
library(dplyr)
library(FlowSOM)
library(flowCore)
library(flowDensity)
```
## Setup file locations
```{r}
outputFolder <- "output/"
# Location of data from Liechti et al.
liechtiData <- "PATH"
```
# Experiments using data from Liechti et al.
## Organize data
### Define channels and lasers
```{r}
# All channels
channels <- c("B515-A", "B610-A", "B660-A", "B710-A", "B780-A", "V450-A",
"V510-A", "V570-A", "V605-A", "V655-A", "V710-A", "V750-A",
"V785-A", "U390-A", "U450-A", "U500-A", "U570-A", "U660-A",
"U740-A", "U785-A", "R670-A", "R730-A", "R780-A", "G575-A",
"G610-A", "G660-A", "G710-A", "G780-A")
# Define the channels by laser
lasers <- list("blue" = c("B515-A", "B610-A", "B660-A", "B710-A", "B780-A"),
"violet" = c("V450-A", "V510-A", "V570-A", "V605-A",
"V655-A", "V710-A", "V750-A", "V785-A"),
"ultraviolet" = c("U390-A", "U450-A", "U500-A", "U570-A", "U660-A",
"U740-A", "U785-A"),
"red" = c("R670-A", "R730-A", "R780-A"),
"green" = c("G575-A", "G610-A", "G660-A", "G710-A", "G780-A"))
# All channels with bimodal expression patterns (selected later in this script)
bimodals <- c("B780-A", "V510-A", "V570-A", "V655-A", "V785-A", "U390-A",
"U500-A", "U570-A", "U785-A", "R730-A", "R780-A", "G660-A",
"G710-A", "G780-A")
# Define the bimodals by laser
lasersBimodals <- list("blue" = c("B780-A"),
"violet" = c("V510-A", "V570-A", "V655-A", "V785-A"),
"ultraviolet" = c("U390-A", "U500-A", "U570-A", "U785-A"),
"red" = c("R730-A", "R780-A"),
"green" = c("G660-A", "G710-A", "G780-A"))
```
### Select FCS files
```{r}
# Get all the files from Liechti et al. with high T-cell viability
metaFile <- paste0(liechtiData, "210808_Viability summary_updated.xlsx")
labels <- data.frame(readxl::read_excel(metaFile, sheet="ICS"),
check.names = FALSE)
labels <- labels[labels[,"FlowJo ID"] != "2745",]
labels <- labels[labels[,"Viable of CD3"] > 25,]
ids <- labels[,"FlowJo ID"]
files <- unlist(lapply(ids, function(x) paste0(liechtiData, x, ".fcs")))
# Select the subset of files send by Sofie van Gassen
availableFiles <- list.files(substr(liechtiData, 0, nchar(liechtiData)-1),
pattern = "fcs", full.names = TRUE)
files <- files[files %in% availableFiles]
# Get a random subset of 100 files from this subset
set.seed(42)
files <- sample(files, 100)
anomalySamples <- files
```
# Determine bimodality
```{r}
agg <- AggregateFlowFrames(files, cTotal = 100000)
exprs <- data.frame(agg@exprs, check.names = FALSE)
exprs[,"File"] <- as.character(exprs[,"File"])
for (channel in channels){
print(channel)
dfs <- data.frame()
for (file in unique(exprs[,"File"])){
subset <- exprs[exprs[,"File"]==file, channel]
kde <- density(subset)
df <- data.frame(file = file, x = kde$x, y = kde$y)
dfs <- rbind(dfs, df)
}
p <- ggplot(dfs, aes(x = x, y = y, group = file)) +
geom_line(alpha = 0.3) +
labs(x = "Marker expression", title = channel)
for (file in files){
ff <- read.FCS(file, which.lines = 1000)
cutoff <- deGate(ff, channel)
p <- p + geom_vline(xintercept = cutoff, color = "red", alpha = 0.3)
}
print(p)
}
```
## Subsampling experiment
In this experiment, we evaluate how many cells are required for different feature
generation techniques.
```{r}
# Define the input cell counts and different settings for quantiles
cellCounts <- c(2000, 1000, 500, 200, 100)
quantileDistances <- c(0.01, 0.05, 0.1, 0.25)
```
```{r}
simulateDownsampling <- function(cellCounts, quantileDistances){
CS <- CytoScan()
ProcessInput <- function(ff){
return(ff)
}
CS$preprocessFunction <- ProcessInput
CS <- addTestdata(CS, files)
data <- data.frame()
for (featMethod in c("quantiles", "EMD")){
print(featMethod)
counts <- cellCounts
correlations <- list()
for (n in counts){
print(n)
if (featMethod == "quantiles"){
for (quantileDist in c(quantileDistances)){
print(quantileDist)
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 10, n = NULL, quantileDist = quantileDist,
recalculate = TRUE)
features <- CS$features$test[[featMethod]]
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 10, n = n, quantileDist = quantileDist,
recalculate = TRUE)
sampled_features <- CS$features$test[[featMethod]]
for (feature in colnames(features)){
data <- rbind(data, data.frame(featMethod = featMethod, n = n,
quantileDist = quantileDist,
feature = feature,
r = cor(features[,feature],
sampled_features[,feature])))
}
}
} else {
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 10, n = NULL, recalculate = TRUE)
features <- CS$features$test[[featMethod]]
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 10, n = n, recalculate = TRUE)
sampled_features <- CS$features$test[[featMethod]]
for (feature in colnames(features)){
data <- rbind(data, data.frame(featMethod = featMethod, n = n,
quantileDist = NA,
feature = feature,
r = cor(features[,feature],
sampled_features[,feature])))
}
}
}
}
return(data)
}
```
```{r}
if (!file.exists("output/downsampling_simulation.csv")){
results <- simulateDownsampling(cellCounts, quantileDistances)
write.csv(results, "output/downsampling_simulation.csv")
}
```
## Laser simulation
### Define the different simulations
We use the custom pre-processing functionality of CytoScan to introduce effects.
In this setting, the effects are introduced upon reading the FCS file.
```{r}
shiftFactors <- seq(0, 1.5, 0.05)
stretchFactors <- seq(1, 2, 0.05)
separateFactors <- seq(0, 1, 0.05)
shiftInput <- function(ff){
if (grepl(anomalySample, ff@description$FILENAME)){
for (channel in effectChannels){
iqr <- IQR(ff@exprs[, channel])
ff@exprs[, channel] <- ff@exprs[, channel] + iqr * effectSize
}
}
return(ff)
}
stretchInput <- function(ff){
if (grepl(anomalySample, ff@description$FILENAME)){
for (channel in effectChannels){
iqr <- IQR(ff@exprs[, channel])
ff@exprs[, channel] <- ff@exprs[, channel] * effectSize
}
}
return(ff)
}
separateInput <- function(ff){
if (grepl(anomalySample, ff@description$FILENAME)){
for (channel in effectChannels){
iqr <- IQR(ff@exprs[, channel])
size <- effectSize * iqr
cutoff <- flowDensity::deGate(ff, channel)
ff@exprs[ff@exprs[,channel] < cutoff, channel] <- ff@exprs[ff@exprs[,channel] < cutoff, channel] - size
ff@exprs[ff@exprs[,channel] >= cutoff, channel] <- ff@exprs[ff@exprs[,channel] >= cutoff, channel] + size
}
}
return(ff)
}
```
### Define functions for laser simulations
```{r}
# This is a helper is used to assess performance
getPerformance <- function(CS, files, modifiedSample, featMethod, slot){
# Computing TP, TN, FP, FN
gt <- data.frame(file = files, gt = files == modifiedSample)
pred <- data.frame(pred = CS[[slot]][[featMethod]])
pred$file <- rownames(pred)
df <- merge(gt, pred)
df$gt <- as.logical(df$gt)
df$pred <- as.logical(df$pred)
TP <- sum(df$gt & df$pred)
TN <- sum(!df$gt & !df$pred)
FP <- sum(!df$gt & df$pred)
FN <- sum(df$gt & !df$pred)
output <- data.frame(modifiedSample = modifiedSample,
featMethod = featMethod,
TP = TP,
TN = TN,
FP = FP,
FN = FN)
return(output)
}
```
```{r}
simulateLasers <- function(anomalySamples, simulatedSetting, featMethods,
lasers){
##############################################################################
# Generate baseline features
CS <- CytoScan()
# Add these variables so we can access them in parallel sockets
anomalySample <<- "None"
effectSize <<- NULL
effectChannels <<- NULL
CS$parallel$parallelVars <- c("CS", "channels", "readInput",
"anomalySample", "effectSize", "effectChannels")
if (simulatedSetting == "shift"){
CS$preprocessFunction <- shiftInput
effectSizes <- shiftFactors
} else if (simulatedSetting == "stretch"){
CS$preprocessFunction <- stretchInput
effectSizes <- stretchFactors
} else if (simulatedSetting == "separate"){
CS$preprocessFunction <- separateInput
effectSizes <- separateFactors
} else if (simulatedSetting == "subsample"){
CS$preprocessFunction <- subsampleInput
effectSizes <- subsampleFactors
}
CS <- addTestdata(CS, files, read = TRUE)
CS$paths$reference <- CS$paths$test
CS$data$reference <- CS$data$test
# Generate all the features
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 20)
}
# Store normal data
BaselineCS <- CS
##############################################################################
results <- data.frame()
for (anomalyIndex in seq_along(anomalySamples)){
print(anomalyIndex)
start <- Sys.time()
anomalySample <<- anomalySamples[anomalyIndex]
# Add the test sample using an effect size and generate features
for (laser in names(lasers)){
effectChannels <<- lasers[[laser]]
for (effectSize in effectSizes){
effectSize <<- effectSize
# Gate the baseline data
CS <- BaselineCS
testFeatures <- CS$features$test
refFeatures <- CS$features$reference
# Remove the data from the baseline CytoScan object
CS$paths$test <- files[files != anomalySample]
CS$paths$reference <- files[files != anomalySample]
for (featMethod in featMethods){
CS$features$test[[featMethod]] <- testFeatures[[featMethod]][rownames(testFeatures[[featMethod]]) != anomalySample,]
CS$features$reference[[featMethod]] <- refFeatures[[featMethod]][rownames(refFeatures[[featMethod]]) != anomalySample,]
}
# Read the anomalous sample with the effects
CS <- addTestdata(CS, files, read = TRUE)
# Generate the output
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
aggSlot = "test", cores = 1)
CS <- Flag(CS, flagMethod = "outlier", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "outliers")
output$simulatedSetting <- simulatedSetting
output$laser <- laser
output$effectSize <- effectSize
output$flagMethod <- "outlier"
results <- rbind(results, output)
CS <- Flag(CS, flagMethod = "novelty", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "novelties")
output$simulatedSetting <- simulatedSetting
output$laser <- laser
output$effectSize <- effectSize
output$flagMethod <- "novelty"
results <- rbind(results, output)
features <- CS$features$test[[featMethod]]
CS$features$test[[featMethod]] <- features[rownames(features) != anomalySample,]
}
}
}
end <- Sys.time()
print(end - start)
}
return(results)
}
```
### Run simulations
Note: this step can take hours to run!
```{r}
featMethods <- c("EMD", "quantiles")
for (effect in c("shift", "stretch", "separate")){
print(effect)
filename <- paste0("output/laserSimulation_", effect, ".csv")
if (!file.exists(filename)){
results <- simulateLasers(anomalySamples, effect, featMethods, lasers)
write.csv(results, filename)
}
}
```
## Biological simulation
### Define the different simulations
```{r}
subsampleFactors <- seq(0.1, 1, 0.1)
```
```{r}
subsampleInput <- function(ff){
if (grepl(anomalySample, ff@description$FILENAME)){
# Get the metaclusters
ff_fSOM <- FlowSOM::NewData(fsom=fSOM, input=ff)
MC <- FlowSOM::GetMetaclusters(ff_fSOM)
# Perform subsampling
otherCells <- ff@exprs[MC != metaclusterID,]
MCCells <- ff@exprs[MC == metaclusterID,]
nCells <- ceiling((1 - effectSize) * nrow(MCCells))
idx <- sample(seq(1, nrow(MCCells)), nCells)
MCCells <- MCCells[idx,]
ff@exprs <- rbind(otherCells, MCCells)
}
return(ff)
}
```
```{r}
simulateSubsample <- function(anomalySamples, featMethods){
# Identify biggest cell population (FlowSOM)
set.seed(42)
agg <- FlowSOM::AggregateFlowFrames(files, cTotal=10**6, channels = channels,
silent=TRUE)
fSOM <<- FlowSOM::FlowSOM(agg, colsToUse = channels, maxMeta = 20, seed = 42)
counts <- FlowSOM::GetCounts(fSOM, level = "metaclusters")
names(counts) <- seq(1, length(counts))
metaclusterID <<- as.numeric(names(counts)[which.max(counts)])
results <- data.frame()
# Loop over all of the anomalous samples
for (anomalyIndex in seq_along(anomalySamples)){
print(anomalyIndex)
start <- Sys.time()
anomalySample <<- anomalySamples[anomalyIndex]
CS <- CytoScan()
# Add these variables so we can access them in parallel sockets
effectSize <<- NULL
CS$parallel$parallelVars <- c("CS", "channels", "readInput",
"anomalySample", "effectSize", "fSOM",
"metaclusterID")
CS$parallel$parallelPackages <- c(CS$parallel$parallelPackages, "FlowSOM")
CS$preprocessFunction <- subsampleInput
effectSizes <- subsampleFactors
CS <- addTestdata(CS, files[files != anomalySample], read = TRUE)
# Copy the test data to the reference data slot (faster than regeneration)
CS$paths$reference <- CS$paths$test
CS$data$reference <- CS$data$test
# Generate all the features
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 20)
}
# Add the test sample using an effect size and generate features
for (effectSize in effectSizes){
effectSize <<- effectSize
CS <- addTestdata(CS, files, read = TRUE)
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
aggSlot = "test", cores = 1)
CS <- Flag(CS, flagMethod = "outlier", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "outliers")
output$simulatedSetting <- "subsample"
output$effectSize <- effectSize
output$flagMethod <- "outlier"
results <- rbind(results, output)
CS <- Flag(CS, flagMethod = "novelty", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "novelties")
output$simulatedSetting <- "subsample"
output$effectSize <- effectSize
output$flagMethod <- "novelty"
results <- rbind(results, output)
features <- CS$features$test[[featMethod]]
CS$features$test[[featMethod]] <- features[rownames(features) != anomalySample,]
}
CS$data$test[[anomalySample]] <- NULL
CS$paths$test <- files[files != anomalySample]
}
end <- Sys.time()
print(end - start)
}
return(results)
}
```
```{r}
filename <- paste0("output/subsampling_simulation.csv")
if (!file.exists(filename)){
results <- simulateSubsample(anomalySamples, featMethods)
write.csv(results, filename)
}
```
## Baseline FPR
### Outlier detection
```{r}
CS <- CytoScan()
ProcessInput <- function(ff){
return(ff)
}
CS$preprocessFunction <- ProcessInput
CS <- addTestdata(CS, files)
CS <- generateFeatures(CS, channels, "quantiles")
CS <- generateFeatures(CS, channels, "EMD")
CS <- Flag(CS, featMethod = "quantiles", "outlier")
CS <- Flag(CS, featMethod = "EMD", "outlier")
table(CS$outliers$quantiles)
table(CS$outliers$EMD)
```
### Novelty detection
```{r}
results = list()
for (file in files){
print(file)
ref_files <- files[files != file]
CS <- CytoScan()
ProcessInput <- function(ff){
return(ff)
}
CS$preprocessFunction <- ProcessInput
CS <- addReferencedata(CS, ref_files)
CS <- addTestdata(CS, file)
CS <- generateFeatures(CS, channels, "quantiles")
CS <- generateFeatures(CS, channels, "EMD", aggSlot = "reference")
CS <- Flag(CS, featMethod = "quantiles", "novelty")
CS <- Flag(CS, featMethod = "EMD", "novelty")
if ((CS$novelties$quantiles[[file]]) == FALSE){
quantile_FPR <- 0
} else {
quantile_FPR <- 1
}
if ((CS$novelties$EMD[[file]]) == FALSE){
EMD_FPR <- 0
} else {
EMD_FPR <- 1
}
results[[file]] <- list("file" = file, "quantile_FPR" = quantile_FPR,
"EMD_FPR" = EMD_FPR)
}
results <- dplyr::bind_rows(results)
```
## Subsample simulation
We use the custom pre-processing functionality of CytoScan to introduce effects.
```{r}
subsampleFactors <- seq(0.1, 1, 0.1)
```
```{r}
subsampleInput <- function(ff){
if (grepl(anomalySample, ff@description$FILENAME)){
# Get the metaclusters
ff_fSOM <- FlowSOM::NewData(fsom=fSOM, input=ff)
MC <- FlowSOM::GetMetaclusters(ff_fSOM)
# Perform subsampling
otherCells <- ff@exprs[MC != metaclusterID,]
MCCells <- ff@exprs[MC == metaclusterID,]
nCells <- ceiling((1 - effectSize) * nrow(MCCells))
idx <- sample(seq(1, nrow(MCCells)), nCells)
MCCells <- MCCells[idx,]
ff@exprs <- rbind(otherCells, MCCells)
}
return(ff)
}
```
```{r}
anomalySamples <- files
featMethods <- c("EMD", "quantiles")
```
```{r}
# This function is used to assess performance
getPerformance <- function(CS, files, modifiedSample, featMethod, slot){
anomalies <- names(CS[[slot]][[featMethod]])[which(CS[[slot]][[featMethod]] == TRUE)]
if (modifiedSample %in% anomalies){
TN <- 0
FP <- 1
} else {
TN <- 1
FP <- 0
}
output <- data.frame(modifiedSample = modifiedSample,
featMethod = featMethod,
TN = TN,
FP = FP)
return(output)
}
```
```{r}
simulateSubsample <- function(anomalySamples, featMethods){
# Identify biggest cell population (FlowSOM)
set.seed(42)
agg <- FlowSOM::AggregateFlowFrames(files, cTotal=10**6, channels = channels,
silent=TRUE)
fSOM <<- FlowSOM::FlowSOM(agg, colsToUse = channels, maxMeta = 20, seed = 42)
counts <- FlowSOM::GetCounts(fSOM, level = "metaclusters")
names(counts) <- seq(1, length(counts))
metaclusterID <<- as.numeric(names(counts)[which.max(counts)])
results <- data.frame()
# Loop over all of the anomalous samples
for (anomalyIndex in seq_along(anomalySamples)){
print(anomalyIndex)
start <- Sys.time()
anomalySample <<- anomalySamples[anomalyIndex]
CS <- CytoScan()
# Add these variables so we can access them in parallel sockets
effectSize <<- NULL
CS$parallel$parallelVars <- c("CS", "channels", "readInput",
"anomalySample", "effectSize", "fSOM",
"metaclusterID")
CS$parallel$parallelPackages <- c(CS$parallel$parallelPackages, "FlowSOM")
CS$preprocessFunction <- subsampleInput
effectSizes <- subsampleFactors
CS <- addTestdata(CS, files[files != anomalySample], read = TRUE)
# Copy the test data to the reference data slot (faster than regeneration)
CS$paths$reference <- CS$paths$test
CS$data$reference <- CS$data$test
# Generate all the features
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
cores = 20)
}
# Add the test sample using an effect size and generate features
for (effectSize in effectSizes){
effectSize <<- effectSize
CS <- addTestdata(CS, files, read = TRUE)
for (featMethod in featMethods){
CS <- generateFeatures(CS, channels = channels, featMethod = featMethod,
aggSlot = "test", cores = 1)
CS <- Flag(CS, flagStrat = "outlier", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "outliers")
output$simulatedSetting <- "subsample"
output$effectSize <- effectSize
output$flagStrat <- "outlier"
results <- rbind(results, output)
CS <- Flag(CS, flagStrat = "novelty", featMethod = featMethod)
output <- getPerformance(CS, files, anomalySample, featMethod, "novelties")
output$simulatedSetting <- "subsample"
output$effectSize <- effectSize
output$flagStrat <- "novelty"
results <- rbind(results, output)
features <- CS$features$test[[featMethod]]
CS$features$test[[featMethod]] <- features[rownames(features) != anomalySample,]
}
CS$data$test[[anomalySample]] <- NULL
CS$paths$test <- files[files != anomalySample]
}
end <- Sys.time()
print(end - start)
}
return(results)
}
```
```{r}
subsampleResults <- simulateSubsample(files, featMethods)
write.csv(subsampleResults, "output/subsample_anomaly.csv")
```
```{r}
result <- subsampleResults %>%
group_by(featMethod, effectSize, simulatedSetting, flagStrat) %>%
summarise(
FPR = sum(FP) / (sum(FP) + sum(TN)),
.groups = "drop" # avoid printing grouping structure message
)
```
```{r sessionInfo, echo=FALSE}
sessionInfo()
```