I want to fit a linear regression with an AR(1) error using arima()
and then rewrite the model into a state-space model using dlmMLE()
and compare their results. However, I don't know how to obtain the necessary information from the result object of dlmMLE()
.
The model is as follows:
y_{t} = \alpha_{0} + \beta_{1}x_{t} + \eta_{t}
where
\eta_t = \phi_{1}\eta_{t-1}+\varepsilon_{t}.
The sample data:
library(tidyverse)
data("Nile")
df <-
Nile %>%
as_tibble() %>%
mutate(y = as.numeric(x)) %>%
mutate(x = rnorm(100))
Fit the model using arima()
:
fit.arima <- arima(df$y, order = c(2, 0, 0), include.mean = TRUE, xreg = df$x)
Rewrite the model into a state-space model and fit it using dlmMLE()
:
library(dlm)
build <- function(theta) {
dlmModReg(X = df$x, # explanatory variable x
dV = exp(theta[1]), # variance of the observation noise
dW = c(exp(theta[2]), exp(theta[3]))) + # variances of the system noise
dlmModARMA(ar = theta[4], # coefficient phi_1 of AR(1) error
sigma2 = exp(theta[5])) # variance of AR(1) error
}
fit.dlm <- dlmMLE(
df$y, # outcome variable y
parm = c(0, 0, 0, 0, 0), # Initial Values of 5 Parameters to be Estimated
build, # Model
hessian = TRUE
)
Now, I want to compare fit.arima
and fit.dlm
by looking at the coefficients and standard errors for the explanatory variable x and AR(1) term computed by each function. As for arima()
, printing the fit.arima
object automatically gives the desired result, but how can I obtain the corresponding result for dlmMLE()
?