Boyang Dai Stat 6120 HW#5#6.27data=read.table("http://www.stat.lsu.edu/exstweb/statlab/datasets/KNNLData/CH06PR27.txt")con = c(1, 1, 1, 1, 1, 1) X1 = c(7, 4, 16, 3, 21, 8) X2 = c(33, 41, 7, 49, 5, 31)Y = c(42, 33, 75, 28, 91, 55) X = matrix(c(con, X1, X2), 6, 3)XX = t(X) %*% X XY = t(X) %*% Yb = solve(XX) %*% XY b[,1][1,] 33.9321033[2,] 2.7847614[3,] -0.2644189Yhat = X %*% b e = Y – Yhat e[,1][1,] -2.69960842[2,] -1.22997279[3,] -1.63735316[4,] -1.32985996[5,] -0.08999801[6,] 6.98679233T = solve(XX) H = X %*% T %*% t(X) H [,1] [,2] [,3] [,4] [,5] [,6][1,] 0.23143293 0.25167585 0.21178735 0.1488684 -0.05475543 0.21099091[2,] 0.25167585 0.31240459 0.09437844 0.2662773 -0.14787283 0.22313666[3,] 0.21178735 0.09437844 0.70442026 -0.3191744 0.10446672 0.20412159[4,] 0.14886839 0.26627729 -0.31917435 0.6142563 0.14143492 0.14833743[5,] -0.05475543 -0.14787283 0.10446672 0.1414349 0.94039955 0.01632707[6,] 0.21099091 0.22313666 0.20412159 0.1483374 0.01632707 0.19708635SSR = sum( (Yhat - mean(Y))^2 ) SSR[1] 3009.926SSE = sum( e^2 ) MSE = SSE/(6-3) MSE = SSE/(6-3)s2b = diag(solve(XX))*MSE s2b [1] 715.4711354 1.6616664 0.2624678Xnew = matrix(c(1, 10, 30), 3, 1) Ynewhat = t(Xnew) %*% b Ynewhat [,1][1,] 53.84715s2Ynewhat = MSE*(1 + t(Xnew) %*% solve(XX) %*% Xnew);s2Ynewhat [,1][1,] 26.1158#7.3a. data=read.table("http://www.stat.lsu.edu/exstweb/statlab/datasets/KNNLData/CH06PR05.txt", col.names = c("y","x1","x2")) model = lm(y ~x1 +x2, data = data)mreduced = lm(y ~ x1, data = data) anova(mreduced, model)Analysis of Variance TableModel 1: y ~ x1Model 2: y ~ x1 + x2 Res.Df RSS Df Sum of Sq F Pr(>F) 1 14 400.55 2 13 94.30 1 306.25 42.219 2.011e-05 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1=> SSR(X2|X1) = 306.25b. Alternatives: H0: β2=β3= 0 and Ha: atleastoneof β2, β3≠0.The value of F*=42.22, which should be compared to F(.99,1,13), which is between F(.99,1,12)=9.33 and F(.99,1,15)=8.68. Since 42.22 is greater than either of these values, reject the null hypothesis and conclude that X2 contributes significantly to the model and cannot be dropped. Since 42.22 is beyond even F(.999, 1,13), the p-value of the test is <0.001.#7.6H0: β2=β3= 0 and Ha: at least one of β2, β3≠0If p-value is larger than 0.005, we conclude H0, otherwise, conclude HaF* = SSR(X2, X3|X1)/2MSE(X1, X2, X3) = 4.1768 > F(0.975, 2, 42)P-value = 0.02216 < 0.025Therefore, we conclude that at least one of β2, β3 is not equal to
View Full Document