Class ARMAEstimateMissing
- All Implemented Interfaces:
Serializable
ARMA class.
Traditional time series analysis as described by Box, Jenkins and Reinsel
(1994) requires the observations be made at equidistant time points
\(t_0,t_1,\ldots,t_n\) where \(t_i = t_0 + i\). When observations are
missing, ARMA requires that they be replaced with suitable
estimates. Class ARMAEstimateMissing offers 4 methods for
estimating missing values: MEDIAN, CUBIC_SPLINE, AR_1, and
AR_P
Method MEDIAN estimates the missing observations in a gap by the
median of the last four time series values before and the first four values
after the gap. If not enough values are available before or after the gap
then the number is reduced accordingly. This method is very fast and simple,
but its use is limited to stationary ergodic series without outliers and
level shifts.
Method CUBIC_SPLINE uses a cubic spline interpolation method to
estimate missing values. Here the interpolation is again done over the last
four time series values before and the first four values after the gap. The
missing values are estimated by the resulting interpolant. This method gives
smooth transitions across missing values.
Method AR_1 assumes that the time series before the gap can be
approximated using an AR(1) process. If the last observation prior to the gap
is made at time point \(t_m\) then this method uses values at
\(t_0,t_1,\ldots,t_m\) to compute the one-step-ahead forecast at origin
\(t_m\). This value is used to estimate the missing value at time point \(t_m
+ 1\). If the value at \(t_m+2\) is also missing then the values at time
points \(t_0,t_1,\ldots,t_m+1\) are used to recompute the AR(1) model, and
then estimate the value at \(t_m+2\) and so on. The coefficient \(\phi_1\) in
the AR(1) model is computed internally by the method of least squares from
class ARMA.
Finally, method AR_P uses an AR(p) model to estimate missing
values using a one-step-ahead forecast similar to method AR_1.
First, class ARAutoUnivariate, is applied to the time series
values just prior to the missing values to determine the optimum
p from the set \(\{0,1,\ldots,\tt{maxlag}\}\) of possible values
and to compute the parameters \(\phi_1,\ldots,\phi_p\) of the resulting AR(p)
model. The parameters are estimated by the least squares method based on
Householder transformations as described in Kitagawa and Akaike (1978).
Denoting the mean of the series \(y_{t_0}, y_{t_1},\ldots,y_{t_m}\) by
\(\mu\) the one-step-ahead forecast at origin \(t_m,\,\, \hat{y_{t_m}}(1)\),
can be computed by the formula $$\hat{y_{t_m}}(1)=\mu(1 -
\sum\nolimits_{j=1}^p\phi_j)+\sum\nolimits_{j=1}^p\phi_j y_{t_m+1-j}\rm{.}$$
This value is used as an estimate for the missing value at \(t_{m+1}\). The
procedure starting with ARAutoUnivariate is then repeated for
every further missing value in the gap. All four estimation methods treat
gaps of missing values in increasing time order.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that missing values should be estimated using an autoregressive time series with 1 lag.static final intIndicates that missing values should be estimated using an autoregressive time series with a maximum lag ofmaxLag.static final intIndicates that missing values should be estimated using cublic spline interpolation.static final intEstimate autoregressive coefficients using least squares.static final intEstimate autoregressive coefficients using maximum likelihood.static final intIndicates that missing values should be estimated using the median of the values just before and after the missing value gap.static final intEstimate autoregressive coefficients using method of moments. -
Constructor Summary
ConstructorsConstructorDescriptionARMAEstimateMissing(int[] tpoints, double[] z) Constructor forARMAEstimateMissing. -
Method Summary
Modifier and TypeMethodDescriptionint[]Returns anintarray of all time points, including values for times with missing values inz.double[]Returns adoubleprecision vector of lengthtpoints[tpoints.length-1]-tpoints[0]+1containing the observed values in the time serieszplus estimates for missing values in gaps identified intpoints.doubleReturns the current value of convergence tolerance used by theAR_1andAR_Pestimation methods.intReturns the method used for estimating the final autoregressive coefficients for missing value estimation methodsAR_1andAR_P.intReturns the maximum number of estimation iterations used by missing value estimation methodsAR_1andAR_P.intReturns the current value of autoregressive lags used in theAR_Pestimation method.doublegetMean()Returns the mean value used to center the series.int[]Returns anintarray of the times with missing values.intReturns the current missing value estimation method.intReturns the number of missing values in the original seriesdoubleReturns the relative error used for theMETHOD_OF_MOMENTSandLEAST_SQARESestimation methods.voidsetConvergenceTolerance(double convergenceTolerance) Sets the covergence tolerance used by theAR_1andAR_Pmissing value estimation methods.voidsetEstimationMethod(int arEstimationMethod) Sets the method used for estimating the autoregressive coefficients for missing value estimation methodsAR_1andAR_P.voidsetMaxIterations(int maxIterations) Sets the maximum number of estimation iterations for missing value estimation methodsAR_1andAR_P.voidsetMaxlag(int maxlag) Sets the maximum number of autoregressive lags when methodAR_Pis selected as the missing value estimation method.voidsetMean(double mean) Sets the mean value used to center the series.voidsetMissingValueMethod(int method) Sets the current missing value estimation method toMEDIAN, CUBIC_SPLINE, AR_1,orAR_P.voidsetRelativeError(double relativeError) Sets the relative error used for theMETHOD_OF_MOMENTSandLEAST_SQUARESestimation methods.
-
Field Details
-
MEDIAN
public static final int MEDIANIndicates that missing values should be estimated using the median of the values just before and after the missing value gap.- See Also:
-
CUBIC_SPLINE
public static final int CUBIC_SPLINEIndicates that missing values should be estimated using cublic spline interpolation.- See Also:
-
AR_1
public static final int AR_1Indicates that missing values should be estimated using an autoregressive time series with 1 lag.- See Also:
-
AR_P
public static final int AR_PIndicates that missing values should be estimated using an autoregressive time series with a maximum lag ofmaxLag. By defaultmaxLag=10, but this can be changed using thesetMaxlagmethod.- See Also:
-
METHOD_OF_MOMENTS
public static final int METHOD_OF_MOMENTSEstimate autoregressive coefficients using method of moments.- See Also:
-
LEAST_SQUARES
public static final int LEAST_SQUARESEstimate autoregressive coefficients using least squares.- See Also:
-
MAX_LIKELIHOOD
public static final int MAX_LIKELIHOODEstimate autoregressive coefficients using maximum likelihood.- See Also:
-
-
Constructor Details
-
ARMAEstimateMissing
public ARMAEstimateMissing(int[] tpoints, double[] z) Constructor forARMAEstimateMissing.- Parameters:
tpoints- anintarray containing the times at which the series values were observed. The values must be strictly increasing. Times for missing values are identified as non-incremental gaps in this series. A gap of missing values inzis assumed when the difference between two consecutive values is greater than 1, i.e. \(t_{i+1}-t_i>1\). The difference is the number of missing values in the gap. The series can have multiple gaps with missing values, but any one gap can have no more than 3 missing values.z- adoublearray containing the values for the time series observed at the times given in the vectortpoints.
-
-
Method Details
-
getMissingValueMethod
public int getMissingValueMethod()Returns the current missing value estimation method.- Returns:
- an
intrepresenting the estimation method used for estimating the missing values in the time series. 0 impliesMEDIAN, 1 impliesCUBIC_SPLINE, 2 impliesAR_1and 3 impliesAR_P.
-
setMissingValueMethod
public void setMissingValueMethod(int method) Sets the current missing value estimation method toMEDIAN, CUBIC_SPLINE, AR_1,orAR_P.- Parameters:
method- Anintscalar. By defaultmethod=AR_1.
-
setEstimationMethod
public void setEstimationMethod(int arEstimationMethod) Sets the method used for estimating the autoregressive coefficients for missing value estimation methodsAR_1andAR_P.- Parameters:
arEstimationMethod- Anintscalar specifying the method used to estimate the autoregressive coefficients. Valid methods areMETHOD_OF_MOMENTS,LEAST_SQUARES, andMAX_LIKELIHOOD. By default,arEstimationMethod=LEAST_SQUARES.
-
getEstimationMethod
public int getEstimationMethod()Returns the method used for estimating the final autoregressive coefficients for missing value estimation methodsAR_1andAR_P.- Returns:
- an
intrepresenting the estimation method used for estimating the autoregressive coefficients. 0 implies METHOD_OF_MOMENTS, 1 implies LEAST_SQUARES, 2 implies MAX_LIKELIHOOD.
-
getMaxIterations
public int getMaxIterations()Returns the maximum number of estimation iterations used by missing value estimation methodsAR_1andAR_P.- Returns:
- An
intscalar equal to the maximum number of iterations for the maximum likelihood missing value estimation method. If this limit is exceeded during thecomputemethod, ARMAEstimateMissing stops execution and issues anARMAMaxLikelihood.IterationLimitExceededException.
-
getConvergenceTolerance
public double getConvergenceTolerance()Returns the current value of convergence tolerance used by theAR_1andAR_Pestimation methods.- Returns:
- a
doublescalar value equal to the convergence tolerance. By default the convergence tolerance is 1.0e-09.
-
setConvergenceTolerance
public void setConvergenceTolerance(double convergenceTolerance) Sets the covergence tolerance used by theAR_1andAR_Pmissing value estimation methods.- Parameters:
convergenceTolerance- Adoublescalar value. Default:convergenceTolerance= 1.0e-09
-
getRelativeError
public double getRelativeError()Returns the relative error used for theMETHOD_OF_MOMENTSandLEAST_SQARESestimation methods.- Returns:
- a
doublescalar containing the stopping criterion for use in the nonlinear equation solver used in both the method of moments and least-squares algorithm.
-
setRelativeError
public void setRelativeError(double relativeError) Sets the relative error used for theMETHOD_OF_MOMENTSandLEAST_SQUARESestimation methods.- Parameters:
relativeError- adoublescalar containing the stopping criterion for use in the nonlinear equation solver used in both the method of moments and least-squares algorithm. Default:relativeError= 2.22045e-14
-
setMaxIterations
public void setMaxIterations(int maxIterations) Sets the maximum number of estimation iterations for missing value estimation methodsAR_1andAR_P. If this limit is exceededARMAEstimateMissingstops execution during the compute method and issues anIterationLimitExceededException.- Parameters:
maxIterations- Anintspecifying the maximum number of iterations for the maximum likelihood estimation. By default,maxIterations=200.
-
getMaxlag
public int getMaxlag()Returns the current value of autoregressive lags used in theAR_Pestimation method.- Returns:
- An
intscalar value equal to the maximum number of autoregressive lags used with theAR_Pmissing value estimation method.
-
setMaxlag
public void setMaxlag(int maxlag) Sets the maximum number of autoregressive lags when methodAR_Pis selected as the missing value estimation method.- Parameters:
maxlag- Anintscalar value equal to the maximum number of autoregressive lags.maxlagmust be greater thanz.length-5. By defaultmaxlag=10.
-
getMean
public double getMean()Returns the mean value used to center the series.- Returns:
- a
doublescalar used to center the series.
-
setMean
public void setMean(double mean) Sets the mean value used to center the series.- Parameters:
mean- adoublescalar used to center the series. By default the median of the series is used for centering.
-
getNumberMissing
public int getNumberMissing()Returns the number of missing values in the original series- Returns:
- An
intscalar value containing the number of missing values in the time series.
-
getMissingTimes
public int[] getMissingTimes()Returns anintarray of the times with missing values.- Returns:
- An
intarray containing the times at which missing values were estimated. If there are no missing values anullarray is returned.
-
getCompleteTimes
public int[] getCompleteTimes()Returns anintarray of all time points, including values for times with missing values inz.- Returns:
- An
intarray of all times fromtpoints[0]=1totpoints.length+nMissing. WherenMissingis the number of values removed from the original time series,nMissing = getNumberMissing().
-
getCompleteTimeSeries
public double[] getCompleteTimeSeries() throws ARMA.MatrixSingularException, ARMA.TooManyCallsException, ARMA.IncreaseErrRelException, ARMA.NewInitialGuessException, ARMA.IllConditionedException, ARMA.TooManyITNException, ARMA.TooManyFcnEvalException, ARMA.TooManyJacobianEvalException, ARMA.ResidualsTooLargeException, ARAutoUnivariate.TriangularMatrixSingularException, ARMAMaxLikelihood.NonStationaryException, ARMAMaxLikelihood.NonInvertibleExceptionReturns adoubleprecision vector of lengthtpoints[tpoints.length-1]-tpoints[0]+1containing the observed values in the time serieszplus estimates for missing values in gaps identified intpoints.- Returns:
- A
doublearray of lengthtpoints[tpoints.length-1]-tpoints[0]+1containing the observed values in the time serieszplus estimates for missing values in gaps identified intpoints. - Throws:
ARAutoUnivariate.TriangularMatrixSingularException- is thrown if the input matrix to ARAutoUnivariate is singular. This can only occur with estimation methodAR_P.ARMA.MatrixSingularException- is thrown if the input matrix is singular.ARMA.TooManyCallsException- is thrown if the number of calls to the function has exceeded the maximum number of iterations times the number of moving average (MA) parameters + 1.ARMA.IncreaseErrRelException- is thrown if the bound for the relative error is too small.ARMA.NewInitialGuessException- is thrown if the iteration has not made good progress.ARMA.IllConditionedException- is thrown if the problem is ill-conditioned.ARMA.TooManyITNException- is thrown if the maximum number of iterations is exceeded.ARMA.TooManyFcnEvalException- is thrown if the maximum number of function evaluations is exceeded.ARMA.TooManyJacobianEvalException- is thrown if the maximum number of Jacobian evaluations is exceeded.ARMA.ResidualsTooLargeException- is thrown if the residuals computed in one step of the Least Squares estimation of the ARMA coefficients become too large.ARMAMaxLikelihood.NonStationaryException- is thrown if the final maximum likelihood estimates for the time series are non-stationary.ARMAMaxLikelihood.NonInvertibleException- is thrown if the final maximum likelihood estimates for the time series are noninvertible.ARMAMaxLikelihood.InitialMAException- is thrown if the initial values provided for the moving average terms usingsetMAare noninvertable. In this case,ARMAMaxLikelihoodterminates and does not compute the time series estimates.
-