7.1 Random walk with drift

A univariate random walk with drift observed with error is: \[\begin{equation} \begin{gathered} x_{t} = x_{t-1} + u + w_{t}, \text{ } w_t \sim \,\text{N}(0,q) \\ y_{t} = x_{t} + v_{t}, \text{ } v_t \sim \,\text{N}(0,r) \end{gathered} \tag{7.2} \end{equation}\]

Create some data from this equation:

u <- 0.01
r <- 0.01
q <- 0.1
TT <- 100
yt <- cumsum(rnorm(TT, u, sqrt(q))) + rnorm(TT, 0, sqrt(r))

Fit with MARSS():

fit <- MARSS(yt)
Success! abstol and log-log tests passed at 35 iterations.
Alert: conv.test.slope.tol is 0.5.
Test with smaller values (<0.1) to ensure convergence.

MARSS fit is
Estimation method: kem 
Convergence test: conv.test.slope.tol = 0.5, abstol = 0.001
Estimation converged in 35 iterations. 
Log-likelihood: -24.85696 
AIC: 57.71391   AICc: 58.13496   
 
      Estimate
R.R     0.0184
U.U     0.0408
Q.Q     0.0633
x0.x0  -0.2653
Initial states (x0) defined at t=0

Standard errors have not been calculated. 
Use MARSSparamCIs to compute CIs and bias estimates.

Get confidence intervals with tidy():

broom::tidy(fit)
   term    estimate   std.error      conf.low    conf.up
1   R.R  0.01843982 0.009894122 -0.0009523011 0.03783194
2   U.U  0.04083656 0.025345531 -0.0088397685 0.09051289
3   Q.Q  0.06328006 0.017784821  0.0284224487 0.09813767
4 x0.x0 -0.26534896 0.281394026 -0.8168711121 0.28617320

The get the estimated states:

head(stats::tsSmooth(fit, type = "xtT"))
  .rownames t  .estimate       .se
1      X.Y1 1 -0.2246253 0.1098830
2      X.Y1 2 -0.1370475 0.1118654
3      X.Y1 3  0.1814517 0.1119369
4      X.Y1 4  0.2708522 0.1119395
5      X.Y1 5  0.3617262 0.1119396
6      X.Y1 6  0.7986076 0.1119396

The get the fitted values (note these are the smoothed fitted values conditioned on all the data):

head(fitted(fit, type = "ytT"))
  .rownames t          y    .fitted
1        Y1 1 -0.2382786 -0.2246253
2        Y1 2 -0.2043381 -0.1370475
3        Y1 3  0.2482112  0.1814517
4        Y1 4  0.2704228  0.2708522
5        Y1 5  0.2608996  0.3617262
6        Y1 6  0.9039099  0.7986076

Read up on fitted values for MARSS models at ?fitted.marssMLE.