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

#for exercise
library(moderndive)
evals_ch6 <- evals %>%
  select(ID, score, age, gender)

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 Sections 6.2 - 6.4 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

Exercise

Fill in the blank for the code that produces the following plot:

htmltools::img(src="images/Figure_06_3.png", height = 400, width = 700)
ggplot(evals_ch6, aes(x = ___, y = ___, color = ___)) +
  ____ +
  labs(x = ___, y = ___, color = ___) +
  ___(method = "lm", se = FALSE)
Remember to include the parentheses for filling in the blank on line 2.
ggplot(evals_ch6, aes(x = age, y = score, color = gender)) +
  geom_point() +
  labs(x = "Age", y = "Teaching Score", color = "Gender") +
  geom_smooth(method = "lm", se = FALSE)
grade_this_code()

Reading Quiz

quiz(
  caption = NULL,
  withMathJax(),
  # Q1
  question_numeric("Q1) What is the age of the youngest professor in the evals data set?",
           answer(29, correct = TRUE),
           allow_retry = TRUE),
  # Q2
  question_numeric("Q2) What is the value of $b_2$ for the regression model score_model_interaction?  Round to 3 decimal places.", 
           answer(-0.446, correct = TRUE),
           step = 0.001,
           allow_retry = TRUE),
  # Q3
  question_wordbank("Q3) Consider the following model where age and gender are the explanatory/predictor variables, and female is the reference group for gender.\n
$\\hat{y} = b_0 + b_1*age + b_2*gender + b_3*age*gender$",
           choices = c("\\( b_{0} \\)", 
                        "\\( b_{1} \\)", 
                        "\\( b_{2} \\)", 
                        "\\( b_{3} \\)", 
                        "\\( b_{0}+b_{2} \\)", 
                        "\\( b_{1}+b_{3} \\)"),
           wordbank = c("intercept for females", "intercept for males", "offset in intercept for males", "offset in slope of age for males", "slope of age for females", "slope of age for males"),
           answer(c("intercept for females", "slope of age for females", "offset in intercept for males", "offset in slope of age for males", "intercept for males", "slope of age for males"), correct = TRUE),
           allow_retry = TRUE),
  # Q4
  question("Q4) What is the value of $1_{is male}(x)$ for the 109th instructor in the evals data set?", 
           type = "learnr_text",
           answer("0", correct = TRUE),
           allow_retry = TRUE),
#Q5
    question_wordbank("Q5) Match each model with the appropriate description.",
          choices = c("lm(score ~ age + gender, data = evals_ch6)", "lm(credit_limit + income ~ debt, data = credit_ch6)", "lm(score ~ age + gender + age*gender, data = evals_ch6)", "lm(debt ~ credit_limit + income, data = credit_ch6)" ),
          wordbank = c("linear regression model with two numeric explanatory variables", "linear regression interaction model", "linear regression parallel slopes model", "not an appropriate use of a linear regression model"),
           answer(c("linear regression parallel slopes model",
                    "not an appropriate use of a linear regression model", "linear regression interaction model", "linear regression model with two numeric explanatory variables"), correct = TRUE),
           allow_retry = TRUE),
  # Q6
   question_numeric("Q6) Consider a model of the form:\n
    y ~ x1 + x2 + x1*x2

How many quantities does this model estimate? That is, how many values will there be in the Estimate column of a regression table for this model? ", 
           answer(4, correct = TRUE),
           allow_retry = TRUE),
   # Q7
question("Q7) Match the model with the appropriate mathematical representation:\n
          lm(debt ~ credit_limit + income)",
           answer("$\\hat{y} = b_1*x_1 + b_2*x_2$"),
           answer("$\\hat{y} = b_1*x_1 + b_2*x_2 + b_3*x_1*x_2$"),
           answer("$\\hat{y} = b_0 + b_1*x_1 + b_2*x_2 + b_3*x_1*x_2$"),
           answer("$\\hat{y} = b_0 + b_1*x_1 + b_2*x_2$", correct = TRUE),
           allow_retry = TRUE),
   # Question 17
   question("Q8) Match the model with the appropriate mathematical representation:\n
          lm(score ~ age + gender + age*gender)",
           answer("$\\hat{y} = b_1*x_1 + b_2*x_2$"),
           answer("$\\hat{y} = b_1*x_1 + b_2*x_2 + b_3*x_1*x_2$"),
           answer("$\\hat{y} = b_0 + b_1*x_1 + b_2*x_2 + b_3*x_1*x_2$", correct = TRUE),
           answer("$\\hat{y} = b_0 + b_1*x_1 + b_2*x_2$"),
           allow_retry = TRUE),
  # Q9
  question_numeric("Q9) After fitting score_model_interaction to the evals_ch6 dataset, what is the value of  $y - \\hat{y}$ for the 4th instructor? Round to 3 decimal places.", 
           answer(0.548, correct = TRUE),
           step = 0.001,
           allow_retry = TRUE),
  # Q10
  question_numeric("Q10) Suppose you ran the following lines of code:\n

    credit_ch6 <- credit_ch6 %>%
      mutate(income_5 = income * 5)

What would the correlation between debt and income_5 in credit_ch6 be? Round to 3 decimal places.", 
           answer(0.464, correct = TRUE),
           step = 0.001,
           allow_retry = TRUE)

)

Submit

Once you are finished:

grade_print_ui("grade")


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