www.gusucode.com > econ 案例源码程序 matlab代码 > econ/AssessModelSpecificationsUsingTheWaldTestExample.m
%% Assess Model Specifications Using the Wald Test % Check for significant lag effects in a time series regression model. %% % Load the U.S. GDP data set. % Copyright 2015 The MathWorks, Inc. load Data_GDP %% % Plot the GDP against time. plot(dates,Data) datetick %% % The series seems to increase exponentially. %% % Transform the data using the natural logarithm. logGDP = log(Data); %% % |logGDP| is increasing in time, so assume that there is a significant lag % 1 effect. To use the Wald test to check if there is a significant lag 2 % effect, you need the: % % * Estimated coefficients of the unrestricted model % * Restriction function evaluated at the unrestricted model coefficient values % * Jacobian of the restriction function evaluated at the unrestricted model coefficient values % * Estimated, unrestricted parameter covariance matrix. % % The unrestricted model is % % $$y_t = \beta_0 + \beta_1 y_{t-1} + \beta_2 y_{t-2} + \varepsilon_t.$$ % %% % Estimate the coefficients of the unrestricted model. LagLGDP = lagmatrix(logGDP,1:2); UMdl = fitlm(table(LagLGDP(:,1),LagLGDP(:,2),logGDP)); %% % |UMdl| is a fitted |LinearModel| model. It contains, among other things, % the fitted coefficients of the unrestricted model. %% % The restriction is $\beta_2 = 0$. Therefore, the restiction function % (_r_) and Jacobian (_R_) are: % % * $r = \beta_2$ % * $R = \left[\matrix{0 & 0 & 1}\right]$ % %% % Specify _r_, _R_, and the estimated, unrestricted parameter covariance % matrix. r = UMdl.Coefficients.Estimate(3); R = [0 0 1]; EstParamCov = UMdl.CoefficientCovariance; %% % Test for a significant lag 2 effect using the Wald test. [h,pValue] = waldtest(r,R,EstParamCov) %% % |h = 1| indicates that the null, restricted hypothesis ($\beta_2 = 0$) % should be rejected in favor of the alternative, unrestricted hypothesis. % |pValue| is quite small, which suggests that there is strong evidence for % this result.