I have a simple model, for which the residuals exhibit auto-correlation beyond one order.
I have a simple model for which I want to include a moving average component up to a third order.
My model is this:
m1<-gamm(y~s(x,k=5), data = Training)
the time series properties of y, shows that this follows an ARMA(0,0,3)
because the residuals of m1
are auto-correlated I want to include a moving average component in m1
The answers for similar questions talk only about an AR(1) process, which is not my case.
You can use the corARMA(p, q)
function in package nlme for this. corAR1(p)
is just a special case function as there are certain efficiencies for that particular model.
You have to pass q
and/or p
for the order of the ARMA(p, q) process with p
specifying the order of the AR terms and q
the order of the MA terms. You also need to pass in a variable that orders the observations. Assuming you have a single time series and you want the MA process to operate at the entire time series level (rather than say within a years but not between) then you should crate a time
variable that indexes the order of the observations; here I assume this variable is called time
.
Then the call is:
m1 <- gamm(y ~ s(x, k = 5), data = Training,
correlation = corARMA(q = 3, form = ~ time))
When looking at the residuals, be sure to extract the normalised residuals as those will include the effect of the estimated MA process:
resid(m1, type = "normalised")