# File:   mit18_05_s22_studio2-grader.r 
# Authors: Jeremy Orloff and Jennifer French
#
# MIT OpenCourseWare: https://ocw.mit.edu
# 18.05 Introduction to Probability and Statistics
# Spring 2022
# For information about citing these materials or our Terms of Use, visit:
# https://ocw.mit.edu/terms.
#
# Grade studio 2
# Expected output in studio2-grader.html
# If this file changes --need to rebuild studio*-grader.html

# Use 'File > Compile report...' to create an R Markdown report from this.
# Because this opens a new session, it doesn't see the environment.
# So we need the following line, which should be commented out when using the grading script for grading.

 source('mit18_05_s22_studio2-solutions.r')  ### COMMENT OUT FOR GRADING
 cat("WARNING: make sure source('mit18_05_s22_studio*-solutions.r') is commented out before grading\n")
## WARNING: make sure source('mit18_05_s22_studio*-solutions.r') is commented out before grading
# For grading, open this file and set working directory to source file location
studio2_problem_1a(12, 0.8, 6, 50000)
## 
## ----------------------------------
## 1a. Simulation.
## Function parameters: ntosses = 12 , phead = 0.8 , k = 6 , ntrials = 50000 
## Estimated probability: P(Y = 6 ) = 0.01622 
## Estimated probability: P(Y <= 6 ) = 0.02006
studio2_problem_1b(12, 0.8, 6)
## -----
## 1b. Exact binomial probabilities
## Function parameters: ntosses = 12 , phead = 0.8 , k = 6 
## Exact probability: P(Y = 6 ) = 0.01550215
studio2_problem_2a() 
## 
## ----------------------------------
## 2a. Plot payoff.
## Parameters: ntosses = 10 
## See plot for 2a

studio2_problem_2b()
## -----
## 2b. Exact computation.
## Parameters: ntosses = 10 , phead = 0.6 
## I used R to compute the expected value of the payoff function 
## The exact value is -3.6 
## This is not good bet
studio2_problem_2c(5000)
## -----
## 2c. Simulated expected payoff.
## Parameters: ntosses = 10 , phead = 0.6 , ntrials = 5000 
## The simulated average payoff is -3.6016
studio2_problem_3(8, 5000)
## 
## ----------------------------------
## (OPTIONAL) Problem 3: Derangement.
## Parameters: n = 8 
## The estimated probability of derangement = 0.3698 
## For n > 2 the answer should be close to 1/e =  0.3678794