Import the data and combine tidal vectors at hourly time step.
knitr::opts_chunk$set(warning = F, message = F, out.width = '100%')
box::use(
dplyr[...],
tidyr[...],
here[...],
janitor[...],
lubridate[...]
)
tz <- 'America/Jamaica'
# import data, combine at hourly timestep
cp <- read.csv(here('data-raw/apa_cp_02.csv')) %>%
mutate(
datetimestamp = ymd_hms(datetimestamp, tz = tz),
loc = 'cp'
) %>%
filter(minute(datetimestamp) == 0) %>%
select(loc, datetimestamp, tide = depth)
db <- read.csv(here('data-raw/apa_db_data_02.csv')) %>%
mutate(
datetimestamp = ymd_hms(datetimestamp, tz = tz),
loc = 'db'
) %>%
filter(minute(datetimestamp) == 0) %>%
select(loc, datetimestamp, tide = depth)
noaa <- read.csv(here('data-raw/noaa_tide_2002.csv')) %>%
clean_names() %>%
unite('datetimestamp', date, time_lst, sep = ' ') %>%
mutate(
datetimestamp = ymd_hm(datetimestamp, tz = tz),
tide = predicted_ft * 0.3048,
loc = 'noaa'
) %>%
select(loc, datetimestamp, tide)
alldat <- bind_rows(cp, db, noaa) %>%
spread(loc, tide) %>%
mutate_if(is.numeric, as.ts)
Pairwise scatterplots of tidal vectors.
par(mfrow = c(1, 3), mar = c(4, 4, 0.5, 0.5))
plot(db ~ cp, alldat)
abline(reg = lm(db ~ cp, alldat), col = 'blue')
plot(noaa ~ cp, alldat)
abline(reg = lm(noaa ~ cp, alldat), col = 'blue')
plot(noaa ~ db, alldat)
abline(reg = lm(noaa ~ db, alldat), col = 'blue')
Use ccfto check lagged correlations, each lag corresponds to one hour.
subs <- 1:90
par(mfrow = c(3, 1), mar = c(4, 4, 0.5, 0.5))
plot(db ~ datetimestamp, alldat[subs, ], type = 'l')
plot(cp ~ datetimestamp, alldat[subs, ], type = 'l')
ccf(alldat$db, alldat$cp, na.action = na.pass)
ccf(alldat$db, alldat$cp, na.action = na.pass, plot = F)
##
## Autocorrelations of series 'X', by lag
##
## -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33
## 0.017 -0.062 -0.101 -0.103 -0.080 -0.047 -0.020 -0.006 -0.008 -0.018 -0.025
## -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22
## -0.013 0.032 0.114 0.232 0.374 0.519 0.646 0.731 0.759 0.723 0.631
## -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11
## 0.499 0.348 0.205 0.090 0.016 -0.016 -0.010 0.019 0.055 0.085 0.099
## -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
## 0.100 0.093 0.094 0.117 0.174 0.269 0.398 0.546 0.692 0.812 0.882
## 1 2 3 4 5 6 7 8 9 10 11
## 0.890 0.832 0.716 0.564 0.400 0.249 0.129 0.051 0.017 0.018 0.039
## 12 13 14 15 16 17 18 19 20 21 22
## 0.065 0.081 0.081 0.069 0.052 0.046 0.064 0.118 0.210 0.332 0.470
## 23 24 25 26 27 28 29 30 31 32 33
## 0.601 0.701 0.750 0.738 0.665 0.541 0.388 0.230 0.089 -0.016 -0.077
## 34 35 36 37 38 39 40 41 42 43
## -0.097 -0.086 -0.058 -0.030 -0.013 -0.012 -0.024 -0.038 -0.039 -0.015
subs <- 1:90
par(mfrow = c(3, 1), mar = c(4, 4, 0.5, 0.5))
plot(noaa ~ datetimestamp, alldat[subs, ], type = 'l')
plot(cp ~ datetimestamp, alldat[subs, ], type = 'l')
ccf(alldat$noaa, alldat$cp, na.action = na.pass)
ccf(alldat$noaa, alldat$cp, na.action = na.pass, plot = F)
##
## Autocorrelations of series 'X', by lag
##
## -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33
## -0.250 -0.287 -0.276 -0.234 -0.184 -0.148 -0.139 -0.159 -0.200 -0.241 -0.260
## -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22
## -0.236 -0.158 -0.027 0.142 0.323 0.485 0.598 0.638 0.597 0.482 0.313
## -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11
## 0.124 -0.055 -0.194 -0.279 -0.307 -0.288 -0.241 -0.192 -0.160 -0.158 -0.184
## -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
## -0.226 -0.263 -0.270 -0.230 -0.133 0.016 0.197 0.383 0.540 0.639 0.659
## 1 2 3 4 5 6 7 8 9 10 11
## 0.595 0.459 0.277 0.082 -0.093 -0.222 -0.294 -0.308 -0.279 -0.228 -0.180
## 12 13 14 15 16 17 18 19 20 21 22
## -0.153 -0.157 -0.189 -0.232 -0.264 -0.262 -0.209 -0.101 0.054 0.235 0.412
## 23 24 25 26 27 28 29 30 31 32 33
## 0.553 0.630 0.628 0.546 0.400 0.217 0.031 -0.127 -0.236 -0.287 -0.285
## 34 35 36 37 38 39 40 41 42 43
## -0.245 -0.191 -0.146 -0.127 -0.139 -0.175 -0.220 -0.248 -0.240 -0.181
subs <- 1:90
par(mfrow = c(3, 1), mar = c(4, 4, 0.5, 0.5))
plot(noaa ~ datetimestamp, alldat[subs, ], type = 'l')
plot(db ~ datetimestamp, alldat[subs, ], type = 'l')
ccf(alldat$noaa, alldat$db, na.action = na.pass)
ccf(alldat$noaa, alldat$db, na.action = na.pass, plot = F)
##
## Autocorrelations of series 'X', by lag
##
## -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33
## -0.041 -0.079 -0.087 -0.079 -0.069 -0.067 -0.079 -0.100 -0.120 -0.123 -0.095
## -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22
## -0.028 0.082 0.226 0.387 0.541 0.663 0.734 0.740 0.681 0.568 0.421
## -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11
## 0.264 0.121 0.008 -0.065 -0.100 -0.106 -0.097 -0.088 -0.087 -0.100 -0.119
## -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
## -0.133 -0.127 -0.087 -0.005 0.118 0.272 0.437 0.589 0.703 0.760 0.750
## 1 2 3 4 5 6 7 8 9 10 11
## 0.675 0.550 0.395 0.236 0.096 -0.010 -0.075 -0.102 -0.103 -0.091 -0.081
## 12 13 14 15 16 17 18 19 20 21 22
## -0.082 -0.096 -0.114 -0.125 -0.113 -0.065 0.024 0.152 0.306 0.466 0.608
## 23 24 25 26 27 28 29 30 31 32 33
## 0.707 0.747 0.721 0.634 0.502 0.348 0.196 0.067 -0.024 -0.075 -0.090
## 34 35 36 37 38 39 40 41 42 43
## -0.082 -0.066 -0.055 -0.057 -0.072 -0.090 -0.100 -0.086 -0.036 0.053