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"))
A list with the following components
The the observed one-step-ahead model residuals: data minus the model predictions conditioned on the data
The one-step-ahead state residuals
The residuals conditioned on the observed data up to time model.residuals
in rows 1 to n and state.residuals
in rows n+1 to n+m. NAs will appear in rows 1 to n in the places where data are missing.
The joint variance of the one-step-ahead residuals. Returned as a n+m x n+m x T matrix.
The Cholesky standardized residuals as a n+m x T matrix. This is residuals
multiplied by the inverse of the lower triangle of the Cholesky decomposition of var.residuals
. The model standardized residuals associated with the missing data are replaced with NA.
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
. The model marginal residuals associated with the missing data are replaced with NA.
The Block Cholesky standardized residuals as a (n+m) x T matrix. This is model.residuals
multiplied by the inverse of the lower triangle of the Cholesky decomposition of var.residuals[1:n,1:n,]
and state.residuals
multiplied by the inverse of the lower triangle of the Cholesky decomposition of var.residuals[(n+1):(n+m),(n+1):(n+m),]
.
The expected value of the model residuals conditioned on the observed data var.obs.residuals
are included for completeness since they are returned for MARSSresiduals.tT()
, but they are not relevant for one-step-ahead residuals. See the discussion there.
For one-step-ahead residuals, this will be the same as the 1:n, 1:n upper diagonal block in var.residuals
since none of the E.obs.residuals
are included for completeness since they are returned for MARSSresiduals.tT()
, but they are not relevant for one-step-ahead residuals. See the discussion there. Note, also included as a code check. They are computed differently, but var.obs.residuals
and var.residuals
should always be the same.
Any warning messages. This will be printed unless object$control$trace = -1
(suppress all error messages).
An object of class marssMLE
.
Algorithm to use. Currently only "SS".
TRUE/FALSE See details.
If TRUE, don't print inversion warnings.
Can be ignored. This will change the Kalman filter/smoother function from the value in object$fun.kf if desired.
Eli Holmes, NOAA, Seattle, USA.
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
Model residuals
MARSSresiduals.tt1
fits the model using the data up to time
State residuals
state.residuals
and rows residuals
. state.residuals[,t]
is
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, residuals
are one sample from this distribution.
To standardize the observed residuals, we will use var.residuals
. Rows/columns 1 to
var.residuals
returned by this function is the conditional variance of the residuals conditioned on the data up to 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:
The interpretation of the Cholesky standardized residuals is not straight-forward when the
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:
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
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
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")
Run the code above in your browser using DataLab