# impute_AR1_Gaussian: Impute missing values of time series based on a Gaussian... In imputeFin: Imputation of Financial Time Series with Missing Values and/or Outliers

## Description

Impute inner missing values (excluding leading and trailing ones) of time series by drawing samples from the conditional distribution of the missing values given the observed data based on a Gaussian AR(1) model as estimated with the function `fit_AR1_Gaussian`. Outliers can be detected and removed.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```impute_AR1_Gaussian( y, n_samples = 1, random_walk = FALSE, zero_mean = FALSE, remove_outliers = FALSE, outlier_prob_th = 0.001, verbose = TRUE, return_estimates = FALSE, tol = 1e-10, maxiter = 100 ) ```

## Arguments

 `y` Time series object coercible to either a numeric vector or numeric matrix (e.g., `zoo` or `xts`) with missing values denoted by `NA`. `n_samples` Positive integer indicating the number of imputations (default is `1`). `random_walk` Logical value indicating if the time series is assumed to be a random walk so that `phi1 = 1` (default is `FALSE`). `zero_mean` Logical value indicating if the time series is assumed zero-mean so that `phi0 = 0` (default is `FALSE`). `remove_outliers` Logical value indicating whether to detect and remove outliers. `outlier_prob_th` Threshold of probability of observation to declare an outlier (default is `1e-3`). `verbose` Logical value indicating whether to output messages (default is `TRUE`). `return_estimates` Logical value indicating if the estimates of the model parameters are to be returned (default is `FALSE`). `tol` Positive number denoting the relative tolerance used as stopping criterion (default is `1e-8`). `maxiter` Positive integer indicating the maximum number of iterations allowed (default is `100`).

## Value

By default (i.e., for `n_samples = 1` and `return_estimates = FALSE`), the function will return an imputed time series of the same class and dimensions as the argument `y` with one new attribute recording the locations of missing values (the function `plot_imputed` will make use of such information to indicate the imputed values), as well as locations of outliers removed.

If `n_samples > 1`, the function will return a list consisting of `n_sample` imputed time series with names: y_imputed.1, y_imputed.2, etc.

If `return_estimates = TRUE`, in addition to the imputed time series `y_imputed`, the function will return the estimated model parameters:

 `phi0` The estimate for `phi0` (numeric scalar or vector depending on the number of time series). `phi1` The estimate for `phi1` (numeric scalar or vector depending on the number of time series). `sigma2` The estimate for `sigma2` (numeric scalar or vector depending on the number of time series).

## Author(s)

Junyan Liu and Daniel P. Palomar

## References

R. J. Little and D. B. Rubin, Statistical Analysis with Missing Data, 2nd ed. Hoboken, N.J.: John Wiley & Sons, 2002.

J. Liu, S. Kumar, and D. P. Palomar, "Parameter estimation of heavy-tailed AR model with missing data via stochastic EM," IEEE Trans. on Signal Processing, vol. 67, no. 8, pp. 2159-2172, 15 April, 2019.

`plot_imputed`, `fit_AR1_Gaussian`, `impute_AR1_t`
 ```1 2 3 4 5``` ```library(imputeFin) data(ts_AR1_Gaussian) y_missing <- ts_AR1_Gaussian\$y_missing y_imputed <- impute_AR1_Gaussian(y_missing) plot_imputed(y_imputed) ```