MARSSresiduals.tt1 | R Documentation |
Calculates the standardized (or auxiliary) one-step-ahead residuals, aka the innovations residuals and their variance. Not exported. Access this function with MARSSresiduals(object, type="tt1")
. To get the residuals as a data frame in long-form, use residuals(object, type="tt1")
.
MARSSresiduals.tt1(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 one-step-ahead residuals. 'conditional' means in this context, conditioned on the observed data up to time t-1
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.tt1
fits the model using the data up to time t-1
. So
\hat{\mathbf{v}}_t = \mathbf{y}_t - \mathbf{Z}\mathbf{x}_t^{t-1} - \mathbf{a} - \mathbf{D}\mathbf{d}_t
where \mathbf{x}_t^{t-1}
is the expected value of \mathbf{X}_t
conditioned on the data from $t=1$ to t-1
from the Kalman filter. \mathbf{y}_t
are your data and missing values will appear as NA.
State residuals
\mathbf{w}_{t+1}
are the difference between the state at time t+1
and the expected value of the state at time t+1
given the state at time t
:
\mathbf{w}_{t+1} = \mathbf{x}_{t+1} - \mathbf{B} \mathbf{x}_{t} - \mathbf{u} - \mathbf{C}\mathbf{c}_{t+1}
The estimated state residuals \hat{\mathbf{w}}_{t+1}
are the difference between estimate of \mathbf{x}_{t+1}
minus the estimate using \mathbf{x}_{t}
.
\hat{\mathbf{w}}_{t+1} = \mathbf{x}_{t+1}^{t+1} - \mathbf{B}\mathbf{x}_{t}^t - \mathbf{u} - \mathbf{C}\mathbf{c}_{t+1}
where \mathbf{x}_{t+1}^{t+1}
is the Kalman filter estimate of the states at time t+1
conditioned on the data up to time t+1
and \mathbf{x}_{t}^t
is the Kalman filter estimate of the states at time t
conditioned on the data up to time t
.
The estimated state residuals \mathbf{w}_{t+1}
are returned in state.residuals
and rows n+1
to n+m
of residuals
. state.residuals[,t]
is \mathbf{w}_{t+1}
(notice time subscript difference). There are no NAs in the estimated state residuals (except for the last time step) as an estimate of the state exists whether or not there are associated data.
res1
and res2
in the code below will be the same.
dat <- t(harborSeal)[2:3,] TT <- ncol(dat) fit <- MARSS(dat) B <- coef(fit, type="matrix")$B U <- coef(fit, type="matrix")$U xt <- MARSSkfss(fit)$xtt[,1:(TT-1)] # t 1 to TT-1 xtp1 <- MARSSkfss(fit)$xtt[,2:TT] # t 2 to TT res1 <- xtp1 - B %*% xt - U %*% matrix(1,1,TT-1) res2 <- MARSSresiduals(fit, type="tt1")$state.residuals
Joint residual variance
In a state-space model, \mathbf{X}
and \mathbf{Y}
are stochastic, and the model and state residuals are random variables \hat{\mathbf{V}}_t
and \hat{\mathbf{W}}_{t+1}
. The joint distribution of \hat{\mathbf{V}}_{t}, \hat{\mathbf{W}}_{t+1}
is the distribution across all the different possible data sets that our MARSS equations with parameters \Theta
might generate. Denote the matrix of \hat{\mathbf{V}}_{t}, \hat{\mathbf{W}}_{t+1}
, as \widehat{\mathcal{E}}_{t}
. That distribution has an expected value (mean) and variance:
\textrm{E}[\widehat{\mathcal{E}}_t] = 0; \textrm{var}[\widehat{\mathcal{E}}_t] = \hat{\Sigma}_t
Our observed residuals residuals
are one sample from this distribution.
To standardize the observed residuals, we will use \hat{\Sigma}_t
. \hat{\Sigma}_t
is returned in var.residuals
. Rows/columns 1 to n
are the conditional variances of the model residuals and rows/columns n+1
to n+m
are the conditional variances of the state residuals. The off-diagonal blocks are the covariances between the two types of residuals. For one-step-ahead residuals (unlike smoothation residuals MARSSresiduals.tT), the covariance is zero.
var.residuals
returned by this function is the conditional variance of the residuals conditioned on the data up to t-1
and the parameter set \Theta
. The conditional variance for the model residuals is
\hat{\Sigma}_t = \mathbf{R}+\mathbf{Z}_t \mathbf{V}_t^{t-1} \mathbf{Z}_t^\top
where \mathbf{V}_t^{t-1}
is the variance of \mathbf{X}_t
conditioned on the data up to time t-1
. This is returned by MARSSkf
in Vtt1
. The innovations variance is also returned in Sigma
from MARSSkf
and are used in the innovations form of the likelihood calculation.
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.
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 one-step-ahead case, the model and state residuals are independent (unlike in the smoothations case) thus the Cholesky and Block Cholesky standardized residuals will be identical (unlike in the smoothations case).
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 the residuals defined as Harvey et al. (1998) define them (second equations), then use normalize=TRUE
. In that case the unconditional variance of residuals will be \mathbf{I}
instead of \mathbf{Q}
and \mathbf{R}
. 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 the observed one-step-ahead model residuals: data minus the model predictions conditioned on the data |
state.residuals |
The one-step-ahead state residuals |
residuals |
The residuals conditioned on the observed data up to time |
var.residuals |
The joint variance of the one-step-ahead residuals. Returned as a n+m x n+m x T matrix. |
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 |
var.obs.residuals |
For one-step-ahead residuals, this will be the same as the 1:n, 1:n upper diagonal block in |
msg |
Any warning messages. This will be printed unless |
Eli Holmes, NOAA, Seattle, USA.
R. H. Shumway and D. S. Stoffer (2006). Section on the calculation of the likelihood of state-space models in Time series analysis and its applications. Springer-Verlag, New York.
Holmes, E. E. 2014. Computation of standardized residuals for (MARSS) models. Technical Report. arXiv:1411.0045.
MARSSresiduals.tT()
, MARSSresiduals.tt()
, fitted.marssMLE()
, plot.marssMLE()
dat <- t(harborSeal)
dat <- dat[c(2,11),]
fit <- MARSS(dat)
MARSSresiduals(fit, type="tt1")$std.residuals
residuals(fit, type="tt1")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.