noetherCyclicalTrend¶
Performs the Noether test for cyclical trend.
Synopsis¶
noetherCyclicalTrend (x)
Required Arguments¶
- float
x[]
(Input) - Array of length
nObservations
containing the data in chronological order.
Return Value¶
Array, p
, of length 3 containing the probabilities of stat[1]
or
more, stat[2]
or more, or stat[3]
or more monotonic sequences.
If stat[0]
is less than 1, p[0]
is set to NaN (not a number).
Optional Arguments¶
fuzz
, float (Input)Nonnegative constant used to determine ties in computing ranks in the combined samples. A tie is declared when two observations in the combined sample are within fuzz of each other.
Default value for
fuzz
is 0.0.stat
(Output)- An array of length 6 containing the following statistics:
Row | Statistics |
---|---|
stat[0] |
The number of consecutive sequences of length three used to detect cyclical trend when tying middle elements are eliminated from the sequence, and the next consecutive observation is used. |
stat[1] |
The number of monotonic sequences of length three in
the set defined by stat[0] . |
stat[2] |
The number of nonmonotonic sequences where tied threesomes are counted as nonmonotonic. |
stat[3] |
The number of monotonic sequences where tied threesomes are counted as monotonic. |
stat[4] |
The number of middle observations eliminated because
they were tied in forming the stat[0] sequences. |
stat[5] |
The number of tied sequences found in forming the
stat[2] and stat[3] sequences. A sequence is
called a tied sequence if the middle element is tied
with either of the two other elements. |
nMissing
(Output)- Number of missing values in
X
.
Description¶
Routine noetherCyclicalTrend
performs the Noether test for cyclical
trend (Noether 1956) for a sequence of measurements. In this test, the
observations are first divided into sets of three consecutive observations.
Each set is then inspected, and if the set is monotonically increasing or
decreasing, the count variable is incremented.
The count variables, stat[1]
, stat[2]
, and stat[3]
, differ in
the manner in which ties are handled. A tie can occur in a set (of size
three) only if the middle element is tied with either of the two ending
elements. Tied ending elements are not considered. In stat[1]
, tied
middle observations are eliminated, and a new set of size 3 is obtained by
using the next observation in the sample. In stat[2]
, the original set
of size three is used, and tied middle observations are counted as
nonmonotonic. In stat[3]
, tied middle observations are counted as
monotonic.
The probabilities of occurrence of the counts are obtained from the binomial distribution with \(p=1/3\), where p is the probability that a random sample of size three from a continuous distribution is monotonic. The binomial sample size is, of course, the number of sequences of size three found (adjusted for ties).
Hypothesis test:
\(H_0 : q=Pr(X_i>X_{i-1}>X_{i-2})+Pr(X_i<X_{i-1}<X_{i-2})\leq 1/3 H_1 : q>1/3\)
Reject if p[0]
(or p[1]
or p[2]
depending on the method used for
handling ties) is less than the significance level of the test.
Assumption: The observations are independent and are from a continuous distribution.
Example¶
A test for cyclical trend in a sequence of 1000 randomly generated observations is performed. Because of the sample used, there are no ties and all three test statistics yield the same result.
from __future__ import print_function
from numpy import *
from pyimsl.stat.noetherCyclicalTrend import noetherCyclicalTrend
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.randomUniform import randomUniform
from pyimsl.stat.writeMatrix import writeMatrix
nmiss = []
stat = []
nobs = 1000
randomSeedSet(123457)
x = randomUniform(nobs)
pvalue = noetherCyclicalTrend(x, stat=stat, nMissing=nmiss)
writeMatrix("P", pvalue)
writeMatrix("STAT", stat, writeFormat="%6i")
print("\n n missing = %d" % (nmiss[0]))
Output¶
n missing = 0
P
1 2 3
0.6979 0.6979 0.6979
STAT
1 2 3 4 5 6
333 107 107 107 0 0