% example ch19ex1.m % illustrates how to construct a regression estimator load ch19ex2_reg_data reg=ch19ex2_reg_data m=reg(:,2)-100; % the second column is the manipulated variable x1=reg(:,3)-200; %the first secondary measurement x2=reg(:,4)-100; %the second secondary measurement y=reg(:,5)-90; dx1=x1-3.66*m; dx2=x2-5.92*m; dy=y-4.05*m; A=[dx1 dx2]; estimator=A\dy % calculation regression estimator % Now load the test data and check Rsquared value load ch19ex2_test_data test=ch19ex2_test_data m=test(:,2)-100; % the second column is the manipulated variable x1=test(:,3)-200; %the first secondary measurement x2=test(:,4)-100; %the second secondary measurement y=test(:,5)-90; dx1=x1-3.66*m; dx2=x2-5.92*m; dy=y-4.05*m; A=[dx1 dx2]; error=dy-A*estimator; norm(error) rsquared=1-norm(error)^2/norm(dy)^2