Problem 1

theta_vals =  c(0, 0.2, 0.4, 0.6, 0.8, 1)
theta_prior = c(0.02, 0.02, 0.02, 0.7, 0.2, 0.04)
n_trials = 10000
sigma = 2
n_data = 256 
confidence = 0.95

Problem 1a

studio9_problem_1a(theta_vals, theta_prior, sigma, n_data, confidence, n_trials) 
## 
## ----------------------------------
## Problem 1a: Simulated type 1 CI error rate for z-confidence intervals 
## Last confidence interval: [ 0.4718141 , 0.9618051 ]
## Type 1 CI-error rate: 0.0494

Problem 1b

studio9_problem_1b(theta_vals, theta_prior, sigma, n_data, confidence, n_trials)
## 
## ----------------------------------
## Problem 1b: Simulated type 1 CI-error rate for t-confidence intervals 
## Last confidence interval: [ 0.8469393 , 1.314208 ]
## Type 1 CI-error rate: 0.0473

Problem 1c

xbar = 0.2
studio9_problem_1c(theta_vals, theta_prior, sigma, n_data, confidence, xbar)
## 
## ----------------------------------
## Problem 1c: Bayesian updating and probability of hypotheses
## 1c(i) theta_prior 0.02 0.02 0.02 0.7 0.2 0.04 
## 1c(i) theta_posterior 0.1574983 0.5664648 0.1574983 0.1184822 5.624715e-05 1.444947e-09 
## 1c(ii) 0.95 z confidence interval: [ -0.0449955 , 0.4449955 ] 
## 1c(iii) prior prob. theta is in the CI: 0.06 
## 1c(iii) posterior prob. theta is in the CI: 0.8814615

Problem 2 (OPTIONAL)

studio9_problem_2(0.55, 400)
## 
## ----------------------------------
## Problem 2: Simulated polling confidence interval
## Confidence interval:  0.52 plus or minus 0.05

MIT OpenCourseWare

https://ocw.mit.edu

18.05 Introduction to Probability and Statistics

Spring 2022

Authors: Jeremy Orloff and Jennifer French

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms