Today

  • You have 55 minutes to complete the 16-question online mock individually.
  • Note questions you want us to discuss.
  • Take a 10-minute break.
  • Compare your answers with the answer script, work through mistakes and ask us questions.

The answers will be made available for discussing particular questions right after the mock.

Main Exam Rules

  • Complete the exam independently on NOW, using R/RStudio on your own or a university computer.
  • You may use two double-sided A4 pages of notes. The exam is otherwise closed book.
  • Access the NOW exam only: no other NOW learning materials or internet resources.
  • No GenAI, collaboration or communication with other students during the exam.

Main Exam Timekeeping

  • Friday 27 November: rooms available from 15:00; exam starts 15:30. Usual room: CHR2501.
  • If you have an access-related room arrangement, use the room in my email. Contact me if you have not received your room details.
  • Standard duration: 90 minutes, finishing at 17:00. Follow your individual timing arrangements for extra time and rest breaks.
  • You are responsible for monitoring your time and submitting within your allowance. Leave a few minutes to check and submit your answers.

Reporting Numerical Answers

  • For numerical-entry answers, report at least three decimal places. You can copy more decimal places directly from R.
  • Use integers for counts and exact whole-number answers, such as 5 parameters or 3 dummy variables.

Load The Data Before You Start

Load the data into R before starting the mock or exam. Follow the data-loading instructions on NOW.

For the exam, a NOW News message one hour before the start will tell you which datasets to load. Have these loaded before the exam begins.

Use an R script for your attempt. Keep it available to compare with the answer script afterwards.

Strategy For The Mock And Main Exam

  • Read all questions first to get an overview and identify those you can answer readily.
  • Start with the questions you find easy. Leave difficult or time-consuming questions until later.
  • If you get stuck, move on and return once you have answered the easier questions.
  • Wrong answers carry no penalty: you do not lose marks for an incorrect answer, so attempt every question.

Leave a few minutes to check your answers and submit within your time allowance.

During The Mock

  • Everyone has 55 minutes to complete the mock.
  • You may use all resources during the mock.
  • If you have prepared exam notes, try using only those notes to see how well they support your work.

If you finish early, check your answers and identify one result you can’t explain in words.

Short Break

Take a 10-minute break after the mock.

Keep your attempt available so you can compare it with the worked answers.

After The Mock: Use The Answers

Download week_09_workshop_answer.R when it is released on NOW and move it into your RStudio Project folder.

  1. Compare your answers and code with the answer script. Run the relevant lines to check the output.
  2. For any mistakes, identify what went wrong and correct your attempt. Can you explain why the corrected answer makes sense?
  3. Ask us about anything you cannot resolve. Show us the question number, your code and the output.

We will discuss particular problems you raise. The question-by-question worked slides are available for these discussions and later revision.

After The Workshop

Find the study guide Statistical concepts, tests and R in NOW → Assessments. It brings together the module topics, key concepts, tests, R commands and relevant formulas.

Choose a question you found difficult. Decide what you need to practise:

  • Choosing the analysis or writing the command.
  • Locating the requested value in the output.
  • Explaining the result, including units and direction.

Use the guide to revisit that topic, practise the matching workshop or problem-set task, then retry without the answers.

Q1: An Equal-Variance t-Test

d_1 <- read_csv("workshop_data/assessment_dataset_01.csv")
m_1 <- t.test(value ~ section, data = d_1,
              var.equal = TRUE, conf.level = .80)
m_1$statistic
#          t 
# -0.4489152

Answer: t = -0.4489. The difference is 1st minus 2nd; the negative sign means the first sample mean is lower.

The null hypothesis is a population mean difference of zero. Equal variances are specified in the question.

Revisit: Weeks 3–4 workshop and lecture slides — equal-variance t-tests and reading the output.

Q2: Degrees Of Freedom

m_1$parameter
#  df 
# 998

Answer: df = 998, the two sample sizes added together minus 2.

The degrees of freedom determine the shape of the t-distribution used for this test.

Revisit: Weeks 3–4 workshop and lecture slides — t-test degrees of freedom.

Q3: The 80% Confidence Interval

m_1$conf.int
# [1] -2.397991  1.154434
# attr(,"conf.level")
# [1] 0.8

Answer: [-2.398, 1.154], for population mean 1st minus 2nd.

Zero is inside the interval: these data do not rule out no population difference at this confidence level.

Use conf.level = .80; the default 95% interval answers a different question.

Revisit: Week 4 workshop and lecture slides — confidence intervals and confidence levels.

Q4-5: Which Tail?

# Q4: area ABOVE 1.75
pt(1.75, df = 14, lower.tail = FALSE)
# [1] 0.05099653
# Q5: area BELOW 0.75
pt(0.75, df = 5)
# [1] 0.7564879

Q4: .051. Q5: .756 (values shown here to three decimal places).

These ask for one-tail probabilities, not two-sided p-values. Use the supplied t-value and df for each question.

Revisit: Week 3 workshop and lecture slides — t-distribution tails and pt().

Q6: Set Up The Difference And SE

Two independent samples; assume equal population variances.

n_x <- 12; n_y <- 10
avg_x <- 100.589; avg_y <- 101.356
sd_x <- 1.297; sd_y <- 1.611
df <- n_x + n_y - 2
pooled_variance <- ((n_x - 1) * sd_x^2 +
                   (n_y - 1) * sd_y^2) / df
se <- sqrt(pooled_variance) * sqrt(1 / n_x + 1 / n_y)
avg_diff <- avg_x - avg_y

Pool the sample variances to estimate the common population variance. Keep the requested difference x minus y throughout.

Revisit: Week 4 workshop and lecture slides — pooled variance, standard error and the t-statistic.

Q6: Divide The Difference By Its SE

avg_diff / se
# [1] -1.238165

Answer: t = -1.2382. The sample mean difference is -0.767, about 1.24 standard errors below the null difference of zero.

The negative sign comes from x minus y. Reversing the subtraction reverses the sign.

Revisit: Week 4 workshop and lecture slides — pooled variance, standard error and the t-statistic.

Q7: A 90% Confidence Interval

tau <- qt(.95, df = df)
avg_diff - tau * se
# [1] -1.835402
avg_diff + tau * se
# [1] 0.3014024

Answer: [-1.835, 0.301], for the population difference mu_x minus mu_y.

A central 90% interval leaves 5% in each tail. Use the cutoff with .95 below it, not .90.

Revisit: Week 4 workshop and lecture slides — confidence intervals and qt().

Q8: Read The Overall F-Statistic

d_3 <- read_csv("workshop_data/assessment_dataset_03.csv")
m_2 <- lm(y ~ x + z, data = d_3)
m_2_summary <- summary(m_2)
m_2_summary$fstatistic
#     value     numdf     dendf 
#  2.859026  2.000000 47.000000

Answer: F = 2.859, with df 2 and 47. Read value; the other two numbers are the degrees of freedom.

The null hypothesis is that both predictor coefficients are zero, comparing this model with an intercept-only model.

Revisit: Week 6 workshop and lecture slides — summary() and the overall F-test.

Q9: Predict The Mean

new_values <- tibble(x = 10, z = 12)
new_values
# # A tibble: 1 × 2
#       x     z
#   <dbl> <dbl>
# 1    10    12
predict(m_2, newdata = new_values)
#        1 
# 17.15589

Answer: 17.1559 (about 17.2).

Supply both predictors, using their original names. This is the predicted mean of y at those predictor values.

Revisit: Week 5 workshop and lecture slides — multiple regression and predict().

Q10: Spread Around The Predicted Mean

sigma(m_2)
# [1] 52.62584

Answer: 52.6258 (about 52.63).

This is the estimated residual standard deviation: spread around the predicted mean, in y’s units.

The model assumes the same residual SD at every x and z. It is different from the predicted mean and from uncertainty about that mean.

Revisit: Week 5 workshop and lecture slides — sigma and residual spread.

Q11: Explained Variation Relative To Total

These supplied numbers describe a separate model with one numeric predictor and an intercept.

n <- 25; K <- 1
rss <- 4186.153; tss <- 19560.807
ess <- tss - rss
rsq <- ess / tss
rsq
# [1] 0.7859928

Answer: R-squared = 0.786: about 78.6% explained and 21.4% unexplained. TSS = ESS + RSS.

Revisit: Week 6 workshop and lecture slides — ESS, RSS, TSS and R-squared.

Q12: Overall F From The Supplied Sums

Df1 <- K
Df2 <- n - K - 1
(ess / Df1) / (rss / Df2)
# [1] 84.47303

Answer: F = 84.47, with df 1 and 23.

Compare explained variation per predictor df with unexplained variation per residual df.

Here the simpler model is intercept-only: its RSS equals TSS. The RSS reduction is ESS, linking this calculation to the model comparisons in Week 8.

Revisit: Week 6 workshop and lecture slides — overall F and its degrees of freedom.

Q13: Adjust For Model Complexity

1 - (1 - rsq) * (n - 1) / (n - K - 1)
# [1] 0.7766882

Answer: adjusted R-squared = 0.777.

It is below the unadjusted value of 0.786 because the adjustment penalises model complexity relative to the available sample size.

Use n = 25 and K = 1 supplied for this question, rather than values from the earlier fitted model.

Revisit: Week 6 workshop and lecture slides — adjusted R-squared.

Q14: Predict A Group Mean

d_ano <- read_csv("workshop_data/anorexia2.csv")
m_3 <- lm(Postwt ~ Treat, data = d_ano)
coef(m_3)
# (Intercept)   Treatctrl    Treatfam 
#   85.696552   -4.588859    4.797566

The reference group is cbt, so its predicted mean equals the intercept.

Treatfam combines the predictor name Treat and level fam; it gives the difference from cbt.

Revisit: Week 7 workshop and lecture slides — categorical predictors and group means.

Q14: Obtain The Predicted Mean

predict(m_3, newdata = tibble(Treat = "cbt"))
#        1 
# 85.69655

Answer: 85.6966.

This is the predicted group mean, rather than a difference between groups.

Revisit: Week 7 workshop and lecture slides — categorical predictors and group means.

Q15: Subtract In The Requested Order

mean_fam <- predict(m_3, newdata = tibble(Treat = "fam"))
mean_cbt <- predict(m_3, newdata = tibble(Treat = "cbt"))
mean_fam - mean_cbt
#        1 
# 4.797566

Answer: 4.7976. The predicted mean for fam is about 4.80 units higher than for cbt.

This also equals the Treatfam coefficient. It is a difference, rather than the predicted mean of fam.

Revisit: Week 7 workshop and lecture slides — group differences and reference levels.

Q16: Add A Continuous Predictor

m_4 <- lm(Postwt ~ Treat + Prewt, data = d_ano)
coef(m_4)
# (Intercept)   Treatctrl    Treatfam       Prewt 
#  49.7711090  -4.0970655   4.5630627   0.4344612

The model has group differences plus a common Prewt slope. The question does not request an interaction.

For fam: predicted Postwt = intercept + fam difference + Prewt slope × Prewt.

Revisit: Week 8 workshop and lecture slides — categorical and continuous predictors together.

Q16: Supply Both Predictor Values

new_person <- tibble(Treat = "fam", Prewt = 80)
new_person
# # A tibble: 1 × 2
#   Treat Prewt
#   <chr> <dbl>
# 1 fam      80
predict(m_4, newdata = new_person)
#        1 
# 89.09106

Answer: 89.0911.

Using the printed coefficients: 49.7711 + 4.5631 + 0.4344612 × 80 ≈ 89.0911.

Revisit: Week 8 workshop and lecture slides — categorical and continuous predictors together.