%% Assess Stability of Subsets of Regression Coefficients
% Conduct a Chow test to assess the stability of a subset of regression coefficients. This example follows from Test Consumption Model for Structural Change.
% Load the U.S. food consumption data set.

load Data_Consumption
P = Data(:,1); 
I = Data(:,2); 
Q = Data(:,3);

%
% Apply the log transformation to each series.

LP = log(P);
LI = log(I);
LQ = log(Q);

%
% Identify the indices before World War II.

preWarIdx = (dates <= 1941);

%
% Consider two regression models: one is log consumption onto log food price, and the other is log consumption onto log income. Plot scatter plots and regression lines for both models.

figure;
subplot(2,2,1)
plot(LP(preWarIdx),LQ(preWarIdx),'bo',LP(~preWarIdx),LQ(~preWarIdx),'r*');
axis tight
grid on
lsline;
xlabel('Log price')
ylabel('Log consumption')
legend('Pre-war observations','Post-war observations',...
    'Location',[0.6,0.6,0.25,0.25])
subplot(2,2,4)
plot(LI(preWarIdx),LQ(preWarIdx),'bo',LI(~preWarIdx),LQ(~preWarIdx),'r*');
axis tight
grid on
lsline
xlabel('Log income')
ylabel('Log consumption')

% A clear break in food price elasticity exists between subsamples before and after the war. However, income elasticity does not appear to have such a break.
%
% Conduct two Chow tests to determine whether there is statistical evidence to reject model continuity for both regression models. Because there are more observations in the complementary subsample than coefficients, conduct a break point test. Consider the elasticities in the test only. That is, specify 0 or false for the intercept (first coefficient), and 1 or true for elasticity (second coefficient).

bp = find(preWarIdx,1,'last'); % Index for 1941
chowtest(LP,LQ,bp,'Coeffs',[0 1],'Display','summary');
chowtest(LI,LQ,bp,'Coeffs',[0 1],'Display','summary');

% The first summary suggests to reject the null hypothesis that price elasticities are equivalent across subsamples at 5% level of significance. The second summary suggests to not reject the null hypothesis that income elasticities are equivalent across subsamples.
%
% Consider a regression model of log consumption onto the logs of price and income. Conduct two break point tests: one that compares price elasticity across subsamples only, and another that compares income elasticity only.

chowtest([LP,LI],LQ,bp,'Coeffs',[0 1 0; 0 0 1]);

% For both tests, there is not enough evidence to reject model stability at 5% level.
% Copyright 2012 The MathWorks, Inc.