/
0_Packages_Parameters.R
92 lines (72 loc) · 2 KB
/
0_Packages_Parameters.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
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
#################################################################
#
# AUDACE - Summer mortality prediction
# Part 0: Packages & parameters
#
#################################################################
#------------------------
# Packages
#------------------------
#----- Data management
library(sf) # For cities boundaries
library(tsModel) # For lagging function
library(abind) # To bind array
#----- Analysis
library(splines) # For ns
library(doParallel) # To Paralllelize analysis
library(dlnm) # Perform DLNM
library(FDboost) # For functional regression
library(MASS) # To simulate coefficients
#----- Plotting
library(colorspace)
library(ggplot2)
library(ggmap)
library(rnaturalearthdata)
library(sf)
library(patchwork)
library(fda) # For axis.intervals function
#-------------------------
# Parameters
#-------------------------
#----- Data
# Data loading
hot_months <- 5:9
clag <- 0:16
climate_labs <- c("AMO", "AO", "NAO", "ONI", "PDO", "PNA", "SOI")
ncl <- length(climate_labs)
region <- c("CMM", "CMQ")
reg_lab <- c("Montreal", "Quebec")
# Colors associated to each climate index
pal <- 1:7
# Labels
longseq <- seq.POSIXt(ISOdate(2000, 1, 1),
ISOdate(2002, min(hot_months) - 1, 1), by = "month")
longseq <- longseq[length(longseq) - rev(clag) + 1]
mon_vec <- month.abb[(min(hot_months) - clag - 1) %% 12 + 1]
year_vec <- -((min(hot_months) - clag - 1) %/% 12)
#----- First-stage parameters
# Temp basis parameters
varper <- c(.5, .9)
varfun <- "bs"
vardeg <- 2
# Lag basis parameters
maxlag <- 10
lagnk <- 2
# Degrees of freedom for seasonality and long-term trend
dfseas <- 4
dfdec <- 1
# Heat wave percentile for AN
heatper <- c(.95, .975, .99)
# Persentile for prediction
predper <- c(seq(.1, .9, by = .1), 1:99, seq(99.1, 99.9, by = .1))
# Acceptable percentiles for MMT
mmtper <- c(.1, .9)
# Simulation number for AF confidence intervals
ns <- 1000
#----- Second-stage parameters
# FDboost parameters
nu <- .01
maxstop <- 500
# Confidence intervals
B <- 2000
ci_level <- .95