```{r setup, warning=FALSE, message=FALSE, include=FALSE}
# Load required packages
library(learnr)
library(xfun)
```

```{r nonbinary_quiz1, echo=FALSE}
question("Q1. Say, we are exploring the association between diet at baseline (no/yes) and systolic blood pressure over 5 follow-ups for each subject. For this repeated measure dataset, which of the following code can be used to fit the mixed effects model with random intercept but fixed slope?. Note: `diet` is the exposure avriable, `systolic` is the systolic blood pressure variable, `subject` is the unique identifier for the subjects, and `visit` is the follow-up visits.",
  answer("fit <- glm(systolic ~ diet, data = longdata, family = gaussian)", message = "glm is being used to fit the regular glm, not the mixed effect model."),
  answer("fit <- lm(systolic ~ diet + visit, data = longdata)", message = "We use lm function to fit linear regression. This model does not account for repeated measurements."),
  answer("fit <- lmer(systolic ~ diet + visit + (1 | subject), data = longdata)", correct = TRUE),
  answer("fit <- glmer(systolic ~ diet + visit + (visit | subject), data = longdata), data = longdata)", message = "This is a model with random intercept and random slope"),
  allow_retry = TRUE,
  random_answer_order = FALSE,
)
```

```{r nonbinary_quiz2, echo=FALSE}
question("Q2. How can we fit the generalized estimating equation (GEE) with exchangeable correlation structure in Q1?",
  answer("fit2 <- lmer(systolic ~ diet + visit + (1 | subject), data = longdata)", message = "We use lmer to fit mixed effects models"),
  answer("fit2 <- gee(systolic ~ diet, data = longdata, id = visit, corstr = 'exchangeable', scale.fix = TRUE, scale.value = 1, family = gaussian)", message = "We must use the correct id variable."),
  answer("fit2 <- gee(systolic ~ diet, data = longdata, id = subject, corstr = 'exchangeable', scale.fix = TRUE, scale.value = 1, family = gaussian)", correct = TRUE),
  answer("fit2 <- gee(systolic ~ diet, data = longdata, id = subject, corstr = 'independence', scale.fix = TRUE, scale.value = 1, family = gaussian)", message = "The question is about the exchangeable correlation structure, not independent correlation structure."),
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```
