-
Notifications
You must be signed in to change notification settings - Fork 1
/
movingquantiles.R
49 lines (43 loc) · 1.68 KB
/
movingquantiles.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
# Compute 2D Moving Quantiles ####
# In our approach, we does not take into account the individual dimension
# That's why, we proceed to a 2 dimensional moving quantile computation
# In the first dimension, for each time, we compute the median
# In the second dimension, for each moving time windows, we compute the moving median
# Setting ####
# Necessary for execution : source('./fun_movingquantiles.R')
# Enough data condition
# Size of temporal windows (in days) : windowSize
setwindowSize <- 60
# Minimal number of exam required by window
setminrequired <- 100
# Compute for all exams ####
# Exams list is saved in the object "listecalc"
kk <- ""
for(qq in 1:length(listecalc)){
kk <- listecalc[qq]
print(paste0(kk, " start"))
# Load data
nomfichier <- sub(pattern = ":",replacement = ".",x = kk,perl = F)
basebio <- read.csv2(paste0(rept,nomfichier,".csv"))
basebio <- basebio[which(!is.na(basebio$value)),]
# Scale data
if (sapply(basebio["value"], sd) != 0 )
{
basebio["value"] <- scale(basebio["value"])
}
# Output directory
reptMovingQuant <- paste0(rept2,"MovingQuantiles/",nomfichier,"/")
if(!dir.exists( reptMovingQuant)){
dir.create( reptMovingQuant ,showWarnings = F)
}
# Compute moving median
if(!file.exists(paste0(reptMovingQuant,nomfichier,".Median.csv"))){
calc <- MovingQuantile2D(basebio,optmean = F, prob = 0.5,minrequired = setminrequired,windowSize = setwindowSize)
# Save result in file because this step take time with a huge amount of data
write.csv2(calc,paste0(reptMovingQuant,nomfichier,".Median.csv"), row.names = F)
print("Median OK")
}else{
print("Moving median already computed")
}
print(paste0(kk," OK"))
}