POLYMATH Report          REG 
 Multiple linear regression 2016-May-31 
Model: y = a0 + a1*x1 + a2*x2

Variable Value 95% confidence
a0 360.836 118.076
a1 -3.75246 1.774
a2 -0.084265 0.140313

R^2   R^2adj   Rmsd   Variance  
0.9835209    0.9725349    3.642287    159.1951   

Source data points and calculated data points
  x1 x2 y y calc Delta y
1 1.61 851 293 283.085 9.91535
2 15.5 820 230 233.575 -3.57518
3 22 1058 172 189.129 -17.1291
4 45 1201 91 90.7726 0.227408
5 33 1357 125 122.657 2.34322
6 40 1115 125 116.782 8.21831

Problem source text
# S. 14 - Simple multiple linear regression
# y = a0 + a1*x1 + a2*x2
# Verified Solution: a0 =360.836, a1 = -3.75246
# a2=-0.084265
y=[293, 230, 172, 91, 125, 125]
x1=[1.61, 15.5, 22, 45, 33, 40]
x2=[851, 820, 1058, 1201, 1357, 1115]
mlinfit x1 x2 y

Matlab formatted problem
Create m file called PolyReg.m and paste the following text into it.
% S. 14 - Simple multiple linear regression
% y = a0 + a1*x1 + a2*x2
% Verified Solution: a0 =360.836, a1 = -3.75246
% a2=-0.084265
function PolyReg
   clc;
   % Known vectors
   y = [293; 230; 172; 91; 125; 125];
   x1 = [1.61; 15.5; 22; 45; 33; 40];
   x2 = [851; 820; 1058; 1201; 1357; 1115];
   % Derived vectors
   % Evaluate regression coefficients
   X = [x1.^0 x1 x2];
   [beta,bint,~,~,stats] = regress(y,X);
   fprintf('Regression model: y = a0 + a1*x1 + a2*x2\n');
   disp([' a0 ' num2str(beta(1,1),'%0.5g') ' Conf. interv.= ' num2str(bint(1,2)-beta(1,1),'%0.5g')]);
   disp([' a1 ' num2str(beta(2,1),'%0.5g') ' Conf. interv.= ' num2str(bint(2,2)-beta(2,1),'%0.5g')]);
   disp([' a2 ' num2str(beta(3,1),'%0.5g') ' Conf. interv.= ' num2str(bint(3,2)-beta(3,1),'%0.5g')]);
   disp(' Regression Statistics ');
   disp([' Correlation Coefficient R^2 = ' num2str(stats(1))]);
   disp([' Variance = ' num2str(stats(4))]);
   y_calc = [x1.^0 x1 x2]*beta;
   % Regression plot
   plot (y, y_calc, 'bo');
   xlabel('y');
   ylabel('yCalc');
   hold on;
   plot (y, y, 'r-');
   hold off;
   % Residuals plot
   figure;
   plot (y, y-y_calc, 'ks');
   xlabel('y');
   ylabel('y-yCalc');
end

General Settings
Number of independent variables = 2
Regression including a free parameter
Number of observations = 6