Week-3 Annotated
Week-3 Annotated
Week 3
5 An example with R
Ei Nco 0
Yi E Yi Bot Xi
E (Y ) = —0
q
(Xi ≠ X̄ )(Yi ≠ Ȳ )
b1 = q
(Xi ≠ X̄ )2
I
The sampling distribution of b1 is normal with mean and variance:
E (b1 ) = —1
‡ 2
V (b1 ) = ‡ 2 (b1 ) =
Sxx
b1 is a linear combination of Yi
n
ÿ
b1 = ki Yi ,
i=1
where
Xi ≠ X̄
ki = q
(Xi ≠ X̄ )2
Sxy CX x̅ Yi I Ʃ Xi x̅
Y Xi x̅ Y
be I TLEY
Week 3 Regression Modelling 6 / 73
Sampling distribution of b1 Sxx É Xi x̅
ELXi x̅ Xi x̅
E Y E X ECY
EX x̅E
Im
F Xi
Normality: A linear combination of independent normal random
variables is normally distributed.
Mean: E (b1 ) = —1
Ʃ
ET ELEM Yi
Xi x̅ E Yi
4 ELA
x̅
Y
Xi F Po Xi x̅ β XD
É Xi x̅ Bot β Xi
EEx
EEEE.fi CA
Week 3 Regression Modelling
O
β Sxx 7 / 73
Sampling distribution of b1
ax a V X
VA
If x y independent XY Vly
‡2
Variance: ‡ 2 (b1 ) = V (b1 ) = Sxx
Cbi V Ʃ Y VLE.CA x̅
Y
VICKI AY CX T.VE
5
Sx
Estimated Variance:
2 MSE
s (b1 ) =
Sxx
(Proved P43)
Ò
MSE
We call s(b1 ) = Sxx the standard error of b1 .
Yi = 2 + Xi + Ái , where Ái ≥ N (0, 82 )
So —0 = 2, —1 = 1 and ‡ = 8.
Assume the X values are 1, 2, . . . , 25, so the sample size is 25.
We learnt from theoretical results that the sampling distribution of b1
is normal with mean 1, and variance S64xx .To construct a simulated
sampling distribution of b1 , we follow steps below:
}
s_b0[i] = sqrt(MSE[i]*(1/n + mean(X)ˆ2/Sxx)) Scb 1T
Week 3 Regression Modelling 13 / 73
Sampling distribution of b1 by simulation
it
β
mean(b1) # empirical mean if b1
## [1] 0.9983658
sdb1 = esigma/sqrt(Sxx) # theoretical sd
sdb1 FE
## [1] 0.2218801
sd(b1) # empirical sd of b1
## [1] 0.2230607
NCR
1.5
1.0
Density
0.5
11 1
0.0
11
0.5 1.0 1.5
b1
Week 3 Regression Modelling 15 / 73
Sampling distribution of (b1 ≠ —1 )/s(b1 )
We have:
b1 ≥ N (—1 , ‡ 2 (b1 ))
Standardize: N
b1 ≠ —1
a
≥ N (0, 1)
‡(b1 )
b1 ≠ —1
≥ tn≠2 ,
s(b1 )
Ò
MSE
where s(b1 ) = Sxx .
normal
t2
0.3
t6
t23
now
density
0.2
In Non
0.1
0.0
−4 −2 0 2 4
the
0.3
Density
0.2
0.1
0.0
−4 −2 0 2 4
(b1 − beta1)/s_b1
α 0105
95
The 100(1 ≠ –)% confidence interval for —1 is:
Ë È
b1 ≠ t–/2 (n ≠ 2)s (b1 ) , b1 + t–/2 (n ≠ 2)s (b1 )
Ò
MSE
where s (b1 ) = Sxx .
55 Ei
2.069 0 2.069
PO
1.0
b1
0.5
0.0
0 10 20 30 40 50
Index
Test statistic
b1
t =
ú
s(b1 )
H0 : —1 Æ 0 (—1 Ø 0) tri z
Ha : —1 > 0 (—1 < 0)
Test statistic
t.li
b1
t =
E
ú
s(b1 )
MSR
5
SSR CY Y É both Xi 75
Eg Cy b x̅ b Xi 45 IT bicxi TT
bisx tt.
T bE
Week 3
bIIE
Regression Modelling
f
27 / 73
Hypothesis testing with —1 at a general value
Two-sided test
H0 : —1 = c v.s. Ha : —1 ”= c
Test statistic
b1 ≠ c
t =
ú
≥ tn≠2 under H0
s (b1 )
Test statistic
b1 ≠ c
t =
ú
≥ tn≠2 under H0
s (b1 )
E (b0 ) = —0
C D
2 2 1 X̄ 2
‡ (b0 ) = V (b0 ) = ‡ +
n Sxx
b Y bit
LC LC of Yi
of Yi
Mean: E (b0 ) = —0
bi ECT x̅ ECBD
E bo E Y
EC EYi x̅ β
ÉELY x̅
β
É pot β
Xi x̅ β
x̅
Week 3
Pot RIEI
Regression Modelling
β β
33 / 73
Sampling distribution of b0
VCkÉYi
VCXtVCY
InVLY Ë
no
2
È EVIXIYI
Variance: ‡ 2 (b0 ) = ‡ 2 1
n + X̄
Sxx
I2COVCi
bo V b
x̅
If Jr
ʰ
É
Week 3 Regression Modelling 34 / 73
Sampling distribution of b0
2
βo
mean(b0) # empirical mean of b0
## [1] 2.014146
sd(b0) # empirical sd of b0
## [1] 3.275723
sdb0 = esigma*sqrt(1/n + mean(X)ˆ2/Sxx)
sdb0 # Theoretical sd of b0
## [1] 3.298485
bo
N Po
0.10
0.08
Density
0.06
0.04
0.02
0.00
−10 −5 0 5 10
b0
An estimator of ‡ 2 (b0 )
C D
2 1 X̄ 2
s (b0 ) = MSE +
n Sxx
Ú 1 2
1 X̄ 2
We call s(b0 ) = MSE n + Sxx the standard error of b0 .
0.2
0.1
0.0
−4 −2 0 2 4
(b0 − beta0)/s_b0
Ë È
b0 ≠ t1≠–/2,n≠2 s (b0 ) , b0 + t1≠–/2,n≠2 s (b0 )
Ú Ë È
1 x̄ 2
where s (b0 ) = MSE n + Sxx .
estimate Z t Cs e
point
Two-sided test
H0 : —0 = c
Ha : —0 ”= c
Test statistic
b0 ≠ c
t =
ú
≥ tn≠2 under H0
s (b0 )
One-sided test
H0 : —0 Æ c (—0 Ø c)
Ha : —0 > c (—0 < c)
Test statistic
b0 ≠ c
t =
ú
s (b0 )
bot bi Xu
Objective: estimate the mean for one or more probability distributions
of Y .
Example: the Toluca Company is interested in the mean number of
work hours for a range of logt sizes for the purposes of finding the
optimum lot size.
E {Ŷh } = E (Yh )
C D
2 1 (Xh ≠ X̄ )2
V {Ŷh } = ‡ +
n Sxx
botbin
LCofYi
Week 3 Regression Modelling 45 / 73
The sampling distribution of Ŷh
y b x̅ b Xn
VEY b Xn x̅
Xn V bi 2Corky b Xn x̅
Y x̅
I an IT I
Week 3 Regression Modelling 46 / 73
The sampling distribution of Ŷh
53
So
y
So
if
I
! "2
Figure 1: The further from X̄ is Xh , the greater is the quantity Xh ≠ X̄ and the
larger is the variance of Ŷh .
Ë È
Ŷh ≠ t1≠–/2,n≠2 s(Ŷh ), Ŷh + t1≠–/2,n≠2 s(Ŷh )
Û 5 6
2
1 (Xh ≠X̄ )
where s(Ŷh ) = MSE n + Sxx .
Denote the level of X for the new trial as Xh and the new observation
on Y as Yh(new ) .
Difference between estimation of the mean response E (Y ) and
prediction of a new response Yh(new ) :
The former one is to estimate the mean of the distribution of Y .
The latter one is to predict an individual outcome drawn from the
distribution of Y .
Ŷh = b0 + b1 Xh
Yh(new ) = —0 + —1 Xh + Áh(new )
V {Yh(new ) } = V {Ŷh } + ‡ 2
S 1 22 T
1 2 1 Xh ≠ X̄
‡ 2 {pred} = ‡ 2 Ŷh + ‡ 2 = ‡ 2 U1 + +
W X
V
n Sxx
S 1 22 T
1 2 1 Xh ≠ X̄
2 2
se2
W X
s {pred} = s Ŷh + = MSE U1 + + V
n Sxx
Ë È
Ŷh ≠ t1≠–/2,n≠2 s{pred}, Ŷh + t1≠–/2,n≠2 s{pred}
Û 5 6
2
1 (Xh ≠X̄ )
where s{pred} = MSE 1 + n + Sxx .
Confidence 1 interval
2 Ŷh ± Prediction interval Ŷh ±
t1≠–/2,n≠2 s Ŷh t1≠–/2,n≠2 s{pred}
Û 5 6 Û 5 6
1 2
(Xh ≠X̄ ) (Xh ≠X̄ )
2 2
1 1
s Ŷh = MSE n + Sxx s{pred} = MSE 1 + n + Sxx
An example with R
## (Intercept) X
## 62.365859 3.570202
b0 = coef(mymodel)[1]
b1 = coef(mymodel)[2]
summary(mymodel)$coefficients
S bo
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 62.365859 26.1774339 2.382428 2.585094e-02
## X 3.570202 0.3469722 10.289592 4.448828e-10
5lb
Week 3 Regression Modelling 59 / 73
Interpretation of the coefficients
Ŷ = 62.37 + 3.5702X
300
FEE
200
i
1
100
50
20 40 60 80 100 120
Lot sizes
alpha = 0.05
s_b0 = summary(mymodel)$coefficients[1,2]
s_b1 = summary(mymodel)$coefficients[2,2]
b0_ci = c(b0 + qt(alpha/2, df = n-2)*s_b0,
b0 + qt(1-alpha/2, df = n-2)*s_b0)
b1_ci = c(b1 + qt(alpha/2, df = n-2)*s_b1,
b1 + qt(1-alpha/2, df = n-2)*s_b1)
b0_ci
## (Intercept) (Intercept)
## 8.213711 116.518006
b1_ci
## X X
## 2.852435 4.287969
confint(mymodel)
## 2.5 % 97.5 %
## (Intercept) 8.213711 116.518006
## X 2.852435 4.287969
With confidence coefficient .95, we estimate that the mean number of
work hours increases by somewhere between 2.85 and 4.29 hours for
each additional unit in the lot.
confint(mymodel, level=0.90)
## 5 % 95 %
## (Intercept) 17.501100 107.230617
## X 2.975536 4.164868
na Bito p value4.4 10
Week 3 reject Ho
Regression Modelling 64 / 73
Equivalence of F Test and t Test
X
Y
correlation
β
anova(mymodel)
p t
##
##
Analysis of Variance Table
to
tes
## Response: Y P
## Df Sum Sq Mean Sq F value Pr(>F)
## X 1 252378 252378 105.88 4.449e-10 ***
## Residuals 23 54825 2384
## ---
## Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1
tail test
g 1.714
Upper Lower tail test 1714
i reject Ho
Ho
β Ho 1170 tail
Ha 170 Ha co for lower
p test Cr is
10.289 10.289 1.714
not 17
p value pvalue 1 4
IE 2t
i Fail to
RejectHo Fail to reject Ho reject
Week 3 Regression Modelling 66 / 73
Hypothesis testing with —
H0 : —1 = 2
Ha : —1 ”= 2
ts = (b1-2)/s_b1
ts
## X
## 4.525441
pvalue = 2*(1-pt(ts, df = n-2))
pvalue
## X
## 0.0001519178 2 Ho
Reject
Week 3 Regression Modelling 67 / 73
Confidence interval for E (Yh )
Let’s try to find a 90% confidence interval for E (Yh ) when Xh = 65.
Ú Ë È
1 (Xh ≠X̄ )2
Ŷh ± t1≠–/2;n≠2 MSE n
+ Sxx
X_h = 65
Y_hat = b0 + b1*X_h
Y_hat
## (Intercept)
## 294.429
MSE = sum(residuals(mymodel)ˆ2) / df.residual(mymodel)
s_Yhat = sqrt(MSE*(1/n +(X_h-mean(X))ˆ2/sum((X-mean(X))ˆ2)))
alpha = 0.1
Y_hat_ci = c(Y_hat - qt(1-alpha/2, n-2)*s_Yhat,
Y_hat + qt(1-alpha/2, n-2)*s_Yhat)
names(Y_hat_ci) = c( lower , upper )
Y_hat_ci
## lower upper
## 277.4315 311.4264
Week 3 Regression Modelling 68 / 73
Prediction interval for Ŷh(new )
## lower upper
## 209.0432 379.8148
With confidence coefficient 90%, the mean work hours required when lots of
65 units are produced is between 277 and 311.
With confidence coefficient 90%, we predict that the number of work hours
required for any lot of 65 units is between 209 and 380.
20,550
95CI
500
95PI
400
300
Y
200
100
0
20 40 60 80 100 120