-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d075436
commit 44c6ab3
Showing
7 changed files
with
234 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ Package: crqa | |
Type: Package | ||
Title: Recurrence Quantification Analysis for Categorical and | ||
Continuous Time-Series | ||
Version: 2.0 | ||
Date: 2020-05-28 | ||
Version: 2.0.1 | ||
Date: 2020-10-29 | ||
Authors@R: c( | ||
person("Moreno I.", "Coco", role = c("cre","aut"), | ||
email="[email protected]"), | ||
|
@@ -31,15 +31,15 @@ Description: | |
and Wallot (2018) <doi:10.1080/00273171.2018.1512846> | ||
for further details about the method. | ||
Depends: R (>= 3.0.0) | ||
Imports: Matrix, pracma, tseriesChaos, gplots, plot3D, rdist | ||
Imports: Matrix, pracma, tseriesChaos, gplots, plot3D, FSA, rdist | ||
License: GPL (>= 2) | ||
Collate: 'crqa.R' 'crqa_helpers.R' 'drpfromts.R' 'lorenzattractor.R' | ||
'mdDelay.R' 'mdFnn.R' 'optimizeParam.R' 'piecewiseRQA.R' | ||
'plotRP.R' 'simts.R' 'spdiags.R' 'wincrqa.R' 'windowdrp.R' | ||
RoxygenNote: 7.1.0 | ||
LazyData: true | ||
NeedsCompilation: yes | ||
Packaged: 2020-06-05 10:08:43 UTC; nak_d | ||
Packaged: 2020-10-29 11:14:04 UTC; nak_d | ||
Author: Moreno I. Coco [cre, aut], | ||
Dan Monster [aut], | ||
Giuseppe Leonardi [aut], | ||
|
@@ -48,4 +48,4 @@ Author: Moreno I. Coco [cre, aut], | |
James D. Dixon [ctb], | ||
John C. Nash [ctb] | ||
Repository: CRAN | ||
Date/Publication: 2020-06-11 19:10:02 UTC | ||
Date/Publication: 2020-10-29 11:40:03 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
useDynLib(crqa, .registration = TRUE) | ||
|
||
export(crqa, | ||
drpfromts, | ||
lorenzattractor, | ||
mdDelay, | ||
mdFnn, | ||
optimizeParam, | ||
piecewiseRQA, | ||
plotRP, | ||
simts, | ||
spdiags, | ||
wincrqa, | ||
windowdrp) | ||
|
||
importFrom("graphics", mtext, hist, matpoints, plot, points) | ||
importFrom("gplots", hist2d) | ||
importFrom("Matrix", diag, t, Matrix, sparseMatrix) | ||
importFrom("plot3D", scatter3D) | ||
importFrom("pracma", circshift, eps, pdist2, polyfit) | ||
importFrom("stats", sd, median, rnorm, runif, var) | ||
importFrom("rdist", cdist) | ||
importFrom("tseriesChaos", mutual, false.nearest) | ||
importFrom("utils", tail) | ||
useDynLib(crqa, .registration = TRUE) | ||
|
||
export(crqa, | ||
drpfromts, | ||
lorenzattractor, | ||
mdDelay, | ||
mdFnn, | ||
optimizeParam, | ||
piecewiseRQA, | ||
plotRP, | ||
simts, | ||
spdiags, | ||
wincrqa, | ||
windowdrp) | ||
|
||
importFrom("graphics", mtext, hist, matpoints, plot, points) | ||
importFrom("gplots", hist2d) | ||
importFrom("FSA", diags) | ||
importFrom("Matrix", diag, t, Matrix, sparseMatrix) | ||
importFrom("plot3D", scatter3D) | ||
importFrom("pracma", circshift, eps, pdist2, polyfit) | ||
importFrom("stats", sd, median, rnorm, runif, var) | ||
importFrom("rdist", cdist) | ||
importFrom("tseriesChaos", mutual, false.nearest) | ||
importFrom("utils", tail) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
## written by Moreno I. Coco 2013 ([email protected]) | ||
## original Matlab code by Rick Dale | ||
|
||
|
@@ -28,67 +27,116 @@ wincrqa <- function(ts1, ts2, windowstep, windowsize, delay, embed, | |
tw = 0, whiteline = FALSE, recpt = FALSE, side = 'both', | ||
method = 'crqa', metric = 'euclidean', | ||
datatype = 'continuous', trend = FALSE){ | ||
|
||
## we do not expect as input a recurrent plot | ||
|
||
irregular = FALSE; # initialize a flag that will be used to check whether the last window is included | ||
## check the different contexts in which the analyses are running | ||
if (method == "rqa"){ | ||
## check that the user as provided the same data to allow windowed recurrence | ||
if (exists("ts2")) ts2 = ts2 else stop("Please provide the same vector as argument of t2") | ||
} | ||
|
||
if (method == "crqa"){ | ||
ts1 = as.vector(as.matrix(ts1)); ts2 = as.vector(as.matrix(ts2)) | ||
points = seq(1, (length(ts1) - (windowsize)-1), windowstep) | ||
maxd = length(ts1) ## the total number of points | ||
points = seq(1, (maxd - (windowsize)-1), windowstep) | ||
} | ||
|
||
if (method == "mdcrqa"){ | ||
ts1 = as.matrix(ts1); ts2 = as.matrix(ts2) | ||
maxd = nrow(ts1) ## the total number of points | ||
points = seq(1, (maxd - (windowsize)-1), windowstep) | ||
} | ||
|
||
## need to make sure to include also "irregular" final segments | ||
fpoint = points[length(points)] ## beginning of last window | ||
## as the dimension of the data often may not be that precise | ||
if (fpoint != (fpoint + windowsize)){ | ||
irregular = TRUE ## flag used later on | ||
fpoint = fpoint + windowsize # update last point | ||
points = c(points, fpoint) ## add final point | ||
} | ||
|
||
crqwin = vector() | ||
tsp = 0 ## set a counter with the win at which rec was found | ||
|
||
# i = 1621 | ||
for (i in points){ | ||
tsp = tsp +1 | ||
|
||
TREND = crawin = vector() | ||
tsp = 0 ## set a counter with the win at which rec was found | ||
|
||
i = 1 | ||
for (i in points){ | ||
tsp = tsp +1 | ||
|
||
ts1win = ts1[i:(i + windowsize - 1)]; | ||
ts2win = ts2[i:(i + windowsize - 1)]; | ||
if (irregular == TRUE & i == fpoint){ ## this is the last window to consider | ||
ixs = i:maxd | ||
# warning(paste("Your latest window was shorter: ", length(ixs))) | ||
} else { | ||
ixs = i:(i + windowsize - 1) | ||
} | ||
|
||
if (method == "crqa" | method == "rqa"){ | ||
## the data consists of two vectors | ||
ts1win = ts1[ixs]; | ||
ts2win = ts2[ixs]; | ||
} | ||
|
||
if (method == "mdcrqa"){ | ||
## the data consists of two matrices | ||
ts1win = ts1[ixs, ]; | ||
ts2win = ts2[ixs, ]; | ||
} | ||
|
||
ans = crqa(ts1win, ts2win, delay, embed, rescale, | ||
radius, normalize, mindiagline, minvertline, | ||
tw, whiteline, recpt, side, method, metric, | ||
datatype) | ||
|
||
RP = ans$RP | ||
if (length(RP) == 1) RP = vector() ## a trick for cases | ||
## with empty recurrence plot | ||
ans = as.numeric( unlist(ans[1:10]) ) | ||
## if trend needs to be calculated do it here | ||
|
||
if (trend == TRUE){ | ||
|
||
if (length(RP) > 0){ | ||
RP = as.matrix(RP) ## diags() has changed behaviour | ||
NX = ncol(RP) | ||
T = vector("numeric", length = NX-1) | ||
|
||
|
||
## below some test matrices | ||
# RP = matrix(1:16,nrow=4) | ||
# RP = cbind(c(2,7), c(1,9), c(10, 12)) | ||
|
||
ans = crqa(ts1win, ts2win, delay, embed, rescale, | ||
radius, normalize, mindiagline, minvertline, | ||
tw, whiteline, recpt, side, method, metric, | ||
datatype) | ||
# do we need to span the full matrix or just half? | ||
## create a vector of indeces for all diagonals of the matrix | ||
# ixi_diag = -(ncol(RP)-1):(nrow(RP)-1) | ||
|
||
RP = ans$RP | ||
if (length(RP) == 1) RP = vector() ## a trick for cases | ||
## with empty recurrence plot | ||
ans = as.numeric( unlist(ans[1:10]) ) | ||
## if trend needs to be calculated do it here | ||
|
||
if (trend == TRUE){ | ||
|
||
if (length(RP) > 0){ | ||
|
||
NX = ncol(RP) | ||
T = vector("numeric", length = NX-1) | ||
|
||
k = 1 | ||
for (k in 1:(NX-1)){ | ||
T[k] = length( | ||
which(diag(RP, k) != F)) / (NX-k)*100; | ||
} | ||
|
||
Ntau = NX - 1 - round(0.1*NX); | ||
|
||
## last 10% of the RP will be skipped | ||
p = polyfit(2:(Ntau+1),T[1:Ntau], 1) # slope | ||
TREND = c(TREND, 1000 * p[1]) | ||
## Webber's definition includes factor 1000 | ||
|
||
} else { TREND = NA} | ||
} else { | ||
TREND = c(TREND, NA) | ||
# k = 1 | ||
for (k in 1:(NX-1)){ ##ixi_diag | ||
# print(diags(RP, k)) ## check the diagonal | ||
ixi_rec = which(diags(RP, k) != F) ## find recurrence | ||
T[k] = length(ixi_rec)/ (NX-k)*100; | ||
} | ||
|
||
Ntau = NX - 1 - round(0.1*NX); | ||
|
||
crawin = rbind(crawin, c(ans, tsp), deparse.level = 0) | ||
## last 10% of the RP will be skipped | ||
p = polyfit(2:(Ntau+1),T[1:Ntau], 1) # slope | ||
TREND = 1000 * p[1] | ||
## Webber's definition includes factor 1000 | ||
|
||
} else { TREND = NA} | ||
} else { | ||
TREND = NA | ||
} | ||
|
||
## name the measures | ||
colnames(crawin) = c("RR", "DET", "NRLINE", "maxL", "L", | ||
"ENTR", "rENTR", "LAM", "TT", "catH", "TREND") | ||
|
||
return(list(crqwin = crawin, TREND = TREND)) | ||
crqwin = rbind(crqwin, c(ans, tsp, TREND), deparse.level = 0) | ||
|
||
} | ||
|
||
## name the measures | ||
colnames(crqwin) = c("RR", "DET", "NRLINE", "maxL", "L", | ||
"ENTR", "rENTR", "LAM", "TT", "catH", "win", "TREND") | ||
|
||
return(as.data.frame(crqwin)) | ||
|
||
} | ||
|
Oops, something went wrong.