www.gusucode.com > econ 案例源码程序 matlab代码 > econ/AssessModelStabilityWithSmallComplementarySubsampleSizeExample.m

    %% Assess Regression Model Stability With Small Complementary Subsample Size
% The break point Chow test is not appropriate for instances when the
% the complementary subsample has as many or fewer observations as
% coefficients in the model.  For these instances, use the forecast 
% test.
%%
% Load the U.S. food consumption data set.  Extract the food price index
% (|P|) and food consumption index (|Q|).  Suppose that data for 1927
% through 1949 are available.

% Copyright 2015 The MathWorks, Inc.

load Data_Consumption
dates = (1927:1949)';
Tbl = DataTable(cellstr(num2str(dates)),{'P','Q'});

figure;
plot(dates,Tbl{:,{'P' 'Q'}},'o-')
axis tight
grid on
xlabel('Year')
ylabel('Index')
title('{\bf Time Series Plot of All Series}')
legend({'Price','Consumption'},'Location','SE')
%%
% Measurements are missing from 1942 through 1947, which correspond to
% World War II. A common assumption is that consumption elasticity is a linear
% function of price elasticity (and perhaps other variables).
%% 
% Identify the indices before World War II.
preWarIdx = (dates <= 1941);
%%
% Because each measurement is already normalized, obtain elasticities by
% applying the log transformation. Plot consumption elasticity as a
% function of price elasticity.
Tbl.LQ = log(Tbl.Q); % Consumption elasticity
Tbl.LP = log(Tbl.P); % Price elasticity

figure;
plot(Tbl.LP(preWarIdx),Tbl.LQ(preWarIdx),'bo',...
    Tbl.LP(~preWarIdx),Tbl.LQ(~preWarIdx),'r*');
axis tight
grid on
lsline;
xlabel('Price elasticity')
ylabel('Consumption elasticity')
legend('Pre-war observations','Post-war observations',...
    'Location','best')
%%
% Because the slopes and intercepts between the subsamples appear to be
% different, the plot suggests to reject model stability.
%%
% Conduct a forecast test including all coefficients, and
% separately for each coefficient.
bp = find(preWarIdx,1,'last');
Coeffs = [1 1; 1 0; 0 1];
chowtest(Tbl(:,{'LP','LQ'}),bp,'Test','forecast','Coeffs',Coeffs);
%%
% All tests fail to reject the null hypothesis of model stability.