
Robust Outlier-Adjusted Mean-Shift Estimation of State-Space Models
Source:R/roams_SSM.R
roams_SSM.RdFits a robust state-space model to time-varying data using iterative parameter estimation and outlier detection. This procedure is inspired by the Iterative Procedure for Outlier Detection (IPOD) algorithm of She and Owen (2011) and is applied over a sequence of regularization parameters (\(\lambda\)'s), identifying outliers via Mahalanobis residuals and re-fitting the model iteratively.
Arguments
- y
A numeric matrix of observations, with each row corresponding to a time point.
- init_par
A numeric vector of initial parameter values for optimization.
- build
A function whose first argument is a parameter vector and that returns a
dlmmodel (as used indlm::dlmMLE()). Thespecify_SSMfunction can be used to create thisbuildfunction. Additional named arguments can be declared inbuildand supplied viabuild_args.- build_args
An optional named list of additional arguments to forward to
buildon every call. For example,build_args = list(u = covariate_matrix)allowsbuildto be written asfunction(par, u) { ... }without requiring a closure or factory function. Default islist().- num_lambdas
Integer. The number of \(\lambda\) values to evaluate. Ignored if
custom_lambdasis specified. Default is 20.- custom_lambdas
Optional numeric vector. If supplied, these are the exact \(\lambda\) values used for model fitting. If not provided or set to
NA, thennum_lambdas\(\lambda\)'s are automatically chosen.- cores
Integer. Number of CPU cores to use for parallel processing. Default is 1 (sequential execution).
- B
Integer. Maximum number of iterations per \(\lambda\). Default is 50.
- lower
Optional numeric vector of lower bounds for optimization. If
NA, defaults to-Inffor all parameters. Must be of same length asinit_par.- upper
Optional numeric vector of upper bounds for optimization. If
NA, defaults toInffor all parameters. Must be of same length asinit_par.- tol
Tolerance level for checking convergence of the ROAMS procedure. Default is
1e-4.- lambda_min
Minimum \(\lambda\) value to consider when constructing the sequence of \(\lambda\)'s. Ignored if
custom_lambdasis specified. Default is 2.- excessive_outliers_iter_limit
Integer. Maximum number of iterations allowed where \(\ge 50\%\) of timepoints are flagged as outliers. This many outliers suggests \(\lambda\) is too low. Allows ROAMS to get through these \(\lambda\)'s quicker. Default is 1.
- control
A named list of control options to pass to
optimviadlm::dlmMLE(). Default islist(parscale = init_par), which can help the optimizer if parameters are on vastly different scales.- thresholding
Character string specifying the outlier thresholding rule. Either
"hard"(default) or"soft". Hard thresholding fully removes flagged observations (sets them to missing), corresponding to an L0 penalty on the outlier shifts \(\pmb{\gamma}\). Soft thresholding applies a continuous LASSO shrinkage to each \(\pmb{\gamma}_t\), partially adjusting observations rather than discarding them entirely, which corresponds to an L1 penalty.
Value
If more than one \(\lambda\) values are used, returns an object of class roams_SSM_list — a list containing a roams_SSM model for each \(\lambda\). If only one \(\lambda\) value is used (i.e. custom_lambdas is manually specified as a single value), returns a single roams_SSM object.
Each roams_SSM object includes:
lambda- The \(\lambda\) value used.prop_outlying- Proportion of non-missing time points identified as outliers.BIC- Bayesian Information Criterion of the final model.loglik- Log-likelihood of the fitted model.RSS- Residual sum of squares.gamma- Matrix of estimated outlier adjustments.iterations- Number of iterations performed.Optimization output from
dlm::dlmMLE()from the final iteration.y- The original data matrix.build- The original build function used to specify the model.
Details
The ROAMS procedure alternates between estimating model parameters via maximum likelihood and identifying outlying observations based on Mahalanobis distance of residuals. For each iteration:
A
dlmmodel is fit usingdlm::dlmMLE().Mahalanobis distance of residuals (Mahalanobis residuals) are computed.
Outlier shift estimates \(\pmb{\gamma}_t\) are updated using the selected thresholding rule.
The adjusted data
adj_yis updated and passed to the next iteration.
Under hard thresholding, observations whose penalised Mahalanobis score \(d_t^2 + \log|\mathbf{S}_{t|t-1}|\) exceeds \(\lambda^2\) are fully removed (set to missing), equivalent to setting \(\hat{\pmb{\gamma}}_t = \mathbf{r}_t\). Under soft thresholding, a LASSO shrinkage operator is applied: \(\hat{\pmb{\gamma}}_t = \max(1 - \lambda / d_t,\, 0)\, \mathbf{r}_t\), where \(d_t\) is the Mahalanobis distance of the one-step-ahead residual. Partial adjustments are retained in the data (adj_y = y - gamma) rather than treating observations as missing.
The algorithm stops when the change in parameters and outlier estimates is sufficiently small or if too many outliers are detected (more than 50% of complete observations).