Roderick Garton > Statistics-Sequences-Turns-0.11 > Statistics::Sequences::Turns
Module Version: 0.11

# NAME

Statistics::Sequences::Turns - Kendall's test for turning-points - peaks or troughs - in a numerical sequence

# SYNOPSIS

``` use strict;
use Statistics::Sequences::Turns 0.11;
my \$turns = Statistics::Sequences::Turns->new();
\$turns->load([qw/2 0 8 5 3 5 2 3 1 1 9 4 4 1 5 5 6 5 8 7 5 3 8 5 6/]); # strings/numbers; or send as "data => \$aref" with each stat call
my \$val = \$turns->observed(state => 5); # other methods include: expected(), variance(), obsdev() and stdev()
\$val = \$turns->zscore(state => 5, tails => 2, ccorr => 1); # # or want an array & get back both z- and p-value
\$val = \$turns->p_value(state => 5, tails => 1); # assuming data are loaded; alias: test()
my \$href = \$turns->stats_hash(values => {observed => 1, p_value => 1}, ccorr => 1); # include any other stat-method as needed
\$turns->dump(values => {observed => 1, expected => 1, p_value => 1}, ccorr => 1, flag => 1, precision_s => 3, precision_p => 7);
# prints: observed = 11.000, expected = 10.900, p_value = 0.5700167```

# DESCRIPTION

For data of the continuous numerical type, a count of turns is incremented if the value on trial i, for i is greater than zero and less than n, is, with respect to its neighbours, a peak (greater than both neighbours) or a trough (less than both neighbours). Comparing this count with the expected number of turns, and the expected variance of this count, for a randomly generated sequence completes the test.

# METHODS

## new

` \$turns = Statistics::Sequences::Turns->new();`

Returns a new Turns object. Expects/accepts no arguments but the classname.

``` \$turns->load(@data);
\$turns->load('sample1' => \@data); # labelled whatever```

Loads data anonymously or by name - see load in the Statistics::Data manpage for details on the various ways data can be loaded and then retrieved (more than shown here). Data must be numerical (ordinal, interval type). All elements must be numerical of the method croaks.

See Statistics::Data for these additional operations on data that have been loaded.

## observed, turncount_observed, tco

``` \$v = \$turns->observed(); # use anonymously loaded data
\$v = \$turns->observed(index => 1); # ... or give the required "index" for the loaded data
\$v = \$turns->observed(label => 'mysequence'); # ... or its "label" value
\$v = \$turns->observed(data => \@data); # ... or just give the data now```

Returns observed number of turns. This is the number of peaks and troughs, starting the count from index 1 of a flat array, checking if both its left/right (or past/future) neighbours are lesser than it (a peak) or greater than it (a trough). Wherever the values in successive indices of the list are equal, they are treated as a single observation/datum - so the following:

` 0 0 1 1 0 1 1 1 0 1`

is counted up for turns as

``` 0 1 0 1 0 1
* * * *```

So there are four turns in this example - two peaks (0 1 0) and two troughs (1 0 1). (If repeated, this sequence would significantly deviate from expectation, p = .035.)

## expected, turncount_expected, tce

``` \$v = \$turns->expected(); # use first-loaded data; or specify by "index" or "label", or give it as "data" - see observed()
\$v = \$turns->expected(data => \@data); # use these data
\$v = \$turns->expected(trials => 10); # don't use actual data; calculate from this number of trials```

Returns the expected number of turns, which is set by N the number of trials/observations/sample-size ...:

E[T] = 2 / 3 (N – 2)

## variance, turncount_variance, tcv

``` \$v = \$turns->variance(); # use first-loaded data; or specify by "index" or "label", or give it as "data" - see observed()
\$v = \$turns->variance(data => \@data); # use these data
\$v = \$turns->variance(trials => number); # don't use actual data; calculate from this number of trials```

Returns the expected variance in the number of turns for the given length of data N.

V[T] = (16N – 29 ) / 90

## obsdev, observed_deviation

``` \$v = \$turns->obsdev(); # use data already loaded - anonymously; or specify its "label" or "index" - see observed()
\$v = \$turns->obsdev(data => \@data); # use these data```

Returns the deviation of (difference between) observed and expected turn-count for the loaded/given sequence (O - E).

## stdev, standard_deviation

``` \$v = \$turns->stdev(); # use data already loaded - anonymously; or specify its "label" or "index" - see observed()
\$v = \$turns->stdev(data => \@data);```

Returns square-root of the variance.

## z_value, zscore, turncount_zscore, tzs

``` \$v = \$turns->z_value(ccorr => 1); # use data already loaded - anonymously; or specify its "label" or "index" - see observed()
\$v = \$turns->z_value(data => \$aref, ccorr => 1);
(\$zvalue, \$pvalue) = \$turns->z_value(data => \$aref, ccorr => 1, tails => 2); # same but wanting an array, get the p-value too```

Returns the zscore from a test of turncount deviation, taking the turncount expected away from that observed and dividing by the root expected turncount variance, by default with a continuity correction in the numerator. Called wanting an array, returns the z-value with its p-value for the tails (1 or 2) given.

## p_value, test, turns_test, tnt

``` \$p = \$turns->p_value(); # using loaded data and default args
\$p = \$turns->p_value(ccorr => 0|1, tails => 1|2); # normal-approximation based on loaded data
\$p = \$turns->p_value(data => \$aref, ccorr => 1, tails => 2); #  using given data (by-passing load and read)```

Test the currently loaded data for significance of the number of turning-points by normal approximation. Note: for turns there is "a fairly rapid tendency of the distribution to normality" (Kendall 1973, p. 24).

## dump

` \$turns->dump(flag => '1|0', text => '0|1|2');`

Print test results to STDOUT. See dump in the Statistics::Sequences manpage for details.

# REFERENCES

Kendall, M. G. (1973). Time-series. London, UK: Griffin. [The test is described on pages 22-24; in the Example 2.1 for this test, the expected number of turns should be calculated with the value 52 (i.e., n - 2), not 54.]

Statistics::Sequences for other tests of sequences, and for sharing data between these tests.

# TO DO/BUGS

Implementation of the serial test for non-overlapping v-nomes.

# REVISION HISTORY

See CHANGES in installation dist for revisions.