Chapter 5 Covariates format
Covariates (aka inputs or exogenous variables) appear as \(\mathbf{c}\) and \(\mathbf{d}\) in the MARSS model and their effects are in the \(\mathbf{C}\) and \(\mathbf{D}\) matrices. As usual, constraints (such as shared or fixed values) can be applied within the matrix, though not across the \(\mathbf{C}\) and \(\mathbf{D}\) matrices. No missing values are allowed in \(\mathbf{c}\) and \(\mathbf{d}\).
\[\begin{equation} \begin{gathered} \mathbf{x}_t = \mathbf{B}_t\mathbf{x}_{t-1} + \mathbf{u}_t + \mathbf{C}_t\mathbf{c}_t + \mathbf{G}_t\mathbf{w}_t, \text{ } \mathbf{w}_t \sim \,\text{MVN}(0,\mathbf{Q}_t) \\ \mathbf{y}_t = \mathbf{Z}_t\mathbf{x}_t + \mathbf{a}_t + \mathbf{D}_t\mathbf{d}_t + \mathbf{H}_t\mathbf{v}_t, \text{ } \mathbf{v}_t \sim \,\text{MVN}(0,\mathbf{R}_t) \\ \mathbf{x}_1 \sim \,\text{MVN}(\boldsymbol{\pi},\boldsymbol{\Lambda}) \text{ or } \mathbf{x}_0 \sim \,\text{MVN}(\boldsymbol{\pi},\boldsymbol{\Lambda}) \end{gathered} \tag{5.1} \end{equation}\]
Covariates are passed in the model list.
MARSS(data, model=list(c=..., d=...))
Your covariates must a matrix with time across the columns (\(p \times T\) matrix) where \(p\) is the number of covariates. No NAs are allowed in covariates. See the chapters in the ATSA book dealing with missing values in your covariates.
Here is an example of a covariate matrix for 2 covariates. \[\begin{equation*} \mathbf{y} = \left[ \begin{array}{ccccccc} 1 & 2 & 5 & 7 & 3.2 & 8\\ 2 & 5 & 3 & 8 & 5.1 & 10.2\end{array} \right] \end{equation*}\]
Factor covariates
If your covariates are factors, like site number or month, and you are estimating a \(a\) value, i.e. level or intercept, for each then you will use a matrix with 0s and 1s. This is identical to how say lm()
would translate your model with factors.
Say your covariate is quarters and you have 3 years of data:
<- rep(paste0("q",1:4), 3) covariate
You translate this to a matrix with four rows and 10 columns. Each row is for a different quarter.
<- unique(covariate)
vals <- length(covariate)
TT <- length(vals)
p <- matrix(0, p, TT)
c for(i in 1:p) c[i,] <- covariate == vals[i]
rownames(c) <- vals
c
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
q1 1 0 0 0 1 0 0 0 1 0 0 0
q2 0 1 0 0 0 1 0 0 0 1 0 0
q3 0 0 1 0 0 0 1 0 0 0 1 0
q4 0 0 0 1 0 0 0 1 0 0 0 1