The type double function is imsls_d_estimate_missing.
Required Arguments
int n_obs (Input) Number of non-missing observations in the time series. The time series must not contain gaps with more than 3 missing values.
int tpoints[] (Input) Vector of length n_obs containing the time points at which the time series values were observed. The time points must be in strictly increasing order. Time points for missing values must lie in the open interval .
float z[] (Input) Vector of length n_obs containing the time series values. The values must be ordered in accordance with the values in vector tpoints. It is assumed that the time series after estimation of missing values contains values at equidistant time points where the distance between two consecutive time points is one. If the non-missing time series values are observed at time points t1, …tn_obs, then missing values between ti and ti+1, i = 1, …, n_obs- 1 , exist if ti+1-ti > 1. The size of the gap between ti and ti+1 is then ti+1-ti- 1. The total length of the time series with non-missing and estimated missing values is tn_obs-ti + 1, or tpoints[n_obs‑1]‑tpoints[0]+1.
Return Value
Pointer to an array of length (tpoints[n_obs-1]-tpoints[0]+1) containing the time series together with estimates for the missing values. If an error occurred, NULL is returned.
IMSLS_METHOD, int method (Input) The method used for estimating the missing values:
Index
Description
0
Use median.
1
Use cubic spline interpolation.
2
Use one-step-ahead forecasts from an AR(1) model.
3
Use one-step-ahead forecasts from an AR(p) model.
If method = 2 is chosen, then all values of gaps beginning at time points or are estimated by method 0. If method= 3 is chosen and the first gap starts at , then the values of this gap are also estimated by method 0. If the length of the series before a gap, denoted len, is greater than 1 and less than 2⋅maxlag, then maxlag is reduced to len/2 for the computation of the missing values within this gap.
Default: method = 3
IMSLS_MAX_LAG, intmaxlag (Input) Maximum lag number when method= 3 was chosen.
Default: maxlag= 10
IMSLS_NTIMES, int *ntimes (Output) Number of elements in the time series with estimated missing values. Note that ntimes = tpoints[n_obs-1]-tpoints[0]+1.
IMSLS_MEAN_ESTIMATE, float mean_estimate (Input) Estimate of the mean of the time series.
IMSLS_RELATIVE_ERROR, float relative_error (Input) Stopping criterion for use in the nonlinear equation solver used by method 2.
Default: relative_error = 100 ×imsls_f_machine(4) for single precision, relative_error = 100 ×imsls_d_machine(4) for double precision.
IMSLS_MAX_ITERATIONS, int max_iterations (Input) Maximum number of iterations allowed in the nonlinear equations solver used by method 2.
Default: max_iterations= 200.
IMSLS_TIMES_ARRAY, int**times (Output) Address of a pointer to an internally allocated array of length ntimes=tpoints[n_obs-1]-tpoints[0]+1 containing the time points of the time series with estimates for the missing values.
IMSLS_TIMES_ARRAY_USER, inttimes[] (Output) Storage for array times is provided by the user. See IMSLS_TIMES_ARRAY.
IMSLS_MISSING_INDEX, int**missing_index (Output) Address of a pointer to an internally allocated array of length (ntimes-n_obs) containing the indices for the missing values in array times. If ntimes-n_obs = 0, then no missing value could be found and NULL is returned.
IMSLS_MISSING_INDEX_USER, intmissing_index[] (Output) Storage for array missing_index is provided by the user. See IMSLS_MISSING_INDEX.
IMSLS_RETURN_USER, floatu_z[] (Output) If specified, u_z is a vector of length tpoints[n_obs‑1]-tpoints[0]+1 containing the time series values together with estimates for missing values.
Description
Traditional time series analysis as described by Box, Jenkins and Reinsel (1994) requires the observations made at equidistant time points . When observations are missing, the problem occurs to determine suitable estimates. Function imsls_f_estimate_missing offers 4 estimation methods:
Method 0 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 1 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 2 assumes that the time series before the gap can be well described by an AR(1) process. If the last observation prior to the gap is made at time point then it uses the time series values at to compute the one-step-ahead forecast at origin . This value is taken as an estimate for the missing value at time point . If the value at is also missing then the values at time points are used to recompute the AR(1) model, estimate the value at and so on. The coefficient in the AR(1) model is computed internally by the method of least squares from function imsls_f_arma.
Finally, method 3 uses an AR(p) model to estimate missing values by a one-step-ahead forecast . First, function imsls_f_auto_uni_ar, applied to the time series prior to the missing values, is used to determine the optimum p from the set {0, 1, ..., max_lag} of possible values and to compute the parameters 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 by μ the one-step-ahead forecast at origin , , can be computed by the formula
This value is used as an estimate for the missing value. The procedure starting with imsls_f_auto_uni_ar is then repeated for every further missing value in the gap. All four estimation methods treat gaps of missing values in increasing time order.
Example
Consider the AR(1) process
We assume that {at} is a Gaussian white noise process, . Then, E[Yt] = 0 and (see Anderson, p. 174).
The time series in the code below was artificially generated from an AR(1) process characterized by and . This process is stationary with VAR[Yt] = 1. As initial value, was taken. The sequence {at} was generated by a random number generator.
From the original series, we remove the observations at time points t=130, t=140, t=141, t=160, t=175, t=176. Then, imsls_f_estimate_missing is used to compute estimates for the missing values by all 4 estimation methods available. The estimated values are compared with the actual values.
#include <imsls.h>
#include <stdio.h>
#include <math.h>
int main()
{
int i, j, k, maxlag = 20, times_1[200], times_2[200], ntemp,