```{r data generation, echo = FALSE, results = "hide"}
n_a <- sample(18:22, 1)
n_b <- sample(18:22, 1)
mean_a_true <- sample(72:78, 1)
diff_true <- sample(c(-6, -4, 0, 4, 6), 1)
sd_pool <- sample(7:10, 1)

scores_a <- round(rnorm(n_a, mean = mean_a_true, sd = sd_pool), 1)
scores_b <- round(rnorm(n_b, mean = mean_a_true - diff_true, sd = sd_pool), 1)

d <- data.frame(
  group = c(rep("A", n_a), rep("B", n_b)),
  score = c(scores_a, scores_b)
)

tt <- t.test(score ~ group, data = d, var.equal = TRUE)
mean_a <- mean(scores_a)
mean_b <- mean(scores_b)
sd_a <- sd(scores_a)
sd_b <- sd(scores_b)
diff_ab <- mean(scores_a) - mean(scores_b)
pval <- unname(tt$p.value)
ci_low <- unname(tt$conf.int[1])

test_sol <- c(TRUE, FALSE, FALSE)
interp_sol <- c(pval >= 0.05, pval < 0.05 & diff_ab > 0, pval < 0.05 & diff_ab < 0)
equal_var_sol <- c(TRUE, FALSE)
test_choices <- c("pooled two-sample t-test", "paired t-test", "chi-squared test")
equal_var_choices <- c("Yes", "No")
interp_choices <- c(
  "There is no significant mean difference between the groups",
  "Group A has a significantly higher mean score than Group B",
  "Group A has a significantly lower mean score than Group B"
)
interp_solution <- if(pval >= 0.05) {
  interp_choices[1]
} else if(diff_ab > 0) {
  interp_choices[2]
} else {
  interp_choices[3]
}
```

Question
========
A lecturer wants to compare exam scores between two independent tutorial groups.
The summarized quiz scores are:

```{r summary table, echo = FALSE}
data.frame(
  group = c("A", "B"),
  n = c(n_a, n_b),
  mean = c(round(mean_a, 1), round(mean_b, 1)),
  sd = c(round(sd_a, 1), round(sd_b, 1))
)
```

How many students are in Group A? `r add_cloze(n_a)`

Using the summary table, compute the mean score of Group A.
`r add_cloze(mean_a, tolerance = 0.1, digits = 1)`

Which test is appropriate for comparing the two independent group means here?
`r add_cloze(test_choices[1], test_choices, type = "schoice")`

What is the p-value of the pooled two-sample t-test?
`r add_cloze(pval, tolerance = 0.001, digits = 3)`

Does the pooled version of the test assume equal variances in the two groups?
`r add_cloze(equal_var_choices[1], equal_var_choices, type = "schoice")`

What is the lower endpoint of the 95% confidence interval for A - B?
`r add_cloze(ci_low, tolerance = 0.02, digits = 2)`

At the 5% level, which conclusion is correct?
`r add_cloze(interp_solution, interp_choices, type = "schoice")`

Compute the difference in means A - B.
`r add_cloze(diff_ab, tolerance = 0.1, digits = 1)`

`r format_metainfo("answerlist")`

Solution
========
The standard procedure is a pooled two-sample t-test. The pooled version
assumes equal variances in the two groups.

The numerical answers can be obtained in R with:

```{r analysis, echo = FALSE, comment = NA}
aggregate(score ~ group, data = d, mean)
t.test(score ~ group, data = d, var.equal = TRUE)
```

Meta-information
================
exname: Mixed statistics cloze
extype: cloze
exclozetype: `r format_metainfo("type")`
exsolution: `r format_metainfo("solution")`
extol: `r format_metainfo("tolerance")`
expoints: 1|1|1|1|1|1|1|1
exshuffle: TRUE
