Lab 6Welcome to Lab 6! In this lab, we will learn about sampling strategies. More information about sampling in the textbook can be found here!(https://www.inferentialthinking.com/chapters/08/5/sampling.html)The data used in this lab will contain salary data and statistics for basketball players from the 2014-2015 NBA season. This data was collected from basketball-reference(http://www.basketball-
...[Show More]
Lab 6
Welcome to Lab 6! In this lab, we will learn about sampling strategies. More information about sampling in the textbook can be found here!
(https://www.inferentialthinking.com/chapters/08/5/sampling.html)
The data used in this lab will contain salary data and statistics for basketball players from the 2014-2015 NBA season. This data was collected from basketball-reference
(http://www.basketball-reference.com) and spotrac (http://www.spotrac.com).
In [2]: # Run this cell, but please don't change it.
# These lines import the Numpy and Datascience modules.
import numpy as np
from datascience import *
# These lines do some fancy plotting magic
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
# Don't change this cell; just run it.
from client.api.notebook import Notebook
ok = Notebook('lab06.ok')
_ = ok.auth(inline=True)
1. Dungeons and Dragons and Sampling
In the game Dungeons & Dragons, each player plays the role of a fantasy character.
A player performs actions by rolling a 20-sided die, adding a "modifier" number to the roll, and comparing the total to a threshold for success. The modifier depends on her
character's competence in performing the action.
For example, suppose Alice's character, a barbarian warrior named Roga, is trying to knock down a heavy door. She rolls a 20-sided die, adds a modifier of 11 to the result
(because her character is good at knocking down doors), and succeeds if the total is greater than 15.
Question 1.1 Write code that simulates that procedure. Compute three values: the result of Alice's roll (roll_result), the result of her roll plus Roga's modifier
(modified_result), and a boolean value indicating whether the action succeeded (action_succeeded). Do not fill in any of the results manually; the entire
simulation should happen in code.
Hint: A roll of a 20-sided die is a number chosen uniformly from the array make_array(1, 2, 3, 4, ..., 20). So a roll of a 20-sided die plus 11 is a number chosen
uniformly from that array, plus 11.
In [5]: possible_rolls = np.arange(1, 20+1, 1) #SOLUTION
roll_result = np.random.choice(possible_rolls) #SOLUTION
modified_result = roll_result + 11 #SOLUTION
action_succeeded = modified_result > 15 #SOLUTION
# The next line just prints out your results in a nice way
# once you're done. You can delete it if you want.
print("On a modified roll of {:d}, Alice's action {}.".format(modified_result, "succeeded" if action_succeeded else
"failed"))
In [ ]: _ = ok.grade('q1_1')
Question 1.2 Run your cell 7 times to manually estimate the chance that Alice succeeds at this action. (Don't use math or an extended simulation.). Your answer should be
a fraction.
In [ ]: rough_success_chance = 1/7 #SOLUTION
In [ ]: _ = ok.grade('q1_2')
Suppose we don't know that Roga has a modifier of 11 for this action. Instead, we observe the modified roll (that is, the die roll plus the modifier of 11) from each of 7 of
her attempts to knock down doors. We would like to estimate her modifier from these 7 numbers.
Question 1.3 Write a Python function called simulate_observations. It should take no arguments, and it should return an array of 7 numbers. Each of the numbers
should be the modified roll from one simulation. Then, call your function once to compute an array of 7 simulated modified rolls. Name that array observations.
On a modified roll of 20, Alice's action succeeded.
This study source was downloaded by 100000824368823 from CourseHero.com on 05-01-2021 04:37:23 GMT -05:00
https://www.coursehero.com/file/24230859/lab06-sol/
This study resource was
shared vi
[Show Less]