/****************** Problem 7.51 (7.53) ****************/ options nodate pageno=1; data one; input x1 x2 x3 x4 y; cards; 33 53 3.32 3.42 29 31 36 3.10 3.26 24 33 51 3.18 3.18 26 37 51 3.39 3.08 22 36 54 3.20 3.41 27 35 35 3.03 3.03 21 59 56 4.78 4.57 33 60 60 4.72 4.72 34 59 60 4.60 4.41 32 60 60 4.53 4.53 34 34 35 2.90 2.95 20 60 59 4.40 4.36 36 60 62 4.31 4.42 34 60 36 4.27 3.94 23 62 38 4.41 3.49 24 62 61 4.39 4.39 32 90 64 7.32 6.70 40 90 60 7.32 7.20 46 92 92 7.45 7.45 55 91 92 7.27 7.26 52 61 62 3.91 4.08 29 59 42 3.75 3.45 22 88 65 6.48 5.80 31 91 89 6.70 6.60 45 63 62 4.30 4.30 37 60 61 4.02 4.10 37 60 62 4.02 3.89 33 59 62 3.98 4.02 27 59 62 4.39 4.53 34 37 35 2.75 2.64 19 35 35 2.59 2.59 16 37 37 2.73 2.59 22 ; run; *PROC REG can be used to get the results requested in this problem, but you should use the relevant formulas to get the results "by hand"; proc reg data=one; model y = x1 x2 x3 x4/covb; run; * Now recompute "by hand"; /******************* Part A *********************/ proc iml; use one; read all var{y} into y; read all var{x1 x2 x3 x4} into xold; reset print; n = nrow(y); x = j(n,1)||xold; bhat = inv(x`*x)*x`*y; sse = y`*y - bhat`*x`*y; k = ncol(xold); s2 = sse/(n-k-1); /****************** Part B **********************/ print 'Part B:'; covbhat = s2*inv(x`*x); /****************** Part C **********************/ print 'Part C:'; xc = (i(n)-(1/n)*j(n,n))*xold; sxx = xc`*xc/(n-1); syx = xc`*y/(n-1); b1hat = inv(sxx)*syx; ybar = y`*j(n,1)/n; xbar = xold`*j(n,1)/n; b0hat = ybar - syx`*inv(sxx)*xbar; /******************** Part D ********************/ print 'Part D:'; r2 = (bhat`*x`*y - n*ybar##2)/(y`*y - n*ybar##2); r2a = ((n-1)*r2 - k)/(n-k-1); quit;