library(learnr)
library(tidyverse)
library(tutorialExtras)
library(gradethis)

gradethis_setup()
knitr::opts_chunk$set(echo = FALSE)
grade_server("grade")
question_text("Name:",
              answer_fn(function(value){
                              if(length(value) >= 1 ) {
                                return(mark_as(TRUE))
                                }
                              return(mark_as(FALSE) )
                              }),
              correct = "submitted",
              allow_retry = FALSE )
grade_button_ui(id = "grade")

Instructions

Complete this tutorial while reading Chapter 7 of the textbook. Each question allows 3 'free' attempts. After the third attempt a 10% deduction occurs per attempt.

You can click the "View Grade" button as many times as you would like to see your current grade and the number of attempts you are on. Before submitting make sure your grade is as expected.

Goals

Reading Quiz

quiz(caption = NULL,
  # Question 1
    question("Q1) What is the gold standard method for understanding causality?", 
           type = "learnr_text",
           answer_fn(function(value){
            if (str_remove_all(str_to_lower(value), " ") %in% 
                c("randomizedexperiment",
                  "randomizedtrial",
                  "randomizedcontroltrial",
                  "randomassignment")) {
                 return(mark_as(TRUE))}
                 return(mark_as(FALSE) ) }),
           allow_retry = TRUE), 
    # Question 2
    question_wordbank("Q2) What is the purpose of the rbernoulli() function?",
           choices = c("fits a linear regression model", "selects columns of a data frame", "randomly selects rows from a data set", "generates results of random coin flips", "selects rows of a data frame"),
           wordbank = c("rbernoulli()", "sample_n()", "lm()",
                        "select()", "filter()"),
           answer(c("lm()", "select()","sample_n()",
                    "rbernoulli()", "filter()"), 
                  correct = TRUE),
           allow_retry = TRUE), 
      # Q3
    question_numeric("Q3) In the simulated coin_flips data, what percentage of the coins 'landed on heads'?", 
           answer(30, correct = TRUE),
           allow_retry = TRUE),  
    # Q4
  question_wordbank("Q4) The following simple linear regression model is used to estimate the 'average treatment effect.' In $\\hat{y} = b_0 + b_1T$ where $b_1 = \\bar{y}_T-\\bar{y}_C$, Match each term with its interpretation.",
           choices = c("\\(b_1\\)", "\\(\\bar{y}_T\\)", "\\(\\bar{y}_C\\)", "T", "\\(\\hat{y}\\)"),
           answer(c("estimated treatment effect", "average outcome in the treatment group", "average outcome in the control group", "indicator variable for whether an individual is in the treatment group", "estimated outcome for an individual"), correct = TRUE),
           allow_retry = TRUE), 
           # Q5
    question("Q5) Which of the following statements are TRUE about the following line of code? rbernouilli(n = 50, p = 0.4)",
           answer("It will result in 30 TRUE values and 20 FALSE values"),
           answer("I cannot determine in advance how many TRUE values will result", correct = TRUE),
           answer("It mimics 50 random 'coin flips', with each coin flip having a 0.4% chance of resulting in 'heads'"),
           answer("It will result in 20 TRUE values and 30 FALSE values"),
           allow_retry = TRUE,
           random_answer_order = TRUE),    
    # Q6
    question_wordbank("Q6) Match each phrase with the variable name (letter) it is typically associated with in a model.",
           choices = c("explanatory variable", "outcome variable", "dependent variable", "omitted variable", "predictor variable", "confounding variable"),
           wordbank = c("X", "Y", "Z"), 
           answer(c("X", "Y", "Y", "Z", "X", "Z"), correct = TRUE),
           allow_retry = TRUE),    
          # Q7
    question("Q7) Which of the following statements are TRUE? Select all that apply.",
           answer("In observational data, the relationship between T and Y, adjusting for Z, will be similar to the relationship between T and Y alone"),
           answer("Randomization ensures that on average, treatment and control groups are equivalent on all observed AND unobserved pre-treatment characteristics", correct = TRUE),
           answer("Adding omitted variables to a model substantially changes the estimated treatment effect in a randomized experiment"),
           answer("You do not have to worry about confounding in a randomized experiment", correct = TRUE),
           allow_retry = TRUE,
           random_answer_order = TRUE),    
          # Q8
    question_numeric("Q8) In the ed_data randomized experiment example (i.e. in the scenario where treatment status was randomly assigned), what percentage of students in the control group were minority students? Round to 1 decimal place.", 
           answer(32.7, correct = TRUE),
           step = 0.1,
           allow_retry = TRUE), 
    # Q9
    question_numeric("Q9) How many students did we randomly assign to the treatment group in the ed_data example?", 
           answer(167, correct = TRUE),
           allow_retry = TRUE)
  )

Submit

Once you are finished:

grade_print_ui("grade")


NUstat/ISDStutorials documentation built on April 17, 2025, 6:15 p.m.