Performs the Cox and Stuart sign test for trends in location and dispersion.
#include <imsls.h>
float *imsls_f_cox_stuart_trends_test (int n_observations, float x[], ..., 0)
The type double function is imsls_d_ cox_stuart_trends_test.
int
n_observations (Input)
Number of observations in x. n_observations must
be greater
than or equal to 3.
float x[]
(Input)
Array of length n_observations
containing the data in chronological order.
Array, pstat, of length 8 containing the probabilities. The first four elements of pstat are computed from two groups of observations.
I pstat[I]
0 Probability of nstat[0] + nstat[2] or more negative signs (ties are considered negative).
1 Probability of obtaining nstat[1] or more positive signs (ties are considered negative).
2 Probability of nstat[0] + nstat[2] or more negative signs (ties are considered positive).
3 Probability of obtaining nstat[1] or more positive signs (ties are considered positive).
The last four elements of pstat are computed from three groups of observations.
4 Probability of nstat[0] + nstat[2] or more negative signs (ties are considered negative).
5 Probability of obtaining nstat[1] or more positive signs (ties are considered negative).
6 Probability of nstat[0] + nstat[2] or more negative signs (ties are considered positive).
7 Probability of obtaining nstat[1] or more positive signs (ties are considered positive).
#include <imsls.h>
float
*imsls_f_cox_stuart_trends_test (int
n_observations, float x[],
IMSLS_DISPERSION, int k, int ids,
IMSLS_FUZZ, float
fuzz,
IMSLS_STAT, int
**nstat,
IMSLS_STAT_USER, int
nstat[],
IMSLS_N_MISSING, int
*n_missing,
IMSLS_RETURN_USER, float
pstat[],
0)
IMSLS_DISPERSION, int k, int ids, (Input)
If IMSLS_DISPERSION is
called, the Cox and Stuart tests for trends in dispersion are computed.
Otherwise, as default, the Cox and Stuart tests for trends in location are
computed. k
is the number of consecutive x elements to be used
to measure dispersion. If ids is zero, the
range is used as a measure of dispersion. Otherwise, the centered sum of squares
is used.
IMSLS_FUZZ, float fuzz
(Input)
Value used to
determine when elements in x are tied.
If |x[i] – x[j]|
is less than or equal to fuzz, x[i] and x[j] are said to be
tied. fuzz
must be nonnegative. Default value for fuzz is 0.0.
IMSLS_STAT, int **nstat
(Output)
Address of a pointer to an internally allocated array of
length 8 containing the following statistics:
I nstat[I]
0 Number of negative differences (two groups)
1 Number of positive differences (two groups)
2 Number of zero differences (two groups)
3 Number of differences used to calculate pstat[0] through pstat[3] (two groups).
4 Number of negative differences (three groups)
5 Number of positive differences (three groups)
6 Number of zero differences (three groups)
7
Number of differences used to
calculate pstat
[4] through pstat[7] (three
groups).
IMSLS_STAT_USER,
int nstat[]
(Output)
Storage for array nstat is provided by
the user.
See
IMSLS_STAT.
IMSLS_N_MISSING, int
*n_missing (Output)
Number of missing values in X.
IMSLS_RETURN_USER, float pstat[]
(Input)
User allocated array of length 8 containing the return
values.
Function imsls_f_cox_stuart_trends_test tests for trends in dispersion or location in a sequence of random variables depending upon the call of IMSLS_DISPERSION. A derivative of the sign test is used (see Cox and Stuart 1955).
For the location test (Default) with two groups, the observations are first divided into two groups with the middle observation thrown out if there are an odd number of observations. Each observation in group one is then compared with the observation in group two that has the same lexicographical order. A count is made of the number of times a group-one observation is less than (nstat[0]), greater than (nstat[1]), or equal to (nstat[2]), its counterpart in group two. Two observations are counted as equal if they are within fuzz of one another.
In the three-group test, the observations are divided into three groups, with the center group losing observations if the division is not exact. The first and third groups are then compared as in the two-group case, and the counts are stored in nstat[4] through nstat[6].
Probabilities in pstat are computed using the binomial distribution with sample size equal to the number of observations in the first group (nstat[3] or nstat[7]), and binomial probability p = 0.5.
The dispersion tests (when optional argument IMSLS_DISPERSION is called) proceed exactly as with the tests for location, but using one of two derived dispersion measures. The input value k is used to define n_observations/k groups of consecutive observations starting with observation 1. The first k observations define the first group, the next k observations define the second group, etc., with the last observations omitted if n_observations is not evenly divisible by k. A dispersion score is then computed for each group as either the range (ids = 0), or a multiple of the variance (ids ¹ 0) of the observations in the group. The dispersion scores form a derived sample. The tests proceed on the derived sample as above.
Ties are defined as occurring when a group one observation is within fuzz of its last group counterpart. Ties imply that the probability distribution of X is not strictly continuous, which means that Pr(X1 > X2) ¹ 0.5 under the null hypothesis of no trend (and the assumption of independent identically distributed observations). When ties are present, the computed binomial probabilities are not exact, and the hypothesis tests will be conservative.
In the following, i indexes an observation from group 1, while j indexes the corresponding observation in group 2 (two groups) or group 3 (three groups).
•
H0 : Pr(Xi >
Xj) =
Pr(Xi
< Xj) = 0.5
H1 :
Pr(Xi
> Xj) < Pr(Xi <
Xj)
Hypothesis of upward trend. Reject if pstat[2] (or pstat[6])is less than
the significance level.
•
H0 : Pr(Xi >
Xj) =
Pr(Xi
< Xj) = 0.5
H1 :
Pr(Xi
> Xj) > Pr(Xi <
Xj)
Hypothesis of downward trend. Reject
if pstat[1] (or pstat[5]) is less than the
significance level.
•
H0 : Pr(Xi >
Xj) =
Pr(Xi
< Xj) = 0.5
H1 :
Pr(Xi
> Xj) ¹ Pr(Xi < Xj)
Two tailed
test. Reject if 2 max(pstat[1], pstat[2]) (or 2
max(pstat[5],
pstat[6]) is
less than the significance level.
1. The observations are a random sample; i.e., the observations are independently and identically distributed.
2. The distribution is continuous.
This example illustrates both the location and dispersion tests. The data, which are taken from Bradley (1968), page 176, give the closing price of AT&T on the New York stock exchange for 36 days in 1965. Tests for trends in location (Default), and for trends in dispersion (IMSLS_DISPERSION) are performed. Trends in location are found.
#include <imsls.h>
#include <stdio.h>
int main()
{
float *pstat=NULL;
int nobs = 36, ids = 0, k = 2, nmiss, *stat = NULL;
float fuzz = 0.001;
float x[] = {
9.5, 9.875, 9.25, 9.5, 9.375, 9.0,
8.75, 8.625, 8.0, 8.25, 8.25, 8.375,
8.125, 7.875, 7.5, 7.875, 7.875, 7.75,
7.75, 7.75, 8.0, 7.5, 7.5, 7.125,
7.25, 7.25, 7.125, 6.75,6.5, 7.0,
7.0, 6.75, 6.625, 6.625, 7.125, 7.75};
pstat = imsls_f_cox_stuart_trends_test(nobs, x,
IMSLS_FUZZ, fuzz,
IMSLS_STAT, &stat,
IMSLS_N_MISSING, &nmiss,
0);
imsls_i_write_matrix("nstat", 1, 8, stat, 0);
imsls_f_write_matrix("pstat", 1, 8, pstat,
IMSLS_WRITE_FORMAT, "%10.5f", 0);
printf("n missing = %d\n", nmiss);
pstat = imsls_f_cox_stuart_trends_test(nobs, x,
IMSLS_DISPERSION, k, ids,
IMSLS_FUZZ, fuzz,
IMSLS_STAT, &stat,
IMSLS_N_MISSING, &nmiss,
0);
imsls_i_write_matrix("nstat", 0, 7, stat, 0);
imsls_f_write_matrix("pstat", 0, 7, pstat, 0);
printf("n missing = %d\n", nmiss);
}
*** WARNING Error from imsls_cox_stuart_trends_test. At least one tie is detected in X.
NSTAT
0 1 2 3 4 5 6 7
0 17 1 18 0 12 0 12
PSTAT
0 1 2 3 4
1.00000 0.00007 1.00000 0.00000 1.00000
5 6 7
0.00024 1.00000 0.00024
n missing = 0
*** WARNING Error from imsls_cox_stuart_trends_test. At least one tie is detected in X.
NSTAT
0 1 2 3 4 5 6 7
4 3 2 9 4 2 0 6
PSTAT
0 1 2 3 4
0.253906 0.910156 0.746094 0.500000 0.343750
5 6 7
0.890625 0.343750 0.890625
n missing = 0
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |