library(gradethis)
library(learnr)
library(qsslearnr)
tutorial_options(exercise.checker = gradethis::grade_learnr)
knitr::opts_chunk$set(echo = FALSE)
tut_reptitle <- "QSS Tutorial 9: Output Report"

Estimation and Confidence Intervals

Randomization

question(
  paste0("Which statement best describes how complete randomization",
         " differs from simple randomization?"),
  answer("Only part of our sample is randomly chosen"),
  answer("We randomize part of the sample but do not randomize the treatment"),
  answer("We choose how much of the sample receives treatment a priori",
         correct = TRUE),
  answer("we randomize the sample, a priori")
)

Mean squared error

question(
  paste0("Let variance and bias be denoted by V(x) and B(x) respectively. ",
         "The the mean squared error (MSE) equals:"),
  answer("V(x^2 ) + B(x)"),
  answer("V(x) + B(x^2 )"),
  answer("V(x)^2 + B(x)"),
  answer("V(x) + B(x)^2", correct = TRUE)
)

Variance of the sample mean

The variance in a population is 5. For a sample of size 10 from that population, what is the variance in the sample mean (express your answer to the nearest 0.1)?

question_text(
  "Answer",
  answer("0.5", correct = TRUE),
  answer(".5", correct = TRUE),
  allow_retry = TRUE
)

Confidence intervals

question(
  "In the context of confidence intervals, what is alpha?",
  answer("The probability that, over repeated sampling, the confidence interval does not contain the true value of a parameter.", correct = TRUE),
  answer("The probability that the confidence interval contains the true value of a parameter, base on the sample size."),
  answer("The probability that the confidence interval contains the true value of a parameter, regardless of the sample size."),
  answer("The bias in the probability that the confidence interval contains the true value of a parameter")
)

Margin of error

In our sample of voters we find that 40% of the participants support Trump. If we want our 95% confidence interval for the true population proportion to be within +/- 1% of the true value, what is the minimum number of participants we must ask?


## Use these two values and check the defintion of the MOE
sd_est <- sqrt(0.4 * (1 - 0.4))
z_val <- 1.96
## Use these two values and check the defintion of the MOE
sd_est <- sqrt(0.4 * (1 - 0.4))
z_val <- 1.96

(z_val * sd_est / 0.01) ^ 2
grade_result(
  fail_if(~ identical(round(.result), 9600), "Did you use 2 instead of 1.96 for the critical value?"),
  pass_if(~ identical(round(.result), 9220))
)

Variance of a sample proportion

I flip a fair coin 27 times. What is the variance of the sample proportion of heads (express to the nearest 0.001)? Hint: what does the central limit theorem say?

question_text(
  "Answer (to the nearest 0.001)",
  answer("0.009", correct = TRUE),
  answer(".009", correct = TRUE),
  allow_retry = TRUE
)

Margin of error for sample proportions {data-allow-skip=TRUE}

Now, I flip a coin of unknown bias 10 times. It comes up heads 8 times. What is the (non-negative) margin of error, calculated from a 95% confidence interval for the true probability the coin comes up heads? Use the console below for calculations and then enter the probability below (to the nearest 0.01).


## 1.96 * sqrt(__var__ / __n__)
1.96 * sqrt(0.8 * (1 - 0.8) / 10)
question_text(
  "Answer (to the nearest 0.01)",
  answer("0.25", correct = TRUE),
  answer(".25", correct = TRUE),
  allow_retry = TRUE
)

Confidence intervals for sample proportions

question(
  paste0("In a sample 50% of the times a coin has landed tails. ",
         "For 95% confidence and a margin of error of 0.001, roughly how many flips should you we need to check if the coin is actually fair?"),
  answer("100,000"),
  answer("500,000"),
  answer("1,000,000", correct = TRUE),
  answer("5,000,000")
)

Submit

submission_ui
submission_server()


mattblackwell/qsslearnr documentation built on Sept. 17, 2022, 6:25 p.m.