Solution Practice Problems 5
Solution Practice Problems 5
STA305
Practice Problems # 5: Linear Models
SOLUTION
These practice problems are not to be handed in. Questions will be taken up in tutorial.
Problem 1. Consider the Farming Example from lectures: There are four different fertilizers (brands A,
B, C, D). We wish to determine if there a difference in the crop yield due to the fertilizer. There are 16
plots of lands available to be tested. Each fertilizer is randomly assigned to four plots. The crop yield (in
kg) of each plot is then measured after the fertilizer is used. Note that Fertilizer C is Nitrogen-based and
the other brands are Phosphorus-based. The data is attached in the file “[Link]”.
2. Write the ANOVA model that is being fit to test the question of interest. Define all terms.
Yij = µ + αj + εij , i = 1, . . . , n = 4; j = 1, . . . , 4, where yij is crop yiled (in kg), µ is the overall
iid
(grand) mean, αj is the effect of fertilizer j, and εij is the error such that εij ∼ N (0, σ 2 ).
4. Test the question of interest with a pooled t-test (i.e., pairwise comparisons).
# data
y = c (65 , 54 , 56 , 60 , 55 , 58 , 62 , 65 , 64 , 67 , 70 , 74 , 60 , 64 , 68 , 70)
a = f a c t o r ( r e p ( c ( a1 , a2 , a3 , a4 ) , each =4))
dat = data . frame ( x=a , y=y )
## P a i r w i s e c o m p a r i s o n s t p o o l e d t e s t ##
with ( dat , p a i r w i s e . t . t e s t ( y , a , p . a d j = none ) )
P a i r w i s e c o m p a r i s o n s u s i n g t t e s t s with p o o l e d SD
data y and a
a1 a2 a3
a2 0 . 7 0 1 0 = =
a3 0 . 0 0 8 4 0.0175 =
a4 0 . 0 5 5 2 0.1092 0.3267
Call :
lm ( f o r m u l a = y ˜ a , data = dat )
Residuals :
Min 1Q Median 3Q Max
= 5.500 = 3.250 = 0.125 3.000 6.250
Coefficients :
Estimat e Std . E r r o r t v a l u e Pr ( >| t | )
( Intercept ) 58.750 2 . 2 4 8 2 6 . 1 3 8 6 . 0 1 e =12 ***
aa2 1.250 3.179 0.393 0.70104
aa3 10.000 3.179 3 . 1 4 6 0 . 0 0 8 4 4 **
aa4 6.750 3.179 2.124 0.05519 .
R e s i d u a l s t a n d a r d e r r o r : 4 . 4 9 5 on 12 d e g r e e s o f freedom
M u l t i p l e R=s q u a r e d : 0 . 5 2 1 7 , Adjusted R=s q u a r e d : 0 . 4 0 2 1
F= s t a t i s t i c : 4 . 3 6 3 on 3 and 12 DF, p=v a l u e : 0 . 0 2 6 9 4
6. What is the estimate of the intercept? What practical quantity (if any) does it estimate?
> with ( dat , t a p p l y ( y , a , mean ) )
a1 a2 a3 a4
58.75 60.00 68.75 65.50
Response : y
Df Sum Sq Mean Sq F v a l u e Pr(>F)
a 3 264.5 88.167 4.3629 0.02694 *
R e s i d u a l s 12 2 4 2 . 5 2 0 . 2 0 8
===
8. Write out the contrast coefficients needed to make the following comparisons:
9. For each of the comparisons above, find the estimate of the contrast.
> f i t <= lm ( y ˜ x = 1 , data=dat )
> L <= matrix ( c (
+ 1 , 0 , = 1, 0 ,
+ 0 , 1 , = 1, 0 ,
+ 0 , 0 , 1 , = 1,
+ 1 , 1 , = 2, 0 ,
+ 1 , 1 , = 3, 1 ) , byrow=T, nrow=5)
> r e q u i r e ( multcomp )
> l i b r a r y ( multcomp )
> summary ( g l h t ( f i t , L ) , t e s t=a d j u s t e d ( ” b o n f e r r o n i ” ) )
S i m u l t a n e o u s T e s t s f o r G e n e r a l L i n e a r Hypotheses
F i t : lm ( f o r m u l a = y ˜ x = 1 , data = dat )
L i n e a r Hypotheses :
Estimat e Std . E r r o r t v a l u e Pr ( >| t | )
1 == 0 = 10.000 3 . 1 7 9 = 3.146 0.0422 *
2 == 0 = 8.750 3 . 1 7 9 = 2.753 0.0876 .
3 == 0 3.250 3.179 1.022 1.0000
4 == 0 = 18.750 5 . 5 0 6 = 3.406 0.0261 *
5 == 0 = 22.000 7 . 7 8 6 = 2.826 0.0765 .
10. Pick one of the contrasts above. Find 95% t-CI for this contrast. Do not use any correction
procedure.
Use the following formula and part (10) to find the CI:
q Pa
(1 − α)100% CI for ψ is: ψ̂ ± tN −a,α/2 Sψ̂ , where Sψ̂ = M SE j=1 c2j /nj .
S i m u l t a n e o u s T e s t s f o r G e n e r a l L i n e a r Hypotheses
F i t : lm ( f o r m u l a = y ˜ x = 1 , data = dat )
L i n e a r Hypotheses :
Estima te Std . E r r o r t v a l u e Pr ( >| t | )
1 == 0 = 10.000 3 . 1 7 9 = 3.146 0.0422 *
2 == 0 = 8.750 3 . 1 7 9 = 2.753 0.0876 .
3 == 0 3.250 3.179 1.022 1.0000
4 == 0 = 18.750 5 . 5 0 6 = 3.406 0.0261 *
5 == 0 = 22.000 7 . 7 8 6 = 2.826 0.0765 .
Problem 2. Five treatments for fever blisters (Treatment 1, 2, 3, 4, and 5) were randomly assigned to
30 patients, with 6 patients receiving each treatment. The number of days from initial appearance of the
blisters until healing is complete is measured for each patient.
We are interested in testing if the treatments differ in treating blisters.
We are given that the estimated coefficients from the dummy/reference coding model are:
β c1 = −2.5000, β
c0 = 7.5000, β c2 = −3.1667, β
c3 = −2.3333, β
c4 = −1.3333.
1. Consider the dummy/reference coding model for these data. Write the linear model that is being
fit. Define all terms.
Dummy Coding:
Y 1 = β̂0
Y 2 = β̂0 + β̂1
Y 3 = β̂0 + β̂2
Y 4 = β̂0 + β̂3
Y 5 = β̂0 + β̂4
2. What practical quantity (if any) does the intercept from the above model estimate?
3. Which treatment has the lowest sample mean? Which has the highest sample mean? Justify.
Y 1 = β̂0 = 7.5
Y 2 = β̂0 + β̂1 = 7.5 − 2.5 = 5
Y 3 = β̂0 + β̂2 = 7.5 − 3.1667 = 4.3333
Y 4 = β̂0 + β̂3 = 7.5 − 2.3333 = 5.1667
Y 5 = β̂0 + β̂4 = 7.5 − 1.3333 = 6.1667
The highest sample mean is Y 1
The lowest sample mean is Y 3
4. Find y5 .
5. Consider the Effects Coding model. Write the linear model that is being fit. Define all terms. Find
the estimates of the regression coefficients.
Effect Coding
β̂0 = µ̂T
β̂1 = µ̂1 − µ̂T = α
b1
β̂2 = µ̂2 − µ̂T = α
b2
β̂3 = µ̂3 − µ̂T = α
b3
β̂4 = µ̂4 − µ̂T = α
b4
6. Consider the Cell Means model. Write the linear model that is being fit. Define all terms. Find the
estimates of the regression coefficients.
(
1 if ith patient under treatment j, where i = 1, . . . , 6, j = 1, 2, 3, 4, 5
Igroupj,i =
0 otherwise
Note: Estimates of the regression coefficients:
β̂1 = µ̂1
β̂2 = µ̂2
β̂3 = µ̂3
β̂4 = µ̂4
β̂5 = µ̂5
7. Write down the null and alternative hypotheses in terms of the regression parameters for each of
the 3 models above.
(b) The mean number of days until is healing is complete for patients taking Treatment 4.
(d) The difference between the mean number of days until healing for Treatment 5 and Treatment
1.
Problem 3. The Fixed Effect Model has been covered in the class. In the question, we consider the
Random Effects Model. Let
yij = µ + αj + εij , i = 1, . . . , n; j = 1, . . . , a,
where yij is the response, µ is the overall mean, αj is the effect of treatment j and εij is the error. If
iid iid
αj ∼ N (0, σα2 ), εij ∼ N (0, σ 2 ) and Cov(αj , εij ) = 0, show that
(a) Var(yij ) = σα2 + σ 2 .
Problem 4. For the one-way ANOVA model: yij = µ + αj + ϵij , i = 1, . . . , nj and j = 1, . . . , a, show
that Pa 2
j=1 nj αj
E [M SA] = σ 2 + .
a−1
a a 2 2
X 2 2 X
SSA = nj Y − N Y
j T =⇒ E(SSA) = nj E Y j − N E Y T .
j=1 j=1
Now,
nj nj nj
!
X X X
2
Yij ∼ N (µ + αj , σ ) =⇒ Yj = Yij ∼ N E(Yij ), Var(Yij ) .
i=1 i=1 i=1
Thus,
2 σ2 σ2
E(Y j ) = Var(Y j ) + (E(Y j ))2 = + (µ + αj )2 = + µ2 + 2µαj + αj2 .
nj nj
Similarly,
a
X Xa a
X a
X a
X
nj σ 2 = N N µ, N σ 2
YT = Yj ∼ N nj (µ + αj ), [as nj = N & nj aj = 0].
j=1 j=1 j=1 j=1 j=1
N µ N σ2 σ2
1
YT = YT ∼ N , = N µ, .
N N N2 N
Thus,
2 σ2 2
E Y T = Var(Y T ) + (E(Y T ))2 = + µ2 =⇒ N E Y T = σ 2 + N µ2 . (2)
N
Now, by (1) and (2), we have
a
X 2 2
E(SSA) = nj E Y j − N E Y T
j=1
a
X
= aσ 2 + N µ2 + nj αj2 − σ 2 − N µ2
j=1
a
X
= (a − 1)σ 2 + nj αj2 .
j=1
Finally,
Pa
1 j=1 nj αj2
E [M SA] = E(SSA) = σ 2 + .
a−1 a−1
yij = µ + αj + εij , i = 1, . . . , n; j = 1, . . . , a,
where yij is the response, µ is the overall (grand) mean, αj = µj − µ is the effect of treatment j, and εij
iid
is the error such that εij ∼ N (0, σ 2 ).
Let Y j be the sample mean of the jth group and Y be the sample grand mean.
Hint: You may use the following facts without proof:
Recall that
n
1X
Yj = Yij .
n i=1
iid
Since Yij ∼ N (µ + αj , σ 2 ) and the sum of linear independent random variables is normal, we have
n
X
Yij ∼ N (n(µ + αj ), nσ 2 ).
i=1
Thus,
σ2 σ2
Yj ∼N µ + αj , = N µj , ,
n n
as αj = µj − µ.
Recall that
a n
1 XX
Y = Yij .
an j=1 i=1
Pn Pa Pn
Since i=1 Yij ∼ N n(µ + αj ), nσ 2 , we have j=1 i=1 Yij ∼ N naµ, naσ 2 ,
σ2
Y ∼ N µ, ,
na
Pa
as j=1 αj = 0.
(c) Show that α̂j = Y j − Y is unbiased estimator of αj . Show all the steps.
Now,
σ2
(d) Show that Cov Y j , Y = na . Show all the steps.
Pa
Note that, since the design is balance (nj = n for all j), Y T = a1 j=1 Y j .
a
1 X
Cov Y j , Y T = Cov Y j , Y j
a j=1
n
1 X
= Cov Y j , Y j
a j=1
1
= Cov Y j , Y 1 + Cov Y j , Y 2 + · · · + Cov Y j , Y j + Cov Y j , Y j+1
a
+ · · · + Cov Y j , Y a .
σ 2 a−1
or any equivalent expression such as n a .
yij = µ + αj + εij , i = 1, . . . , nj ; j = 1, . . . , a,
To find the least squares estimates, we need to minimize the RSS with respect to µ and αj .
Taking the partial derivatives of RSS with respect to µ and αj and setting them to zero, we get:
a X nj
∂RSS X
= −2 (Yij − µ − αj ) = 0, (1)
∂µ j=1 i=1
nj
∂RSS X
= −2 (Yij − µ − αj ) = 0 for each j. (2)
∂αj i=1
It follows that:
a nj
1 XX
µ̂ = Yij = Y T .
N j=1 i=1
1
Pnj
where Y j = nj i=1 Yij is the sample mean of the j-th group.
α̂j = Y j − µ̂ = Y j − Y T .
Problem 7. A study will be conducted to compare k new treatments with a control treatment. A
completely randomized design will be used to plan the study. One of the key decisions for the researchers
is whether an equal number of experimental units should be allocated to each of the k + 1 groups.
Specifically, if nc experimental units are randomly allocated to the control group, and n experimental
units are allocated to each of the k new treatments, then how large should nc be in relation to n?
To answer this question, it has been decided to choose nc to minimize the variance of the difference
between the control effect and any treatment effect. In other words, the variance of α̂c − α̂j must be
minimized (j = 1, 2, . . . , k).
In this notation:
1. Suppose that the total number of experimental units is N , and that this number is fixed. How
should nc and n be chosen to minimize the variance of α̂c − α̂j ?
2. Write the expression for the 95% confidence interval for αc − αj .
Since the total number of experimental units is fixed as N , we have the constraint:
nc + kn = N.
To minimize V (α̂c − α̂j ), we differentiate with respect to n and set the derivative to 0:
k 1
σ2 − = 0.
(N − kn)2 n2