Description Usage Arguments Details Value References See Also Examples
Derive the phase lag of two variables. This is based on a harmonic transformation of a multi-linear regression of the form Y = aX + b dX/dt + c proposed by Camuffo and Bernardi (1982). Renner et al., 2019 adapted their version to calculate the time difference using the coefficients a and b determined by linear regression.
1 | camuffo_phaselag_time(Y, X, dX, ...)
|
Y |
Time series of dependend variable. |
X |
Time series of the reference variable, which should be close to a harmonic. |
dX |
Time derivative of X, eg. simply use c(NA,diff(X)). |
... |
Further arguments to phaselag_time, set nday and timeunitperday. |
This function performs a multi-linear regression and then calls the function phaselag_time() to estimate the time difference. This function then also returns the regression statistics using the function mlm.output.statlong()
Returns a data.table with columns statistic and value
please cite the following paper when using this code Renner, M., Brenner, C., Mallick, K., Wizemann, H.-D., Conte, L., Trebs, I., Wei, J., Wulfmeyer, V., Schulz, K., and Kleidon, A.: Using phase lags to evaluate model biases in simulating the diurnal cycle of evapotranspiration: a case study in Luxembourg, Hydrol. Earth Syst. Sci., 23, 515-535, https://doi.org/10.5194/hess-23-515-2019, 2019.
[phaselag_time()] for the core function
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 | # example with 1h timesteps in minutes as unit
library(data.table)
nday = 24
timeunitperday = 24 * 60#' time unit minutes
dt = data.table(time = seq(0.5,timeunitperday, by = timeunitperday/nday))
dt[ , Date := as.IDate("2007-07-07")]
dt[ , ptime := time * 2* pi / timeunitperday]
dt[ , ptimecos := cos(ptime - pi) ]
dt[ , Rsd := ifelse(ptimecos<0,0,800 * ptimecos)]
dt
dt[ , LEnolag := Rsd/2 + 30 * rnorm(1) , by = time ]
# create a series with a lag of one hour
(lagLE = 60 * 2 * pi / timeunitperday)
dt[ , ptimecos_lag1h := cos(ptime - pi - lagLE) ]
dt[ , LElag1h := ifelse(ptimecos_lag1h<0,0, 400 * ptimecos_lag1h ) + 30 * rnorm(1) , by = time ]
# estimate the first order difference from the reference series (Rsd)
dt[ ,dRsd := c(NA, diff(Rsd))]
# now call the function camuffo_phaselag_time()
dt[ , camuffo_phaselag_time(Y = LElag1h, X = Rsd, dX = dRsd, dt = .SD, nday = nday, timeunitperday = timeunitperday)]
dt[ , camuffo_phaselag_time(Y = LEnolag, X = Rsd, dX = rep(NA,24), dt = .SD, nday = nday, timeunitperday = timeunitperday)]
# plot stuff
plot(Rsd ~ time, data = dt)
lines(LEnolag ~ time, data = dt, col = 3)
lines(LElag1h ~ time, data = dt, col = 4)
plot(LEnolag ~ Rsd, data = dt, col = 3, type = "b")
lines(LElag1h ~ Rsd, data = dt, col = 4, type = "b", pch = 0)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.