36-401 Modern Regression HW #5 Solutions: Air - Flow
36-401 Modern Regression HW #5 Solutions: Air - Flow
18 20 22 24 26 10 15 20 25 30 35 40
50 55 60 65 70 75 80
Air.Flow
26
24
Water.Temp
22
20
18
90
85
Acid.Conc.
80
75
10 15 20 25 30 35 40
stack.loss
50 55 60 65 70 75 80 75 80 85 90
1
(b)
##
## Call:
## lm(formula = stack.loss ~ Air.Flow + Water.Temp + Acid.Conc.,
## data = stackloss)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.2377 -1.7117 -0.4551 2.3614 5.6978
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -39.9197 11.8960 -3.356 0.00375 **
## Air.Flow 0.7156 0.1349 5.307 5.8e-05 ***
## Water.Temp 1.2953 0.3680 3.520 0.00263 **
## Acid.Conc. -0.1521 0.1563 -0.973 0.34405
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.243 on 17 degrees of freedom
## Multiple R-squared: 0.9136, Adjusted R-squared: 0.8983
## F-statistic: 59.9 on 3 and 17 DF, p-value: 3.016e-09
The F -test yields a p-value of 3.016 × 10−9 , which strongly suggests that at least one of the predictors
has a significant association with Stack Loss. The univariate t-tests suggest that both Air Flow and
Water Temperature have significant associations with Stack Loss, even after accounting for all other
predictors.
(c)
library(knitr)
kable(confint(model, level = 0.9), digits = 2,
caption = "90% Confidence Intervals for Regression Coefficients")
5% 95 %
(Intercept) -60.61 -19.23
Air.Flow 0.48 0.95
Water.Temp 0.66 1.94
Acid.Conc. -0.42 0.12
2
(d)
Table 2: 99% Prediction Interval for Stack Loss given Airflow = 58,
Water temperature = 20 and Acid = 86
(e)
In part (b) we saw the p-value for the t-test testing this hypothesis is 0.3440, so we fail to reject H0 .
This hypothesis can also equivalently be tested using a partial F -test. Table 3 shows the ANOVA table for
the regression and the partial F -test of H0 again yields the p-value of 0.3440.
kable(anova(model), digits = 3, caption = "ANOVA Table for Regression")
3
Problem 2 [20 points]
!
βb1
βb =
βb2
= (X T X)−1 X T Y
−1
X11 X21 Y1
X11 · · · X1n .. .. X11 ··· X1n ..
=
X21 · · · X2n . . X21 ··· X2n .
X1n X2n Yn
X n Xn −1 X n
2
X1i X1i X2i X1i Yi
i=1 i=1 i=1
= X
n Xn X n
2
X1i X2i X2i X2i Yi
i=1 i=1 i=1
X n −1 X
n
2
X1i 0 X1i Yi
i=1 i=1
=
n
X X n
2
0 X2i X2i Yi
i=1 i=1
1
n 0 n
X 2
X
X1i
X Y
1i i
= i=1
i=1
1 X n
0
n
X X2i Yi
2
X2i i=1
i=1
n
X
X1i Yi
i=1
n
X
2
X1i
i=1
=
X n
X2i Yi
i=1
n
X
2
X 2i
i=1
As we saw in Homework 2, these are the least square estimators for the two separate univariate regressions
through the origin.
4
Problem 3 [20 points]
(a)
##
## Call:
## lm(formula = Y ~ X - 1)
##
## Residuals:
## 1 2 3 4
## -0.70098 0.57353 0.06373 0.06373
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## X1 -2.6029 1.3382 -1.945 0.3023
## X2 3.0686 0.3249 9.444 0.0672 .
## X3 3.2059 0.3490 9.185 0.0690 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9102 on 1 degrees of freedom
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9995
## F-statistic: 2766 on 3 and 1 DF, p-value: 0.01398
mytable <- summary(model3)$coefficients
row.names(mytable) <- c("Intercept","X1","X2")
kable(mytable)
The F -test yields a p-value of 0.0139, which suggests that at least one of X1 and X2 has a significant
association with Y . However, as indicated by the t-tests, there is not enough evidence to conclude individually
that X1 has a significant association with Y (after accounting for X2 ), or that X2 has a significant association
with Y (after accounting for X1 ).
5
(b)
library(xtable)
# you can use this package to convert R objects into nice LaTeX tables/matrices
print(xtable(t(X) %*% X), tabular.environment = "pmatrix",
include.rownames = FALSE, include.colnames = FALSE, hline.after = NULL)
print(xtable(solve(t(X) %*% X)), tabular.environment = "pmatrix",
include.rownames = FALSE, include.colnames = FALSE, hline.after = NULL)
4.00 24.00 28.00
X T X = 24.00 174.00 192.00
28.00 192.00 222.00
2.16 0.06 −0.32
(X T X)−1 = 0.06 0.13 −0.12
−0.32 −0.12 0.15
(c)
βb = (X T X)−1 X T Y
−2.60
= 3.07
3.21
(d)
H = X(X T X)−1 X T
0.41 0.49 0.05 0.05
0.49 0.60 −0.04 −0.04
=0.05 −0.04 1.00 −0.00
(e)
b = σ 2 (X T X)−1
Var(β)
2.16 0.06 −0.32
= σ 2 0.06 0.13 −0.12
−0.32 −0.12 0.15
6
Note: This is the variance-covariance matrix of β.
b Notice it depends on the true (unknown) distribution of
the data. The standard errors provided by R’s summary command are plug-in estimates for the square root
of the diagonal elements of Var(β).
b That is, R gives you
n op n q op+1
b βbk )
se( = σ b (X T X)−1jj
k=0 j=1
v
u n op+1
1 X nq
(X T X)−1
u
=t e2i jj
n − (p + 1) i=1 j=1
1.4702941
= 0.9101821 · 0.3570028
0.3834825
1.3382353
= 0.3249375
0.3490389