Assign3 2023 Sol
Assign3 2023 Sol
Total marks: 60
Due date: Saturday, Nov. 4 at 11:59pm
Reminder:
• Follow the Assignment Guidelines.
• Select pages when submitting to Gradescope.
• One-line R commands should only be used to verify answers.
• When performing a test, state the hypotheses, test statistic
and distribution, p-value or critical value, and conclusion. If
unspecified, use the default 5% significance level.
midterm = c(82.54,79.37,77.78,60.32,65.08,69.84,61.90,61.90,44.44,
63.49,80.95,84.13,76.19,88.89,73.02,85.71,71.43,84.13,84.13,69.84)
final = c(85.67,84.44,80.83,69.06,67.73,81.75,73.62,62.61,66.56,
65.52,82.38,94.13,65.58,96.68,86.40,87.95,74.92,84.56,85.99,57.34)
(a) [4] Perform the paired t-test for the above data.
Answer. The hypotheses are stated in the question. We first find
the differences for each pair:
1
The mean of di is d¯ = 4.432. The sample variance based on di is
given by
1 X ¯ 2 = 60.00 .
s2 = (di − d)
20 − 1
The paired t-statistic has value
d¯
Tobs = = 2.559 .
(s2 /20)0.5
The reference distribution is t with 19 degrees of freedom. We
compute the p-value as
for the two-sided alternative. Because 0.019 < 0.05, we reject the
null hypothesis that students perform similarly on the midterm
and the final (δ = 0) in favour of the claim that performances are
different at the conventional level 0.05.
(b) [4] If one mistakes the problem for a two-sample problem, what
would be the conclusion based on a two-sample t-test? (Perform
the standard t-test.)
Answer. The hypotheses are
H0 : µm = µf , H1 : µm ̸= µf .
2
The reference distribution is t with n1 + n2 − 2 = 38 and so the
p-value would be
3
(assumed to be useful), how many pairs of observations should
she collect for this separate study?
Remark: independent thinking is needed as nothing discussed in
class can be directly applied.
Answer. We do a sample size calculation based on the paired
t-test. Note that other approaches are acceptable as long as they
are reasonable given the context and carried out correctly.
Let δ = µfinal − µmidterm . The null hypothesis is that H0 : δ ≤ 3
and the alternative is that H1 : δ > 3. Let n be the number of
pairs inPthe new study. Taking d¯new = ȳnew:final − ȳnew:midterm and
n
(di −d¯new )2
s2new = i=1 n−1 as defined in (a), the test statistic
d¯new − 3
t0 =
(s2new /n)0.5
has a t-distribution with n − 1 degrees of freedom under the as-
sumption δ = 3. The upper α = 0.05 quantile of this distribution
is given by qn = qt(1 − α, n − 1).
To do a power calculation, we use the current data to obtain an
effect size δ = d¯ = 4.432. Under the alternative δ = 4.432, the
statistic
d¯new − 4.432 1.132
t1 = = t0 −
(s2new /n)0.5 (s2new /n)0.5
has a t-distribution with n − 1 degrees of freedom. This implies
that we can compute the power for a given n as
4
using s2 = 60 from the current data. To get 1 − β ≥ 0.8, we find
that we need at least n = 291 pairs in the new study.
R code:
nn = 10:300
alpha = 0.05
svar = var(final-midterm)
pows = pt(qt(1-alpha,nn-1)-1.132/sqrt(svar/nn), nn-1, lower.tail=F)
nn[which(pows > 0.8)[1]]
5
Both are acceptable. The outcome is highly significant, and we
reject the null hypothesis that students perform similarly on the
midterm and the final at the conventional level 0.05.
Note: other tests are acceptable as long as they are reasonable
given the context and carried out correctly.
This problem asks you to go over all routine data analysis for the
complete randomized design and a bit more.
Their SS is computed as
4
X
SSb = 4 (ȳi· − ȳ·· )2 = 0.00361875.
i=1
6
and the treatment SS is computed as
4
X
SStrt =4 (ȳ·j − ȳ·· )2 = 0.8762688.
j=1
Source DF SS MSS F
Volunteer 3 0.0036 0.0012
Treatment 3 0.8763 0.2921 44.21
Error 9 0.0594 0.0066
Total 15 0.9393
(b) [2] Test the hypothesis for H0 : treatment effects are the same.
Answer. The F-statistic is found in the ANOVA table. The
p-value is computed as
7
(c) [8] Regardless of the outcome of (b), use Tukey’s method to con-
struct simultaneous confidence intervals for differences in treat-
ment means.
Answer. The pairwise treatment differences for (1, 2), (1, 3),
(1, 4), (2, 3), (2, 4), (3, 4) are estimated as
qtukey(0.95, 4, 9) = 4.41489 .
(d) [4] Construct a 95% two-sided CI for τ1 + τ3 − 2τ2 using the rec-
ommended universal recipe.
8
Answer. We estimate θ = τ1 + τ3 − 2τ2 by
θ̂ = (ȳ·1 − ȳ·· ) + (ȳ·3 − ȳ·· ) − 2(ȳ·2 − ȳ·· )
= ȳ·1 + ȳ·3 − 2ȳ·2 = 0.0925 .
When regarded as a random variable (rather than an observed
value), θ̂ is the linear combination of 3 independent means where
each is a mean of 4 observations. Hence, we have
3
Var(θ̂) = (1/4 + 1/4 + 1)σ 2 = σ 2 .
2
We naturally estimate it by
d θ̂) = 3 MSS(error) = 0.0099
Var(
2
which has 9 degrees of freedom. Note qt(0.975, 9) = 2.262157.
Hence, a 95% CI for θ = τ1 + τ3 − 2τ2 is given by
√
0.0925 ± 2.262157 0.0099 = (−0.133, 0.318) .
9
(Source: Box, Hunter, and Hunter, altered slightly).
The following code might be useful.
n = 4
k1 = 4
k2 = 3
dat = data.frame(times = c(0.31,0.82,0.43,0.45,
0.45,1.10,0.45,0.71,
0.46,0.88,0.63,0.66,
0.43,0.72,0.76,0.62,
0.36,0.92,0.44,0.56,
0.29,0.61,0.35,1.02,
0.40,0.49,0.31,0.71,
0.23,1.24,0.40,0.38,
0.22,0.30,0.23,0.30,
0.21,0.37,0.25,0.36,
0.18,0.38,0.24,0.31,
0.23,0.29,0.22,0.33),
group = rep(c("A","B","C","D"), n*k2),
poison = rep(c("I","II","III"), each=n*k1))
(a) [8] Construct the analysis of variance table for this two-way layout
design.
Answer. The calculations for the SS corresponding to the main
effects are similar to that described in Q(2a). The interaction SS
is given by
3 X
X 4
SSint =4 (ȳij. − ȳi.. − ȳ.j. + ȳ... )2 .
i=1 j=1
10
Source DF SS MSS F
Treatment 3 0.9212 0.3071 13.80
Poison 2 1.033 0.5165 23.22
Interaction 6 0.2501 0.0417 1.874
Error 36 0.8007 0.0222
Total 47 2.0014
R code:
I = 4
J = 3
n = 4
yy1 = matrix(c(0.31,0.82,0.43,0.45,
0.45,1.10,0.45,0.71,
0.46,0.88,0.63,0.66,
0.43,0.72,0.76,0.62), 4, 4, byrow=T)
yy2 = matrix(c(0.36,0.92,0.44,0.56,
0.29,0.61,0.35,1.02,
0.40,0.49,0.31,0.71,
0.23,1.24,0.40,0.38), 4, 4, byrow=T)
yy3 = matrix(c(0.22,0.30,0.23,0.30,
0.21,0.37,0.25,0.36,
0.18,0.38,0.24,0.31,
0.23,0.29,0.22,0.33), 4, 4, byrow=T)
mean.trt = colMeans(rbind(yy1,yy2,yy3))
mean.poison = c(mean(yy1), mean(yy2), mean(yy3))
mean.int = rbind(colMeans(yy1),colMeans(yy2),colMeans(yy3))
ybar = mean(mean.trt)
# Compute SS
SS.trt = n*J*sum((mean.trt-ybar)^2)
SS.poison = n*I*sum((mean.poison-ybar)^2)
SS.int = n*sum((mean.int
-matrix(rep(mean.poison,I),J,I,byrow=F)
-matrix(rep(mean.trt,J),J,I,byrow=T)
11
+ybar)^2)
SS.total = sum((yy1-ybar)^2) + sum((yy2-ybar)^2) + sum((yy3-ybar)^2)
SS.err = SS.total - SS.poison - SS.trt - SS.int
# Compute MSS
MS.trt = SS.trt / (I-1)
MS.poison = SS.poison / (J-1)
MS.int = SS.int / ((I-1)*(J-1))
MS.err = SS.err / (I*J*(n-1))
# Compute F-statistic
F.trt = MS.trt / MS.err
F.poison = MS.poison / MS.err
F.int = MS.int / MS.err
(b) [4] Test the hypotheses of whether the effects of poison and treat-
ment are significant.
Answer. For each of the factors, we test the hypotheses that the
main effects are equal (H0 ) against the alternative that at least
two of the levels have different effects.
The 95% quantiles of F3,36 and F2,36 are 2.866266 and 3.259446,
respectively.
Using these reference distributions and the observed F-statistics
obtained in (a), we reject H0 for both treatment and poison and
conclude that both have significant effects.
R code:
qf(0.95, 3, 36)
qf(0.95, 2, 36)
(c) [4] Test the hypothesis of whether the interaction effect is signifi-
cant.
Answer. For the interaction, we test the hypotheses that the
interaction effects are equal (H0 ) against the alternative that the
effects are not all equal.
12
The 95% quantile of F6,36 is 2.363751.
Using this reference distribution and the observed F-statistic ob-
tained in (a), we do not reject H0 and conclude that the interaction
between treatment and poison is not significantly different from
0.
R code:
qf(0.95, 6, 36)
13