function running in package gregmisc
At 9:23 AM +0200 7/23/02, Xavier.Abulker at fimat.com wrote:
Hello, I've got a problem using the function "running" in package gregmisc For example: test<-c(1,2,3,4,5) running(test,fun=var,width=3) gives 1:1 1:2 1:3 2:4 3:5 NA NA 2 3 4 which is wrong because var(test[1:3]) [1] 1 Where am I wrong?
Look at the definition of running:
running
function (X, fun = mean, width = min(length(X), 20), allow.fewer = FALSE,
...)
running2(X = X, fun = mean, width = width, allow.fewer = allow.fewer,
...)
You can see that running() calls running2(), but does not pass the
value of its argument `fun' to running2(). So try running2() instead:
running2(1:5,fun=var,width=3)
1:1 1:2 1:3 2:4 3:5 NA NA 1 1 1
Thanks Xavier
Trying some other functions besides var() can help understand what's going on:
running(1:5,fun=max,width=3)
1:1 1:2 1:3 2:4 3:5 NA NA 2 3 4
running(1:5,fun=function(x) 0,width=3)
1:1 1:2 1:3 2:4 3:5 NA NA 2 3 4
args(running)
function (X, fun = mean, width = min(length(X), 20), allow.fewer = FALSE,
...)
NULL
At this point the results suggest, even without inspecting the
definition of running(), that running() ignores `fun' and always
returns the mean.
Looks like the author needs to fix running(), but fortunately
running2() is available.
-Don
-------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA -------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._