Learn R Programming

MARSS (version 3.10.12)

residuals.marssMLE: MARSS Residuals

Description

Calculates the residuals, residuals variance, and standardized residuals for both the one-step-ahead (conditioned on data up to t-1) and smoothed (conditioned on all the data) residuals.

Usage

# S3 method for marssMLE
residuals(object,..., conditioning=c("T", "t-1"), normalize=FALSE, silent=FALSE)

Arguments

object

An object of class marssMLE.

...

Additional arguments to be passed to the residuals functions. For conditioning="T", Harvey=TRUE can be passed into to use the Harvey et al (1998) algorithm.

conditioning

"T" for smoothed residuals and "t-1" for one-step-ahead residuals.

normalize

TRUE/FALSE

silent

If TRUE, do not print inversion warnings.

Value

Smoothed residuals

If conditioning="T", a list with the following components

model.residuals

The smoothed model residuals (data minus model predicted values) as a n x T matrix. The residuals are conditioned on all the data and the set of model parameters. Called the smoothations. This is different than the Kalman filter innovations which are conditioned on the data up to \(t-1\).

state.residuals

The smoothed state residuals.

residuals

The residuals as a (n+m) x T matrix with model.residuals on top and state.residuals below.

var.residuals

The variance of the model residuals and state residuals as a (n+m) x (n+m) x T matrix with the model residuals variance in rows/columns 1 to n and state residuals variances in rows/columns n+1 to n+m.

std.residuals

The Cholesky standardized residuals as a (n+m) x T matrix. This is residuals multiplied by the inverse of the Cholesky decomposition of var.residuals.

mar.residuals

The marginal standardized residuals as a (n+m) x T matrix. This is residuals multiplied by the inverse of the diagonal matrix formed by the square-root of the diagonal of var.residuals.

E.obs.residuals

The expected value of the model residuals conditioned on the observed data. Returned as a n x T matrix. For observed data, this will be the observed model residuals. For unobserved data, this will be 0 if \(\mathbf{R}\) is diagonal but non-zero if \(\mathbf{R}\) is non-diagonal. See MARSSresiduals.tT.

var.obs.residuals

The variance of the model residuals conditioned on the observed data. Returned as a n x n x T matrix. For observed data, this will be 0. See MARSSresiduals.tT.

msg

Any warning messages. This will be printed unless Object$control$trace = -1 (suppress all error messages).

One-step-ahead residuals

If conditioning="t-1", a list with the following components

residuals

The model residuals (data minus model predicted values), as a n x T matrix. The residuals are conditioned on the data up to time \(t-1\) and the set of model parameters. Called the innovations. Residuals associated with missing data will appear as NA.

var.residuals

The variance of the model residuals as a n x n x T matrix.

std.residuals

The Cholesky standardized model residuals as a n x T matrix. This is residuals multiplied by the inverse of the Cholesky decomposition of var.residuals.

mar.residuals

The marginal standardized model residuals as a n x T matrix. This is residuals multiplied by the inverse of the diagonal matrix formed by the square-root of the diagonal of var.residuals.

msg

Any warning messages. This will be printed unless Object$control$trace = -1 (suppress all error messages).

Details

For smoothed residuals, see MARSSresiduals.tT.

For one-step-ahead residuals, see MARSSresiduals.tt1.

Standardized residuals

std.residuals are Cholesky standardized residuals. These are the residuals muliplied by the inverse of the Cholesky decomposition of the variance matrix of the residuals: $$ \hat{\Sigma}_t^{-1/2} \hat{\mathbf{v}}_t.$$ These residuals are uncorrelated.

The interpretation of the Cholesky standardized residuals is not straight-forward when the Q and R variance-covariance matrices are non-diagonal. The residuals which were generated by a non-diagonal variance-covariance matrices are transformed into orthogonal residuals in MVN(0,I) space. For example, if v is 2x2 correlated errors with variance-covariance matrix R. The transformed residuals (from this function) for the i-th row of v is a combination of the row 1 effect and the row 1 effect plus the row 2 effect. So in this case, row 2 of the transformed residuals would not be regarded as solely the row 2 residual but rather how different row 2 is from row 1, relative to expected. If the errors are highly correlated, then the Cholesky standardized residuals can look rather non-intuitive.

mar.residuals are the marginal standardized residuals. These are the residuals muliplied by the inverse of the diagonal matrix formed from the square-root of the diagonal of the variance matrix of the residuals: $$ \textrm{dg}(\hat{\Sigma}_t)^{-1/2} \hat{v}_t,$$ where 'dg(A)' is the square matrix formed from the diagonal of A, aka diag(diag(A)). These residuals will be correlated if the variance matrix is non-diagonal.

Normalized residuals

If normalize=FALSE, the unconditional variance of \(V_t\) and \(W_t\) are R and Q and the model is assumed to be written as $$ y_t = Z x_t + a + v_t$$ $$ x_t = B x_{t-1} + u + w_t$$ If normalize=TRUE, the model is assumed to be written $$ y_t = Z x_t + a + Hv_t$$ $$ x_t = B x_{t-1} + u + Gw_t$$ with the variance of \(V_t\) and \(W_t\) equal to I (identity).

Missing or left-out data

See the discussion of smoothed residuals for missing and left-out data in MARSSresiduals.tT.

References

Holmes, E. E. 2014. Computation of standardized residuals for (MARSS) models. Technical Report. arXiv:1411.0045.

See also the discussion and references in MARSSresiduals.tT and MARSSresiduals.tt1.

See Also

MARSSresiduals.tT, MARSSresiduals.tt1, plot.marssMLE

Examples

Run this code
# NOT RUN {
  dat <- t(harborSeal)
  dat <- dat[c(2,11),]
  MLEobj <- MARSS(dat)
  
  #state smoothed residuals
  state.resids1 <- residuals(MLEobj)$state.residuals
  #this is the same as
  states <- MLEobj$states
  Q <- coef(MLEobj,type="matrix")$Q
  state.resids2 <- states[,2:30]-states[,1:29]-matrix(coef(MLEobj,type="matrix")$U,2,29)
  #compare the two
  cbind(t(state.resids1[,-30]), t(state.resids2))

  #normalize to variance of 1
  state.resids1 <- residuals(MLEobj, normalize=TRUE)$state.residuals
  state.resids2 <- (solve(t(chol(Q))) %*% state.resids2)
  cbind(t(state.resids1[,-30]), t(state.resids2))

  #one-step-ahead standardized residuals
  residuals(MLEobj, conditioning="t-1")$std.residuals
# }

Run the code above in your browser using DataLab