%% Exercise 8, 2011

Y=[230 181 165 150 97 192 181 189 172 170]';
X=[125 99 97 115 120 100 80 90 95 125;
   200 55 105 85 0 150 85 120 110 130;
   109 107 98 71 82 103 111 93 86 78]';
[n p]=size(X);

X=[ones(n,1) X]; % adding one colum

beta=inv(X'*X)*X'*Y

e=Y-X*beta; % deviation

r2=1-e'*e/(sum((Y-mean(Y)).^2)) % coefficient of determination

r2_adj=r2-p*(1-r2)/(n-(p+1))