-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 21.4 KB
/
.Rhistory
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
oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/oc.500.csv")
###combine all into one single file
oc.500 <- oc[row.index.oc, ]
##plot spectral outliers using both udev and f-ratio
x <- 1:500
oc.500$pls.reld <- oc.500$pls.udev/oc.500$pls.pred
avg <- oc.500$pls.pred
udev <- oc.500$pls.udev
rd <- round(mean(oc.500$pls.reld),2)
avg.outl <- oc.500$pls.pred[oc.500$pls.reld > 0.557]
udev.outl <- oc.500$pls.udev[oc.500$pls.reld > 0.557]
ind <- which(oc.500$pls.pred %in% avg.outl)
ind
###combine all into one single file
oc.500 <- pls.oc[row.index.oc, ]
str(oc.500)
oc.500$pls.reld <- oc.500$udev/oc.500$pred
avg <- oc.500$pls.pred
udev <- oc.500$pls.udev
rd <- round(mean(oc.500$pls.reld),2)
avg.outl <- oc.500$pls.pred[oc.500$pls.reld > 0.557]
udev.outl <- oc.500$pls.udev[oc.500$pls.reld > 0.557]
ind <- which(oc.500$pls.pred %in% avg.outl)
ind
avg
avg <- oc.500$pred
udev <- oc.500$udev
rd <- round(mean(oc.500$pls.reld),2)
avg.outl <- oc.500$pls.pred[oc.500$pls.reld > 0.557]
udev.outl <- oc.500$pls.udev[oc.500$pls.reld > 0.557]
ind <- which(oc.500$pls.pred %in% avg.outl)
udev
ind
avg.outl <- oc.500$pred[oc.500$pls.reld > 0.557]
udev.outl <- oc.500$udev[oc.500$pls.reld > 0.557]
ind <- which(oc.500$pred %in% avg.outl)
ind
avg.outl
outl.df <- oc.500[oc.500$pls.reld > 0.557,]
head(outl.df)
dim(oc.500)
length(ind)
##plot spectral outliers using both udev and f-ratio
x <- 1:500
oc.500$pls.reld <- oc.500$udev/oc.500$pred
avg <- oc.500$pred
udev <- oc.500$udev
rd <- round(mean(oc.500$pls.reld),2)
avg.outl <- oc.500$pred[oc.500$pls.reld > 0.557]
udev.outl <- oc.500$udev[oc.500$pls.reld > 0.557]
outl.df <- oc.500[oc.500$pls.reld > 0.557,]
ind <- which(oc.500$pred %in% avg.outl)
head(outl.df)
lenth(avg.outl)
length(avg.outl)
dim(oc.500)
outl.df <- oc.500[oc.500$pls.reld > 0.557,]
outl.df
rows(outl.df)
row.names(outl.df)
outl.df$obs
oc.lab.valid.trun[4686]
hea(oc.500)
head(oc.500)
##Get all spc and scores for outliers
ok.flag.scores <- ok.valid.scores[ind,]
plot(pca$x)
points(pca$x[rows,1], pca$x[rows,2], col="blue", pch=16)
points(pca$x[rows.valid,1], pca$x[rows.valid,2], col="red", pch=16)
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows,1], pca$x[rows,2], col="blue", pch=16)
points(pca$x[rows.valid,1], pca$x[rows.valid,2], col="red", pch=16)
rows.calib <- rows[rows <= 34122]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16)
points(pca$x[rows.valid,1], pca$x[rows.valid,2], col="red", pch=16)
ok.valid <- ok[34123:nrow(sample.fratio)]
ok.valid <- ok[34123:length(sample.fratio)]
length(ok.valid)
ok.valid <- ok[34123:nrow(spc)]
ok.valid.fratio <- ok.valid[-rows.na]
str(ok.valid.fratio)
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16) ##calib outliers
points(ok.valid.scores.trun[ok.valid.fratio>0.99,1],ok.valid.scores.trun[ok.valid.fratio>0.99,2], col="green", pch=16)
length(ok.valid.scores.trun[ok.valid.fratio>0.99,1])
tmp.fratio.flag <- ok.valid.scores.trun[ok.valid.fratio>0.99,1]
tmp.fratio.flag
points(ok.valid.scores.trun[ind,1],ok.valid.scores.trun[ind,2], col="red", pch=16) ##udev outliers
ind
str(ok.flag.scores)
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16) ##calib outliers
points(ok.valid.scores.trun[ok.valid.fratio>0.99,1],ok.valid.scores.trun[ok.valid.fratio>0.99,2], col="green", pch=16)
points(ok.flag.scores[,1],ok.flag.scores[,2], col="red", pch=16) ##udev outliers
ok.flag.fratio.scores <- ok.valid.scores[ok.valid.fratio>0.00,]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16) ##calib outliers
points(ok.flag.fratio.scores[,1],ok.flag.fratio.scores[,2], col="green", pch=16)
ok.flag.fratio.scores <- ok.valid.scores[ok.valid.fratio>0.99,]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16) ##calib outliers
points(ok.flag.fratio.scores[,1],ok.flag.fratio.scores[,2], col="green", pch=16)
points(ok.flag.scores[,1],ok.flag.scores[,2], col="red", pch=16) ##udev outliers
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##calib outliers
points(ok.flag.fratio.scores[,1],ok.flag.fratio.scores[,2], col="green", pch=16,xlim = c(-25,30), ylim = c(-15,15))
points(ok.flag.scores[,1],ok.flag.scores[,2], col="red", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
ind
str(ok.valid.scores)
##Get all spc and scores for outliers
ok.flag.scores <- ok.valid.scores[row.index.oc,]
length(row.index.oc)
##Get all spc and scores for outliers
flag.udev.scores <- ok.valid.scores[row.index.oc,]
flag.fratio.scores <- ok.valid.scores[row.index.oc,]
flagged.udev <- flag.udev.scores[ind,]
str(flagged.udev)
flagged.fratio <- flag.fratio.scores[flagged.fratio.scores>0.99,]
str(ok.valid.fratio)
str(ok.valid.fratio)
##index for fratio
fratio.500 <- ok.valid.fratio[row.index.oc]
str(flag.udev.scores)
ind.fratio <- which(fratio.500 > 0.99)
ind.fratio
ind
##Get all spc and scores for outliers
flag.udev.scores <- ok.valid.scores[row.index.oc,]
flag.fratio.scores <- ok.valid.scores[row.index.oc,]
flagged.udev <- flag.udev.scores[ind,]
flagged.fratio <- flag.fratio.scores[ind.fratio,]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##calib outliers
str(fratio.500)
str(flagged.udev)
str(flagged.fratio)
points(flagged.fratio[,1], flagged.fratio[,2],col="green", pch=16,xlim = c(-25,30), ylim = c(-15,15))
points(flagged.udev[,1],flagged.udev[,2], col="red", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
#track row index with fprob higher than 0.99
rows <- which(ok>0.99)
rows.calib <- rows[rows <= 34122]
rows.valid <- rows[rows>34122]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16)
points(pca$x[rows.valid,1], pca$x[rows.valid,2], col="red", pch=16)
######################
## compare with udeviation outlier for validation sets
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
###remove na samples from OC
rows.na <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/nasamplesoc.csv")
rows.na <- rows.na[,2]
pls.oc <- pls.oc[-rows.na,]
ok.valid <- ok[34123:nrow(spc)]
ok.valid.fratio <- ok.valid[-rows.na]
ok.valid.scores <- pca$x[34123:nrow(spc),]
ok.valid.scores.trun <- ok.valid.scores[-rows.na,]
##get 500 samples
set.seed(1000)
#select rows randomly 500
#for OC
row.index.oc <- sample(nrow(sbl.oc), 500)
###combine all into one single file
oc.500 <- pls.oc[row.index.oc, ]
scores.500 <- ok.valid.scores.trun[row.index.oc,]
fratio.500 <- ok.valid.fratio[row.index.oc,]
fratio.500 <- ok.valid.fratio[row.index.oc]
length(fratio.500)
udev.500 <- oc.500$udev
##outliers
fratio.outl.scores <- scores.500[fratio.500>0.99,]
udev.outl.scores <- scores.500[udev.500 > 0.557,]
##plot
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##calib outliers
points(fratio.outl.scores[,1], fratio.outl.scores[,2],col="green", pch=16,xlim = c(-25,30), ylim = c(-15,15))
points(udev.outl.scores[,1],udev.outl.scores[,2], col="red", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
#track row index with fprob higher than 0.99
rows <- which(ok>0.99)
load("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/Fratio/spc.recons.oc.RData")
load("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/full_data_trun6000/sub.calib.oc.RData")
load("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/full_data_trun6000/sub.valid.oc.RData")
spc <- rbind(sub.calib.oc$spc, sub.valid.oc$spc) #calib = 1:34122, valid = 34133:42673
spc.orig.oc <- scale(spc, scale=FALSE)
spc.res <- (spc.recons.oc - spc.orig.oc)^2
spc.res <- sqrt(rowSums(spc.res))
for(i in 1:length(spc.res)){
sample.fratio <- (length(spc.res)-1) * spc.res^2/sum((spc.res[-i])^2)
}
ok <- pf(sample.fratio, 1, length(spc.res))
#track row index with fprob higher than 0.99
rows <- which(ok>0.99)
rows.calib <- rows[rows <= 34122]
rows.valid <- rows[rows>34122]
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca$x[rows.calib,1], pca$x[rows.calib,2], col="blue", pch=16)
load("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/Fratio/pca.oc.RData")
points(pca.oc$x[rows.calib,1], pca.oc$x[rows.calib,2], col="blue", pch=16)
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows.calib,1], pca.oc$x[rows.calib,2], col="blue", pch=16)
points(pca.oc$x[rows.valid,1], pca.oc$x[rows.valid,2], col="red", pch=16)
######################
## compare with udeviation outlier for validation sets
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
###remove na samples from OC
rows.na <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/nasamplesoc.csv")
rows.na <- rows.na[,2]
pls.oc <- pls.oc[-rows.na,]
ok.valid <- ok[34123:nrow(spc)]
ok.valid.fratio <- ok.valid[-rows.na]
ok.valid.scores <- pca$x[34123:nrow(spc),]
ok.valid.scores.trun <- ok.valid.scores[-rows.na,]
##get 500 samples
set.seed(1000)
#select rows randomly 500
#for OC
row.index.oc <- sample(nrow(sbl.oc), 500)
###combine all into one single file
oc.500 <- pls.oc[row.index.oc, ]
scores.500 <- ok.valid.scores.trun[row.index.oc,]
fratio.500 <- ok.valid.fratio[row.index.oc]
###remove na samples from OC
rows.na <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/nasamplesoc.csv")
rows.na <- rows.na[,2]
pls.oc <- pls.oc[-rows.na,]
ok.valid <- ok[34123:nrow(spc)]
ok.valid.fratio <- ok.valid[-rows.na]
ok.valid.scores <- pca$x[34123:nrow(spc),]
ok.valid.scores <- pca.oc$x[34123:nrow(spc),]
ok.valid.scores.trun <- ok.valid.scores[-rows.na,]
##get 500 samples
set.seed(1000)
#select rows randomly 500
#for OC
row.index.oc <- sample(nrow(sbl.oc), 500)
#select rows randomly 500
#for OC
row.index.oc <- sample(nrow(pls.oc), 500)
###combine all into one single file
oc.500 <- pls.oc[row.index.oc, ]
scores.500 <- ok.valid.scores.trun[row.index.oc,]
fratio.500 <- ok.valid.fratio[row.index.oc]
udev.500 <- oc.500$udev
##outliers
fratio.outl.scores <- scores.500[fratio.500>0.99,]
udev.outl.scores <- scores.500[udev.500 > 0.557,]
##plot
plot(pca$x, xlim = c(-25,30), ylim = c(-15,15))
##plot
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows.calib,1], pca.oc$x[rows.calib,2], col="blue", pch=16)##calib
points(pca.oc$x[rows.valid,1], pca.oc$x[rows.valid,2], col="red", pch=16)##valid
points(fratio.outl.scores[,1], fratio.outl.scores[,2],col="green", pch=16) ##valid on 500 samples
points(udev.outl.scores[,1],udev.outl.scores[,2], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
str(fratio.outl.scores)
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
dim(pls.oc)
dim(valid.scores)
valid.scores <- ok[34123:nrow(spc)]
str(valid.scores)
valid.scores <- scores[34123:nrow(spc),]
scores <- pca.oc$x
str(scores)
valid.scores <- scores[34123:nrow(spc),]
str(valid.scores)
pls.oc$reld <- pls.oc$udev / pls.oc$pred
str(pls.oc)
index.udev <- which(pls.oc$reld>0.557)
index.udev
plot(valid.scores)
points(valid.scores[index.udev,], col="blue")
pls.oc$fratio <- ok
str(ok)
pls.oc$fratio <- ok[34123:nrow(spc)]
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(valid.scores, col="blue", pch=16)##calib
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc[rows,], col="blue", pch=16)##calib
points(pca.oc[rows,1],pca.oc[rows,2] col="blue", pch=16)##calib
points(pca.oc[rows,1],pca.oc[rows,2], col="blue", pch=16)##calib
str(pca.oc)
points(pca.oc$x[rows,] col="blue", pch=16)##calib
points(pca.oc$x[rows,], col="blue", pch=16)##calib
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
quantile(pls.oc$reld,0.95)
quantile(pls.oc$reld,0.99)
udev.outl.scores <- scores.500[udev.500 > 1.51,]
index.udev <- which(pls.oc$reld>1.51)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##calib
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
test <- pls.oc[pls.oc$reld > 1.51,]
str(test)
test$reld
quantile(pls.oc$reld, 0.995)
index.udev <- which(pls.oc$reld>3.02)
length(index.udev)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##calib
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
quantile(pls.oc$reld, 0.999)
valid.scores <- scores[34123:nrow(spc),] #for plotting validation sets only
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
pls.oc$reld <- pls.oc$udev / pls.oc$pred
pls.oc$fratio <- ok[34123:nrow(spc)]
index.udev <- which(pls.oc$reld>8.29)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##calib
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
######################
## compare with udeviation outlier for validation sets
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
OutVals = boxplot(pls.oc)$reld
OutVals = boxplot(pls.oc$reld)
OutVals = boxplot(pls.oc$reld)
OutVals = boxplot(pls.oc)$reld
OutVals
?pd
##plot only validation
plot(pca.oc$x[rows,])##valid
rows
##plot only validation
plot(valid.scores)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
##plot only validation
plot(valid.scores)##valid
ok <- pf(pls.oc$reld, 1, nrow(valid.scores))
nrow(valid.scores)
str(pls.oc)
ok <- pf(pls.oc$reld, 1, nrow(valid.scores))
pls.oc$reld <- pls.oc$udev / pls.oc$pred
pls.oc$fratio <- ok[34123:nrow(spc)]
index.udev <- which(pls.oc$reld>8.29)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
ok <- pf(pls.oc$reld, 1, nrow(valid.scores))
str(ok)
quantile(ok,0.95)
temp <- ok[ok>0.544]
length(temp)
plot(valid.scores)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
index.pf <- which(index.fratio>0.544)
points(valid.scores[index.pf,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
str(pls.oc$reld)
sd(pls.oc$reld)
mean(pls.oc$reld)
pls.oc$reld <- pls.oc$udev / pls.oc$pred
pls.oc$fratio <- ok[34123:nrow(spc)]
index.udev <- which(pls.oc$reld>2.676)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
valid.scores <- scores[34123:nrow(spc),] #for plotting validation sets only
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
pls.oc$reld <- pls.oc$udev / pls.oc$pred
pls.oc$fratio <- ok[34123:nrow(spc)]
index.udev <- which(pls.oc$reld>2.676)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
index.fratio
pls.oc$fratio <- ok[34123:nrow(spc)]
head(pls.oc)
str(ok)
ok <- pf(sample.fratio, 1, length(spc.res))
valid.scores <- scores[34123:nrow(spc),] #for plotting validation sets only
pls.oc <- read.csv("C:/Users/sdangal/Documents/ModelChoice_17SEPT2018/newResults/uncertainty/pls.pred.oc.csv")
pls.oc$reld <- pls.oc$udev / pls.oc$pred
pls.oc$fratio <- ok[34123:nrow(spc)]
index.udev <- which(pls.oc$reld>2.676)
index.fratio <- which(pls.oc$fratio>0.99)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
quantile(pls.oc$reld, 0.99)
quantile(pls.oc$reld, 0.999)
quantile(pls.oc$reld, 0.995)
index.udev <- which(pls.oc$reld>3.02)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
##plot only validation
plot(valid.scores)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
index.udev
which(max(pls.oc$reld))
which(pls.oc$reld == max(pls.oc$reld))
pls.oc$reld[index.udev]
pls.oc$fratio[index.udev]
index.fratio <- which(pls.oc$fratio>0.95)
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
#plot(valid.scores)
#points(valid.scores[index.udev,], col="blue")
plot(pca.oc$x, xlim = c(-25,30), ylim = c(-15,15))
points(pca.oc$x[rows,], col="blue", pch=16)##valid
points(valid.scores[index.fratio,],col="green", pch=16) ##valid on 500 samples
points(valid.scores[index.udev,], col="yellow", pch=16,xlim = c(-25,30), ylim = c(-15,15)) ##udev outliers
library(raster)
area.km2 <- raster("Y:/sdangal/DayCent/cropped_mask/mask/area_km2.tif")
files <- list.files("/mnt/WHRC/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
year <- 1978
files <- list.files("/mnt/WHRC/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
files
files <- list.files("Y:/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
files
?substr
tmp <- strsplit(files, "/")[[1]][8]
tmp
tmp <- strsplit(files, "/")[[1]][6]
tmp
tmp <- substr(tmp, 1,11)
tmp
tmp <- strsplit(files, "/")[[2]][6]
tmp
for(year in 1978:1982){
files <- list.files("Y:/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
for(i in 1:length(files)){
ok <- strsplit(files, "/")[[i]][6]
ok <- substr(tmp, 1,11)
tmp <- raster(files[i]) * area.km2
tmp1 <- cellStats(tmp, sum) / cellStats(area.km2, sum)
cat(ok, tmp1, "\n")
}
}
tmp <- strsplit(files, "/")[[i]][6]
tmp
length(files)
ok <- strsplit(files, "/")[6]
ok
ok <- strsplit(files, "/")[[6]]
ok
files
ok <- strsplit(files[1], "/")[[6]]
ok <- strsplit(files[1], "/")[[1]][6]
ok
ok <- strsplit(files[1], "/")[[2]][6]
ok <- strsplit(files[2], "/")[[1]][6]
ok
for(year in 1978:1982){
files <- list.files("Y:/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
for(i in 1:length(files)){
ok <- strsplit(files[i], "/")[[1]][6]
ok <- substr(tmp, 1,11)
tmp <- raster(files[i]) * area.km2
tmp1 <- cellStats(tmp, sum) / cellStats(area.km2, sum)
cat(ok, tmp1, "\n")
}
}
for(year in 1978:1982){
files <- list.files("Y:/sdangal/DayCent/test_clm/prcp", pattern = paste0(year), full.names=TRUE)
for(i in 1:length(files)){
ok <- strsplit(files[i], "/")[[1]][6]
ok <- substr(ok, 1,11)
tmp <- raster(files[i]) * area.km2
tmp1 <- cellStats(tmp, sum) / cellStats(area.km2, sum)
cat(ok, tmp1, "\n")
}
}