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

gradethis_setup(pass = "Submitted",
                fail = "Submitted",
                error_checker.message = "Submitted",
                fail.hint = FALSE
                )

tutorialExtras_setup(is_exam = TRUE)

knitr::opts_chunk$set(echo = FALSE)

load("data/cdc.rda")
lock_server("lock", 
            ex = c("App1", "App2", "App3"), ex_pts = c(3, 3, 3),
            manual = c("App1-desc", "App3-desc"), manual_pts = c(1, 1))
# student name
question_text("Name:",
              answer_fn(function(value){
                              if(length(value) >= 1 ) {
                                return(mark_as(TRUE))
                                }
                              return(mark_as(FALSE) )
                              }),
              incorrect = "Submitted",
              allow_retry = FALSE )

Instructions

Note: this is a sample exam to provide examples of types and styles of questions that may be asked. It does not necessarily represent the exact length of the exam.

You have 50 minutes to complete this exam. The exam covers the material learned from Preface - Chapter 4. You are allowed one page of notes front and back.

Once you are finished:

Concept

#reading check 2
#exam(
#  shuffle = TRUE,
quiz(
  caption = NULL,
  #Q1
  question_dropdown(
  "The following code is in a code chunk: $\\quad 8/2 \\; = 4$
  <br/> What is the output?",
  answer("4"),
  answer("TRUE"),
  answer("FALSE"),
  answer("NA"),
  answer("Error", correct = TRUE),
  answer("0"),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"),
  question_dropdown(
    "In a typical dataframe, cells correspond to ___.",
    answer("columns"),
    answer("rows"),
    answer("values", correct = TRUE),
    answer("variables"),
    answer("observations"),
    allow_retry = TRUE,
    correct = "Submitted",
    incorrect = "Submitted"
  ),
  question_dropdown(
  "Which of the following shows the relationship between two categorical variables?",
    answer("linegraph"),
    answer("histogram"),
    answer("stacked barplot", correct = TRUE),
    answer("grouped boxplot"),
    answer("none of these"),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
  question_blank(
  "We use `geom_jitter()` and/or transparancy of points (alpha) to solve what specific issue when making scatterplots? ___",
  answer_fn(function(value){
            if(value %in% c("overplotting", "over plotting", "over-plotting",
                            "overploting", "over ploting", "over-ploting",
                            "overplot", "over plot", "over-plot") ) {
                                return(mark_as(TRUE))
                                }
                              return(mark_as(FALSE) )
                              }),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
 question_dropdown(
  paste("The table provides data for a single individual, John Statman, who received a health evaluation every five years from the age of 20-55. <br/>", htmltools::img(src="images/01_tableC.png", height = 300, width = 700), " <br/> <br/> Which type of graphic would be most useful for visualizing the relationship between `Age` and `Weight`?"),
    answer("histogram"),
    answer("scatterplot"),
    answer("linegraph", correct = TRUE),
    answer("boxplot"),
    answer("barplot"),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
 question_numeric(
 paste("The table provides data for a single individual, John Statman, who received a health evaluation every five years from the age of 20-55. <br/>", htmltools::img(src="images/01_tableC.png", height = 300, width = 700), " <br/> <br/> how many variables are categorical?"),
    answer(3, correct = TRUE),
    allow_retry = TRUE,
    correct = "Submitted",
    incorrect = "Submitted"
 ),
  question_dropdown(
  paste("Below is a boxplot of a unimodal distribution. Which of the following statements is TRUE concerning this distribution? <br/>", htmltools::img(src="images/02_boxplot.png", height = 350, width = 400) ),
  #box = 11,
  answer("The distribution is skewed left and the mean is less than the median."),
  answer("The distribution is skewed right and the mean is less than the median."),
  answer("The distribution is skewed left and the mean is greater than the median."),
  answer("The distribution is skewed right and the mean is greater than the median.", correct = TRUE),
  answer("The distribution is symmetric and the mean is equal to the median."),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
  question_wordbank(
  "Suppose we have a dataset of 500 student's exam scores for a lecture class. The professor decided to curve the exam such that 5 points were added to everyone's exam score.",
  box = 8,
  choices = c("How would the average exam score change?",
              "How would the median exam score change?",
              "How would the range of exam scores change?"),
  wordbank = c("Increase","Decrease", "Stay the same"),
  answer(c("Increase", "Increase", "Stay the same"), correct = TRUE),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
 question_text(
  "Name one statistic that is invariant to outliers.",
  answer(c("median"), correct = TRUE),
  answer(c("IQR"), correct = TRUE),
  answer(c("iqr"), correct = TRUE),
  answer(c("Interquartile Range"), correct = TRUE),
  answer(c("mode"), correct = TRUE),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
  question_wordbank(
  "Match each task with the appropriate function/verb that will accomplish it.",
  box = 4,
  arrange = "ordered",
  choices = c("initialize the plotting space", "keep only desired variables", "pipe operator for linking wrangling functions"),
  wordbank = c("%>%", "count()", "ggplot()", "filter()", "select()", "+", "geom_*()"),
  answer(c("ggplot()", "select()", "%>%"), correct = TRUE),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  ),
  question_dropdown(
  "Suppose we have a dataset (some data) and we want to calculate the mean of one of the numerical variables per level/category for a categorical variable and then order the results with the smallest mean at the top of the output. Which general sequence of functions/verbs would achieve this?",
  #box = 11,
  answer("some data %>% filter() %>% summarize() %>% arrange()"),
  answer("some data %>% filter() %>% summarize() %>% arrange(desc())"),
  answer("some data %>% arrange() %>% filter() %>% summarize()"),
  answer("some data %>% arrange() %>% count()"),
  answer("some data %>% group_by() %>% summarize() %>% arrange()", correct = TRUE),
  answer("some data %>% group_by() %>% summarize() %>% arrange(desc())"),
  allow_retry = TRUE,
  correct = "Submitted",
  incorrect = "Submitted"
  )

)

Application

The following applications use the cdc dataset which has been preloaded for you. See the CDC Dataset tab for more information about the dataset

Application 1

Construct a side-by-side boxplot of height by gender.


ggplot(cdc, aes(x = gender, y = height)) +
  geom_boxplot()
grade_this_code(
  correct = "Submitted",
  incorrect = "Submitted"
)

Describe and compare the distribution, including center, spread, skew, and outliers.

question_text("", incorrect = "Submitted",
              answer("ManuallyGradedEverythingWrong", 
                     correct = TRUE),
              allow_retry = TRUE,
              rows = 7)

Application 2

For male survey participants, compute the count of men in each genhlth category.

Then add a new variable called proportion which is equal to the count/sum(count). Where count should be whatever you called your variable.

Make sure you print/output your results.


cdc %>% 
  filter(gender == "m") %>% 
  count(genhlth) %>% 
  mutate(proportion = n/sum(n))
grade_this_code(
  correct = "Submitted",
  incorrect = "Submitted"
)

Application 3

Construct a barplot that shows the relationship of gender in each of the genhlth groups?


ggplot(cdc, aes(x = genhlth, fill = gender)) +
  geom_barplot()
grade_this_code(
  correct = "Submitted",
  incorrect = "Submitted"
)

Explain what the barplot tells us about the relationship between genhlth and gender for our respondents.

question_text("", incorrect = "Submitted",
              answer("ManuallyGradedEverythingWrong", 
                     correct = TRUE),
              allow_retry = TRUE,
              rows = 7)

CDC Data Codebook

Each variable corresponds to a question that was asked in the survey.

Glimpse the data

glimpse(cdc)

Skim the data

skim(cdc)

Submit

Once you are finished:

lock_check_ui(id = "lock")
lock_button_ui(id = "lock")


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