-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.r
54 lines (35 loc) · 1.24 KB
/
bootstrap.r
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
###
# Bootstrap
###
library(optparse) # parse script arguments in a pythonic way
library(boot)
# configure parser and parse arguments
optionList = list(
make_option(c("--datasets"),
type="character", help="Paths to the dataset files (separated by ;)", metavar="character"))
# parse script arguments
optParser <- OptionParser(option_list=optionList)
opt <- parse_args(optParser)
if (is.null(opt$datasets)){ # print and stop script if dataset file path is missing
print_help(optParser)
stop("Missing dataset files argument")
}
dataset_paths <- strsplit(opt$datasets, ";")
datasetList <- c()
i <- 1
for (path in dataset_paths){
datasetList[[i]] <- read.csv(path, sep=",", header=TRUE)
}
# join datasets
inclusionProbDf <- rbindlist(datasetList)
cat("Calculate median and confidence intervalls...")
# use the bootstrap library to calculate median and confidence intervalls
## Bootstrap of the inclusion probabilities
median_function <-function(x,d){
return(quantile(x[d],probs=c(0.5)))
}
medians<- boot(inclusionProbDf, median_function, R=1000) # find the medians by sampling
medians
confidenceIntervalls<-boot.ci(medians, conf=0.95, R=1000) # calculate the 95% confidence intervalls by sampling
confidenceIntervalls
cat("...Done.")