MARSSresiduals.tt | R Documentation |
Calculates the standardized (or auxiliary) contemporaneous residuals, aka the residuals and their variance conditioned on the data up to time t
. Contemporaneous residuals are only for the observations. Not exported. Access this function with MARSSresiduals(object, type="tt")
.
MARSSresiduals.tt(object, method = c("SS"), normalize = FALSE,
silent = FALSE, fun.kf = c("MARSSkfas", "MARSSkfss"))
object |
An object of class |
method |
Algorithm to use. Currently only "SS". |
normalize |
TRUE/FALSE See details. |
silent |
If TRUE, don't print inversion warnings. |
fun.kf |
Can be ignored. This will change the Kalman filter/smoother function from the value in object$fun.kf if desired. |
This function returns the conditional expected value (mean) and variance of the model contemporaneous residuals. 'conditional' means in this context, conditioned on the observed data up to time t
and a set of parameters.
Model residuals
\mathbf{v}_t
is the difference between the data and the predicted data at time t
given \mathbf{x}_t
:
\mathbf{v}_t = \mathbf{y}_t - \mathbf{Z} \mathbf{x}_t - \mathbf{a} - \mathbf{d}\mathbf{d}_{t}
The observed model residuals \hat{\mathbf{v}}_t
are the difference between the observed data and the predicted data at time t
using the fitted model. MARSSresiduals.tt
fits the model using the data up to time t
. So
\hat{\mathbf{v}}_t = \mathbf{y}_t - \mathbf{Z}\mathbf{x}_t^{t} - \mathbf{a} - \mathbf{D}\mathbf{d}_{t}
where \mathbf{x}_t^{t}
is the expected value of \mathbf{X}_t
conditioned on the data from 1 to t
from the Kalman filter. \mathbf{y}_t
are your data and missing values will appear as NA. These will be returned in residuals
.
var.residuals
returned by the function is the conditional variance of the residuals conditioned on the data up to t
and the parameter set \Theta
. The conditional variance is
\hat{\Sigma}_t = \mathbf{R}+\mathbf{Z} \mathbf{V}_t^{t} \mathbf{Z}^\top
where \mathbf{V}_t^{t}
is the variance of \mathbf{X}_t
conditioned on the data up to time t
. This is returned by MARSSkfss
in Vtt
.
Standardized residuals
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 unlike marginal residuals.
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 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.
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
\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).
MARSSresiduals()
returns the residuals defined as in the first equations. To get normalized residuals (second equation) as used in Harvey et al. (1998), then use normalize=TRUE
. In that case the unconditional variance of residuals will be \mathbf{I}
instead of \mathbf{R}
and \mathbf{Q}
. Note, that the normalized residuals are not the same as the standardized residuals. In former, the unconditional residuals have a variance of \mathbf{I}
while in the latter it is the conditional residuals that have a variance of \mathbf{I}
.
A list with the following components
model.residuals |
The observed contemporaneous model residuals: data minus the model predictions conditioned on the data 1 to t. A n x T matrix. NAs will appear where the data are missing. |
state.residuals |
All NA. There are no contemporaneous residuals for the states. |
residuals |
The residuals. |
var.residuals |
The joint variance of the residuals conditioned on observed data from 1 to t-. This only has values in the 1:n,1:n upper block for the model residuals. |
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 |
Because state residuals do not exist, this will be equivalent to the Cholesky standardized residuals, |
E.obs.residuals |
The expected value of the model residuals conditioned on the observed data 1 to t. Returned as a n x T matrix. |
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.
MARSSresiduals.tT()
, MARSSresiduals.tt1()
, fitted.marssMLE()
, plot.marssMLE()
dat <- t(harborSeal)
dat <- dat[c(2,11),]
fit <- MARSS(dat)
# Returns a matrix
MARSSresiduals(fit, type="tt")$std.residuals
# Returns a data frame in long form
residuals(fit, type="tt")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.