Skip to content

Commit

Permalink
version 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
morenococo authored and cran-robot committed Oct 29, 2020
1 parent d075436 commit 44c6ab3
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 137 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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]"),
Expand Down Expand Up @@ -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],
Expand All @@ -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
12 changes: 6 additions & 6 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ec2a83b1eebbedfdebf9da4effbe22f0 *DESCRIPTION
d0d6994e20de47c258cdcf708a0580a5 *NAMESPACE
4dc3363a73f751b1d7ca6d2539d96ea7 *NEWS.md
1c92fcecf292a403b571e0b62a3465ef *DESCRIPTION
bb7766780645c44eb3565570eaeabd85 *NAMESPACE
12e02f965e6c03518a24d3cf972321d9 *NEWS.md
781e6090f124daea60ffb1449f28141f *R/crqa.R
6ea85a41a9ed85025c3e483bfeac54a7 *R/crqa_helpers.R
56ee6cba73bb998b71a33a9fb546b59e *R/drpfromts.R
Expand All @@ -12,8 +12,8 @@ faf8b3d44e48b184df0d04c818408c88 *R/piecewiseRQA.R
4739592ef7aee15b860cb90637f82933 *R/plotRP.R
0264d4c328a7a32ec30714b4a3e16dc8 *R/simts.R
ef263b24aca130d3cc80288cd67e1fd4 *R/spdiags.R
9842641ec92253e357501920bee5e434 *R/wincrqa.R
a1d4f52b660adbb23a400861464029b2 *R/windowdrp.R
440bc17fa3d14b68ced4735b28055c2c *R/wincrqa.R
f298f8fdd2470c8a13528955450ae39b *R/windowdrp.R
3196caadb8b7015eeec83c4f45f3ce99 *README.md
849715e38ed85547eed537e789296fcb *data/crqa.RData
52c8527b184b3da3bf66cc70cf42fd42 *inst/CITATION
Expand All @@ -31,7 +31,7 @@ dd8ae8f8e4393e3cf1b499c40acbdb24 *man/lorenzattractor.Rd
a02045e8733e9ba46c6d094654cfdb68 *man/simts.Rd
47cbd9f5cd8e35b18bbaf1039e858951 *man/spdiags.Rd
210cd9a2a47c02b84284c2ff5eff6a55 *man/text.Rd
9b010573eca496fe4ba2d225034ba298 *man/wincrqa.Rd
46fae6c9032ad871e47b1da1abcb3dad *man/wincrqa.Rd
024d3cfd55e7f8487bd631edb8fc3c7e *man/windowdrp.Rd
e855afb600b4fcd14f84d1e7a6834d16 *src/init.c
a9de526d2dd2130a3b2c4eae51b6c365 *src/jspd.f
49 changes: 25 additions & 24 deletions NAMESPACE
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)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# crqa (cross-recurrence quantification analysis)

# crqa 2.0.1

* Fixed bug on wincrqa() and windowdrp() to run windowed RQA on multidimensional data.
* Simplified output of wincrqa() now returning a dataframe
* Included new import from FSA() package to use diags() function.

# crqa 2.0.0

# Major features
Expand Down
152 changes: 100 additions & 52 deletions R/wincrqa.R
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

Expand Down Expand Up @@ -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))

}

Loading

0 comments on commit 44c6ab3

Please sign in to comment.