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

```{r researchquestion_quiz1, echo=FALSE}
question("Let you have five categorical variables 'age', 'sex', 'race', 'education', and 'income' in your data frame called mydat. You labelled these variables as factvars <- c('age', 'sex', 'race', 'education', 'income') and are interested in converting these categorical variables to factors at once. How could you do it in R?",
  answer("mydat <- lapply(mydat, factvars)"),
  answer("mydat <- lapply(mydat[factvars], as.factor)"),
  answer("mydat[factvars] <- lapply(mydat[factvars], as.factor)", correct = TRUE),
  answer("mydat[factvars] <- lapply(mydat, as.factor)"),
  allow_retry = TRUE,
  incorrect = "Incorrect. See the `lapply` fuction for deatils. Also, see the 'RHC data' chapter. ",
  random_answer_order = TRUE
)
```

```{r researchquestion_quiz2, echo=FALSE}
question("Let we are interested in exploring the relationship between rheumatoid arthritis (binary exposure variable defined as whether the doctor ever told the participant has rheumatoid arthritis) and diabetes (binary outcome variable defined as whether the doctor ever told the participant has diabetes) among US adults using NHANES 2015-16 dataset. What are the PICOT elements in this example:",
  answer("P: US adults, I: Diabetes, C: No diabetes, O: Rheumatoid arthritis, T: 2015-16"),
  answer("P: US population, I: Rheumatoid arthritis, C: No rheumatoid arthritis, O: Diabetes, T: 2015-16"),
  answer("P: US adults, I: Rheumatoid arthritis, C: No rheumatoid arthritis, O: Diabetes, T: 2015-16", correct = TRUE),
  answer("P: US adults, I: Rheumatoid arthritis, C: No rheumatoid arthritis, O: Diabetes, T: 2 years"),
  answer("P: US adults, I: Diabetes, C: No diabetes, O: Rheumatoid arthritis, T: 2 years"),
  answer("P: US population, I: Rheumatoid arthritis, C: No rheumatoid arthritis, O: Diabetes, T: 1 year"),
  allow_retry = TRUE,
  incorrect = "Hint: see the 'NHANES data' chapter. Note that P: Population, I: Intervention/exposure, C: Control/unexposed, O: Outcome, T: Time.",
  random_answer_order = TRUE
)
```

```{r researchquestion_quiz3, echo=FALSE}
# Define the answer options
steps <- c(
    "Download all the necessary data files, e.g., demographic, examination, diet.",
    "Merge all the data files",
    "Subset the data as per the eligibility criteria",
    "Recode/define variables", 
    "Check missingness and data summaries"
  )

question_rank("Sort the steps of creating an analytic dataset for a causal question using NHANES 2017-18",
  answer(steps, correct = TRUE),
  answer(rev(steps), correct = FALSE, message = "Other direction!"),
  allow_retry = TRUE,
  incorrect = "Hints: We usually recode covariates in our analytic dataset than the full dataset, i.e., we recode variables once done with data merging and subsetting."
)
```
