NAG Library Function Document
nag_tsa_cp_binary (g13ndc)
1 Purpose
nag_tsa_cp_binary (g13ndc) detects change points in a univariate time series, that is, the time points at which some feature of the data, for example the mean, changes. Change points are detected using binary segmentation using one of a provided set of cost functions.
2 Specification
#include <nag.h> |
#include <nagg13.h> |
void |
nag_tsa_cp_binary (Nag_TS_ChangeType ctype,
Integer n,
const double y[],
double beta,
Integer minss,
const double param[],
Integer mdepth,
Integer *ntau,
Integer tau[],
double sparam[],
NagError *fail) |
|
3 Description
Let denote a series of data and denote a set of ordered (strictly monotonic increasing) indices known as change points, with and . For ease of notation we also define . The change points, , split the data into segments, with the th segment being of length and containing .
Given a cost function,
, nag_tsa_cp_binary (g13ndc) gives an approximate solution to
where
is a penalty term used to control the number of change points. The solution is obtained in an iterative manner as follows:
1. |
Set , and |
2. |
Set . If , where is a user-supplied control parameter, then terminate the process for this segment. |
3. |
Find that minimizes
|
4. |
Test
|
5. |
If inequality (1) is false then the process is terminated for this segment. |
6. |
If inequality (1) is true, then is added to the set of change points, and the segment is split into two subsegments, and . The whole process is repeated from step 2 independently on each subsegment, with the relevant changes to the definition of and (i.e., is set to when processing the left hand subsegment and is set to when processing the right hand subsegment.
|
The change points are ordered to give
.
nag_tsa_cp_binary (g13ndc) supplies four families of cost function. Each cost function assumes that the series,
, comes from some distribution,
. The parameter space,
is subdivided into
containing those parameters allowed to differ in each segment and
those parameters treated as constant across all segments. All four cost functions can then be described in terms of the likelihood function,
and are given by:
where the
is the maximum likelihood estimate of
within the
th segment. Four distributions are available; Normal, Gamma, Exponential and Poisson distributions. Letting
the log-likelihoods and cost functions for the four distributions, and the available subdivisions of the parameter space are:
- Normal distribution:
- Mean changes:
- Variance changes:
- Both mean and variance change:
- Gamma distribution:
- Exponential Distribution:
- Poisson distribution:
- Mean changes:
when calculating for the Poisson distribution, the sum is calculated for rather than .
4 References
Chen J and Gupta A K (2010) Parametric Statistical Change Point Analysis With Applications to Genetics Medicine and Finance Second Edition Birkhäuser
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
5 Arguments
- 1:
– Nag_TS_ChangeTypeInput
-
On entry: a flag indicating the assumed distribution of the data and the type of change point being looked for.
- Data from a Normal distribution, looking for changes in the mean, .
- Data from a Normal distribution, looking for changes in the standard deviation .
- Data from a Normal distribution, looking for changes in the mean, and standard deviation .
- Data from a Gamma distribution, looking for changes in the scale parameter .
- Data from an exponential distribution, looking for changes in .
- Data from a Poisson distribution, looking for changes in .
Constraint:
, , , , or .
- 2:
– IntegerInput
-
On entry: , the length of the time series.
Constraint:
.
- 3:
– const doubleInput
-
On entry: , the time series.
if , that is the data is assumed to come from a Poisson distribution, is used in all calculations.
Constraints:
- if , or , , for ;
- if , each value of y must be representable as an integer;
- if , each value of y must be small enough such that , for , can be calculated without incurring overflow.
- 4:
– doubleInput
-
On entry:
, the penalty term.
There are a number of standard ways of setting
, including:
- SIC or BIC
-
- AIC
-
- Hannan-Quinn
-
where
is the number of parameters being treated as estimated in each segment. This is usually set to
when
and
otherwise.
If no penalty is required then set . Generally, the smaller the value of the larger the number of suggested change points.
- 5:
– IntegerInput
-
On entry: the minimum distance between two change points, that is .
Constraint:
.
- 6:
– const doubleInput
-
On entry:
, values for the parameters that will be treated as fixed. If
,
param may be set to
NULL.
If
- if param is NULL, , the standard deviation of the Normal distribution, is estimated from the full input data. Otherwise .
If
- If param is NULL, , the mean of the Normal distribution, is estimated from the full input data. Otherwise .
If
,
must hold the shape,
, for the Gamma distribution, otherwise
param is not referenced.
Constraint:
if or , .
- 7:
– IntegerInput
-
On entry:
, the maximum depth for the iterative process, which in turn puts an upper limit on the number of change points with
.
If
then no limit is put on the depth of the iterative process and no upper limit is put on the number of change points, other than that inherent in the length of the series and the value of
minss.
- 8:
– Integer *Output
-
On exit: , the number of change points detected.
- 9:
– IntegerOutput
-
Note: the dimension,
dim, of the array
tau
must be at least
- when ;
- otherwise.
On exit: the first
elements of
tau hold the location of the change points. The
th segment is defined by
to
, where
and
.
The remainder of
tau is used as workspace.
- 10:
– doubleOutput
-
On exit: the estimated values of the distribution parameters in each segment
- , or
-
and
for , where and is the mean and standard deviation, respectively, of the values of in the th segment.
It should be noted that when and when , for all and .
-
and
for , where and are the shape and scale parameters, respectively, for the values of in the th segment. It should be noted that for all .
- or
- for , where is the mean of the values of in the th segment.
The remainder of
sparam is used as workspace.
- 11:
– NagError *Input/Output
-
The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INTERNAL_ERROR
-
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_REAL
-
On entry, and .
Constraint: if or and , then .
- NE_REAL_ARRAY
-
On entry, and .
Constraint: if , or then , for .
On entry, , is too large.
- NW_TRUNCATED
-
To avoid overflow some truncation occurred when calculating the cost function, . All output is returned as normal.
To avoid overflow some truncation occurred when calculating the parameter estimates returned in
sparam. All output is returned as normal.
7 Accuracy
The calculation of means and sums of squares about the mean during the evaluation of the cost functions are based on the one pass algorithm of
West (1979) and are believed to be stable.
8 Parallelism and Performance
nag_tsa_cp_binary (g13ndc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
None.
10 Example
This example identifies changes in the mean, under the assumption that the data is normally distributed, for a simulated dataset with observations. A BIC penalty is used, that is , the minimum segment size is set to and the variance is fixed at across the whole input series.
10.1 Program Text
Program Text (g13ndce.c)
10.2 Program Data
Program Data (g13ndce.d)
10.3 Program Results
Program Results (g13ndce.r)
This example plot shows the original data series, the estimated change points and the estimated mean in each of the identified segments.