Compare AR model specifications for a simulated response series using `lmtest`.

Consider the AR(3) model:

where
is Gaussian with mean 0 and variance 1. Specify this model using `arima`.

Mdl = arima('Constant',1,'Variance',1,'AR',{0.9,-0.5,0.4});

`Mdl` is a fully specified, AR(3) model.

Simulate presample and effective sample responses from `Mdl`.

T = 100;
rng(1); % For reproducibility
n = max(Mdl.P,Mdl.Q); % Number of presample observations
y = simulate(Mdl,T + n);

`y` is a a random path from `Mdl` that includes presample observations.

Specify the restricted model:

where
is Gaussian with mean 0 and variance
.

Mdl0 = arima(3,0,0);
Mdl0.AR{3} = 0;

The structure of `Mdl0` is the same as `Mdl`. However, every parameter is unknown, except that
. This is an equality constraint during estimation.

Estimate the restricted model using the simulated data (`y`).

[EstMdl0,EstParamCov] = estimate(Mdl0,y((n+1):end),...
'Y0',y(1:n),'display','off');
phi10 = EstMdl0.AR{1};
phi20 = EstMdl0.AR{2};
phi30 = 0;
c0 = EstMdl0.Constant;
phi0 = [c0;phi10;phi20;phi30];
v0 = EstMdl0.Variance;

`EstMdl0` contains the parameter estimates of the restricted model.

`lmtest` requires the unrestricted model score evaluated at the restricted model estimates. The unrestricted model gradient is

MatY = lagmatrix(y,1:3);
LagY = MatY(all(~isnan(MatY),2),:);
cGrad = (y((n+1):end)-[ones(T,1),LagY]*phi0)/v0;
phi1Grad = ((y((n+1):end)-[ones(T,1),LagY]*phi0).*LagY(:,1))/v0;
phi2Grad = ((y((n+1):end)-[ones(T,1),LagY]*phi0).*LagY(:,2))/v0;
phi3Grad = ((y((n+1):end)-[ones(T,1),LagY]*phi0).*LagY(:,3))/v0;
vGrad = -1/(2*v0)+((y((n+1):end)-[ones(T,1),LagY]*phi0).^2)/(2*v0^2);
Grad = [cGrad,phi1Grad,phi2Grad,phi3Grad,vGrad]; % Gradient matrix
score = sum(Grad)'; % Score under the restricted model

Evaluate the unrestricted parameter covariance estimator using the restricted MLEs and the outer product of gradients (OPG) method.

EstParamCov0 = inv(Grad'*Grad);
dof = 1; % Number of model restrictions

Test the null hypothesis that
at a 1% significance level using `lmtest`.

[h,pValue] = lmtest(score,EstParamCov0,dof,0.1)

h =
1
pValue =
2.2524e-09

`pValue` is close to 0, which suggests that there is strong evidence to reject the restricted, AR(2) model in favor of the unrestriced, AR(3) model.