Packages

class ARMA extends ForecasterVec

The ARMA class provides basic time series analysis capabilities for Auto- Regressive 'AR' and Moving-Average 'MA' models. In an 'ARMA(p, q)' model, 'p' and 'q' refer to the order of the Auto-Regressive and Moving-Average components of the model. Given time series data stored in vector 'y', its next value 'y_t = y(t)' may be predicted based on prior values of 'y' and its noise:

y_t = δ + Σ(φ_i y_t-i) + Σ(θ_i e_t-i) + e_t

where 'δ' is a constant, 'φ' is the auto-regressive coefficient vector, 'θ' is the moving-average coefficient vector, and 'e' is the noise vector. ------------------------------------------------------------------------------

Linear Supertypes
ForecasterVec, Predictor, Model, Fit, Error, QoF, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ARMA
  2. ForecasterVec
  3. Predictor
  4. Model
  5. Fit
  6. Error
  7. QoF
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new ARMA(y: VectoD)

    y

    the original input vector (time series data)

Value Members

  1. def acF: VectoD

    Return the autocorrelation.

    Return the autocorrelation. Must call 'train' first.

    Definition Classes
    ForecasterVec
  2. def analyze(x_: MatriD = null, y_: VectoD = y, x_e: MatriD = null, y_e: VectoD = y): ForecasterVec

    Analyze a dataset using this model using ordinary training with the 'train' method.

    Analyze a dataset using this model using ordinary training with the 'train' method.

    x_

    the training/full the data/input matrix (ignore)

    y_

    the training/full the response/output vector

    x_e

    the test/full data/input matrix (ignore)

    y_e

    the test/full response/output vector

    Definition Classes
    ForecasterVecPredictor
  3. def corrMatrix(xx: MatriD): MatriD

    Return the correlation matrix for the columns in data matrix 'xx'.

    Return the correlation matrix for the columns in data matrix 'xx'.

    xx

    the data matrix shose correlation matrix is sought

    Definition Classes
    Predictor
  4. def diagnose(e: VectoD, yy: VectoD, yp: VectoD, w: VectoD = null, ym_: Double = noDouble): Unit

    Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses.

    Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted.

    e

    the m-dimensional error/residual vector (yy - yp)

    yy

    the actual response/output vector to use (test/full)

    yp

    the predicted response/output vector (test/full)

    w

    the weights on the instances (defaults to null)

    ym_

    the mean of the actual response/output vector to use (training/full)

    Definition Classes
    FitQoF
    See also

    Regression_WLS

  5. def eval(y_e: VectoD = y): ForecasterVec

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    y_e

    the test/full actual response/output vector

    Definition Classes
    ForecasterVec
  6. def eval(x_e: MatriD, y_e: VectoD): ForecasterVec

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    x_e

    the test/full data/input matrix (ignored, pass null)

    y_e

    the test/full actual response/output vector

    Definition Classes
    ForecasterVecModel
  7. def eval_(e: VectoD = residuals, y: VectoD = y, yp: VectoD = predictAll ()): ARMA

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    e

    vector of residuals

    y

    vector of observed values

    yp

    vector of predicted values

  8. def evalf(y_e: VectoD, yf: VectoD): ForecasterVec

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    Compute the error (difference between actual and predicted) and useful diagnostics for the dataset.

    y_e

    the test/full actual response/output vector

    yf

    the vector of forecasts

    Definition Classes
    ForecasterVec
  9. def f_(z: Double): String

    Format a double value.

    Format a double value.

    z

    the double value to format

    Definition Classes
    QoF
  10. def fit: VectoD

    Return the Quality of Fit (QoF) measures corresponding to the labels given above in the 'fitLabel' method.

    Return the Quality of Fit (QoF) measures corresponding to the labels given above in the 'fitLabel' method. Note, if 'sse > sst', the model introduces errors and the 'rSq' may be negative, otherwise, R^2 ('rSq') ranges from 0 (weak) to 1 (strong). Override to add more quality of fit measures.

    Definition Classes
    FitQoF
  11. def fitLabel: Seq[String]

    Return the labels for the Quality of Fit (QoF) measures.

    Return the labels for the Quality of Fit (QoF) measures. Override to add additional QoF measures.

    Definition Classes
    FitQoF
  12. def fitMap: Map[String, String]

    Build a map of quality of fit measures (use of LinkedHashMap makes it ordered).

    Build a map of quality of fit measures (use of LinkedHashMap makes it ordered).

    Definition Classes
    QoF
  13. final def flaw(method: String, message: String): Unit
    Definition Classes
    Error
  14. def forecast(t: Int = y.dim, h: Int = 1): VectoD

    Produce h-steps-ahead forecast for ARMA models.

    Produce h-steps-ahead forecast for ARMA models.

    t

    the time point from which to make forecasts (in the original scale)

    h

    the number of steps to forecast, must be at least one.

    Definition Classes
    ARMAForecasterVec
    See also

    ams.sunysb.edu/~zhu/ams586/Forecasting.pdf

  15. def forecast(yf: MatriD, t: Int, h: Int): VectoD

    Produce a vector of size 'h', of 1 through 'h'-steps ahead forecasts for the model.

    Produce a vector of size 'h', of 1 through 'h'-steps ahead forecasts for the model.

    forecast the following time points: t, t+1, ..., t-1+h.

    Note, invoke 'forecastAll' to create the 'yf' matrix.

    yf

    the y-forecast matrix for all time and horizons

    t

    the time point from which to make forecasts

    h

    the forecasting horizon, number of steps ahead to produce forecasts

    Definition Classes
    ForecasterVec
  16. def forecastAll(h: Int = 1): MatriD

    Forecast values for all time points using 1 through 'h'-steps ahead forecasts.

    Forecast values for all time points using 1 through 'h'-steps ahead forecasts. The 'h'-th row of matrix is the horizon 'h' forecast (where 'h = 0' is actual data).

    h

    the forecasting horizon, number of steps ahead to produce forecasts

    Definition Classes
    ARMAForecasterVec
  17. def forecastAll(h: Int, p: Int): MatriD

    Forecast values for all time points using 1 through 'h'-steps ahead forecasts.

    Forecast values for all time points using 1 through 'h'-steps ahead forecasts. The 'h'-th row of matrix is the horizon 'h' forecast (where 'h = 0' is actual data).

    h

    the forecasting horizon, number of steps ahead to produce forecasts, must be > 0

    p

    the order of the model (e.g, p in AR, q in MA) or number of values to use in making forecasts, must be > 0

    Definition Classes
    ForecasterVec
  18. def forecastAll2(h: Int): MatriD

    Forecast values for all 'm' time points and all horizons (1 through 'h'-steps ahead).

    Forecast values for all 'm' time points and all horizons (1 through 'h'-steps ahead). Record these in the 'yf' matrix, where

    yf(t, k) = k-steps ahead forecast for y_t

    Note, 'yf.col(0)' is set to 'y' (the actual time-series values). Do not forecast errors, rather use observed errors from training and make sure not to use errors that would correspond to knowing future errors (all future errors should be assumed to be 0).

    h

    the maximum forecasting horizon, number of steps ahead to produce forecasts

    See also

    https://otexts.com/fpp3/arima-forecasting.html, section 9.8

  19. def forecastX(y: VectoD, t: Int, h: Int = 1): Double

    Produce h-steps ahead forecast on the testing data during cross validation.

    Produce h-steps ahead forecast on the testing data during cross validation. Likely to need overriding.

    y

    the current response vector

    t

    the time point/index to be forecast

    h

    the forecasting horizon, number of steps ahead to produce forecast

    Definition Classes
    ForecasterVec
  20. def forwardSel(cols: Set[Int] = null, index_q: Int = index_rSq): (Int, ARMA)

    Perform forward selection to find the most predictive variables to add the existing model, returning the variables to add and the new model.

    Perform forward selection to find the most predictive variables to add the existing model, returning the variables to add and the new model. Note, all lags up and including 'p' define the model. FIX - select subsets of the lags, e.g., Set (1, 2, 5)

    cols

    the lags/columns currently included in the existing model (ignored)

    index_q

    index of Quality of Fit (QoF) to use for comparing quality

    Definition Classes
    ARMAForecasterVecPredictor
    See also

    Fit for index of QoF measures.

  21. def forwardSel2(step: VectoI = VectorI (1, 1), cols: Set[Int] = null, index_q: Int = index_rSq): (Int, ARMA)

    Perform forward selection to find the most predictive variables to add the existing model, returning the variables to add and the new model.

    Perform forward selection to find the most predictive variables to add the existing model, returning the variables to add and the new model. Note, all lags up and including 'p' define the model. FIX - select subsets of the lags, e.g., Set (1, 2, 5)

    step

    the amount to increment p and q for each iteration

    cols

    the lags/columns currently included in the existing model (ignored)

    index_q

    index of Quality of Fit (QoF) to use for comparing quality

    See also

    Fit for index of QoF measures.

  22. def getX: MatriD

    Return the 'used' data matrix 'x' (for such models, it's null).

    Return the 'used' data matrix 'x' (for such models, it's null).

    Definition Classes
    ForecasterVecPredictor
  23. def getY: VectoD

    Return the 'used' response vector 'y'.

    Return the 'used' response vector 'y'. Mainly for derived classes where 'y' is transformed, e.g., TranRegression, Regression4TS.

    Definition Classes
    ForecasterVecPredictor
  24. def help: String

    Return the help string that describes the Quality of Fit (QoF) measures provided by the Fit class.

    Return the help string that describes the Quality of Fit (QoF) measures provided by the Fit class. Override to correspond to 'fitLabel'.

    Definition Classes
    FitQoF
  25. def hparameter: HyperParameter

    Return the hyper-parameters.

    Return the hyper-parameters.

    Definition Classes
    ForecasterVecModel
  26. def init(v: VectoD): Unit

    Initialize variables based on working time-series 'v'.

    Initialize variables based on working time-series 'v'. Note, 'z', the centered time series, is computed later based on the MLE estimated mean μ.

    v

    the working vector/time-series

  27. def ll(ms: Double = mse0, s2: Double = sig2e, m2: Int = m): Double

    The log-likelihood function times -2.

    The log-likelihood function times -2. Override as needed.

    ms

    raw Mean Squared Error

    s2

    MLE estimate of the population variance of the residuals

    Definition Classes
    Fit
    See also

    www.stat.cmu.edu/~cshalizi/mreg/15/lectures/06/lecture-06.pdf

    www.wiley.com/en-us/Introduction+to+Linear+Regression+Analysis%2C+5th+Edition-p-9780470542811 Section 2.11

  28. val modelConcept: URI

    An optional reference to an ontological concept

    An optional reference to an ontological concept

    Definition Classes
    Model
  29. def modelName: String

    Return the model name including its current hyper-parameters, e.g., ARMA(2, 1).

    Return the model name including its current hyper-parameters, e.g., ARMA(2, 1).

    Definition Classes
    ARMAModel
  30. def mse_: Double

    Return the mean of squares for error (sse / df._2).

    Return the mean of squares for error (sse / df._2). Must call diagnose first.

    Definition Classes
    Fit
  31. def nll(b: VectoD): Double

    The negative log-likelihood function to be minimized.

    The negative log-likelihood function to be minimized.

    b

    the input parameter vector

    See also

    math.unice.fr/~frapetti/CorsoP/Chapitre_4_IMEA_1.pdf, page 36

    spia.uga.edu/faculty_pages/monogan/teaching/ts/Barima.pdf

    stats.stackexchange.com/questions/77663/arima-estimation-by-hand

  32. def pacF: VectoD

    Return the partial autocorrelation.

    Return the partial autocorrelation. Must call 'train' first.

    Definition Classes
    ForecasterVec
  33. def parameter: VectoD

    Return the parameter vector (φ concatenated with θ).

    Return the parameter vector (φ concatenated with θ).

    Definition Classes
    ARMAModel
  34. def plotFunc(fVec: VectoD, name: String, show: Boolean = true): Unit

    Plot a function, e.g., Auto-Correlation Function 'ACF', Partial Auto-Correlation Function 'PACF'.

    Plot a function, e.g., Auto-Correlation Function 'ACF', Partial Auto-Correlation Function 'PACF'.

    fVec

    the vector given function values

    name

    the name of the function

    show

    whether to show the fVec values

    Definition Classes
    ForecasterVec
  35. def plotFunc2(fVec: VectoD, name: String, show: Boolean = true): Unit

    Plot a function, e.g., Auto-Correlation Function 'ACF', Partial Auto-Correlation Function 'PACF' with confidence bound.

    Plot a function, e.g., Auto-Correlation Function 'ACF', Partial Auto-Correlation Function 'PACF' with confidence bound.

    fVec

    the vector given function values

    name

    the name of the function

    show

    whether to show the fVec values

    Definition Classes
    ForecasterVec
  36. def predict(z: MatriD): VectoD

    Predict the value of 'y = f(z)' for each row of matrix 'z'.

    Predict the value of 'y = f(z)' for each row of matrix 'z'.

    z

    the new matrix to predict

    Definition Classes
    ForecasterVecPredictor
  37. def predict(y_null: VectoD = null): Double

    Return the horizon 1 forecast beyond the end of the time-series.

    Return the horizon 1 forecast beyond the end of the time-series.

    y_null

    the actual response/output vector to use (ignored)

    Definition Classes
    ForecasterVecPredictor
  38. def predict(z: VectoI): Double

    Given a new discrete data/input vector 'z', predict the 'y'-value of 'f(z)'.

    Given a new discrete data/input vector 'z', predict the 'y'-value of 'f(z)'.

    z

    the vector to use for prediction

    Definition Classes
    Predictor
  39. def predictAll(): VectoD

    Return the vector of predicted/fitted values on the training/full dataset.

    Return the vector of predicted/fitted values on the training/full dataset. Based on 'zp' calculated in the 'updateFittedValues' method.

    Definition Classes
    ARMAForecasterVec
  40. def predictAllz(): VectoD

    Return the vector of zero-centered predicted/fitted values on the training/full dataset.

    Return the vector of zero-centered predicted/fitted values on the training/full dataset. Based on 'zp' calculated in the 'updateFittedValues' method.

    Definition Classes
    ARMAForecasterVec
  41. def report: String

    Return a basic report on the trained model.

    Return a basic report on the trained model.

    Definition Classes
    ForecasterVecModel
  42. def resetDF(df_update: PairD): Unit

    Reset the degrees of freedom to the new updated values.

    Reset the degrees of freedom to the new updated values. For some models, the degrees of freedom is not known until after the model is built.

    df_update

    the updated degrees of freedom (model, error)

    Definition Classes
    Fit
  43. def residual: VectoD

    Return the vector of residuals/errors.

    Return the vector of residuals/errors.

    Definition Classes
    ForecasterVecPredictor
  44. def residuals: VectoD

    Obtain residuals/errors in the original scale.

  45. def setPQ(pq: VectoI): ARMA

    Set values for the model orders 'p' and 'q'.

    Set values for the model orders 'p' and 'q'. Note, intercept/mean counts as a parameter for the time series.

    pq

    the vector of model orders

  46. def showParameterEstimates(): Unit

    Show estimates for parameters.

  47. def summary(b: String, modelEq: String): String

    Return a detailed summary of the trained model.

    Return a detailed summary of the trained model.

    b

    the symbol(s) used for the parameters

    modelEq

    the model equation as a string

    Definition Classes
    ForecasterVec
  48. def summary(b: VectoD, stdErr: VectoD, vf: VectoD, show: Boolean = false): String

    Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.

    Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.

    b

    the parameters/coefficients for the model

    vf

    the Variance Inflation Factors (VIFs)

    show

    flag indicating whether to print the summary

    Definition Classes
    Fit
  49. def test(modelName: String, doPlot: Boolean = true): Unit

    Test the model on the full dataset (i.e., train and evaluate on full dataset).

    Test the model on the full dataset (i.e., train and evaluate on full dataset).

    modelName

    the name of the model being tested

    doPlot

    whether to plot the actual vs. predicted response

    Definition Classes
    Predictor
  50. def train(): ARMA

    Train/fit an ARMA model to the times series data.

    Train/fit an ARMA model to the times series data. Must call 'setPQ' first. It uses BFGS, a Quasi-Newton optimizer, to minimize the negative log-likelihood.

  51. def train(x_null: MatriD, y_: VectoD): ForecasterVec

    Given a time-series 'y_', train the forecasting function 'y = f(y_)', where 'f(y_)' is a function of the lagged values of 'y_', by fitting its parameters.

    Given a time-series 'y_', train the forecasting function 'y = f(y_)', where 'f(y_)' is a function of the lagged values of 'y_', by fitting its parameters.

    x_null

    the training/full data/input matrix (ignored, pass 'null')

    y_

    the training/full response/output vector

    Definition Classes
    ForecasterVecModel
  52. def updateFittedValues(): Double

    Update the vector of fitted values 'zp', the vector of errors 'e', and return the negative log-likelihood '-ll'.

    Update the vector of fitted values 'zp', the vector of errors 'e', and return the negative log-likelihood '-ll'.

    See also

    Fit for definition of 'll'.