From 03a6524f60231324de3558fdadcbf383a90f8b1c Mon Sep 17 00:00:00 2001 From: sklesse Date: Thu, 31 Jul 2025 09:27:03 +0200 Subject: [PATCH] Update rwi.stats.running.R I have added a check whether the rwi dataset has been detrended using difference=T, thus having a grand mean of 0. If so, it needs to be transposed by an arbitrary positive number, otherwise normalize1() messes up the dataset and can divide a series by a slightly negative value, returning false rbar and eps values. --- R/rwi.stats.running.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/rwi.stats.running.R b/R/rwi.stats.running.R index 302d605..1c65d20 100644 --- a/R/rwi.stats.running.R +++ b/R/rwi.stats.running.R @@ -81,7 +81,9 @@ rwi.stats.running <- function(rwi, ids=NULL, period=c("max", "common"), stop("'window.length' is smaller than 'min.corr.overlap'") } } - tmp <- normalize1(rwi, n, prewhiten) + rwi.mean<-round(mean(unlist(rwi),na.rm=T)) + if(rwi.mean==0){rwi<-rwi+100} #this is a check whether your dataset has been detrended using difference=T, thus having a grand mean of 0. If so, it needs to be transposed by an arbitrary positive number, otherwise normalize1() messes up the dataset and can divide a series by a slightly negative value. + tmp <- normalize1(rwi, n, prewhiten) if(!all(tmp$idx.good)) { warning("after prewhitening, 'rwi' contains column(s) without at least four observations", call.=FALSE)