View source: R/MARSSresiduals.R
MARSSresiduals | R Documentation |
The normal residuals function is residuals()
. MARSSresiduals()
returns residuals as a list of matrices while residuals()
returns the same information in a data frame. This function calculates the residuals, residuals variance, and standardized residuals for the one-step-ahead (conditioned on data up to t-1
), the smoothed (conditioned on all the data), and contemporaneous (conditioned on data up to t
) residuals.
MARSSresiduals(object, ..., type = c("tT", "tt1", "tt"),
normalize = FALSE, silent = FALSE,
fun.kf = c("MARSSkfas", "MARSSkfss"))
object |
An object of class |
... |
Additional arguments to be passed to the residuals functions. For type="tT", |
type |
|
normalize |
TRUE/FALSE See details. |
silent |
If TRUE, do not print inversion warnings. |
fun.kf |
Kalman filter function to use. Can be ignored. |
For smoothed residuals, see MARSSresiduals.tT()
.
For one-step-ahead residuals, see MARSSresiduals.tt1()
.
For contemporaneous residuals, see MARSSresiduals.tt()
.
Standardized residuals
Standardized residuals have been adjusted by the variance of the residuals at time t
such that the variance of the residuals at time t
equals 1. Given the normality assumption, this means that one typically sees +/- 2 confidence interval lines on standardized residuals plots.
std.residuals
are Cholesky standardized residuals. These are the residuals multiplied by the inverse of the lower triangle of the Cholesky decomposition of the variance matrix of the residuals:
\hat{\Sigma}_t^{-1/2} \hat{\mathbf{v}}_t.
These residuals are uncorrelated with each other, although they are not necessarily temporally uncorrelated (innovations residuals are temporally uncorrelated).
The interpretation of the Cholesky standardized residuals is not straight-forward when the \mathbf{Q}
and \mathbf{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 \textrm{MVN}(0,\mathbf{I})
space. For example, if v is 2x2 correlated errors with variance-covariance matrix \mathbf{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 multiplied 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{\mathbf{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.
The Block Cholesky standardized residuals are like the Cholesky standardized residuals except that the full variance-covariance matrix is not used, only the variance-covariance matrix for the model or state residuals (respectively) is used for standardization. For the model residuals, the Block Cholesky standardized residuals will be the same as the Cholesky standardized residuals because the upper triangle of the lower triangle of the Cholesky decomposition (which is what we standardize by) is all zero. For type="tt1"
and type="tt"
, the Block Cholesky standardized state residuals will be the same as the Cholesky standardized state residuals because in the former, the model and state residuals are uncorrelated and in the latter, the state residuals do not exist. For type="tT"
, the model and state residuals are correlated and the Block Cholesky standardized residuals will be different than the Cholesky standardized residuals.
Normalized residuals
If normalize=FALSE
, the unconditional variance of \mathbf{V}_t
and \mathbf{W}_t
are \mathbf{R}
and \mathbf{Q}
and the model is assumed to be written as
\mathbf{y}_t = \mathbf{Z} \mathbf{x}_t + \mathbf{a} + \mathbf{v}_t
\mathbf{x}_t = \mathbf{B} \mathbf{x}_{t-1} + \mathbf{u} + \mathbf{w}_t
If normalize=TRUE
, the model is assumed to be written as
\mathbf{y}_t = \mathbf{Z} \mathbf{x}_t + \mathbf{a} + \mathbf{H}\mathbf{v}_t
\mathbf{x}_t = \mathbf{B} \mathbf{x}_{t-1} + \mathbf{u} + \mathbf{G}\mathbf{w}_t
with the variance of \mathbf{V}_t
and \mathbf{W}_t
equal to \mathbf{I}
(identity).
Missing or left-out data
See the discussion of residuals for missing and left-out data in MARSSresiduals.tT()
.
A list of the following components
model.residuals |
The model residuals (data minus model predicted values) as a n x T matrix. |
state.residuals |
The state residuals. This is the state residual for the transition from |
residuals |
The residuals as a (n+m) x T matrix with |
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. The last time step will be all NA since the state residual is for |
std.residuals |
The Cholesky standardized residuals as a (n+m) x T matrix. This is |
mar.residuals |
The marginal standardized residuals as a (n+m) x T matrix. This is |
bchol.residuals |
The Block Cholesky standardized residuals as a (n+m) x T matrix. This is |
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 |
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 |
msg |
Any warning messages. This will be printed unless Object$control$trace = -1 (suppress all error messages). |
Eli Holmes, NOAA, Seattle, USA.
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()
, MARSSresiduals.tt1()
and MARSSresiduals.tt()
.
residuals.marssMLE()
, MARSSresiduals.tT()
, MARSSresiduals.tt1()
, plot.marssMLE()
dat <- t(harborSeal)
dat <- dat[c(2,11),]
fit <- MARSS(dat)
#state smoothed residuals
state.resids1 <- MARSSresiduals(fit, type="tT")$state.residuals
#this is the same as
states <- fit$states
Q <- coef(fit, type="matrix")$Q
state.resids2 <- states[,2:30]-states[,1:29]-matrix(coef(fit,type="matrix")$U,2,29)
#compare the two
cbind(t(state.resids1[,-30]), t(state.resids2))
#normalize to variance of 1
state.resids1 <- MARSSresiduals(fit, type="tT", 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
MARSSresiduals(fit, type="tt1")$std.residuals
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.