# Checking Residual for Serial Dependence in R

I have residuals that I got from an ARMA-GARCH model via rugarch package:

ug_spec <- ugarchspec(distribution.model="std", mean.model=list(armaOrder=c(1,0)),variance.model=list(garchOrder=c(1,1)))
ugfit=ugarchfit(spec = ug_spec, data =x)
residue=as.numeric(unlist(residuals(ugfit)))


the as.numeric(unlist()) is just to get the part of the result I want. First off, was that the correct way to get the residuals off a data that has been fitted to the ARMA(1,0)GARCH(1,1) model?

I have to now check the residuals for any serial dependence, and decided to use Box.test with the Ljung-Box type:

   Box.test(residue, lag=5, type="Ljung", fitdf=1)


I set fitdf=1 as per the instruction in the vignette to place p+q as the fitdf. The result is this:

Box-Ljung test

data:  residue
X-squared = 15.548, df = 4, p-value = 0.00369


The p-value < 0.05, which doesn't make sense since I've previously detrended and de-seasonalized the data before fitting it to the ARMA-GARCH model (best fit by BIC). Does this mean that there is, indeed, serial autocorrelation even though I've done all I was supposed to in pursuit to get rid of it, or did I make a mistake in the usage of Box.test?