ME1 EC2 mock exam — 4 hours with R beside you, from the normal to confidence intervals, four versions and a mark out of 50 (and why exercise 1 is worth double)
The EC2 of Statistical Methods I is the second half of the subject in a single afternoon: 4 hours with your laptop, 4 linked exercises and 50 points, from the normal distribution to confidence intervals, with RStudio open and an .R file you upload to the campus at the end. This mock exam reproduces it: the same 20, 10, 10 and 10 points plus a 5-point extra bonus, the R environment on the right with your version’s data already loaded, boxes that mark themselves to two decimals and criteria to mark your own proofs. When you hand in you see your mark out of 50, whether it is enough to pass by coursework, the part-by-part breakdown and the solution to each part with its R code and the real output.
There are four original versions: A, B and C follow the 2025-26 EC2 (the same kinds of exercise with other contexts and other data) and D swaps some parts for syllabus content that did not come up that year. No statement is real: the data were generated with a script, the answers come from running the solution code once in R, and it has been checked that no value matches the real exam.
Table of Contents
Take the mock exam
Choose the version and how you want to do it. When you start, the exam fills the window: the statement on the left and R on the right (on a phone, two tabs). The clock counts the 4 hours of the real exam.
The mock exam needs JavaScript. Below you will find what the exam is like and what each exercise covers.
Two independent parts: a sum of many variables (part a) and a joint density with a transformation (parts b to h). In the parts with a Check, write the numerical value in the box; the working, on paper.
Let be the fraction of a recorded lecture that each of the 30 students in the group watches, independent and with common density , . Let (the «full videos» watched between all of them). Using R and applying, if possible, the Central Limit Theorem, find approximately . Check: , and the probability.
Solution
- E(Xᵢ) 0.75
- Var(Xᵢ) 0.04
- Probability 0.32
With R
f <- function(x) 3 * x^2 integrate(f, 0, 1)$value # 1: it is a density mu <- integrate(function(x) x * f(x), 0, 1)$value s2 <- integrate(function(x) x^2 * f(x), 0, 1)$value - mu^2 c(mu, s2) n <- 30 pnorm(22, mean = n * mu, sd = sqrt(n * s2)) # P(S <= 22), approximated by the CLT
[1] 1 [1] 0.7500 0.0375 [1] 0.3186759
and , so . By the CLT, (variance) and . The CLT applies because the are independent, identical and with finite variance, and 30 terms of such a smooth density are enough.
When I switch my phone on in the morning, is the minutes until the first virtual campus email and the minutes until the first class group message. Their joint density is , , , with . The check boxes are filled in with . Find so that is a density. Check: its value with .
Solution
- K 6
With R
la <- 3 # check value g <- function(x, y) exp(-(2 * x + la * y)) # the density without K double_int <- function(h, M = Inf) integrate(function(y) sapply(y, function(yy) integrate(function(x) h(x, yy), 0, M)$value), 0, M)$value K <- 1 / double_int(g); K
[1] 6
The double integral over the support must be 1. Since the exponential splits into an factor and a factor, the double integral is the product of two exponential integrals: you get and, with , . In R it is checked with two nested integrate calls (the inner one with sapply).
Find the marginal densities of and and identify them, if possible, with a known distribution. Check: and with .
Solution
- E(X) 0.50
- E(Y) 0.33
With R
f <- function(x, y) K * g(x, y) fX <- function(x) sapply(x, function(xx) integrate(function(y) f(xx, y), 0, Inf)$value) fY <- function(y) sapply(y, function(yy) integrate(function(x) f(x, yy), 0, Inf)$value) EX <- integrate(function(x) x * fX(x), 0, Inf)$value EY <- integrate(function(y) y * fY(y), 0, Inf)$value c(EX, EY)
[1] 0.5000000 0.3333333
Integrate the other variable over its range: , exponential with rate 2, and , exponential with rate . Since , X and Y are independent. With : and .
Find the joint moment generating function of and where it exists. Check: with .
Solution
- φ(1, 1) 3
With R
phi <- function(s, t) double_int(function(x, y) exp(s * x + t * y) * f(x, y), M = 100) # up to 100: with Inf, Inf · 0 phi(1, 1)
[1] 3
. With independence it is the product of the two marginal mgfs: , for (outside that the integral diverges). With , . In R, the double integral goes up to 100 and not to Inf: with Inf you get and integrate complains.
Find . Check: its value with .
Solution
- Cov(X, Y) 0
With R
EXY <- double_int(function(x, y) x * y * f(x, y)) EXY - EX * EY # Cov(X, Y)
[1] 7.025553e-09
Being independent, and . It also comes from differentiating the mgf: . R gives a number around : that is the error of the numerical integration, not a covariance.
Let and . Find the joint density function of , with its support. Check: with .
Solution
- f(U,V)(1, 0.5) 0.32
With R
fUV <- function(u, v) f((u + v) / 2, (u - v) / 2) * 1 / 2 # |J| = 1/2 fUV(1, 0.5)
[1] 0.3161977
Invert the transformation: , , with Jacobian , so . Then on ( and become and ). With , . The typical mistake is forgetting or the support: without it, the marginal in the next part comes out wrong.
Find the marginal density of , . Check: with .
Solution
- f_U(1) 0.51
With R
fU <- function(u) integrate(function(v) fUV(u, v), -u, u)$value fU(1)
[1] 0.5132893
For each , integrate from to : . It is the sum of two exponentials with different rates (it is not a gamma: that only happens with equal rates). With , .
Find the marginal density of , . Check: and with .
Solution
- f_V(0.5) 0.44
- f_V(−0.5) 0.27
With R
fV <- function(v) integrate(function(u) fUV(u, v), abs(v), Inf)$value c(fV(0.5), fV(-0.5))
[1] 0.4414553 0.2677562
For each , runs from to , and you must split and : . It is skewed: the tail is driven by X and the one by Y. With : and . Check: it integrates to 1 adding the two pieces.
How long the lab server takes to start every morning (in minutes) is a positive continuous variable with density , , with unknown , and we know that . Last week’s 10 start-ups are already in the boots vector of your script.
boots <- c(1.199, 1.542, 1.578, 0.7, 2.788, 0.991, 3.055, 1.202, 2.539, 2.156)
Let be a simple random sample from this population. Find an estimator of by the method of moments, , and another by maximum likelihood, . Mark yourself with the criteria.
Solution
Marking criteria:
- Sets equal to 0.5
- Solves 0.5
- Writes the log-likelihood of the sample 0.5
- Differentiates, sets to 0 and reaches (and checks it is a maximum) 0.5
Set the population mean equal to the sample mean: and solve. You get . For maximum likelihood: ; differentiating, and . The second derivative at that point is : it is a maximum. The two estimators need not agree: they use different information from the sample.
With the data in boots, find the two estimates of and compare them.
Solution
- Moments 7.85
- Max. likelihood 8.89
With R
boots <- c(1.199, 1.542, 1.578, 0.7, 2.788, 0.991, 3.055, 1.202, 2.539, 2.156) x <- boots; n <- length(x) mom <- (mean(x) / gamma(4/3))^3 # method of moments mv <- mean(x^3) # maximum likelihood c(mom, mv)
[1] 7.853633 8.894533
and . They are close but not equal: with 10 or 12 values the difference is normal. The moments one only uses ; the maximum likelihood one uses the transformation that turns the data into exponentials, which is what really carries the information about the parameter.
Compare the maximum likelihood estimate with the one optim gives numerically in R, using the moments estimate as the starting value.
Solution
- optim 8.89
With R
logL <- function(th) sum(log(3 * x^2 / th) - x^3 / th) o <- optim(mom, logL, method = "L-BFGS-B", lower = 1e-6, control = list(fnscale = -1)) o$par
[1] 8.894533
optim maximises the log-likelihood with fnscale = -1 (by default it minimises) and gives 8.89, the same as the formula up to the fourth decimal. With one parameter, the "L-BFGS-B" method with a positive lower is better: that way the parameter does not wander into negative values, where the logarithm does not exist.
Find the moment generating function of and identify its distribution. (Hint: first find the density of .)
Solution
Marking criteria:
- Correct change of variable for , with its Jacobian 0.75
- Identifies Y as exponential with mean 0.25
- , 0.75
- Identifies it: gamma with shape and rate 0.25
, , so : an exponential with mean , with mgf . Since is the mean of independent exponentials, , the mgf of a gamma with shape and rate . This part is the key to the next three.
Prove that the maximum likelihood estimator is unbiased.
Solution
Check with R
set.seed(2) # 10.000 samples of size 10 with θ = 8 th <- replicate(10000, mean(8 * rexp(10))) # X³ ~ exp with mean θ c(mean(th), var(th), 8^2 / 10) # mean ≈ θ and variance ≈ θ²/n
[1] 7.984268 6.385102 6.400000
Marking criteria:
- Uses (or the mean of the gamma in part d) 1
- Linearity: 1
: bias 0. It also follows from the gamma(, ): its mean is . The R simulation confirms it: the mean of 10,000 estimates lands next to the true value.
Prove that is consistent.
Solution
Marking criteria:
- 0.5
- Unbiased with variance tending to 0 ⇒ MSE → 0 ⇒ consistent (Chebyshev) 0.5
, which tends to 0. Being unbiased, , and by Chebyshev : it is consistent. (The law of large numbers works too: is a mean of variables with mean .)
Prove that is efficient.
Solution
Marking criteria:
- Computes the Fisher information: 0.5
- Cramér–Rao bound = , and unbiased ⇒ efficient 0.5
and, with , . The Cramér–Rao bound for unbiased estimators is , exactly : it attains it, so it is efficient. The simulation in part e gives a variance almost equal to the bound.
The battery life (in hours) of the 32 laptops in the computer lab was measured under normal class use. The data are already in the before vector of your script.
before <- c(6.52, 6.95, 5.58, 6.63, 5.34, 6.54, 7.41, 5.38, 5.53, 7.08,
6.3, 5.43, 4.72, 6.47, 7.02, 7.41, 5.41, 7.33, 6.97, 6.36,
6.4, 6.66, 5.2, 7.07, 6.63, 6.96, 6.66, 7.23, 5.59, 5.65,
6.16, 5.23)And the data for part d:
after <- c(7.23, 6.98, 4.96, 7.03, 6.34, 6.56, 7.61, 5.45, 6.36, 6.07,
7.67, 6.58, 5.07, 5.92, 5.62, 9.16, 6.93, 7.94, 8.05, 7.38,
7.28, 9.45, 6.31, 10.21, 7.24, 6.61, 6.69, 7.76, 4.81, 5.18,
7.94, 5.47)Assuming the data are normal, , with known standard deviation , find the maximum likelihood estimate of and a 90 % confidence interval with R.
Solution
- μ̂₁ 6.31
- Lower limit 6.07
- Upper limit 6.54
With R
before <- c(6.52, 6.95, 5.58, 6.63, 5.34, 6.54, 7.41, 5.38, 5.53, 7.08, 6.3, 5.43, 4.72, 6.47, 7.02, 7.41, 5.41, 7.33, 6.97, 6.36, 6.4, 6.66, 5.2, 7.07, 6.63, 6.96, 6.66, 7.23, 5.59, 5.65, 6.16, 5.23) after <- c(7.23, 6.98, 4.96, 7.03, 6.34, 6.56, 7.61, 5.45, 6.36, 6.07, 7.67, 6.58, 5.07, 5.92, 5.62, 9.16, 6.93, 7.94, 8.05, 7.38, 7.28, 9.45, 6.31, 10.21, 7.24, 6.61, 6.69, 7.76, 4.81, 5.18, 7.94, 5.47) x <- before; n <- length(x); sigma <- 0.8 z <- qnorm(1 - 0.1 / 2) c(mean(x), mean(x) - z * sigma / sqrt(n), mean(x) + z * sigma / sqrt(n))
[1] 6.306875 6.074258 6.539492
The MLE of a normal mean is hours. With known , the pivot is and the interval is = (6.07, 6.54). R has no function for this case (t.test uses the t): write it by hand with qnorm.
The same, but with unknown . Compare with the interval in the previous part.
Solution
- Lower limit 6.08
- Upper limit 6.54
With R
t.test(x, conf.level = 0.9)$conf.int
[1] 6.076797 6.536953 attr(,"conf.level") [1] 0.9
With unknown it is replaced by and the pivot becomes a : (6.08, 6.54), width 0.46 against 0.47. It is narrower: the t has heavier tails than the normal, but here the sample standard deviation () is smaller than the assumed , and that weighs more than the gap between the quantiles.
With unknown mean and standard deviation, give the maximum likelihood estimate of and a 95 % confidence interval for with R.
Solution
- σ̂² 0.57
- Lower limit 0.38
- Upper limit 1.04
With R
s2mv <- (n - 1) * var(x) / n # MLE of σ²: divides by n c(s2mv, (n - 1) * var(x) / qchisq(1 - 0.05 / 2, n - 1), (n - 1) * var(x) / qchisq(0.05 / 2, n - 1))
[1] 0.5708277 0.3787222 1.0414938
The MLE of divides by , not : (R’s var divides by ). The pivot is , and when solving for the quantiles swap places: the high quantile goes at the bottom. Interval: (0.38, 1.04), not at all symmetric around the estimate, because the chi-square is not.
After a system update, the battery of the same 32 laptops is measured again, in the same order. The data are already in the after vector of your script. Also assuming these data are normal, use R to find a 95 % confidence interval for the variance ratio and justify whether they can be considered equal.
Solution
- Lower limit 0.17
- Upper limit 0.72
- Equal variances? No
With R
var.test(before, after, conf.level = 0.95)$conf.int # σ²(before) / σ²(after)
[1] 0.1726093 0.7243874 attr(,"conf.level") [1] 0.95
With two normal samples, , and var.test gives the interval for : (0.17, 0.72). It does not contain 1 (it lies entirely below), so the variances cannot be considered equal: after the update the battery life varies more from one laptop to another. Note: even if they differ, part f does not use this to choose a formula, because the samples are paired and you work with the differences.
Let there be two paired normal samples of size and the difference of each pair, with independent . Prove that , where is the standard deviation of the differences.
Solution
Marking criteria:
- 0.5
- 0.5
- and independent (Fisher’s theorem) 0.5
- simplifies to and is a 0.5
The key is that, by subtracting within each pair, the are a single normal sample: whatever happens between the two measurements of the same individual stops mattering. Then it is the one-sample t: standard normal, chi-square with degrees by Fisher’s theorem, independent, and ; dividing, cancels out. Write down every result you use: that is what earns the marks.
Using the two previous parts, give the maximum likelihood estimate of the mean difference (after − before) and a 95 % confidence interval for it with R. Interpret.
Solution
- d̄ 0.56
- Lower limit 0.20
- Upper limit 0.93
- Is there a change? Yes
With R
d <- after - before # difference for each one: after - before mean(d) t.test(after, before, paired = TRUE, conf.level = 0.95)$conf.int
[1] 0.56375 [1] 0.1994413 0.9280587 attr(,"conf.level") [1] 0.95
Estimate: hours. Interval with t.test(..., paired = TRUE): (0.20, 0.93). It lies entirely above 0: the mean battery life has changed with 95 % confidence (it went up). The typical mistake is treating the two samples as independent: it throws away the fact that each pair is the same individual and gives a much wider interval.
The minutes the university VPN stays connected before dropping follow an , with unknown . Let be a simple random sample and ; the MLE of is . The data for the last part are already in the drops vector of your script.
drops <- c(0.82, 0.36, 0.03, 0.11, 0.34, 0.53, 0.12, 0.2, 0.42, 1.37,
0.28, 0.2, 1.12, 1.23, 0.06, 0.17, 0.93, 0.47, 0.65, 0.35)Find the distribution of .
Solution
Marking criteria:
- Writes the mgf of each term (with its domain) 1
- Product by independence: , the mgf of a gamma(, ) 1
Each has mgf , ; by independence, the sum’s is the product: , , which is the mgf of a gamma(, ). Since the mgf determines the distribution, is that gamma.
Find the density of and identify it.
Solution
Marking criteria:
- Change of variable with 1
- Simplifies: disappears and a is left 1
With , the gamma density of T becomes , with : the density of a , which no longer depends on . That is why works as a pivot: it depends on the parameter and the sample, but its distribution is known and has no parameters.
Build a confidence interval for using as the pivot.
Solution
Marking criteria:
- Sets up 1
- Solves for : 1
Leave the same probability in each tail of the and divide by (it does not flip the inequalities). It is an exact interval: it works for any , not only for large samples.
Build an asymptotic confidence interval for .
Solution
Marking criteria:
- Fisher information and 1
- Replaces by in the variance: 1
The MLE is asymptotically normal with variance : with , . Standardising and putting where the variance needs gives the interval. It only works for large , and it is symmetric around , unlike the exact one.
With the values in drops, use R to find the exact and asymptotic intervals for at 90 %. Compare them.
Solution
- Exact: lower 1.36
- Exact: upper 2.86
- Asymptotic: lower 1.30
- Asymptotic: upper 2.80
With R
drops <- c(0.82, 0.36, 0.03, 0.11, 0.34, 0.53, 0.12, 0.2, 0.42, 1.37, 0.28, 0.2, 1.12, 1.23, 0.06, 0.17, 0.93, 0.47, 0.65, 0.35) x <- drops; n <- length(x); T <- sum(x); a <- 0.1 c(qchisq(a / 2, 2 * n), qchisq(1 - a / 2, 2 * n)) / (2 * T) # exact: 2λT ~ chi2(2n) l <- n / T # MLE of λ l + c(-1, 1) * qnorm(1 - a / 2) * l / sqrt(n) # asymptotic
[1] 1.358059 2.856479 [1] 1.295491 2.802870
Exact: (1.36, 2.86). Asymptotic: (1.30, 2.80). They are close, but the asymptotic one is shifted to the left and symmetric; the exact one respects the chi-square skewness. With 20 values, the exact one is the one to trust. Careful with qchisq: the degrees of freedom are , not .
I want to compare two classmates’ hits on the last 25 questions of the virtual campus quizzes (1 = right, 0 = wrong). The data are already in the vectors x (first classmate) and y (second) of your script.
x <- c(1, 1, 1, 1, 0, 1, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 0, 0,
1, 1, 1, 0, 1)
y <- c(1, 1, 0, 1, 0, 0, 0, 1, 1, 1,
0, 0, 0, 1, 0, 1, 1, 1, 0, 1,
1, 1, 1, 0, 1)The last part (second bonus) does not use these data.
First bonus. Use R to give the maximum likelihood estimate of each proportion and of their difference.
Solution
- p̂₁ 0.76
- p̂₂ 0.60
- p̂₁ − p̂₂ 0.16
With R
x <- c(1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1) y <- c(1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1) p1 <- mean(x); p2 <- mean(y) c(p1, p2, p1 - p2)
[1] 0.76 0.60 0.16
With 0/1 data (Bernoulli), the MLE of is the mean: , and, by the invariance of the MLE, that of the difference is the difference: 0.16.
Find an asymptotic 99 % confidence interval for . Can we say the hit rates differ?
Solution
- Lower limit -0.17
- Upper limit 0.49
- Different? No
With R
m <- length(x); n <- length(y); z <- qnorm(1 - 0.01 / 2) (p1 - p2) + c(-1, 1) * z * sqrt(p1 * (1 - p1) / m + p2 * (1 - p2) / n)
[1] -0.1748182 0.4948182
= (-0.17, 0.49). It contains 0: with these data you cannot say they differ. Before using it, check that , and those of the other sample are not too small (that the normal is reasonable).
Second bonus. Let and , all independent. Use R to find the value such that .
Solution
- a 23.68
With R
qchisq(0.95, df = 6 + 8) # P(W <= a) = 0.95 with W ~ chi2(14)
[1] 23.68479
Each is a standard normal, so its square is a ; so is each . The sum of 14 independent chi-square(1) is a (reproductive property) and is its 0.95 quantile: 23.68.
Two independent parts: a sum of many variables (part a) and a joint density with a transformation (parts b to h). In the parts with a Check, write the numerical value in the box; the working, on paper.
Let be the fraction of a 40-question test that each of 24 students leaves blank, independent and with common density , . Let (the «whole tests» left blank). Using R and applying, if possible, the Central Limit Theorem, find approximately . Check: , and the probability.
Solution
- E(Xᵢ) 0.33
- Var(Xᵢ) 0.06
- Probability 0.19
With R
f <- function(x) 2 * (1 - x) integrate(f, 0, 1)$value # 1: it is a density mu <- integrate(function(x) x * f(x), 0, 1)$value s2 <- integrate(function(x) x^2 * f(x), 0, 1)$value - mu^2 c(mu, s2) n <- 24 1 - pnorm(9, mean = n * mu, sd = sqrt(n * s2)) # P(S >= 9), approximated by the CLT
[1] 1 [1] 0.33333333 0.05555556 [1] 0.1932381
and , so . By the CLT, (variance) and . Mind the tail: «at least 9» is , not .
and are the hours two power banks, the big one and the small one, keep charging the phone. Their joint density is , , , with . The check boxes are filled in with . Find so that is a density. Check: its value with .
Solution
- K 0.50
With R
la <- 0.5 # check value g <- function(x, y) exp(-la * (x + 2 * y)) # the density without K double_int <- function(h, M = Inf) integrate(function(y) sapply(y, function(yy) integrate(function(x) h(x, yy), 0, M)$value), 0, M)$value K <- 1 / double_int(g); K
[1] 0.5
The double integral over the support must be 1. Since the exponential splits into an factor and a factor, the double integral is the product of two exponential integrals: you get and, with , . In R it is checked with two nested integrate calls (the inner one with sapply).
Find the marginal densities of and and identify them, if possible, with a known distribution. Check: and with .
Solution
- E(X) 2
- E(Y) 1
With R
f <- function(x, y) K * g(x, y) fX <- function(x) sapply(x, function(xx) integrate(function(y) f(xx, y), 0, Inf)$value) fY <- function(y) sapply(y, function(yy) integrate(function(x) f(x, yy), 0, Inf)$value) EX <- integrate(function(x) x * fX(x), 0, Inf)$value EY <- integrate(function(y) y * fY(y), 0, Inf)$value c(EX, EY)
[1] 1.9999996 0.9999999
Integrate the other variable over its range: , exponential with rate , and , exponential with rate . Since , X and Y are independent. With : and .
Find the joint moment generating function of and where it exists. Check: with .
Solution
- φ(0.25, 0.5) 4
With R
phi <- function(s, t) double_int(function(x, y) exp(s * x + t * y) * f(x, y), M = 100) # up to 100: with Inf, Inf · 0 phi(0.25, 0.5)
[1] 4
. With independence it is the product of the two marginal mgfs: , for (outside that the integral diverges). With , . In R, the double integral goes up to 100 and not to Inf: with Inf you get and integrate complains.
Find . Check: its value with .
Solution
- Cov(X, Y) 0
With R
EXY <- double_int(function(x, y) x * y * f(x, y)) EXY - EX * EY # Cov(X, Y)
[1] 6.137907e-07
Being independent, and . It also comes from differentiating the mgf: . R gives a number around : that is the error of the numerical integration, not a covariance.
Let and . Find the joint density function of , with its support. Check: with .
Solution
- f(U,V)(1, 0.5) 0.13
With R
fUV <- function(u, v) f((u + v) / 2, (u - v) / 2) * 1 / 2 # |J| = 1/2 fUV(1, 0.5)
[1] 0.1338154
Invert the transformation: , , with Jacobian , so . Then on ( and become and ). With , . The typical mistake is forgetting or the support: without it, the marginal in the next part comes out wrong.
Find the marginal density of , . Check: with .
Solution
- f_U(1) 0.24
With R
fU <- function(u) integrate(function(v) fUV(u, v), -u, u)$value fU(1)
[1] 0.2386512
For each , integrate from to : , the sum of two exponentials with rates and . With , .
Find the marginal density of , . Check: and with .
Solution
- f_V(0.5) 0.26
- f_V(−0.5) 0.20
With R
fV <- function(v) integrate(function(u) fUV(u, v), abs(v), Inf)$value c(fV(0.5), fV(-0.5))
[1] 0.2596003 0.2021769
For each , runs from to , and you must split and : . It is skewed: the tail is driven by X and the one by Y. With : and . Check: it integrates to 1 adding the two pieces.
The fraction of phone battery left when I get home is a variable with density , , with unknown , and we know that . The data from 10 days are already in the battery vector of your script.
battery <- c(0.897, 0.707, 0.458, 0.976, 0.716, 0.434, 0.751, 0.578, 0.963, 0.716)
Let be a simple random sample from this population. Find an estimator of by the method of moments, , and another by maximum likelihood, . Mark yourself with the criteria.
Solution
Marking criteria:
- Sets equal to 0.5
- Solves 0.5
- Writes the log-likelihood of the sample 0.5
- Differentiates, sets to 0 and reaches (and checks it is a maximum) 0.5
Set and solve for . You get . For maximum likelihood: ; differentiating, and . The second derivative at that point is : it is a maximum. The two estimators need not agree: they use different information from the sample.
With the data in battery, find the two estimates of and compare them.
Solution
- Moments 0.39
- Max. likelihood 0.36
With R
battery <- c(0.897, 0.707, 0.458, 0.976, 0.716, 0.434, 0.751, 0.578, 0.963, 0.716) x <- battery; n <- length(x) mom <- (1 - mean(x)) / mean(x) # method of moments mv <- -mean(log(x)) # maximum likelihood c(mom, mv)
[1] 0.3896609 0.3635697
and . They are close but not equal: with 10 or 12 values the difference is normal. The moments one only uses ; the maximum likelihood one uses the transformation that turns the data into exponentials, which is what really carries the information about the parameter.
Compare the maximum likelihood estimate with the one optim gives numerically in R, using the moments estimate as the starting value.
Solution
- optim 0.36
With R
logL <- function(th) sum(-log(th) + (1 / th - 1) * log(x)) o <- optim(mom, logL, method = "L-BFGS-B", lower = 1e-6, control = list(fnscale = -1)) o$par
[1] 0.3635715
optim maximises the log-likelihood with fnscale = -1 (by default it minimises) and gives 0.36, the same as the formula up to the fourth decimal. With one parameter, the "L-BFGS-B" method with a positive lower is better: that way the parameter does not wander into negative values, where the logarithm does not exist.
Find the moment generating function of and identify its distribution. (Hint: first find the density of .)
Solution
Marking criteria:
- Correct change of variable for , with its Jacobian 0.75
- Identifies Y as exponential with mean 0.25
- , 0.75
- Identifies it: gamma with shape and rate 0.25
, , so , : an exponential with mean , with mgf . Since is the mean of independent exponentials, , the mgf of a gamma with shape and rate . This part is the key to the next three.
Prove that the maximum likelihood estimator is unbiased.
Solution
Check with R
set.seed(2) # 10.000 samples of size 10 with β = 0.4 be <- replicate(10000, -mean(log(runif(10)^0.4))) c(mean(be), var(be), 0.4^2 / 10) # mean ≈ β and variance ≈ β²/n
[1] 0.39934529 0.01599971 0.01600000
Marking criteria:
- Uses (or the mean of the gamma in part d) 1
- Linearity: 1
: bias 0. It also follows from the gamma(, ): its mean is . The R simulation confirms it: the mean of 10,000 estimates lands next to the true value.
Prove that is consistent.
Solution
Marking criteria:
- 0.5
- Unbiased with variance tending to 0 ⇒ MSE → 0 ⇒ consistent (Chebyshev) 0.5
, which tends to 0. Being unbiased, , and by Chebyshev : it is consistent. (The law of large numbers works too: is a mean of variables with mean .)
Prove that is efficient.
Solution
Marking criteria:
- Computes the Fisher information: 0.5
- Cramér–Rao bound = , and unbiased ⇒ efficient 0.5
and, with , . The Cramér–Rao bound for unbiased estimators is , exactly : it attains it, so it is efficient. The simulation in part e gives a variance almost equal to the bound.
The resting heart rate (beats per minute) of 30 students who join the university gym was measured. The data are already in the before vector of your script.
before <- c(74, 63, 64, 74, 68, 52, 69, 69, 70, 72,
68, 68, 73, 70, 52, 61, 63, 60, 70, 61,
67, 58, 80, 67, 58, 62, 67, 82, 63, 65)And the data for part d:
after <- c(75, 53, 57, 77, 64, 54, 69, 70, 71, 67,
62, 73, 67, 71, 45, 55, 64, 53, 66, 62,
61, 54, 83, 62, 52, 60, 65, 75, 57, 59)Assuming the data are normal, , with known standard deviation , find the maximum likelihood estimate of and a 95 % confidence interval with R.
Solution
- μ̂₁ 66.33
- Lower limit 63.47
- Upper limit 69.20
With R
before <- c(74, 63, 64, 74, 68, 52, 69, 69, 70, 72, 68, 68, 73, 70, 52, 61, 63, 60, 70, 61, 67, 58, 80, 67, 58, 62, 67, 82, 63, 65) after <- c(75, 53, 57, 77, 64, 54, 69, 70, 71, 67, 62, 73, 67, 71, 45, 55, 64, 53, 66, 62, 61, 54, 83, 62, 52, 60, 65, 75, 57, 59) x <- before; n <- length(x); sigma <- 8 z <- qnorm(1 - 0.05 / 2) c(mean(x), mean(x) - z * sigma / sqrt(n), mean(x) + z * sigma / sqrt(n))
[1] 66.33333 63.47062 69.19604
The MLE of a normal mean is beats per minute. With known , the pivot is and the interval is = (63.47, 69.20). R has no function for this case (t.test uses the t): write it by hand with qnorm.
The same, but with unknown . Compare with the interval in the previous part.
Solution
- Lower limit 63.74
- Upper limit 68.92
With R
t.test(x, conf.level = 0.95)$conf.int
[1] 63.74197 68.92470 attr(,"conf.level") [1] 0.95
With unknown it is replaced by and the pivot becomes a : (63.74, 68.92), width 5.18 against 5.73. It is narrower: the t has heavier tails than the normal, but here the sample standard deviation () is smaller than the assumed , and that weighs more than the gap between the quantiles.
With unknown mean and standard deviation, give the maximum likelihood estimate of and a 99 % confidence interval for with R.
Solution
- σ̂² 46.56
- Lower limit 26.69
- Upper limit 106.44
With R
s2mv <- (n - 1) * var(x) / n # MLE of σ²: divides by n c(s2mv, (n - 1) * var(x) / qchisq(1 - 0.01 / 2, n - 1), (n - 1) * var(x) / qchisq(0.01 / 2, n - 1))
[1] 46.55556 26.68673 106.44393
The MLE of divides by , not : (R’s var divides by ). The pivot is , and when solving for the quantiles swap places: the high quantile goes at the bottom. Interval: (26.69, 106.44), not at all symmetric around the estimate, because the chi-square is not.
After 6 weeks of training the heart rate of the same 30 students is measured again, in the same order. The data are already in the after vector of your script. Also assuming these data are normal, use R to find a 95 % confidence interval for the variance ratio and justify whether they can be considered equal.
Solution
- Lower limit 0.30
- Upper limit 1.33
- Equal variances? Yes
With R
var.test(before, after, conf.level = 0.95)$conf.int # σ²(before) / σ²(after)
[1] 0.3003407 1.3257590 attr(,"conf.level") [1] 0.95
With two normal samples, , and var.test gives the interval for : (0.30, 1.33). It contains 1, so there is no reason to say the variances differ: they can be considered equal. Note: even if they differ, part f does not use this to choose a formula, because the samples are paired and you work with the differences.
Let there be two paired normal samples of size and the difference of each pair, with independent . Prove that , where is the standard deviation of the differences.
Solution
Marking criteria:
- 0.5
- 0.5
- and independent (Fisher’s theorem) 0.5
- simplifies to and is a 0.5
The key is that, by subtracting within each pair, the are a single normal sample: whatever happens between the two measurements of the same individual stops mattering. Then it is the one-sample t: standard normal, chi-square with degrees by Fisher’s theorem, independent, and ; dividing, cancels out. Write down every result you use: that is what earns the marks.
Using the two previous parts, give the maximum likelihood estimate of the mean difference (after − before) and a 99 % confidence interval for it with R. Interpret.
Solution
- d̄ -2.90
- Lower limit -4.89
- Upper limit -0.91
- Is there a change? Yes
With R
d <- after - before # difference for each one: after - before mean(d) t.test(after, before, paired = TRUE, conf.level = 0.99)$conf.int
[1] -2.9 [1] -4.8927044 -0.9072956 attr(,"conf.level") [1] 0.99
Estimate: beats per minute. Interval with t.test(..., paired = TRUE): (-4.89, -0.91). It lies entirely below 0: the mean heart rate has changed with 99 % confidence (it went down). The typical mistake is treating the two samples as independent: it throws away the fact that each pair is the same individual and gives a much wider interval.
How long a PDF of notes takes to download from the virtual campus (in seconds) is the sum of two exponential phases with the same rate, connecting and transferring: a gamma with shape 2 and rate , with density , . Let be a simple random sample and ; the MLE of is . The data for the last part are already in the downloads vector of your script.
downloads <- c(0.46, 2.06, 1.49, 0.88, 3.14, 4.95, 6.72, 0.39, 2, 2.44,
1.39, 2.14, 3.92, 2.11, 2.73)Find the distribution of .
Solution
Marking criteria:
- Writes the mgf of each term (with its domain) 1
- Product by independence: , the mgf of a gamma(, ) 1
Each has mgf , ; by independence, the sum’s is the product: , , which is the mgf of a gamma(, ). Since the mgf determines the distribution, is that gamma.
Find the density of and identify it.
Solution
Marking criteria:
- Change of variable with 1
- Simplifies: disappears and a is left 1
With , the gamma density of T becomes , with : the density of a , which no longer depends on . That is why works as a pivot: it depends on the parameter and the sample, but its distribution is known and has no parameters.
Build a confidence interval for using as the pivot.
Solution
Marking criteria:
- Sets up 1
- Solves for : 1
Leave the same probability in each tail of the and divide by (it does not flip the inequalities). It is an exact interval: it works for any , not only for large samples.
Build an asymptotic confidence interval for .
Solution
Marking criteria:
- Fisher information and 1
- Replaces by in the variance: 1
The MLE is asymptotically normal with variance : with , . Standardising and putting where the variance needs gives the interval. It only works for large , and it is symmetric around , unlike the exact one.
With the values in downloads, use R to find the exact and asymptotic intervals for at 95 %. Compare them.
Solution
- Exact: lower 0.55
- Exact: upper 1.13
- Asymptotic: lower 0.52
- Asymptotic: upper 1.11
With R
downloads <- c(0.46, 2.06, 1.49, 0.88, 3.14, 4.95, 6.72, 0.39, 2, 2.44, 1.39, 2.14, 3.92, 2.11, 2.73) x <- downloads; n <- length(x); T <- sum(x); a <- 0.05 c(qchisq(a / 2, 4 * n), qchisq(1 - a / 2, 4 * n)) / (2 * T) # exact: 2λT ~ chi2(4n) l <- 2 * n / T # MLE of λ l + c(-1, 1) * qnorm(1 - a / 2) * l / sqrt(2 * n) # asymptotic
[1] 0.549725 1.131147 [1] 0.5232166 1.1063326
Exact: (0.55, 1.13). Asymptotic: (0.52, 1.11). They are close, but the asymptotic one is shifted to the left and symmetric; the exact one respects the chi-square skewness. With 15 values, the exact one is the one to trust. Careful with qchisq: the degrees of freedom are , not .
I want to compare the two library photocopiers: in 30 copies from each, 1 = fine, 0 = jams. The data are already in the vectors x (the corridor one) and y (the room one) of your script.
x <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 0, 1, 1, 0, 1, 1, 1, 1, 1)
y <- c(0, 1, 1, 1, 0, 0, 1, 1, 1, 1,
0, 0, 1, 1, 1, 1, 0, 1, 0, 1,
0, 1, 1, 1, 0, 1, 0, 0, 0, 1)The last part (second bonus) does not use these data.
First bonus. Use R to give the maximum likelihood estimate of each proportion and of their difference.
Solution
- p̂₁ 0.90
- p̂₂ 0.60
- p̂₁ − p̂₂ 0.30
With R
x <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1) y <- c(0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1) p1 <- mean(x); p2 <- mean(y) c(p1, p2, p1 - p2)
[1] 0.9 0.6 0.3
With 0/1 data (Bernoulli), the MLE of is the mean: , and, by the invariance of the MLE, that of the difference is the difference: 0.30.
Find an asymptotic 95 % confidence interval for . Can we say the good copies differ?
Solution
- Lower limit 0.09
- Upper limit 0.51
- Different? Yes
With R
m <- length(x); n <- length(y); z <- qnorm(1 - 0.05 / 2) (p1 - p2) + c(-1, 1) * z * sqrt(p1 * (1 - p1) / m + p2 * (1 - p2) / n)
[1] 0.09443724 0.50556276
= (0.09, 0.51). It does not contain 0: the difference is significant at that level. Before using it, check that , and those of the other sample are not too small (that the normal is reasonable).
Second bonus. Let and , all independent. Use R to find the value such that .
Solution
- a 23.54
With R
qchisq(0.90, df = 4 + 12) # P(W >= a) = 0.10 => a is the quantile 0.90 de chi2(16)
[1] 23.54183
Standardising, each term is a and the sum a . « with probability 0.10» is the same as « with 0.90»: is the 0.90 quantile, 23.54. The typical mistake is using qchisq(0.10, 16).
Two independent parts: a sum of many variables (part a) and a joint density with a transformation (parts b to h). In the parts with a Check, write the numerical value in the box; the working, on paper.
Let be the fraction of the lab server RAM used by each of 40 processes, independent and with common density , . Let . Using R and applying, if possible, the Central Limit Theorem, find approximately . Check: , and the probability.
Solution
- E(Xᵢ) 0.60
- Var(Xᵢ) 0.04
- Probability 0.21
With R
f <- function(x) 12 * x^2 * (1 - x) integrate(f, 0, 1)$value # 1: it is a density mu <- integrate(function(x) x * f(x), 0, 1)$value s2 <- integrate(function(x) x^2 * f(x), 0, 1)$value - mu^2 c(mu, s2) n <- 40 pnorm(23, mean = n * mu, sd = sqrt(n * s2)) # P(S <= 23), approximated by the CLT
[1] 1 [1] 0.60 0.04 [1] 0.2145977
and , so . By the CLT, (variance) and .
and are the minutes two teammates who answer equally fast take to reply in the project group. Their joint density is , , , with . The check boxes are filled in with . Find so that is a density. Check: its value with .
Solution
- K 4
With R
la <- 2 # check value g <- function(x, y) exp(-la * (x + y)) # the density without K double_int <- function(h, M = Inf) integrate(function(y) sapply(y, function(yy) integrate(function(x) h(x, yy), 0, M)$value), 0, M)$value K <- 1 / double_int(g); K
[1] 4
The double integral over the support must be 1. Since the exponential splits into an factor and a factor, the double integral is the product of two exponential integrals: you get and, with , . In R it is checked with two nested integrate calls (the inner one with sapply).
Find the marginal densities of and and identify them, if possible, with a known distribution. Check: and with .
Solution
- E(X) 0.50
- E(Y) 0.50
With R
f <- function(x, y) K * g(x, y) fX <- function(x) sapply(x, function(xx) integrate(function(y) f(xx, y), 0, Inf)$value) fY <- function(y) sapply(y, function(yy) integrate(function(x) f(x, yy), 0, Inf)$value) EX <- integrate(function(x) x * fX(x), 0, Inf)$value EY <- integrate(function(y) y * fY(y), 0, Inf)$value c(EX, EY)
[1] 0.5 0.5
Integrate the other variable over its range: , exponential with rate , and , exponential with rate . Since , X and Y are independent. With : and .
Find the joint moment generating function of and where it exists. Check: with .
Solution
- φ(1, 1) 4
With R
phi <- function(s, t) double_int(function(x, y) exp(s * x + t * y) * f(x, y), M = 100) # up to 100: with Inf, Inf · 0 phi(1, 1)
[1] 4
. With independence it is the product of the two marginal mgfs: , for (outside that the integral diverges). With , . In R, the double integral goes up to 100 and not to Inf: with Inf you get and integrate complains.
Find . Check: its value with .
Solution
- Cov(X, Y) 0
With R
EXY <- double_int(function(x, y) x * y * f(x, y)) EXY - EX * EY # Cov(X, Y)
[1] 7.692435e-09
Being independent, and . It also comes from differentiating the mgf: . R gives a number around : that is the error of the numerical integration, not a covariance.
Let and . Find the joint density function of , with its support. Check: with .
Solution
- f(U,V)(1, 0.5) 0.27
With R
fUV <- function(u, v) f((u + v) / 2, (u - v) / 2) * 1 / 2 # |J| = 1/2 fUV(1, 0.5)
[1] 0.2706706
Invert the transformation: , , with Jacobian , so . Then on ( and become and ). With , . The typical mistake is forgetting or the support: without it, the marginal in the next part comes out wrong.
Find the marginal density of , . Check: with .
Solution
- f_U(1) 0.54
With R
fU <- function(u) integrate(function(v) fUV(u, v), -u, u)$value fU(1)
[1] 0.5413411
For each , integrate from to : , giving : a gamma with shape 2 and rate , as the sum of two independent exponentials with the same rate must be. With , .
Find the marginal density of , . Check: and with .
Solution
- f_V(0.5) 0.37
- f_V(−0.5) 0.37
With R
fV <- function(v) integrate(function(u) fUV(u, v), abs(v), Inf)$value c(fV(0.5), fV(-0.5))
[1] 0.3678794 0.3678794
For each , runs from to , and you must split and : . It is a Laplace: symmetric around 0, because X and Y are interchangeable. With : and . Check: it integrates to 1 adding the two pieces.
The university bus delay over its timetable (in minutes) is a variable with density , , with unknown , and we know that . The delays of 12 days are already in the delays vector of your script.
delays <- c(0.334, 0.092, 0.107, 1.862, 0.749, 0.68, 0.478, 0.113, 1.977, 0.232,
0.305, 0.183)Let be a simple random sample from this population. Find an estimator of by the method of moments, , and another by maximum likelihood, . Mark yourself with the criteria.
Solution
Marking criteria:
- Sets equal to 0.5
- Solves 0.5
- Writes the log-likelihood of the sample 0.5
- Differentiates, sets to 0 and reaches (and checks it is a maximum) 0.5
Set and solve for . You get . For maximum likelihood: ; differentiating, and . The second derivative at that point is : it is a maximum. The two estimators need not agree: they use different information from the sample.
With the data in delays, find the two estimates of and compare them.
Solution
- Moments 0.37
- Max. likelihood 0.40
With R
delays <- c(0.334, 0.092, 0.107, 1.862, 0.749, 0.68, 0.478, 0.113, 1.977, 0.232, 0.305, 0.183) x <- delays; n <- length(x) mom <- mean(x) / (1 + mean(x)) # method of moments mv <- mean(log(1 + x)) # maximum likelihood c(mom, mv)
[1] 0.3721222 0.4032305
and . They are close but not equal: with 10 or 12 values the difference is normal. The moments one only uses ; the maximum likelihood one uses the transformation that turns the data into exponentials, which is what really carries the information about the parameter.
Compare the maximum likelihood estimate with the one optim gives numerically in R, using the moments estimate as the starting value.
Solution
- optim 0.40
With R
logL <- function(th) sum(-log(th) - (1 + 1 / th) * log(1 + x)) o <- optim(mom, logL, method = "L-BFGS-B", lower = 1e-6, control = list(fnscale = -1)) o$par
[1] 0.4032321
optim maximises the log-likelihood with fnscale = -1 (by default it minimises) and gives 0.40, the same as the formula up to the fourth decimal. With one parameter, the "L-BFGS-B" method with a positive lower is better: that way the parameter does not wander into negative values, where the logarithm does not exist.
Find the moment generating function of and identify its distribution. (Hint: first find the density of .)
Solution
Marking criteria:
- Correct change of variable for , with its Jacobian 0.75
- Identifies Y as exponential with mean 0.25
- , 0.75
- Identifies it: gamma with shape and rate 0.25
, , so , : an exponential with mean , with mgf . Since is the mean of independent exponentials, , the mgf of a gamma with shape and rate . This part is the key to the next three.
Prove that the maximum likelihood estimator is unbiased.
Solution
Check with R
set.seed(2) # 10.000 samples of size 12 with β = 0.3 be <- replicate(10000, mean(log(1 + (exp(0.3 * rexp(12)) - 1)))) c(mean(be), var(be), 0.3^2 / 12) # mean ≈ β and variance ≈ β²/n
[1] 0.29945518 0.00764579 0.00750000
Marking criteria:
- Uses (or the mean of the gamma in part d) 1
- Linearity: 1
: bias 0. It also follows from the gamma(, ): its mean is . The R simulation confirms it: the mean of 10,000 estimates lands next to the true value.
Prove that is consistent.
Solution
Marking criteria:
- 0.5
- Unbiased with variance tending to 0 ⇒ MSE → 0 ⇒ consistent (Chebyshev) 0.5
, which tends to 0. Being unbiased, , and by Chebyshev : it is consistent. (The law of large numbers works too: is a mean of variables with mean .)
Prove that is efficient.
Solution
Marking criteria:
- Computes the Fisher information: 0.5
- Cramér–Rao bound = , and unbiased ⇒ efficient 0.5
and, with , . The Cramér–Rao bound for unbiased estimators is , exactly : it attains it, so it is efficient. The simulation in part e gives a variance almost equal to the bound.
The build time (in seconds) of 36 lab projects was measured with the usual compiler. The data are already in the before vector of your script.
before <- c(42.2, 43.5, 37.8, 49.9, 42.9, 39.3, 39.8, 39.4, 42, 39,
37.5, 41.7, 41.1, 41.3, 42.6, 40.1, 37.8, 45.9, 42.2, 41.3,
37.3, 43.9, 45.3, 44.2, 40.7, 41.5, 42.8, 43.4, 43.4, 38.7,
44.9, 39.2, 40.2, 40.5, 39.7, 39.5)And the data for part d:
after <- c(40.8, 41.6, 34, 45.7, 40.7, 37, 38.7, 37.1, 39.8, 36,
34.4, 39.6, 40.2, 40.1, 38.3, 38.5, 32.7, 42.3, 43.6, 40.3,
35.8, 40.1, 42.5, 39.6, 38.5, 37.4, 41.3, 40.2, 41, 37.1,
38.8, 35.3, 43.5, 36.1, 38.2, 38.4)Assuming the data are normal, , with known standard deviation , find the maximum likelihood estimate of and a 99 % confidence interval with R.
Solution
- μ̂₁ 41.46
- Lower limit 40.17
- Upper limit 42.75
With R
before <- c(42.2, 43.5, 37.8, 49.9, 42.9, 39.3, 39.8, 39.4, 42, 39, 37.5, 41.7, 41.1, 41.3, 42.6, 40.1, 37.8, 45.9, 42.2, 41.3, 37.3, 43.9, 45.3, 44.2, 40.7, 41.5, 42.8, 43.4, 43.4, 38.7, 44.9, 39.2, 40.2, 40.5, 39.7, 39.5) after <- c(40.8, 41.6, 34, 45.7, 40.7, 37, 38.7, 37.1, 39.8, 36, 34.4, 39.6, 40.2, 40.1, 38.3, 38.5, 32.7, 42.3, 43.6, 40.3, 35.8, 40.1, 42.5, 39.6, 38.5, 37.4, 41.3, 40.2, 41, 37.1, 38.8, 35.3, 43.5, 36.1, 38.2, 38.4) x <- before; n <- length(x); sigma <- 3 z <- qnorm(1 - 0.01 / 2) c(mean(x), mean(x) - z * sigma / sqrt(n), mean(x) + z * sigma / sqrt(n))
[1] 41.45833 40.17042 42.74625
The MLE of a normal mean is seconds. With known , the pivot is and the interval is = (40.17, 42.75). R has no function for this case (t.test uses the t): write it by hand with qnorm.
The same, but with unknown . Compare with the interval in the previous part.
Solution
- Lower limit 40.24
- Upper limit 42.68
With R
t.test(x, conf.level = 0.99)$conf.int
[1] 40.24126 42.67541 attr(,"conf.level") [1] 0.99
With unknown it is replaced by and the pivot becomes a : (40.24, 42.68), width 2.43 against 2.58. It is narrower: the t has heavier tails than the normal, but here the sample standard deviation () is smaller than the assumed , and that weighs more than the gap between the quantiles.
With unknown mean and standard deviation, give the maximum likelihood estimate of and a 90 % confidence interval for with R.
Solution
- σ̂² 6.99
- Lower limit 5.05
- Upper limit 11.20
With R
s2mv <- (n - 1) * var(x) / n # MLE of σ²: divides by n c(s2mv, (n - 1) * var(x) / qchisq(1 - 0.1 / 2, n - 1), (n - 1) * var(x) / qchisq(0.1 / 2, n - 1))
[1] 6.987986 5.051369 11.198190
The MLE of divides by , not : (R’s var divides by ). The pivot is , and when solving for the quantiles swap places: the high quantile goes at the bottom. Interval: (5.05, 11.20), not at all symmetric around the estimate, because the chi-square is not.
The same 36 projects are built again, in the same order, with a new compiler. The data are already in the after vector of your script. Also assuming these data are normal, use R to find a 90 % confidence interval for the variance ratio and justify whether they can be considered equal.
Solution
- Lower limit 0.51
- Upper limit 1.56
- Equal variances? Yes
With R
var.test(before, after, conf.level = 0.9)$conf.int # σ²(before) / σ²(after)
[1] 0.505861 1.561866 attr(,"conf.level") [1] 0.9
With two normal samples, , and var.test gives the interval for : (0.51, 1.56). It contains 1, so there is no reason to say the variances differ: they can be considered equal. Note: even if they differ, part f does not use this to choose a formula, because the samples are paired and you work with the differences.
Let there be two paired normal samples of size and the difference of each pair, with independent . Prove that , where is the standard deviation of the differences.
Solution
Marking criteria:
- 0.5
- 0.5
- and independent (Fisher’s theorem) 0.5
- simplifies to and is a 0.5
The key is that, by subtracting within each pair, the are a single normal sample: whatever happens between the two measurements of the same individual stops mattering. Then it is the one-sample t: standard normal, chi-square with degrees by Fisher’s theorem, independent, and ; dividing, cancels out. Write down every result you use: that is what earns the marks.
Using the two previous parts, give the maximum likelihood estimate of the mean difference (after − before) and a 95 % confidence interval for it with R. Interpret.
Solution
- d̄ -2.42
- Lower limit -3.02
- Upper limit -1.83
- Is there a change? Yes
With R
d <- after - before # difference for each one: after - before mean(d) t.test(after, before, paired = TRUE, conf.level = 0.95)$conf.int
[1] -2.425 [1] -3.02469 -1.82531 attr(,"conf.level") [1] 0.95
Estimate: seconds. Interval with t.test(..., paired = TRUE): (-3.02, -1.83). It lies entirely below 0: the mean time has changed with 95 % confidence (it went down). The typical mistake is treating the two samples as independent: it throws away the fact that each pair is the same individual and gives a much wider interval.
The phone GPS position error on campus (in metres) has density , , with unknown . Let be a simple random sample and ; the MLE of is . The data for the last part are already in the gps vector of your script.
gps <- c(2.09, 0.97, 0.92, 0.96, 1.67, 2.07, 0.42, 0.2, 0.64, 0.58,
0.42, 0.03, 0.34, 0.65, 1.28, 2.37, 1.46, 1.32)Find the distribution of .
Solution
Marking criteria:
- Writes the mgf of each term (with its domain) 1
- Product by independence: , the mgf of a gamma(, ) 1
First : , and : . By independence, the sum’s mgf is the product: , , which is the mgf of a gamma(, ). Since the mgf determines the distribution, is that gamma.
Find the density of and identify it.
Solution
Marking criteria:
- Change of variable with 1
- Simplifies: disappears and a is left 1
With , the gamma density of T becomes , with : the density of a , which no longer depends on . That is why works as a pivot: it depends on the parameter and the sample, but its distribution is known and has no parameters.
Build a confidence interval for using as the pivot.
Solution
Marking criteria:
- Sets up 1
- Solves for : 1
Leave the same probability in each tail of the and divide by (it does not flip the inequalities). It is an exact interval: it works for any , not only for large samples.
Build an asymptotic confidence interval for .
Solution
Marking criteria:
- Fisher information and 1
- Replaces by in the variance: 1
The MLE is asymptotically normal with variance : with , . Standardising and putting where the variance needs gives the interval. It only works for large , and it is symmetric around , unlike the exact one.
With the values in gps, use R to find the exact and asymptotic intervals for at 99 %. Compare them.
Solution
- Exact: lower 0.33
- Exact: upper 1.14
- Asymptotic: lower 0.26
- Asymptotic: upper 1.07
With R
gps <- c(2.09, 0.97, 0.92, 0.96, 1.67, 2.07, 0.42, 0.2, 0.64, 0.58, 0.42, 0.03, 0.34, 0.65, 1.28, 2.37, 1.46, 1.32) x <- gps; n <- length(x); T <- sum(x^2); a <- 0.01 c(qchisq(a / 2, 2 * n), qchisq(1 - a / 2, 2 * n)) / (2 * T) # exact: 2λΣX² ~ chi2(2n) l <- n / T # MLE of λ l + c(-1, 1) * qnorm(1 - a / 2) * l / sqrt(n) # asymptotic
[1] 0.331753 1.142173 [1] 0.2623232 1.0730924
Exact: (0.33, 1.14). Asymptotic: (0.26, 1.07). They are close, but the asymptotic one is shifted to the left and symmetric; the exact one respects the chi-square skewness. With 18 values, the exact one is the one to trust. Careful with qchisq: the degrees of freedom are , not .
I want to compare two bus lines to campus: on 24 days each, 1 = on time, 0 = late. The data are already in the vectors x (first line) and y (second line) of your script.
x <- c(1, 1, 1, 0, 0, 1, 0, 1, 0, 1,
1, 1, 0, 1, 0, 1, 1, 0, 0, 1,
1, 0, 1, 0)
y <- c(1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 0, 1, 1, 0, 1,
0, 0, 1, 1)The last part (second bonus) does not use these data.
First bonus. Use R to give the maximum likelihood estimate of each proportion and of their difference.
Solution
- p̂₁ 0.58
- p̂₂ 0.75
- p̂₁ − p̂₂ -0.17
With R
x <- c(1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0) y <- c(1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1) p1 <- mean(x); p2 <- mean(y) c(p1, p2, p1 - p2)
[1] 0.5833333 0.7500000 -0.1666667
With 0/1 data (Bernoulli), the MLE of is the mean: , and, by the invariance of the MLE, that of the difference is the difference: -0.17.
Find an asymptotic 90 % confidence interval for . Can we say the punctuality differ?
Solution
- Lower limit -0.39
- Upper limit 0.05
- Different? No
With R
m <- length(x); n <- length(y); z <- qnorm(1 - 0.1 / 2) (p1 - p2) + c(-1, 1) * z * sqrt(p1 * (1 - p1) / m + p2 * (1 - p2) / n)
[1] -0.38697769 0.05364436
= (-0.39, 0.05). It contains 0: with these data you cannot say they differ. Before using it, check that , and those of the other sample are not too small (that the normal is reasonable).
Second bonus. Let and , all independent. Use R to find the value such that .
Solution
- a 5.81
With R
qchisq(0.01, df = 7 + 9) # P(W >= a) = 0.99 => a is the quantile 0.01 de chi2(16)
[1] 5.812212
Each term is the square of a standard normal: the sum is a . Leaving 0.99 to the right means leaving 0.01 to the left: is the 0.01 quantile, 5.81.
Two independent parts: a sum of many variables (part a) and a joint density with a transformation (parts b to h). In the parts with a Check, write the numerical value in the box; the working, on paper.
The incidents opened each day in the computer lab follow a Poisson with mean 0.8, independent from one day to the next. Let be the total number of incidents in 50 teaching days. Find in three ways: with the CLT without correction, with the CLT and the continuity correction, and exactly. Why can the exact one be computed?
Solution
- CLT, no correction 0.79
- CLT, with correction 0.81
- Exact 0.81
With R
la <- 0.8; n <- 50 c(n * la, n * la) # E(S) and Var(S): S ~ Pois(40) pnorm(45, n * la, sqrt(n * la)) # CLT without correction pnorm(45.5, n * la, sqrt(n * la)) # CLT with continuity correction ppois(45, n * la) # exact
[1] 40 40 [1] 0.7854023 [1] 0.8077477 [1] 0.8096501
A sum of independent Poissons is Poisson (reproductive property, seen with the mgf): , so the exact value is ppois(45, 40) = 0.81. With the CLT, : without correction ; with it, since S is an integer, and , which almost hits the exact one. The continuity correction is what turns a so-so approximation into a good one with discrete variables.
When the cafeteria opens, is the minutes until the first order and the minutes until the second. Their joint density is , , with . The check boxes are filled in with . Find so that is a density. Check: its value with .
Solution
- K 4
With R
la <- 2 # check value g <- function(x, y) ifelse(x < y, exp(-la * y), 0) # the density without K (0 < x < y) double_int <- function(h, M = Inf) integrate(function(y) sapply(y, function(yy) integrate(function(x) h(x, yy), 0, min(yy, M))$value), 0, M)$value K <- 1 / double_int(g); K
[1] 4
The double integral over the support must be 1. Integrating first in from 0 to : , you get and, with , . In R it is checked with two nested integrate calls (the inner one with sapply).
Find the marginal densities of and and identify them, if possible, with a known distribution. Check: and with .
Solution
- E(X) 0.50
- E(Y) 1
With R
f <- function(x, y) K * g(x, y) fX <- function(x) sapply(x, function(xx) integrate(function(y) f(xx, y), xx, Inf)$value) fY <- function(y) sapply(y, function(yy) integrate(function(x) f(x, yy), 0, yy)$value) EX <- integrate(function(x) x * fX(x), 0, Inf)$value EY <- integrate(function(y) y * fY(y), 0, Inf)$value c(EX, EY)
[1] 0.5 1.0
Integrate the other variable over its range: , exponential with rate , and , gamma with shape 2 and rate . Here (the support is not a rectangle): X and Y are not independent. Mind the limits: for , goes from to ; for , goes from 0 to . With : and .
Find the joint moment generating function of and where it exists. Check: with .
Solution
- φ(0.5, 0.5) 2.67
With R
phi <- function(s, t) double_int(function(x, y) exp(s * x + t * y) * f(x, y), M = 100) # up to 100: with Inf, Inf · 0 phi(0.5, 0.5)
[1] 2.666667
. Integrating first in (from to ) and then in : , for (outside that the integral diverges). With , . In R, the double integral goes up to 100 and not to Inf: with Inf you get and integrate complains.
Find . Check: its value with .
Solution
- Cov(X, Y) 0.25
With R
EXY <- double_int(function(x, y) x * y * f(x, y)) EXY - EX * EY # Cov(X, Y)
[1] 0.25
With the mgf: , and , so = 0.25 with . It is positive: if the first order is late, so is the second (Y = X + the time until the second one).
Let (the first order) and (how long the second takes after the first). Find the joint density of , with its support. Are they independent? Check: with .
Solution
- f(U,V)(1, 0.5) 0.20
With R
fUV <- function(u, v) f(u, u + v) # U = X, V = Y - X: |J| = 1 fUV(1, 0.5)
[1] 0.1991483
Inverse: , , with . You get , (from comes and ). It factors into a function of times one of over a rectangle: U and V are independent, each exponential with rate , even though X and Y were not. With , .
Find the marginal density of , . Check: with .
Solution
- f_U(1) 0.27
With R
fU <- function(u) integrate(function(v) fUV(u, v), 0, Inf)$value fU(1)
[1] 0.2706706
Integrate from 0 to : , the same as (of course: U = X). With , .
Find the marginal density of . Check: and with .
Solution
- f_V(0.5) 0.74
- P(V > 1) 0.14
With R
fV <- function(v) integrate(function(u) fUV(u, v), 0, Inf)$value c(fV(0.5), integrate(function(v) sapply(v, fV), 1, Inf)$value) # f_V(0.5) and P(V > 1)
[1] 0.7357589 0.1353353
Integrating from 0 to : . The time from the first order to the second is another exponential with rate , which «does not remember» when the first one came. With : and .
The time (in minutes) between two requests reaching the faculty IT service follows an exponential with unknown rate . The 12 times of one morning are already in the waits vector of your script.
waits <- c(1.34, 2.53, 0.84, 1.15, 2.19, 2.07, 0.59, 2.41, 1.84, 0.44,
0.05, 2.06)Let be a simple random sample from an exponential with rate . Find the estimator of by the method of moments and by maximum likelihood.
Solution
Marking criteria:
- Moments: ⇒ 1
- Log-likelihood , derivative and 1
Both methods give the same, : the exponential mean is and . Agreeing does not make it «better»: part e shows it is biased.
With the data in waits, find the two estimates.
Solution
- Moments 0.69
- Max. likelihood 0.69
With R
waits <- c(1.34, 2.53, 0.84, 1.15, 2.19, 2.07, 0.59, 2.41, 1.84, 0.44, 0.05, 2.06) x <- waits; n <- length(x) mom <- 1 / mean(x) # method of moments mv <- 1 / mean(x) # maximum likelihood c(mom, mv)
[1] 0.6853227 0.6853227
Both are requests per minute (one every 1.46 minutes on average).
Compare with what optim gives, starting at the moments estimate.
Solution
- optim 0.69
With R
logL <- function(th) sum(log(th) - th * x) o <- optim(mom, logL, method = "L-BFGS-B", lower = 1e-6, control = list(fnscale = -1)) o$par
[1] 0.6853227
Since the starting point is already the maximum, optim stays at 0.69: a check that the derivative is right.
Find the distribution of with the mgf and compute .
Solution
Marking criteria:
- : gamma(, ) 1
- 1
By independence the mgf of the sum is the product: , that of a gamma with shape and rate . For lower the power by one and recognise another gamma density: (valid for ).
Is unbiased? If not, correct it so that it is. Check: the corrected estimate with the data.
Solution
- Corrected 0.63
With R
set.seed(2) # the mean of the MLE with n = 12 and λ = 0.5 l <- replicate(10000, 1 / mean(rexp(12, 0.5))) c(mean(l), 12 * 0.5 / 11) # simulated and nλ/(n - 1) (n - 1) / sum(x) # the corrected estimator with the data
[1] 0.5476156 0.5454545 [1] 0.6282125
: it overestimates (bias ). The corrected one is , unbiased. With the data, . The simulation with and gives a mean of 0.55, next to , not 0.5.
Prove that is consistent, even though it is biased.
Solution
Marking criteria:
- Law of large numbers: 0.5
- Continuity of at ⇒ (or MSE → 0) 0.5
The bias tends to 0 and so does the variance (), so the MSE tends to 0: it is consistent. Faster: by the law of large numbers and is continuous. Biased is not the opposite of consistent.
Is the corrected estimator efficient?
Solution
Marking criteria:
- Cramér–Rao bound: , bound 0.5
- : not efficient (it is asymptotically) 0.5
With , , which is larger than the bound : it does not attain it, so it is not efficient. The ratio : it is asymptotically efficient.
The time (in minutes) of the bus trip from home to university was measured on 28 mornings. The data are already in the morning vector of your script.
morning <- c(23.2, 23, 22.2, 26.6, 22, 26.6, 24, 22.5, 21.8, 22.5,
24.6, 23.6, 21.6, 23, 21.2, 21.6, 26.4, 25.1, 26.2, 23,
22.2, 21.8, 23.1, 22.9, 24, 26.2, 22, 24.1)And the data for part d:
afternoon <- c(21.7, 21.1, 19.9, 20.3, 21.4, 16.9, 21.1, 23.3, 22.3, 26.1,
23.8, 22.8, 23.5, 23.9, 22.4, 13.6, 21.5, 22.3, 25.6, 29.4,
24.2, 26.3, 25.5, 22.3)Assuming the data are normal, , with known standard deviation , find the maximum likelihood estimate of and a 95 % confidence interval with R.
Solution
- μ̂₁ 23.46
- Lower limit 22.91
- Upper limit 24.02
With R
morning <- c(23.2, 23, 22.2, 26.6, 22, 26.6, 24, 22.5, 21.8, 22.5, 24.6, 23.6, 21.6, 23, 21.2, 21.6, 26.4, 25.1, 26.2, 23, 22.2, 21.8, 23.1, 22.9, 24, 26.2, 22, 24.1) afternoon <- c(21.7, 21.1, 19.9, 20.3, 21.4, 16.9, 21.1, 23.3, 22.3, 26.1, 23.8, 22.8, 23.5, 23.9, 22.4, 13.6, 21.5, 22.3, 25.6, 29.4, 24.2, 26.3, 25.5, 22.3) x <- morning; n <- length(x); sigma <- 1.5 z <- qnorm(1 - 0.05 / 2) c(mean(x), mean(x) - z * sigma / sqrt(n), mean(x) + z * sigma / sqrt(n))
[1] 23.46429 22.90869 24.01988
The MLE of a normal mean is minutes. With known , the pivot is and the interval is = (22.91, 24.02). R has no function for this case (t.test uses the t): write it by hand with qnorm.
The same, but with unknown . Compare with the interval in the previous part.
Solution
- Lower limit 22.81
- Upper limit 24.12
With R
t.test(x, conf.level = 0.95)$conf.int
[1] 22.81225 24.11632 attr(,"conf.level") [1] 0.95
With unknown it is replaced by and the pivot becomes a : (22.81, 24.12), width 1.30 against 1.11. It is wider: the t has heavier tails than the normal, but here the sample standard deviation () is larger or similar than the assumed , and that weighs more than the gap between the quantiles.
With unknown mean and standard deviation, give the maximum likelihood estimate of and a 95 % confidence interval for with R.
Solution
- σ̂² 2.73
- Lower limit 1.77
- Upper limit 5.24
With R
s2mv <- (n - 1) * var(x) / n # MLE of σ²: divides by n c(s2mv, (n - 1) * var(x) / qchisq(1 - 0.05 / 2, n - 1), (n - 1) * var(x) / qchisq(0.05 / 2, n - 1))
[1] 2.726582 1.767453 5.238611
The MLE of divides by , not : (R’s var divides by ). The pivot is , and when solving for the quantiles swap places: the high quantile goes at the bottom. Interval: (1.77, 5.24), not at all symmetric around the estimate, because the chi-square is not.
On 24 afternoons (other days, independent of the mornings) the return trip was measured. The data are already in the afternoon vector of your script. Assuming normality, use R to find a 95 % interval for , decide whether the variances can be considered equal and, with that decision, a 95 % interval for .
Solution
- Ratio: lower 0.12
- Ratio: upper 0.62
- Equal variances? No
- Difference: lower -0.55
- Difference: upper 2.38
With R
var.test(morning, afternoon, conf.level = 0.95)$conf.int # σ²(morning) / σ²(afternoon) t.test(morning, afternoon, var.equal = FALSE, conf.level = 0.95)$conf.int # Welch
[1] 0.1243026 0.6217664 attr(,"conf.level") [1] 0.95 [1] -0.5505428 2.3791143 attr(,"conf.level") [1] 0.95
var.test gives (0.12, 0.62): it does not contain 1, the variances differ (in the afternoon traffic makes the trip much more variable). That is why the difference of means uses Welch (var.equal = FALSE), not the pooled variance: (-0.55, 2.38). It contains 0: you cannot say one trip is longer than the other on average, even though the afternoon one is more irregular.
With known , prove that for the interval to have a margin of error (half-width) of at most you need .
Solution
Marking criteria:
- Writes the half-width and sets 1
- Solves for and squares; is an integer: round up 1
(everything is positive, so squaring keeps the direction). Since is an integer, take the first one that works: ceiling. Rounding down would give a margin slightly larger than .
With minutes, how many mornings should be measured to estimate the mean morning time with a margin of 0.4 minutes at 95 %?
Solution
- n 55
With R
E <- 0.4 # margin I want ceiling((qnorm(0.975) * sigma / E)^2) # sample size
[1] 55
, so . With the 28 mornings available the margin is almost 0.56: bringing it down to 0.4 needs almost twice the data (the margin goes with ).
The maintenance alerts the university app sends each day follow a Poisson with unknown mean . The alerts of 30 days are already in the alerts vector of your script.
alerts <- c(3, 6, 2, 1, 6, 3, 1, 2, 5, 1,
3, 5, 1, 6, 4, 3, 7, 6, 8, 2,
6, 6, 7, 5, 4, 3, 0, 5, 2, 2)Find the MLE of and, with the CLT, its approximate distribution for large .
Solution
Marking criteria:
- ⇒ 1
- CLT: 1
The derivative of the log-likelihood, , vanishes at . Since , the CLT gives : the variance depends on the parameter itself, and that shapes the interval.
Build an asymptotic interval for .
Solution
Marking criteria:
- Standardises: 1
- Replaces by in the variance: 1
With the approximate pivot and under the root, . (Solving for without plugging in gives a quadratic: the Wilson interval; another valid answer.)
With the days in alerts, use R to find the estimate and the asymptotic 95 % interval.
Solution
- λ̂ 3.83
- Lower limit 3.13
- Upper limit 4.53
With R
alerts <- c(3, 6, 2, 1, 6, 3, 1, 2, 5, 1, 3, 5, 1, 6, 4, 3, 7, 6, 8, 2, 6, 6, 7, 5, 4, 3, 0, 5, 2, 2) x <- alerts; n <- length(x); a <- 0.05 l <- mean(x) # MLE of λ c(l, l + c(-1, 1) * qnorm(1 - a / 2) * sqrt(l / n)) # asymptotic
[1] 3.833333 3.132724 4.533942
alerts per day; interval (3.13, 4.53).
How many days should be observed for the 95 % interval margin to be 0.5 alerts? Use the estimate from part c as the value of .
Solution
- n 59
With R
E <- 0.5 ceiling(qnorm(1 - a / 2)^2 * l / E^2) # n for a margin of 0.5 (with λ ≈ l)
[1] 59
, and rounding up, days. Since the variance grows with , the more alerts there are, the more days you need for the same margin.
The exact interval for a Poisson uses its link with the chi-square: , with . Compute it with R at 95 % and compare it with the one in part c.
Solution
- Exact: lower 3.16
- Exact: upper 4.60
With R
T <- sum(x) c(qchisq(a / 2, 2 * T), qchisq(1 - a / 2, 2 * T + 2)) / (2 * n) # exact (Garwood)
[1] 3.164810 4.601336
(3.16, 4.60), against the asymptotic (3.13, 4.53). The exact one is a bit wider and shifted to the right: the Poisson is skewed and the asymptotic interval does not see it. With 30 days they are fairly close; with little data, the exact one is the one to use.
Two versions of a workshop sign-up form are tested: 40 people see the first and 35 the second (1 = signs up, 0 = does not). The data are already in the vectors x and y of your script.
x <- c(0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
1, 1, 0, 1, 1, 0, 0, 1, 1, 1,
1, 1, 1, 0, 0, 0, 1, 1, 1, 0)
y <- c(0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 0, 1, 0)The last part (second bonus) does not use these data.
First bonus. Use R to give the maximum likelihood estimate of each proportion and of their difference.
Solution
- p̂₁ 0.55
- p̂₂ 0.20
- p̂₁ − p̂₂ 0.35
With R
x <- c(0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0) y <- c(0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0) p1 <- mean(x); p2 <- mean(y) c(p1, p2, p1 - p2)
[1] 0.55 0.20 0.35
With 0/1 data (Bernoulli), the MLE of is the mean: , and, by the invariance of the MLE, that of the difference is the difference: 0.35.
Find an asymptotic 95 % confidence interval for . Can we say the sign-ups differ?
Solution
- Lower limit 0.15
- Upper limit 0.55
- Different? Yes
With R
m <- length(x); n <- length(y); z <- qnorm(1 - 0.05 / 2) (p1 - p2) + c(-1, 1) * z * sqrt(p1 * (1 - p1) / m + p2 * (1 - p2) / n)
[1] 0.1467022 0.5532978
= (0.15, 0.55). It does not contain 0: the difference is significant at that level. Before using it, check that , and those of the other sample are not too small (that the normal is reasonable).
Second bonus. Let and be independent standard normals. Use R to find the value such that .
Solution
- a 3.33
With R
qf(0.95, df1 = 5, df2 = 10) # P(F <= a) = 0.95 with F ~ F(5, 10)
[1] 3.325835
On top, a over its degrees; below, a over its own, independent: the ratio is an and is its 0.95 quantile, 3.33. The order of the degrees matters: gives another number.
If you choose On paper, click «Download the exam (PDF)»: it comes with the cover page, the empty marks table and the boxes of each part, without solutions. R stays beside you for whatever needs it, as in the classroom. It is the best way to train for the real exam, because in EC2 the working is most of the mark.
version D rotates content: exercise 1 compares the CLT with and without the continuity correction and uses a joint density on a triangular support whose variables are not independent; exercise 2 estimates an exponential whose MLE is biased and has to be corrected; exercise 3 compares two independent samples with different variances (Welch) and works out a sample size; and exercise 4 builds intervals for a Poisson, the asymptotic one and the exact one. The bonus swaps the chi-square for an F.
What ME1’s EC2 is like
It takes place in the classroom, on your own laptop (RStudio installed and the battery at 100 %) inside the exam’s secure browser. It lasts 4 hours and is worth 50 points, the other half of the subject mark. There are 4 exercises, each with its own context and several linked parts: one usually needs the result of the previous one. There are calculations and proofs by hand and parts with R, and every result is given with two decimals. The extra bonus adds up to 5 points on top.
| Exercise | What is asked | Topics | Points |
|---|---|---|---|
| 1 | A sum of many variables with the CLT, and a joint density: the constant, the marginals, the joint mgf, the covariance and the change to , with its marginals | 6 and 7 | 20 |
| 2 | A density with a parameter: method of moments and maximum likelihood estimators, with data and with optim; the distribution of the MLE through the mgf, and that it is unbiased, consistent and efficient | 9 and 10 | 10 |
| 3 | Intervals with R for a normal (known and unknown σ, the variance), the variance ratio of two samples and the mean difference of paired data, with the proof of the t | 8 and 11 | 10 |
| 4 | A pivot: the distribution of a sum with the mgf, the change to a chi-square, the exact and the asymptotic interval, and both with data | 8 and 11 | 10 |
| Bonus | The difference of two proportions (estimate and interval) and a quantile of a sum of chi-squares | 8, 9 and 11 | +5 |
Look at the chart: exercise 1 is worth twice as much as any other and is almost all on paper, and the proofs (purple border) are concentrated in 2 and 4. Exercise 3 is the most «R» one: if your script has t.test, var.test and the variance interval, those are 8 almost certain points.
What you can bring: two sheets and your .R
You walk into EC2 with two things of your own:
- A handwritten cheat sheet of two sheets, both sides (in EC1 it was one). Results are allowed (mgfs of the models, sampling distributions, interval formulas, the Fisher information), but not proofs. The cheat sheet at the end of this article is a good base for yours.
- A single
.Rfile you upload to the campus before a deadline, with your code from classes and labs. The «For your script» section of each topic’s exercises has that topic’s code already commented.
And at the end, you upload the .R with the code for each exercise. Without it, that exercise is not marked, even if the results are right. In the mock exam, the script on the right plays that role: you can download it when you hand in.
Trusting that you will «work out» the interval formula on the day. In exercise 3 there is no time to derive anything: have t.test(x, conf.level = …), t.test(x, y, paired = TRUE), var.test(x, y) and the two lines of the σ² interval with qchisq in your script, and on your cheat sheet, which pivot goes with each case.
How it is marked
Each part is a cell of the marks table (1.a, 1.b… 4.e and the three bonus parts). There are two kinds:
- Parts with a result. You write it in its boxes and it is marked automatically, with a 0.01 tolerance (comma or point both work). If there are several boxes, each is worth its share. The paper parts of exercise 1 ask for a check value: the formula is general, with , and the box is filled in with a specific given in the statement. That checks your formula is right without having to type it.
- Proofs. There is no number to check, so when you hand in you get the criteria with their points (for example, «writes the log-likelihood», «differentiates and sets to 0», «checks it is a maximum») and you tick the ones you did. That is how the lecturer marks: step by step.
The parts that need working in the exam have the «I worked it out on paper» box. Unticked they score 0 even if the result is right, with a note of what you would have had: in the real exam, a number with no working does not score. The ones done only with R do not have it, because their «working» is the code in the .R.
The mark is out of 50, with the bonus on top, and the mock exam tells you which zone you are in with the rules of the 2026/27 course guide: with 25 or more the EC is passed and kept for the final and the resit; with over 20 it counts towards passing by coursework if EC1 and EC2 add up to 50; with 20 or less this part goes to the final. As EC2 is the second test, what you need depends on what you got in EC1:
With 30 or more in EC1, in EC2 just over 20 is enough; with 25, you need another 25. The subject mark is (EC1 + EC2) / 10, plus the extra from the virtual classroom quizzes and the bonuses, and the ME1 calculator works it out with your real marks.
The four versions
| Version | Exercise 1 | Exercise 2 | Exercise 3 | Exercise 4 |
|---|---|---|---|---|
| A | The class video (CLT) and the phone alerts, exponentials with rates 2 and λ | The lab server start-up ( exponential) | The battery of 32 laptops before and after an update | The VPN that drops: exponential |
| B | Blank tests (CLT, «at least») and two power banks with rates λ and 2λ | The battery when I get home ( exponential) | Heart rate before and after 6 weeks at the gym | Downloading the notes: gamma with shape 2 |
| C | The server RAM (CLT) and the project group, two equal exponentials | The bus delay ( exponential) | Build time with the new compiler | The GPS error: exponential |
| D | Poisson incidents with and without correction; the first and second cafeteria orders | Requests to the IT service: a biased MLE | The morning and afternoon trip: Welch and sample size | The app alerts: Poisson, asymptotic and exact |
In each version, the bonus compares two proportions with 0/1 data (right answers, photocopiers, buses, a form) and asks for a quantile: of a , of a from above and from below, or of an .
How the mock exam works
Choose version and mode. «On screen» shows the parts with their boxes from the start. «On paper» hides them while you do the exam by hand and lets you download the blank exam.
R is on your right. It is the site’s R environment (R in the browser, with RStudio’s panels): the script ec2-A.R (or your version’s) already has the data for exercises 2, 3, 4 and the bonus in their vectors, and a gap under each exercise. Ctrl + Enter runs the line and Ctrl + Shift + Enter, everything. The first time R takes a few seconds to load; after that it is instant. The divider in the middle can be dragged to give more room to the statement or to R, and on a phone you switch between «Exam» and «R» with the tabs at the top.
To check a double integral with R, two nested integrate calls are enough, the inner one with sapply. If the integral has in it (an mgf), do not take it to Inf: you get and integrate fails. With a large limit, like 100, it works. The exercise 1 solutions do it that way.
Hand in. The button asks for confirmation if you leave parts out. You see the mark out of 50, the marks table, your zone, the proof criteria to tick and, for each part, the worked solution with its R code and its real output, your mistakes marked and a «Revise this topic» link. With «Download my .R script» you take away what you wrote.
Nothing is stored on any server: if you reload the page, you start from scratch. You can repeat each version as many times as you like, but the second time it no longer measures the same thing.
How to split the 4 hours
With 240 minutes and 50 points you get about 4.5 minutes per point, but here the split is uneven: exercise 1 is long and on paper, exercise 3 is quick if you have the code, and 2 and 4 are standard proofs that, if you have practised them, come out almost from memory. A split that works, leaving half an hour to check:
| Block | Points | Minutes | Why |
|---|---|---|---|
| Exercise 1 | 20 | 80 | The CLT is quick with R (mean and variance with integrate); the joint density is seven linked parts: watch the Jacobian and the support |
| Exercise 2 | 10 | 45 | Moments and likelihood on paper; data and optim with R; the properties follow from the distribution of the MLE |
| Exercise 3 | 10 | 30 | All with R except the proof of the paired t |
| Exercise 4 | 10 | 40 | mgf of the sum, change of variable and solving for ; both intervals with data, in R |
| Bonus | 5 | 15 | The proportions are three lines of R; the quantile, one |
| Checking and uploading the .R | — | 30 | Check the two decimals, that the script runs end to end and save it |
80 + 45 + 30 + 40 + 15 + 30 = 240 minutes. If a part gets stuck, write down the result you were missing as an assumption («if gamma(n, λ)…», as exercise 4’s own statement does) and carry on: almost every part can be solved with the previous one given.
What is examined: exercise by exercise
Each exercise matches one or two ME1 topics on the site. Each topic’s exam-style exercises have parts with the same format and their cheat sheet, and its proofs article has the ones that come up.
| Exercise | Topic | Theory | Proofs | Exercises |
|---|---|---|---|---|
| — | The normal distribution | Theory | Proofs | Exercises |
| 1 | Transformations and joint distributions | Theory | Proofs | Exercises |
| 1 | Inequalities and limit theorems | Theory | Proofs | Exercises |
| 3, 4 and bonus | Sampling distributions (χ², t, F) | Theory | Proofs | Exercises |
| 2 | Point estimation | Theory | Proofs | Exercises |
| 2 | Properties of estimators | Theory | Proofs | Exercises |
| 3 and 4 | Confidence intervals and sample size | Theory | Proofs | Exercises |
The normal has no exercise of its own, but it is in all of them: the CLT, the intervals and the bonus use it constantly.
Typical mistakes in EC2
- Forgetting the Jacobian or the support when changing variables. With , , and the support becomes ; without that, the marginals do not integrate to 1.
- Integrating the marginal over the rectangle when the support is a triangle. If , for the goes from to .
- «At least» with the wrong tail in the CLT. , and with a discrete variable, the continuity correction.
- The MLE of with
var.vardivides by ; the MLE divides by . - The chi-square quantiles in the right place. In the interval, the high quantile goes in the lower limit.
- Treating paired data as independent. Before and after on the same individual:
t.test(after, before, paired = TRUE), which works with the differences. - The pivot’s degrees of freedom. If ,
qchisqtakes , not ; and in the F, the order of the degrees matters. - Saying «unbiased» without computing the expectation. Two methods giving the same estimator says nothing about its bias: for the exponential has some.
optimminimising. To maximise the log-likelihood,control = list(fnscale = -1).- The code in the console. What is not in the
.Rdoes not exist for the marking.
Cheat sheet: what you can put on your two sheets
The essentials in 30 seconds: the CLT turns a sum of many variables into a normal with mean and variance ; in a joint density, the constant comes from integrating to 1, the marginals from integrating out the other variable and, if on a rectangle, they are independent; a change of variables brings and a new support; estimators come from equating moments or differentiating the log-likelihood; unbiased is , consistent is MSE → 0 and efficient is reaching the Cramér–Rao bound; and an interval is a pivot solved for the parameter.
| I want to… | How | In R |
|---|---|---|
| Approximate a sum (CLT) | pnorm(s, n * mu, sqrt(n * s2)) | |
| Continuity correction | pnorm(k + 0.5, …) | |
| Constant of a joint density | two nested integrate (sapply) | |
| Marginals and independence | ; independent if on a rectangle | — |
| Joint mgf | ; with independence, the product | integrate up to a large value |
| Covariance | — | |
| Change of variables | — | |
| Sum of exponentials | equal: gamma(2, λ); different: | dgamma |
| Method of moments | and solve | mean(x) |
| Maximum likelihood | and second derivative | optim(ini, logL, method = "L-BFGS-B", lower = 1e-6, control = list(fnscale = -1)) |
| Unbiased, consistent | ; | simulate with replicate |
| Efficient | ; bound | — |
| Mean, σ known | qnorm(1 - a / 2) | |
| Mean, σ unknown | t.test(x, conf.level = 0.95) | |
| Variance | qchisq | |
| Variance ratio | pivot ; does it contain 1? | var.test(x, y) |
| Paired data | t.test(y, x, paired = TRUE) | |
| Two means, different variances | Welch | t.test(x, y, var.equal = FALSE) |
| Exponential pivot | qchisq(c(a / 2, 1 - a / 2), 2 * n) / (2 * T) | |
| Asymptotic interval of the MLE | — | |
| Two proportions | mean(x) - mean(y) | |
| Sample size | , rounding up | ceiling(…) |
| Sums of squared normals | standardised, they add up to a with as many degrees as terms | qchisq(p, k), qf(p, k1, k2) |
What to revise on the site
If a part comes out red, the «Revise this topic» link in its solution takes you to the exercises (or the proofs) of the topic that explains it. Before trying again with another version:
- The exam-style exercises of topics 6 to 11: they have parts with points, like these, and their «For your script».
- The proofs of topics 6, 8, 9, 10 and 11: the change of variables, the t, the likelihood, the Cramér–Rao bound and the pivots.
- The EC1 mock exam, if you still have to resit the first part.
- The R playground to practice with your own script with nothing to install.
- The ME1 calculator, to see whether your two ECs are enough to pass by coursework.
Summary
| What | What it is like |
|---|---|
| Length and points | 4 hours, 50 points (20 + 10 + 10 + 10) and a 5-point extra bonus |
| Material | Laptop with RStudio, a two-sheet handwritten cheat sheet and your .R; at the end you upload the exam’s .R |
| Mock exam marking | Boxes to two decimals (0.01 tolerance), check values for the formulas, criteria for the proofs, «I worked it out on paper» |
| What the mark means | 25 or more: passed and kept; over 20: counts if you reach 50 with EC1; 20 or less: to the final |
| Versions | A, B and C as in 2025-26; D with what did not come up |
Three ideas for exam day: exercise 1 is worth 20 points, so do not leave it for the end; in any change of variables, Jacobian and support before anything else; and in the intervals, say which pivot you use: that is already half the part, and R does the rest.
Keep goingAll Statistics articlesDid this article help you? Here is how you can support SergioLearns →



