.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "TS 3pm" .TH TS 3pm "2018-11-02" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PDL::Stats::TS \-\- basic time series functions .SH "DESCRIPTION" .IX Header "DESCRIPTION" The terms \s-1FUNCTIONS\s0 and \s-1METHODS\s0 are arbitrarily used to refer to methods that are threadable and methods that are \s-1NOT\s0 threadable, respectively. Plots require PDL::Graphics::PGPLOT. .PP ***EXPERIMENTAL!*** In particular, bad value support is spotty and may be shaky. \s-1USE WITH DISCRETION\s0! .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use PDL::LiteF; \& use PDL::NiceSlice; \& use PDL::Stats::TS; \& \& my $r = $data\->acf(5); .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "acf" .IX Subsection "acf" .Vb 1 \& Signature: (x(t); int h(); [o]r(h+1)) .Ve .PP Autocorrelation function for up to lag h. If h is not specified it's set to t\-1 by default. .PP acf does not process bad values. .PP usage: .PP .Vb 1 \& perldl> $a = sequence 10 \& \& # lags 0 .. 5 \& \& perldl> p $a\->acf(5) \& [1 0.7 0.41212121 0.14848485 \-0.078787879 \-0.25757576] .Ve .SS "acvf" .IX Subsection "acvf" .Vb 1 \& Signature: (x(t); int h(); [o]v(h+1)) .Ve .PP Autocovariance function for up to lag h. If h is not specified it's set to t\-1 by default. .PP acvf does not process bad values. .PP usage: .PP .Vb 1 \& perldl> $a = sequence 10 \& \& # lags 0 .. 5 \& \& perldl> p $a\->acvf(5) \& [82.5 57.75 34 12.25 \-6.5 \-21.25] \& \& # autocorrelation \& \& perldl> p $a\->acvf(5) / $a\->acvf(0) \& [1 0.7 0.41212121 0.14848485 \-0.078787879 \-0.25757576] .Ve .SS "diff" .IX Subsection "diff" .Vb 1 \& Signature: (x(t); [o]dx(t)) .Ve .PP Differencing. \s-1DX\s0(t) = X(t) \- X(t\-1), \s-1\fBDX\s0\fR\|(0) = X(0). Can be done inplace. .PP diff does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "inte" .IX Subsection "inte" .Vb 1 \& Signature: (x(n); [o]ix(n)) .Ve .PP Integration. Opposite of differencing. \s-1IX\s0(t) = X(t) + X(t\-1), \s-1\fBIX\s0\fR\|(0) = X(0). Can be done inplace. .PP inte does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "dseason" .IX Subsection "dseason" .Vb 1 \& Signature: (x(t); indx d(); [o]xd(t)) .Ve .PP Deseasonalize data using moving average filter the size of period d. .PP dseason processes bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "fill_ma" .IX Subsection "fill_ma" .Vb 1 \& Signature: (x(t); int q(); [o]xf(t)) .Ve .PP Fill missing value with moving average. xf(t) = sum(x(t\-q .. t\-1, t+1 .. t+q)) / 2q. .PP fill_ma does handle bad values. Output pdl bad flag is cleared unless the specified window size q is too small and there are still bad values. .PP .Vb 1 \& my $x_filled = $x\->fill_ma( $q ); .Ve .SS "filter_exp" .IX Subsection "filter_exp" .Vb 1 \& Signature: (x(t); a(); [o]xf(t)) .Ve .PP Filter, exponential smoothing. xf(t) = a * x(t) + (1\-a) * xf(t\-1) .PP filter_exp does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "filter_ma" .IX Subsection "filter_ma" .Vb 1 \& Signature: (x(t); indx q(); [o]xf(t)) .Ve .PP Filter, moving average. xf(t) = sum(x(t\-q .. t+q)) / (2q + 1) .PP filter_ma does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "mae" .IX Subsection "mae" .Vb 1 \& Signature: (a(n); b(n); float+ [o]c()) .Ve .PP Mean absolute error. \s-1MAE\s0 = 1/n * sum( abs(y \- y_pred) ) .PP Usage: .PP .Vb 1 \& $mae = $y\->mae( $y_pred ); .Ve .PP mae processes bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "mape" .IX Subsection "mape" .Vb 1 \& Signature: (a(n); b(n); float+ [o]c()) .Ve .PP Mean absolute percent error. \s-1MAPE\s0 = 1/n * sum(abs((y \- y_pred) / y)) .PP Usage: .PP .Vb 1 \& $mape = $y\->mape( $y_pred ); .Ve .PP mape processes bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "wmape" .IX Subsection "wmape" .Vb 1 \& Signature: (a(n); b(n); float+ [o]c()) .Ve .PP Weighted mean absolute percent error. avg(abs(error)) / avg(abs(data)). Much more robust compared to mape with division by zero error (cf. Schütz, W., & Kolassa, 2006). .PP Usage: .PP .Vb 1 \& $wmape = $y\->wmape( $y_pred ); .Ve .PP wmape processes bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "portmanteau" .IX Subsection "portmanteau" .Vb 1 \& Signature: (r(h); longlong t(); [o]Q()) .Ve .PP Portmanteau significance test (Ljung-Box) for autocorrelations. .PP Usage: .PP .Vb 1 \& perldl> $a = sequence 10 \& \& # acf for lags 0\-5 \& # lag 0 excluded from portmanteau \& \& perldl> p $chisq = $a\->acf(5)\->portmanteau( $a\->nelem ) \& 11.1753902662994 \& \& # get p\-value from chisq distr \& \& perldl> use PDL::GSL::CDF \& perldl> p 1 \- gsl_cdf_chisq_P( $chisq, 5 ) \& 0.0480112934306748 .Ve .PP portmanteau does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles. .SS "pred_ar" .IX Subsection "pred_ar" .Vb 1 \& Signature: (x(d); b(p|p+1); int t(); [o]pred(t)) .Ve .PP Calculates predicted values up to period t (extend current series up to period t) for autoregressive series, with or without constant. If there is constant, it is the last element in b, as would be returned by ols or ols_t. .PP pred_ar does not process bad values. .PP .Vb 1 \& CONST => 1, .Ve .PP Usage: .PP .Vb 1 \& perldl> $x = sequence 2 \& \& # last element is constant \& perldl> $b = pdl(.8, \-.2, .3) \& \& perldl> p $x\->pred_ar($b, 7) \& [0 1 1.1 0.74 0.492 0.3656 0.31408] \& \& # no constant \& perldl> p $x\->pred_ar($b(0:1), 7, {const=>0}) \& [0 1 0.8 0.44 0.192 0.0656 0.01408] .Ve .SS "season_m" .IX Subsection "season_m" Given length of season, returns seasonal mean and var for each period (returns seasonal mean only in scalar context). .PP Default options (case insensitive): .PP .Vb 8 \& START_POSITION => 0, # series starts at this position in season \& MISSING => \-999, # internal mark for missing points in season \& PLOT => 1, # boolean \& # see PDL::Graphics::PGPLOT::Window for next options \& WIN => undef, # pass pgwin object for more plotting control \& DEV => \*(Aq/xs\*(Aq, # open and close dev for plotting if no WIN \& # defaults to \*(Aq/png\*(Aq in Windows \& COLOR => 1, .Ve .PP See PDL::Graphics::PGPLOT for detailed graphing options. .PP .Vb 1 \& my ($m, $ms) = $data\->season_m( 24, { START_POSITION=>2 } ); .Ve .SS "plot_dseason" .IX Subsection "plot_dseason" Plots deseasonalized data and original data points. Opens and closes default window for plotting unless a pgwin object is passed in options. Returns deseasonalized data. .PP Default options (case insensitive): .PP .Vb 4 \& WIN => undef, \& DEV => \*(Aq/xs\*(Aq, # open and close dev for plotting if no WIN \& # defaults to \*(Aq/png\*(Aq in Windows \& COLOR => 1, # data point color .Ve .PP See PDL::Graphics::PGPLOT for detailed graphing options. .SH "METHODS" .IX Header "METHODS" .SS "plot_acf" .IX Subsection "plot_acf" Plots and returns autocorrelations for a time series. .PP Default options (case insensitive): .PP .Vb 3 \& SIG => 0.05, # can specify .10, .05, .01, or .001 \& DEV => \*(Aq/xs\*(Aq, # open and close dev for plotting \& # defaults to \*(Aq/png\*(Aq in Windows .Ve .PP Usage: .PP .Vb 1 \& perldl> $a = sequence 10 \& \& perldl> p $r = $a\->plot_acf(5) \& [1 0.7 0.41212121 0.14848485 \-0.078787879 \-0.25757576] .Ve .SH "REFERENCES" .IX Header "REFERENCES" Brockwell, P.J., & Davis, R.A. (2002). Introcution to Time Series and Forecasting (2nd ed.). New York, \s-1NY:\s0 Springer. .PP Schütz, W., & Kolassa, S. (2006). Foresight: advantages of the MAD/Mean ratio over the \s-1MAPE.\s0 Retrieved Jan 28, 2010, from http://www.saf\-ag.com/226+M5965d28cd19.html .SH "AUTHOR" .IX Header "AUTHOR" Copyright (C) 2009 Maggie J. Xiong .PP All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file \s-1COPYING\s0 in the \s-1PDL\s0 distribution.