This has been an interesting discussion.
If you load and display the following script it will show
important patterns in the centering behaviour of the
sliding window scheme.
Script follows:
Note 'Sliding windows'
Statisticians often want sliding windows and to
treat the end effects with some device which shortens
the window.
In the discussion R.E. Boss raised this issue and
June Kim clarified that the specification of the
problem she had defined was distinct from it.
If the points are equally spaced then the
specification leads to interesting centering issues.
To examine the centering of the windows
apply the mean to an index vector.
The following illustrates the centering using the
functions posted by June Kim
For the Boss type of sliding window the adverb
fsw below gives centred windows for the function
being applied. For the adverb the arguments are
in June Kim's original order.
I do not understand Roger's view that the inverted
order is more consistent with the practise with
other dyadic functions. It is commonest to have
a parameter on the left and the data on the right.
)
mean =: +/%#
NB. Definitions for adverb fsw
pre =: [: I. 2 | i.
pre1=: ([EMAIL PROTECTED])
fsw =: 1 : 0
:
a =. pre x
p =. x (a ([EMAIL PROTECTED])"0 _ ]) y
main =. x u\ y
q =. |. x ((-a) ([EMAIL PROTECTED])"0 _ ]) y
if. x >#y do. NB. if window longer than data
n =. <.-: x - #y
n1 =. n - 2|#y
p =. (-n)}.p
q =. n1 }.q
end.
p,main,q
)
NB. Examples
NB. June Kim's model aggregates bigger groups
NB. at the beginning and the end
(5 sw~ d),. (5 < fsw d)
NB. Now look at the centering
a =: i. #d
mean each (5 sw~ a),. (5 < fsw a)
NB. As the width gets larger the period
NB. dropped at the beginning and the end
NB. is increased
mean each (9 sw ~ a) ,. (9 < fsw a)
NB. And if you try a window longer than
NB. length you get a region with no
NB. 'sliding' at all.
mean each (13 sw ~ a) ,. (13 < fsw a)
NB. The nature of the centering may not
NB. be important for the source problem,
NB. but it surely constrains the extent
NB. to which it is relevant in other contexts.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm