Kkronm {DCCA} | R Documentation |
This is an auxiliary function and requires some context to be used adequadely. It computes equation (19) in Prass and Pumi (2019), returning a square matrix defined by
K* = (Jm \%x\% J*)'(Q \%x\% Q)(Jm \%x\% J*)
where:
J
is an (m+1)*(h+1) - m*h*s
by (m+1)*(h+1) - m*h*s
lower triangular matrix with all non-zero entries equal to one, with s = 1
if overlap = TRUE and s = 0
, otherwise;
Jm
corresponds to the first m+1
rows and columns of J
;
J*
corresponds to the last m+1
rows of J
;
Q = I-P
, where P
is the m+1
by m+1
projection matrix into the subspace generated by degree nu+1
polynomials.
Kkronm(m = 3, nu = 0, h = 0, overlap = TRUE, K = NULL)
m |
a positive integer indicating the size of the window for the polinomial fit. |
nu |
a non-negative integer denoting the degree of the polinomial fit applied on the integrated series. |
h |
an integer indicating the lag. |
overlap |
logical: if true (the default), overlapping boxes are used for calculations. Otherwise, non-overlapping boxes are applied. |
K |
optional: the matrix defined by |
an (m+1)[(m+1)*(h+1) - m*h*s]
by (m+1)[(m+1)*(h+1) - m*h*s]
matrix, where s = 1
if overlap = TRUE and s = 0
, otherwise. This matrix corresponds to equation (19) in Prass and Pumi (2019).
Taiane Schaedler Prass
Prass, T.S. and Pumi, G. (2019). On the behavior of the DFA and DCCA in trend-stationary processes <arXiv:1910.10589>.
Jn
which creates the matrix J
, Qm
which creates Q
and Km
which creates K
.
m = 3
h = 1
J = Jn(n = m+1+h)
Q = Qm(m = m, nu = 0)
# using K
K = Km(J = J[1:(m+1),1:(m+1)], Q = Q)
Kkron0 = Kkronm(K = K, h = h)
# using m and nu
Kkron = Kkronm(m = m, nu = 0, h = h)
# using kronecker product from R
K = Km(J = J[1:(m+1),1:(m+1)], Q = Q)
Kh = rbind(matrix(0, nrow = h, ncol = m+1+h),
cbind(matrix(0, nrow = m+1, ncol = h), K))
KkronR = K %x% Kh
# using the definition K* = (Jm %x% J)'(Q %x% Q)(Jm %x% J)
J_m = J[1:(m+1),1:(m+1)]
J_h = J[(h+1):(m+1+h),1:(m+1+h)]
KkronD = t(J_m %x% J_h)%*%(Q %x% Q)%*%(J_m %x% J_h)
# comparing the results
sum(abs(Kkron0 - Kkron))
sum(abs(Kkron0 - KkronR))
sum(abs(Kkron0 - KkronD)) # difference due to rounding error
## Not run:
# Function Kkronm is computationaly faster than a pure implementation in R:
m = 100
h = 1
J = Jn(n = m+1)
Q = Qm(m = m, nu = 0)
# using Kkronm
t1 = proc.time()
Kkron = Kkronm(m = m, nu = 0, h = 1)
t2 = proc.time()
# elapsed time:
t2-t1
# Pure R implementation:
K = Km(J = J, Q = Q)
Kh = rbind(matrix(0, nrow = h, ncol = m+1+h),
cbind(matrix(0, nrow = m+1, ncol = h), K))
t3 = proc.time()
KkronR = K %x% Kh
t4 = proc.time()
# elapsed time
t4-t3
## End(Not run)