|
|
|
First we need to read data in (CH06FI05.DAT )
> X1<-data[,1] > X2<-data[,2] > Y<-data[,3] > X1 [1] 68.5 45.2 91.3 47.8 46.9 66.1 49.5 52.0 48.9 38.4 87.9 72.8 88.4 42.9 52.5 [16] 85.7 41.3 51.7 89.6 82.7 52.3 > X2 [1] 16.7 16.8 18.2 16.3 17.3 18.2 15.9 17.2 16.6 16.0 18.3 17.1 17.4 15.8 17.8 [16] 18.4 16.5 16.3 18.1 19.1 16.0 > Y [1] 174.4 164.4 244.2 154.6 181.6 207.5 152.8 163.2 145.4 137.2 241.9 191.1 [13] 232.0 145.3 161.1 209.7 146.4 144.0 232.6 224.1 166.5
> X X1 X2 [1,] 1 68.5 16.7 [2,] 1 45.2 16.8 [3,] 1 91.3 18.2 [4,] 1 47.8 16.3 [5,] 1 46.9 17.3 [6,] 1 66.1 18.2 [7,] 1 49.5 15.9 [8,] 1 52.0 17.2 [9,] 1 48.9 16.6 [10,] 1 38.4 16.0 [11,] 1 87.9 18.3 [12,] 1 72.8 17.1 [13,] 1 88.4 17.4 [14,] 1 42.9 15.8 [15,] 1 52.5 17.8 [16,] 1 85.7 18.4 [17,] 1 41.3 16.5 [18,] 1 51.7 16.3 [19,] 1 89.6 18.1 [20,] 1 82.7 19.1 [21,] 1 52.3 16.0
X1 X2 21.0 1302.40 360.00 X1 1302.4 87707.94 22609.19 X2 360.0 22609.19 6190.26 > t(X)%*%Y [,1] 3820.00 X1 249643.35 X2 66072.75 > solve(t(X)%*%X) X1 X2 29.72892348 0.0721834719 -1.992553186 X1 0.07218347 0.0003701761 -0.005549917 X2 -1.99255319 -0.0055499173 0.136310637
> b [,1] -68.85707 X1 1.45456 X2 9.36550
[,1] [,2] [1,] 187.1841 -12.7841146 [2,] 154.2294 10.1705737 [3,] 234.3963 9.8036764 [4,] 153.3285 1.2714690 [5,] 161.3849 20.2150722 [6,] 197.7414 9.7585779 [7,] 152.0551 0.7449178 [8,] 167.8666 -4.6666316 [9,] 157.7382 -12.3381967 [10,] 136.8460 0.3539791 [11,] 230.3874 11.5126289 [12,] 197.1849 -6.0849209 [13,] 222.6857 9.3142995 [14,] 141.5184 3.7815611 [15,] 174.2132 -13.1132116 [16,] 228.1239 -18.4238900 [17,] 145.7470 0.6530062 [18,] 159.0013 -15.0013134 [19,] 230.9870 1.6129777 [20,] 230.3161 -6.2160615 [21,] 157.0644 9.4356009
> plot(Y.hat,e) > plot(X1,e) > plot(X2,e) > plot(X1*X2,e) > plot(Y.hat,abs(e)) > qqnorm(e)
[,1] [1,] 721072.4 > J<-one%*%t(one) > one<-cbind(rep(1,21)) > J<-one%*%t(one) > dim(J) [1] 21 21 > SSTO<-t(Y)%*%Y-t(Y)%*%J%*%Y/21 > SSTO [,1] [1,] 26196.21 > SSE<-t(Y)%*%Y-t(b)%*%t(X)%*%Y > SSE [,1] [1,] 2180.927 > SSR<-SSTO-SSE > SSR [,1] [1,] 24015.28
> F.star [,1] [1,] 99.1035 > 1-pf(F.star,2,21-2-1) [1] 1.921431e-10 > R2<-SSR/SSTO > R2 [,1] [1,] 0.9167465
> SB2 X1 X2 3602.03467 8.74593958 -241.4229923 X1 8.74594 0.04485151 -0.6724426 X2 -241.42299 -0.67244260 16.5157558
[1] -194.948 > b[1]+qt(.975,18)*sqrt(SB2[1,1]) [1] 57.23387 > b[2]-qt(.975,18)*sqrt(SB2[2,2]) [1] 1.009623 > b[2]+qt(.975,18)*sqrt(SB2[2,2]) [1] 1.899497 > b[3]-qt(.975,18)*sqrt(SB2[3,3]) [1] 0.8274411 > b[3]+qt(.975,18)*sqrt(SB2[3,3]) [1] 17.90356
> Xh%*%b [,1] [1,] 191.1039 > Xh%*%SB2%*%t(Xh) [,1] [1,] 7.65517 > Xh%*%b-qt(.975,18)*sqrt(Xh%*%SB2%*%t(Xh)) [,1] [1,] 185.2911 > Xh%*%b+qt(.975,18)*sqrt(Xh%*%SB2%*%t(Xh)) [,1] [1,] 196.9168
> Xh [,1] [,2] [,3] [1,] 1 65.4 17.6 [2,] 1 53.1 17.7 > 2*qf(1-.1,2,18) [1] 5.247894 > qt(1-.1/4,18) [1] 2.100922 > Xh%*%b [,1] [1,] 191.1039 [2,] 174.1494 > Xh%*%SB2%*%t(Xh) [,1] [,2] [1,] 7.65517 10.09869 [2,] 10.09869 21.14717 > diag(Xh%*%SB2%*%t(Xh)) [1] 7.65517 21.14717 > diag(Xh%*%SB2%*%t(Xh))+SSE/18 [1] 128.8178 142.3098 > sqrt(diag(Xh%*%SB2%*%t(Xh))+SSE/18) [1] 11.34979 11.92937 > Xh%*%b-qt(1-.1/4,18)*sqrt(diag(Xh%*%SB2%*%t(Xh))+SSE/18) [,1] [1,] 167.2589 [2,] 149.0867 > Xh%*%b+qt(1-.1/4,18)*sqrt(diag(Xh%*%SB2%*%t(Xh))+SSE/18) [,1] [1,] 214.9490 [2,] 199.2121
> model.matrix(fit) (Intercept) X1 X2 1 1 68.5 16.7 2 1 45.2 16.8 3 1 91.3 18.2 4 1 47.8 16.3 5 1 46.9 17.3 6 1 66.1 18.2 7 1 49.5 15.9 8 1 52.0 17.2 9 1 48.9 16.6 10 1 38.4 16.0 11 1 87.9 18.3 12 1 72.8 17.1 13 1 88.4 17.4 14 1 42.9 15.8 15 1 52.5 17.8 16 1 85.7 18.4 17 1 41.3 16.5 18 1 51.7 16.3 19 1 89.6 18.1 20 1 82.7 19.1 21 1 52.3 16.0 > par(mfrow=c(2,3)) > plot(fit) > summary(fit) Call: lm(formula = Y ~ X1 + X2)
Coefficients:
Residual standard error: 11.01 on 18 degrees
of freedom
Correlation of Coefficients:
Response: Y Terms added sequentially (first to last)
[1] "coefficients" "residuals" "fitted.values" "effects" [5] "R" "rank" "assign" "df.residual" [9] "contrasts" "terms" "call" > names(summary(fit)) [1] "call" "terms" "residuals" "coefficients" "sigma" [6] "df" "r.squared" "fstatistic" "cov.unscaled" "correlation" > names(anova(fit)) names(anova(fit)) [1] "Df" "Sum of Sq" "Mean Sq" "F Value" "Pr(F)" > anova(fit)$Pr [1] 4.639555e-11 3.332136e-02 NA > summary(fit)$sigma [1] 11.00739 |