I have 4 data objects (AR1, AR2, AR3, and AR4) which contain the regression output information (each obtained after running dynlm function which is part of dynlm package). I tried to run the following function which should return test statistics obtained by LjungBox function (part of the portes package) for each of these models (where I use the number of observations of the model and the length of the coefficients variable):
ljungbox <- function(x) {
qx <- floor(0.7 * nobs(ARx)^(1/3))
dfx <- qx - length(ARx$coefficients)
LjungBox(ARx$residuals, lags = 1:qx, fitdf = dfx)
}
However, when trying to get the output of the function for the first model, it results in a following error:
> print(ljungbox(1))
Error in nobs(ARx) : object 'ARx' not found
What could be the problem and how can I solve it?
Thanks in advance!
Mareks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.