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

```{r propensityscore_quiz1, echo=FALSE}
question("Q1. Consider the following matching formula: formula.match <- as.formula(diabetes ~ sex + age + race + smoking'). Which R codes can be used to match one exposed to one unexposed based on their propensity score, where propensity score is defined as the probability of being exposed to diabetes?)",
  answer("matchit(formula.match, data = dat.analytic, method = 'exact', ratio = 1)"),
  answer("matchit(formula.match, data = dat.analytic, method = 'full')"),
  answer("matchit(formula.match, data = dat.analytic, method = 'nearest')", correct = TRUE),
  answer("matchit(formula.match, data = dat.analytic, method = 'exact')"),
  incorrect = "See the method argument in this example, which is the key to this question.",
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```

```{r propensityscore_quiz2, echo=FALSE}
question("Q2. What is the key difference between Zanutto (2006), DuGoff et al. (2014), and Austin et al. (2018) methods in propensity score analysis with complex survey data? ",
  answer("Different in terms of outcome modelling"),
  answer("Different in terms of assessing covariate balance"),
  answer("Different in terms of exposure/treatment modelling", correct = TRUE),
  answer("There is no difference"),
  incorrect = "Check the steps of each of these three techniques.",
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```

```{r propensityscore_quiz3, echo=FALSE}
question("Q3. Say, we are exploring the association between diabetes (exposure) and CVD (outcome) using NHANES 2017-18 dataset. Age, sex, race, income, diet, smoking, and hypertension are the confounders. The name of the survey features are: psu, strata, survey.weight. Which of the following code can be used to estimate the propensity score using Austin et al. (2018) approach?",
  answer("ps.austin <- glm(diabetes ~ age + sex + race + income + diet + smoking + hypertension, data = dat.analytic, family = binomial)$fitted.values"),
  answer("ps.austin <- glm(cvd ~ age + sex + race + income + diet + smoking + hypertension, data = dat.analytic, family = binomial)$fitted.values"),
  answer("ps.austin <- svyglm(diabetes ~ age + sex + race + income + diet + smoking + hypertension, design = survey.design, family = binomial)$fitted.values", correct = TRUE),
  answer("ps.austin <- glm(diabetes ~ age + sex + race + income + diet + smoking + hypertension + psu + strata + survey.weight, data = dat.analytic, family = binomial)$fitted.values"),
  incorrect = "There is only one key difference between Zanutto (2006), DuGoff et al. (2014), and Austin et al. (2018) methods. Check the steps of each of these techniques.",
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```

```{r propensityscore_quiz4, echo=FALSE}
question("Q4. For Q3, we match an exposed subject (having diabetes) with a control subject (no diabetes) without replacement within the caliper of 0.2 times the standard deviation of the logit of the propensity score. The name of the matched dataset is 'mydata.match'. The name of the survey design on full data is 'design.full', and the subset of the design on the matched dataset is 'design.match'. What could be the outcome model for DuGoff et al. (2014) method when we are interested in population-level estimates?",
  answer("fit <- glm(cvd ~ diabetes, data = mydata.match, family = binomial)"),
  answer("fit <- glm(cvd ~ diabetes + age + sex + race + income + diet + smoking + hypertension, data = mydata.match, family = binomial)"),
  answer("fit <- svyglm(cvd ~ diabetes, design = design.match, family = binomial)", correct = TRUE),
  answer("fit <- svyglm(cvd ~ diabetes + age + sex + race + income + diet + smoking + hypertension, design = design.full, family = binomial)"),
  incorrect = "To get a population-level estimate, you should utilize the survey features as the design in your outcome model.",
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```

```{r propensityscore_quiz5, echo=FALSE}
question("Q5. What could be your outcome model when you perform propensity score matching with multiple imputation?",
  answer("fit[[i]] <- glm(cvd ~ diabetes, data = mydata.match, family = binomial)"),
  answer("fit[[i]] <- glm(cvd ~ diabetes + age + sex + race + income + diet + smoking + hypertension, data = mydata.match, family = binomial)"),
  answer("fit[[i]] <- svyglm(cvd ~ diabetes, design = design.match, family = binomial)", correct = TRUE),
  answer("fit[[i]] <- svyglm(cvd ~ diabetes + age + sex + race + income + diet + smoking + hypertension, design = design.full, family = binomial)"),
  incorrect = "You should utilize the survey features as the design in your outcome model.",
  allow_retry = TRUE,
  random_answer_order = TRUE
)
```
