-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_analysis.Rmd
1453 lines (1234 loc) · 101 KB
/
Data_analysis.Rmd
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Data analysis"
output: html_document
date: "`r Sys.Date()`"
---
```{r setup, include=FALSE}
renv::restore()
library(tidyverse)
library(mgcv)
library(lubridate)
library(timetk)
library(RcppRoll)
library(dLagM)
library(dlnm)
library(zoo)
theme_set(theme_gray())
library(knitr)
library(kableExtra)
library(sf)
library(tmap)
library(gridExtra)
library(lubridate)
library(timetk)
library(RcppRoll)
library(dLagM)
library(dlnm)
library(zoo)
theme_set(theme_gray())
library(js)
library(sjPlot)
library(verification)
library(ROCR)
library(pROC)
# Read data
source("data_read.R")
```
# Geo Mapping
```{r Spatial analysis}
theme_map <- theme_bw()+
theme(panel.grid.major = element_line(colour = "transparent"))
plot(st_geometry(hydro_bavaria))
ggplot()+
geom_sf(data = hydro_bavaria)
# Plot with catchment points
ggplot()+
geom_sf(data = hydro_bavaria, fill = "transparent") +
geom_sf(data = pegel_prop_sf, aes(color = as.factor(unique(ID))), size = 3)+
labs(color = "Catchment ID")+
scale_color_viridis_d()+
theme_map
ggsave("./graphics/Max/Catchments_hydro_bavaria_dots.png", width = 12, height = 9)
# Plot hydrobavaria and admin bavaria
ggplot()+
geom_sf(data = hydro_bavaria, fill = "white")+
geom_sf(data = admin_bavaria, fill = "transparent", color = "red")+
geom_sf(data = pegel_prop_sf, aes(color = as.factor(unique(ID))), size = 3)+
labs(color = "Catchment ID")+
scale_color_viridis_d()+
theme_map
ggsave("./graphics/Max/hydro_admin_bavaria.png", width = 12, height = 9)
# Catchments with rivers and Donau/Main for orientation
waterways_three %>%
ggplot()+
geom_sf(data = hydro_bavaria, fill = "transparent")+
geom_sf(data = waterways_three, color = "blue", size = 1.5)+
geom_sf(data = pegel_prop_sf, aes(color = as.factor(unique(ID))), size = 3)+
labs(color = "Catchment ID")+
scale_color_viridis_d()+
theme_map
ggsave("./graphics/Max/map_rivers_catchments.png", width = 12, height = 9)
```
### tmap geographical overview
```{r}
tmap_mode("view")
tm_shape(hydro_bavaria)+
tm_polygons(id = "NameString")+
tm_shape(waterways_three)+
tm_lines(col = "blue")+
tm_shape(pegel_prop_sf)+
tm_markers(size = 0.3)
```
# Low flow analysis ----
```{r Analysis of low flow events}
# First visualizations
plot_drainage <- function(dataset, year = c(2000), member_input = "kbe") {
# Abflussmenge für unterschiedliche Pegel über die Zeit
dataset %>% filter(YY %in% year, member == member_input) %>%
ggplot(mapping = aes(x = date, y = drainage, color = waterlevel)) +
geom_line() +
scale_y_continuous(trans='log10') +
geom_point(data = dataset %>% filter(YY %in% year, member == member_input, lowlevel == TRUE),
aes(x = date, y = drainage), color = "purple") +
labs(title = "Abflussmenge für unterschiedliche Pegel über die Zeit",
y = "Abflussmenge (in m³/s, Log-Skala)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2")
}
plot_drainage_unmarked <- function(dataset, year = c(2000), member_input = "kbe") {
# Abflussmenge für unterschiedliche Pegel über die Zeit
dataset %>% filter(YY %in% year, member == member_input) %>%
ggplot(mapping = aes(x = date, y = drainage, color = waterlevel)) +
geom_line() +
scale_y_continuous(trans='log10') +
labs(title = "Abflussmenge für unterschiedliche Pegel über die Zeit",
y = "Abflussmenge (in m³/s, Log-Skala)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2")
}
plot_single_drainage <- function(dataset, year = c(2000), member_input = "kbe") {
# Abflussmenge für einen Pegel über die Zeit
dataset %>% filter(YY %in% year, member == member_input) %>%
ggplot(mapping = aes(x = date, y = drainage)) +
geom_line() +
scale_y_continuous(trans='log10') +
geom_line(mapping = aes(y = nm7q), color = "red") +
geom_point(data = dataset %>% filter(YY %in% year, member == member_input, lowlevel == TRUE),
aes(x = date, y = drainage), color = "purple") +
labs(title = "Abflussmenge für einen Pegel über die Zeit",
y = "Abflussmenge (in m³/s, Log-Skala)",
x = "Datum") +
theme(text = element_text(size = 20)) +
scale_color_brewer(palette = "Dark2")
}
plot_single_drainage(hydro_total %>% filter(name_waterlevel == "10304"), year = 2000:2003)
# -> Daten sind saisonal
ggsave("Plots/Chris/analysis/single_drainage_Isar-Mittenwald_2000-2003.png", width = 12, height = 9)
plot_drainage(hydro_total, year = 2000)
ggsave("Plots/Chris/analysis/drainage_total_2000_kbe.png", width = 12, height = 9)
plot_drainage_unmarked(hydro_total, year = 2000)
ggsave("Plots/Chris/analysis/drainage_total_unmarked_2000_kbe.png", width = 12, height = 9)
# Visualisierung der 10 Member für 10304, Jahr 2000
hydro_total_10304 <- hydro_total %>% filter(name_waterlevel == "10304")
ggplot(data = subset(hydro_total_10304, YY %in% 2000), mapping = aes(x = date, y = drainage, color = member, alpha = 0.01)) +
geom_line() +
labs(title = "Abfluss des Pegels Isar Mittenwald im Jahr 2000 getrennt \nnach Simulationsreihen",
y = "Abflussmenge (in m³/s, Log-Skala)",
x = "Datum") +
scale_y_continuous(trans='log10')+
theme(text = element_text(size = 20)) +
scale_color_brewer(palette = "Paired")
ggsave("Plots/Chris/analysis/all_member_drainage_Isar-Mittenwald_2000.png", width = 12, height = 9)
# Tables for futher plots
table_days_low_flow <- hydro_total %>%
group_by(waterlevel, YY) %>%
count(lowlevel, name = "number_low_flows") %>%
filter(lowlevel == TRUE) %>%
mutate(avg_number_low_flows = number_low_flows / length(unique(hydro_total$member)))
table_days_low_flow_by_hydro_year <- hydro_total %>%
group_by(hydro_year, waterlevel, YY) %>%
count(lowlevel, name = "number_low_flows") %>%
filter(lowlevel == TRUE) %>%
mutate(avg_number_low_flows = number_low_flows / length(unique(hydro_total$member)))
# Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen für die 3 Wasserstände
ggplot(data = table_days_low_flow, mapping = aes(x = YY, y = avg_number_low_flows, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen \nim Zeitverlauf (aller Member)",
y = "Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2")
ggsave("Plots/Chris/analysis/yearly_avg_number_of_low_flow_days.png", width = 12, height = 9)
# Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen für die 3 Wasserstände je Jahreszeit
ggplot(data = table_days_low_flow_by_hydro_year, mapping = aes(x = YY, y = avg_number_low_flows, color = waterlevel)) +
geom_line() +
geom_point() +
labs(
title = "Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen je Jahreszeit \nim Zeitverlauf (aller Member)",
y = "Jährliche durchschnittliche Anzahl von Niedrigwasser-Tagen",
x = "Datum") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter"))) +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2")
ggsave("Plots/Chris/analysis/yearly_avg_number_of_low_flow_days_per_season.png", width = 12, height = 9)
```
# Analysis of drivers ----
```{r Analysis of drivers}
# Read tables
table_yearly_avg_min_groundwaterdepth <-
readRDS("data/tables/driver_analysis/table_yearly_avg_min_groundwaterdepth.RDS")
table_yearly_avg_min_soilwater <- readRDS("data/tables/driver_analysis/table_yearly_avg_min_soilwater.RDS")
table_yearly_avg_min_snowstorage <- readRDS("data/tables/driver_analysis/table_yearly_avg_min_snowstorage.RDS")
table_yearly_avg_min_airtmp <- readRDS("data/tables/driver_analysis/table_yearly_avg_min_airtmp.RDS")
table_yearly_avg_max_precip <- readRDS("data/tables/driver_analysis/table_yearly_avg_max_precip.RDS")
table_yearly_avg_max_glorad <- readRDS("data/tables/driver_analysis/table_yearly_avg_max_glorad.RDS")
table_yearly_avg_max_relhum <- readRDS("data/tables/driver_analysis/table_yearly_avg_max_relhum.RDS")
table_yearly_avg_max_infiltration <- readRDS("data/tables/driver_analysis/table_yearly_avg_max_infiltration.RDS")
# Tables for futher plots
table_yearly_max_prec_by_member <- hydro_total %>%
group_by(waterlevel, YY, hydro_year, member) %>%
summarise(max_precip = max(precip))
table_yearly_avg_max_prec <- hydro_total %>%
group_by(waterlevel, YY, hydro_year, member) %>%
summarise(max_precip = max(precip)) %>%
group_by(waterlevel, YY, hydro_year) %>%
summarise(avg_max_precip = mean(max_precip))
table_yearly_avg_max_airtmp <- hydro_total %>%
group_by(waterlevel, YY, hydro_year, member) %>%
summarise(max_airtmp = max(airtmp)) %>%
group_by(waterlevel, YY, hydro_year) %>%
summarise(avg_max_airtemp = mean(max_airtmp))
table_yearly_avg_max_snowstorage <- hydro_total %>%
group_by(waterlevel, YY, hydro_year, member) %>%
summarise(max_snowstorage = max(snowstorage)) %>%
group_by(waterlevel, YY, hydro_year) %>%
summarise(avg_max_snowstorage = mean(max_snowstorage))
table_yearly_avg_max_soilwater <- hydro_total %>%
group_by(waterlevel, YY, hydro_year, member) %>%
summarise(max_soilwater = max(soilwater)) %>%
group_by(waterlevel, YY, hydro_year) %>%
summarise(avg_max_soilwater = mean(max_soilwater))
# Model drivers: avg and groundwaterdepth
# Plots
ggplot(data = table_yearly_avg_max_prec, mapping = aes(x = YY, y = avg_max_precip, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglichem Niederschlag \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglichem Niederschlag \n(in mm/24h)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/yearly_avg_max_prec.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_airtmp, mapping = aes(x = YY, y = avg_max_airtemp, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglicher Lufttemperatur \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglicher Lufttemperatur \n(in °C)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/yearly_avg_max_airtemp.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_snowstorage, mapping = aes(x = YY, y = avg_max_snowstorage, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglichem Schneespeicher \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglichem Schneespeicher \n(in mm)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/yearly_avg_max_snowstorage.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_soilwater, mapping = aes(x = YY, y = avg_max_soilwater, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglicher Oberflächennahe \nrelative Bodenfeuchte je Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglicher \noberflächennaher relative Bodenfeuchte (in %)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/yearly_avg_max_soilwater.png", width = 12, height = 9)
# Plots for model drivers
ggplot(data = table_yearly_avg_min_groundwaterdepth, mapping = aes(x = YY, y = avg_min_groundwaterdepth, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Minimum des Grundwasserstandes \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Minimum des täglichem \nGrundwasserstandes (in m unter Oberfläche)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_min_groundwaterdepth.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_min_soilwater, mapping = aes(x = YY, y = avg_min_soilwater, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Minimum der täglichen oberflächennahen \nrelativen Bodenfeuchte je Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Minimum der täglichen oberflächennahen \nrelativen Bodenfeuchte (in %)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_min_soilwater.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_min_snowstorage, mapping = aes(x = YY, y = avg_min_snowstorage, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Minimum an täglichem Schneespeicher \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Minimum an täglichem Schneespeicher \n(in mm)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_min_snowstorage.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_min_airtmp, mapping = aes(x = YY, y = avg_min_airtmp, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Minimum an täglicher Lufttemperatur \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Minimum an täglicher Lufttemperatur \n(in °C)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_min_airtmp.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_precip, mapping = aes(x = YY, y = avg_max_precip, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglichem Niederschlag \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglichem Niederschlag \n(in mm/24h)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_max_precip.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_glorad, mapping = aes(x = YY, y = avg_max_glorad, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglich einfallender \nkurzwelligen Strahlung je Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglich einfallender \nkurzwelligen Strahlung (in Wh/m²)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_max_glorad.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_relhum, mapping = aes(x = YY, y = avg_max_relhum, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglicher relativer \nLuftfeuchtigkeit je Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglicher relativer \nLuftfeuchtigkeit (in %)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_max_relhum.png", width = 12, height = 9)
ggplot(data = table_yearly_avg_max_infiltration, mapping = aes(x = YY, y = avg_max_infiltration, color = waterlevel)) +
geom_line() +
geom_point() +
labs(title = "Jährliches durchschnittliches Maximum an täglicher Versickerung \nje Jahreszeit im Zeitverlauf (aller Member)",
y = "Jährliches durchschnittliches Maximum an täglicher Versickerung \n(in mm/24h)",
x = "Datum") +
guides(color=guide_legend(title="Pegel")) +
theme(text = element_text(size = 20),
legend.position="bottom") +
scale_color_brewer(palette = "Dark2") +
facet_wrap(vars(hydro_year), labeller = as_labeller(c(`summer` = "Sommer", `winter` = "Winter")))
ggsave("Plots/Chris/analysis/driver_plots/yearly_avg_max_infiltration.png", width = 12, height = 9)
```
## Chris: Extreme value analysis
```{r Chris: Global extreme value analysis}
### Quantile: -------------------------------------------------------------
# Define the quantiles for which you want to calculate the percentage of the target variable
quantiles <- c(0.05, 0.1, 0.25, 0.75, 0.9, 0.95)
# Create an empty matrix to store the percentage values
quantile_percents <- matrix(nrow=length(quantiles), ncol=ncol(hydro_total[, 15:22]))
# Loop over each predictor variable and calculate the percentage of the target variable for each quantile
for (i in 15:22) {
# Get the quantile values for the current predictor variable
quantile_values <- quantile(hydro_total[, i], probs=quantiles)
for (j in 1:length(quantiles)) {
# Calculate the percentage of the target variable for the current quantile and predictor variable
quantile_percents[j, i - 14] <-
sum((hydro_total[hydro_total[, i] >= quantile_values[j], "lowlevel"]) == "TRUE")/sum(
hydro_total[, "lowlevel"] == "TRUE")
}
}
# Print the results
colnames(quantile_percents) <- colnames(hydro_total)[15:22]
rownames(quantile_percents) <- paste0(quantiles*100, "%")
quantile_percents <- round(quantile_percents, digits = 3)
quantile_percents
# Save the table as a PDF file
pdf("tables/quantile_percents.pdf", height=4, width=10)
grid.table(quantile_percents)
dev.off()
### Ranges: ---------------------------------------------------------------
# Define the quantiles for which you want to calculate the percentage of the target variable
quantiles_ranges <- seq(0, 1, by=0.1)
# Create an empty matrix to store the percentage values
quantile_percents_ranges <- matrix(nrow=length(quantiles_ranges)-1, ncol=ncol(hydro_total[, 15:22]))
# Loop over each predictor variable and calculate the percentage of the target variable for each range
for (i in 15:22) {
# Get the quantile values for the current predictor variable
quantile_values <- quantile(hydro_total[, i], probs=quantiles_ranges)
for (j in 1:(length(quantiles_ranges)-1)) {
# Calculate the percentage of the target variable for the current range and predictor variable
quantile_percents_ranges[j, i - 14] <-
sum((hydro_total[hydro_total[, i] >= quantile_values[j] & hydro_total[, i] < quantile_values[j+1], "lowlevel"]) == "TRUE")/sum((hydro_total[, "lowlevel"]) == "TRUE")
}
}
# Print the results
colnames(quantile_percents_ranges) <- colnames(hydro_total)[15:22]
rownames(quantile_percents_ranges) <-
paste0(quantiles_ranges[-length(quantiles_ranges)]*100, "% - ", quantiles_ranges[-1]*100, "%")
quantile_percents_ranges <- round(quantile_percents_ranges, digits = 3)
quantile_percents_ranges
# Save the table as a PDF file
pdf("tables/quantile_percents_ranges.pdf", height=4, width=10)
grid.table(quantile_percents_ranges)
dev.off()
```
```{r Chris local extreme value analysis}
pegel_list <- list(hydro_summer_20203, hydro_summer_11502, hydro_summer_10304,
hydro_winter_20203, hydro_winter_11502, hydro_winter_10304)
pegel_names <- c("hydro_summer_20203", "hydro_summer_11502", "hydro_summer_10304",
"hydro_winter_20203", "hydro_winter_11502", "hydro_winter_10304")
counter_names <- 1
# Define the quantiles for which you want to calculate the percentage of the target variable
quantiles_ranges <- seq(0, 1, by=0.1)
colum_names <- c("avg_precip", "avg_airtmp", "avg_glorad", "avg_relhum", "avg_soilwater", "avg_snowstorage",
"groundwaterdepth", "avg_infiltration", "max_precip")#, "avg_snowstorage_drain")
colum_names_long <- c("Mittlerer\nNiederschlag", "Mittlere\nLufttemperatur",
"Mittlere\neinfallende\nkurzwellige Strahlung", "Mittlere\nrelative\nLuftfeuchte",
"Mittlere\noberflächennahe\nrelative\nBodenfeuchte", "Mittlerer\nSchneespeicher",
"Grundwasserstand", "Mittlere\nVersickerung", "Maximaler\nNiederschlag")
for (pegel in pegel_list) {
i = 1
# Create an empty matrix to store the percentage values
quantile_percents_ranges <- matrix(nrow=length(quantiles_ranges)-1, ncol=length(colum_names))
# Loop over each predictor variable and calculate the percentage of the target variable for each range
for (col_name in colum_names) {
# Get the quantile values for the current predictor variable
quantile_values <- quantile(pegel[, col_name], probs=quantiles_ranges, na.rm = TRUE)
for (j in 1:(length(quantiles_ranges)-1)) {
# Calculate the percentage of the target variable for the current range and predictor variable
quantile_percents_ranges[j, i] <-
sum((pegel[pegel[, col_name] >= quantile_values[j] & pegel[, col_name] < quantile_values[j+1],
"lowlevel"]) == "TRUE", na.rm = TRUE)/sum((pegel[, "lowlevel"]) == "TRUE", na.rm = TRUE)
}
i = i + 1
}
# Print the results
colnames(quantile_percents_ranges) <- colum_names_long
rownames(quantile_percents_ranges) <- paste0(
quantiles_ranges[-length(quantiles_ranges)]*100, "% - ", quantiles_ranges[-1]*100, "%")
quantile_percents_ranges <- round(quantile_percents_ranges, digits = 3)
# Save as table
saveRDS(object = quantile_percents_ranges,
file = paste0("data/tables/extreme_values/quantile_percents_ranges_", pegel_names[counter_names], ".RDS"))
# Save the table as a PDF file
pdf(paste0("tables/extreme_values/quantile_percents_ranges_", pegel_names[counter_names], ".pdf"), height=4, width=16)
grid.table(quantile_percents_ranges)
dev.off()
counter_names = counter_names + 1
}
```
```{r Extreme value analysis subset}
pegel <- hydro_summer_11502
pegel_names <- "hydro_summer_11502_subset"
counter_names <- 1
# Define the quantiles for which you want to calculate the percentage of the target variable
quantiles_ranges <- seq(0, 1, by=0.1)
colum_names <- c("avg_airtmp", "avg_soilwater")
colum_names_long <- c("Mittlere\nLufttemperatur", "Mittlere\noberflächennahe\nrelative\nBodenfeuchte")
i = 1
# Create an empty matrix to store the percentage values
quantile_percents_ranges <- matrix(nrow=length(quantiles_ranges)-1, ncol=length(colum_names))
# Loop over each predictor variable and calculate the percentage of the target variable for each range
for (col_name in colum_names) {
# Get the quantile values for the current predictor variable
quantile_values <- quantile(pegel[, col_name], probs=quantiles_ranges, na.rm = TRUE)
for (j in 1:(length(quantiles_ranges)-1)) {
# Calculate the percentage of the target variable for the current range and predictor variable
quantile_percents_ranges[j, i] <-
sum((pegel[pegel[, col_name] >= quantile_values[j] & pegel[, col_name] < quantile_values[j+1],
"lowlevel"]) == "TRUE", na.rm = TRUE)/sum((pegel[, "lowlevel"]) == "TRUE", na.rm = TRUE)
}
i = i + 1
}
# Print the results
colnames(quantile_percents_ranges) <- colum_names_long
rownames(quantile_percents_ranges) <- paste0(
quantiles_ranges[-length(quantiles_ranges)]*100, "% - ", quantiles_ranges[-1]*100, "%")
quantile_percents_ranges <- round(quantile_percents_ranges, digits = 3)
# Save as table
saveRDS(object = quantile_percents_ranges,
file = paste0("data/tables/extreme_values/quantile_percents_ranges_", pegel_names[counter_names], ".RDS"))
# Save the table as a PDF file
pdf(paste0("tables/extreme_values/quantile_percents_ranges_", pegel_names[counter_names], ".pdf"), height=4, width=16)
grid.table(quantile_percents_ranges)
dev.off()
counter_names = counter_names + 1
```
## Stationary analysis
```{r}
library(tseries)
stationary_drainage_mean_p <- function(waterlevel, season) {
name <- paste0("stationar_", season, "_", waterlevel, "_")
member_names <- levels(hydro_total$member)
for (i in 1:length(member_names)) {
assign(paste0(name, i),
kpss.test(get(paste0("hydro_", season, "_", waterlevel, "_", member_names[i]))$drainage)$p.value)
}
mean(get(paste0(name, "1")), get(paste0(name, "2")), get(paste0(name, "3")), get(paste0(name, "4")),
get(paste0(name, "5")), get(paste0(name, "6")), get(paste0(name, "7")), get(paste0(name, "8")),
get(paste0(name, "9")), get(paste0(name, "10")))
}
stationary_drainage_mean_p("10304", "winter")
stationary_drainage_mean_p("10304", "summer")
stationary_drainage_mean_p("11502", "winter")
stationary_drainage_mean_p("11502", "summer")
stationary_drainage_mean_p("20203", "winter")
stationary_drainage_mean_p("20203", "summer")
# nur die Zeitreihe von drainage für 20203/winter ist zum Signifikanzniveau 0.05 signifikant nicht-stationär;
# bei allen anderen Zeitreihen von drainage kann die Annahme der Stationarität nicht abgelehnt werden
stationary_lowlevel_mean_p <- function(waterlevel, season) {
name <- paste0("stationar_", season, "_", waterlevel, "_")
member_names <- levels(hydro_total$member)
for (i in 1:length(member_names)) {
assign(paste0(name, i),
kpss.test(get(paste0("hydro_", season, "_", waterlevel, "_", member_names[i]))$lowlevel)$p.value)
}
mean(get(paste0(name, "1")), get(paste0(name, "2")), get(paste0(name, "3")), get(paste0(name, "4")),
get(paste0(name, "5")), get(paste0(name, "6")), get(paste0(name, "7")), get(paste0(name, "8")),
get(paste0(name, "9")), get(paste0(name, "10")))
}
stationary_lowlevel_mean_p("10304", "winter")
stationary_lowlevel_mean_p("10304", "summer")
stationary_lowlevel_mean_p("11502", "winter")
stationary_lowlevel_mean_p("11502", "summer")
stationary_lowlevel_mean_p("20203", "winter")
stationary_lowlevel_mean_p("20203", "summer")
# die Zeitreihen von lowlevel für 10304/winter, 20203/winter, 20203/summer sind zum Signifikanzniveau 0.05 signifikant nicht-stationär:
# für die Zeitreihen von lowlevel für 10304/summer, 11502/winter, 11502/summer kann die Annahme der Stationarität nicht abgelehnt werden
```
# Several member visualization
```{r}
hydro_summer_10304 %>%
filter(YY %in% seq(1990, 2020, 5)) %>%
ggplot(aes(x = date, y = avg_airtmp,col = member)) +
geom_line(alpha = 0.2)+
facet_wrap(~ YY, scales = "free_x")
```
```{r}
plot_ts_facet <- function(variable, data, period = 5, ...) {
data %>%
filter(YY %in% seq(1990, 2020, period)) %>%
ggplot(aes_string(x = "date", y = variable, col = "member")) +
geom_path(alpha = 0.2)+
facet_wrap(~ YY, scales = "free_x")+
labs(...)
}
```
# Summer
```{r}
plot_ts_facet("avg_airtmp", hydro_summer_10304, period = 5, title = 10304)
plot_ts_facet("avg_airtmp", hydro_summer_11502, period = 5, title = 11502)
plot_ts_facet("avg_airtmp", hydro_summer_20203, period = 5, title = 20203)
plot_ts_facet("avg_relhum", hydro_summer_10304, period = 5, title = 10304)
plot_ts_facet("avg_relhum", hydro_summer_11502, period = 5, title = 11502)
plot_ts_facet("avg_relhum", hydro_summer_20203, period = 5, title = 20203)
plot_ts_facet("avg_glorad", hydro_summer_10304, period = 5, title = 10304)
plot_ts_facet("avg_glorad", hydro_summer_11502, period = 5, title = 11502)
plot_ts_facet("avg_glorad", hydro_summer_20203, period = 5, title = 20203)
```
### Auto corr
```{r}
library(car)
## drainage
# autocorrelation function, mean acf for drainage (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_drainage_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_drainage_", k, "_", i, "_", j), as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$drainage, plot = FALSE)$acf))
assign(paste0("df_acf_drainage_", k, "_", i), bind_cols(get(paste0("df_acf_drainage_", k, "_", i)), get(paste0("acf_drainage_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_drainage_", k, "_", i), rowMeans(get(paste0("df_acf_drainage_", k, "_", i))[, 2:11]))
}
}
# -> Drainage ist in allen Teildatensätzen positiv autokorreliert -> Modell, das diese Autokorrelation berücksichtigt, nötig
# ACF-Plots for drainage (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_drainage_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_drainage_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_drainage_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_drainage_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_drainage_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_drainage_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Abflusses für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# Partial autocorrelation function, mean pacf for drainage (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_drainage_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_drainage_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$drainage, plot = FALSE)$acf))
assign(paste0("df_pacf_drainage_", k, "_", i),
bind_cols(get(paste0("df_pacf_drainage_", k, "_", i)), get(paste0("pacf_drainage_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_drainage_", k, "_", i), rowMeans(get(paste0("df_pacf_drainage_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 2 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 3 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 3 (nicht durchgängig), bis lag = 1 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# PACF-Plots for drainage (across all members) separated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_drainage_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_drainage_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_drainage_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_drainage_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_drainage_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_drainage_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Abflusses für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
## lowlevel
# autocorrelation function, mean acf for lowlevel (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_lowlevel_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_lowlevel_", k, "_", i, "_", j), as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$lowlevel, plot = FALSE)$acf))
assign(paste0("df_acf_lowlevel_", k, "_", i), bind_cols(get(paste0("df_acf_lowlevel_", k, "_", i)), get(paste0("acf_lowlevel_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_lowlevel_", k, "_", i), rowMeans(get(paste0("df_acf_lowlevel_", k, "_", i))[, 2:11]))
}
}
# -> Lowlevel ist in allen Teildatensätzen positiv autokorreliert -> Modell, das diese Autokorrelation berücksichtigt, nötig
# ACF-Plots for lowlevel (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_lowlevel_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_lowlevel_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_lowlevel_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_lowlevel_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_lowlevel_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_lowlevel_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. von Niedrigwasserevents für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# Partial autocorrelation function, mean pacf for lowlevel (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_lowlevel_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_lowlevel_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$lowlevel, plot = FALSE)$acf))
assign(paste0("df_pacf_lowlevel_", k, "_", i),
bind_cols(get(paste0("df_pacf_lowlevel_", k, "_", i)), get(paste0("pacf_lowlevel_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_lowlevel_", k, "_", i), rowMeans(get(paste0("df_pacf_lowlevel_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 4 (nicht durchgängig), bis lag = 1 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 4 (nicht durchgängig), bis lag = 1 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 1 (durchgängig) signifikant
# PACF-Plots for lowlevel (across all members) seperated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_lowlevel_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. v. Niedrigwasserevents für Isar Mittenw., Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_lowlevel_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. von Niedrigwasserevents für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_lowlevel_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. von Niedrigwasserevents für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_lowlevel_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. von Niedrigwasserevents für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_lowlevel_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. von Niedrigwasserevents für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_lowlevel_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. von Niedrigwasserevents für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# DurbinWatsonTest für GAM auf Datensatz hydro_winter_10304_kbe
durbinWatsonTest(gam_1)
# p < 0.05, Wert der Teststatistik: 0.3839 -> Es scheint positive Autokorrelation vorzuliegen
### Driver
## Precip
# autocorrelation function, mean acf for precip (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_precip_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_precip_", k, "_", i, "_", j),
as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$precip, plot = FALSE)$acf))
assign(paste0("df_acf_precip_", k, "_", i),
bind_cols(get(paste0("df_acf_precip_", k, "_", i)), get(paste0("acf_precip_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_precip_", k, "_", i), rowMeans(get(paste0("df_acf_precip_", k, "_", i))[, 2:11]))
}
}
# -> Precip ist in allen Teildatensätzen leicht positiv autokorreliert -> Modell, das diese Autokorrelation berücksichtigt, wäre von Vorteil
# ACF-Plots for precip (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_precip_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_precip_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_precip_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_precip_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_precip_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_precip_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. des Niederschlags für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# partial autocorrelation function, mean pacf for precip (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_precip_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_precip_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$precip, plot = FALSE)$acf))
assign(paste0("df_pacf_precip_", k, "_", i),
bind_cols(get(paste0("df_pacf_precip_", k, "_", i)), get(paste0("pacf_precip_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_precip_", k, "_", i), rowMeans(get(paste0("df_pacf_precip_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 2 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 1 (durchgängig) signifikant
# PACF-Plots for precip (across all members) seperated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_precip_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_precip_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_precip_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_precip_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_precip_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_precip_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. des Niederschlags für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
## Airtmp
# autocorrelation function, mean acf for airtmp (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_airtmp_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_airtmp_", k, "_", i, "_", j),
as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$airtmp, plot = FALSE)$acf))
assign(paste0("df_acf_airtmp_", k, "_", i),
bind_cols(get(paste0("df_acf_airtmp_", k, "_", i)), get(paste0("acf_airtmp_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_airtmp_", k, "_", i), rowMeans(get(paste0("df_acf_airtmp_", k, "_", i))[, 2:11]))
}
}
# -> Airtmp ist in allen Teildatensätzen positiv autokorreliert -> Modell, das diese Autokorrelation berücksichtigt, nötig
# ACF-Plots for airtmp (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_airtmp_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_airtmp_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_airtmp_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_airtmp_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_airtmp_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_airtmp_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Autokor. zw. Beob. der Temperatur für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# partial autocorrelation function, mean pacf for airtmp (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_airtmp_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_airtmp_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$airtmp, plot = FALSE)$acf))
assign(paste0("df_pacf_airtmp_", k, "_", i),
bind_cols(get(paste0("df_pacf_airtmp_", k, "_", i)), get(paste0("pacf_airtmp_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_airtmp_", k, "_", i), rowMeans(get(paste0("df_pacf_airtmp_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 7 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 5 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 7 (nicht durchgängig), bis lag = 3 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 5 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 6 (durchgängig) signifikant
# PACF-Plots for airtmp (across all members) seperated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_airtmp_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_airtmp_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_airtmp_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_airtmp_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_airtmp_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_airtmp_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der Temperatur für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
## Glorad
# autocorrelation function, mean acf for glorad (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_glorad_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_glorad_", k, "_", i, "_", j),
as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$glorad, plot = FALSE)$acf))
assign(paste0("df_acf_glorad_", k, "_", i),
bind_cols(get(paste0("df_acf_glorad_", k, "_", i)), get(paste0("acf_glorad_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_glorad_", k, "_", i), rowMeans(get(paste0("df_acf_glorad_", k, "_", i))[, 2:11]))
}
}
# -> Glorad ist in allen Teildatensätzen positiv autokorreliert -> Modell, das diese Autokorrelation berücksichtigt, nötig
# ACF-Plots for glorad (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_glorad_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_glorad_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_glorad_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_glorad_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_glorad_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_glorad_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der einfall. kurzw. Strahlung für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# partial autocorrelation function, mean pacf for glorad (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_glorad_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_glorad_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$glorad, plot = FALSE)$acf))
assign(paste0("df_pacf_glorad_", k, "_", i),
bind_cols(get(paste0("df_pacf_glorad_", k, "_", i)), get(paste0("pacf_glorad_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_glorad_", k, "_", i), rowMeans(get(paste0("df_pacf_glorad_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 7 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 9 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 7 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 8 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 6 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 7 (durchgängig) signifikant
# PACF-Plots for glorad (across all members) seperated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_glorad_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_glorad_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_glorad_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_glorad_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_glorad_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_glorad_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der einfall. kurzw. Strahlung für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
## Relhum
# autocorrelation function, mean acf for relhum (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_relhum_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_relhum_", k, "_", i, "_", j),
as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$relhum, plot = FALSE)$acf))
assign(paste0("df_acf_relhum_", k, "_", i),
bind_cols(get(paste0("df_acf_relhum_", k, "_", i)), get(paste0("acf_relhum_", k, "_", i, "_", j))))
}
assign(paste0("acf_mean_relhum_", k, "_", i), rowMeans(get(paste0("df_acf_relhum_", k, "_", i))[, 2:11]))
}
}
# -> Relhum ist in allen Teildatensätzen positiv autokorreliert (vor allem für Pegel 20203) -> Modell, das diese Autokorrelation berücksichtigt, nötig
# ACF-Plots for relhum (across all members) separated by each waterlevel and season
plot(x = 0:37, y = acf_mean_relhum_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_relhum_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_relhum_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_relhum_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_relhum_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 0:37, y = acf_mean_relhum_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "ACF", main = "Autokor. zw. Beob. der relativen Luftfeuchte für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
# partial autocorrelation function, mean pacf for relhum (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_pacf_relhum_", k, "_", i), data.frame(Names = 1:37))
for (j in levels(hydro_total$member)) {
assign(paste0("pacf_relhum_", k, "_", i, "_", j),
as.data.frame(pacf(get(paste0("hydro_", k, "_", i, "_", j))$relhum, plot = FALSE)$acf))
assign(paste0("df_pacf_relhum_", k, "_", i),
bind_cols(get(paste0("df_pacf_relhum_", k, "_", i)), get(paste0("pacf_relhum_", k, "_", i, "_", j))))
}
assign(paste0("pacf_mean_relhum_", k, "_", i), rowMeans(get(paste0("df_pacf_relhum_", k, "_", i))[, 2:11]))
}
}
# 10304, Winter: Autokorrelationskoeffizient bis lag = 3 (durchgängig) signifikant
# 10304, Summer: Autokorrelationskoeffizient bis lag = 3 (durchgängig) signifikant
# 11502, Winter: Autokorrelationskoeffizient bis lag = 3 (durchgängig) signifikant
# 11502, Summer: Autokorrelationskoeffizient bis lag = 3 (durchgängig) signifikant
# 20203, Winter: Autokorrelationskoeffizient bis lag = 5 (durchgängig) signifikant
# 20203, Summer: Autokorrelationskoeffizient bis lag = 4 (nicht durchgängig), bis lag = 1 (durchgängig) signifikant
# PACF-Plots for relhum (across all members) seperated by each waterlevel and season
plot(x = 1:37, y = pacf_mean_relhum_winter_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für Isar Mittenwald, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_relhum_summer_10304, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für Isar Mittenwald, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_relhum_winter_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für Iller Kempten, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_relhum_summer_11502, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für Iller Kempten, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_relhum_winter_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für fränk. Saale Salz, Winter") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
plot(x = 1:37, y = pacf_mean_relhum_summer_20203, ylim = c(-0.1, 1), type = "h", xlab = "lag", ylab = "PACF", main = "Part. Autokor. zw. Beob. der relativen Luftfeuchte für fränk. Saale Salz, Sommer") + abline(h = 0) + abline(h = c(-0.05, 0.05), col = "blue", lty = "dashed")
## Soilwater
# autocorrelation function, mean acf for soilwater (across all members) separated by each waterlevel and season
for (k in c("winter", "summer")) {
for (i in pegel_ids) {
assign(paste0("df_acf_soilwater_", k, "_", i), data.frame(Names = 1:38))
for (j in levels(hydro_total$member)) {
assign(paste0("acf_soilwater_", k, "_", i, "_", j),
as.data.frame(acf(get(paste0("hydro_", k, "_", i, "_", j))$soilwater, plot = FALSE)$acf))
assign(paste0("df_acf_soilwater_", k, "_", i),
bind_cols(get(paste0("df_acf_soilwater_", k, "_", i)), get(paste0("acf_soilwater_", k, "_", i, "_", j))))
}