Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Show all work. Submit your solutions in a pdf document on Canvas. Include your R code (which must be
commented and properly indented) in the pdf file. Also submit one text file with all your R code (comments
and all) clearly labeled with the problem it goes with. This must be properly indented. Before every solution
with random sampling use set.seed(3701).
Question 1 (15 points).
Let’s consider a slightly different data generating model for paired data. Suppose we want to compare
students scores of a standardized test before and after taking a prep course. There are n students that will be
taking the test. Let X be the yet-to-be observed random variable of the score before the course and Y be the
yet-to-be observed random variable of the score after the course. Moreover, we let X and Y be the linear
combinations of two common latent variable, i.e., the model for the ith student is Xi = µ1 + a1Ai + b1Bi
Yi = µ2 + a2Ai + b2Bi,
where µj , aj , bj , j = 1, 2 are constants. Ai
, Bi are independent both within the same subject and across
different subjects. Ai’s are iid ∼ N(0, σ2A), Bi
is are iid N(0, σ2B).
(a) (4 points) What are the distributions of Xi and Yi
, respectively? If we let Zi = Xi −Yi
, does this data
generating model still satisfy the assumptions for paired t-test? Why?
(b) (5 points) Let µ1 = 68, µ2 = 70, σ2
A = 2, σ2
B = 1, a1 = 2, b1 = 1, a2 = 1, b2 = 2. It can
be show that E[X] = 68, E[Y ] = 70. Use simulation to produce a 99% confidence interval for
Var(X) = E[(X−68)2
] and a 99% confidence interval for Var(Y ) = E[(Y −70)2
]. Set reps = 105
.
(c) (3 points) Now we are interested in paired t-test for
H0 : µ1 = µ2
Ha : µ1 ̸= µ2,
with data assumed to be coming from our data generating model. Create a function named mypaired.pval
that generate realizations of the random p-value of this test. Your function should have the following
arguments
• mu1, mean of X
• mu2, mean of Y
• a1,b1,a2,b2 as defined in our data generating model
• sigmaA, standard deviation of A
• sigmaAB, standard deviation of B
1
• n, sample size (number of pairs)
• reps, number of replications.
The function should output a vector containing the realizations of the random p-value.
(d) (4 points) Use µ1 = 68, µ2 = 68.5, σ2
A = 2, σ2
B = 1, a1 = 2, b1 = 1, a2 = 1, b2 = 2, α = 0.05. Set
reps = 1000. Test your function by creating a simulation based estimation of the power curve with
the sample size n ∈ {20, 25, . . . , 200}. Produce a pointwise 95% confidence interval for the power
curve with the Clopper-Peason CI and include the curves for the lower bound and upper bound of CI
in the same plot of the estimated power curve.