Data Science C8 | P Value | Null Hypothesis

Please download to get full document.

View again

of 25
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Documents

Published:

Views: 57 | Pages: 25

Extension: PDF | Download: 8

Share
Related documents
Description
Project
Transcript
  project2 November 9, 2016 1 Project 2: Inference and Capital Punishment Welcome to Project 2! You will investigate the relationship between murder and capital punish-ment (the death penalty) in the United States. By the end of the project, you should know howto:1. Test whether observed data appears to be a random sample from a distribution2. Analyze a natural experiment3. Implement and interpret a sign test4. Create a function to run a general hypothesis test5. Analyze visualizations and draw conclusions from them AdministriviaPiazza  While collaboration is encouraged on this and other assignments, sharing answersis never okay. In particular, posting code or other assignment answers publicly on Piazza (orelsewhere) is academic dishonesty. It will result in a reduced project grade at a minimum. If youwish to ask a question and include code, you  must  make it a private post. Partners  You may complete the project with up to one partner. Partnerships are an exceptionto the rule against sharing answers. If you have a partner, one person in the partnership shouldsubmit your project on Gradescope and include the other partner in the submission. (Gradescopewill prompt you to fill this in.)Your partner  must be in your lab section . You can ask your TA to pair you with someone fromyour lab if you’re unable to find a partner. (That will happen in lab the week the project comesout.) Due Date and Checkpoint  Part of the project will be due early. Parts 1 and 2 of the project(out of 5) are due  Tuesday, November 1st at 7PM . Unlike the final submission, this early check-point will be graded for completion. It will be worth approximately 10% of the total project grade.Simply submit your partially-completed notebook as a PDF, as you would submit any other note- book. (See the note above on submitting with a partner.)The entire project (parts 1, 2, 3, 4, and 5) will be due  Tuesday, November 9th at 7PM . (Again,see the note above on submitting with a partner.)1  On to the project! Run the cell below  to prepare the automatic tests. The automated tests forthis project  definitely don’t  catch all possible errors; they’re designed to help you avoid somecommon mistakes. Merely passing the tests does not guarantee full credit on any question. In [204]:  # Run this cell to set up the notebook, but please don't change it. import numpy as np from  datascience import  * # These lines do some fancy plotting magic. import matplotlib %  matplotlib  inline import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') import warnings warnings.simplefilter('ignore',  FutureWarning ) from  client.api.assignment import  load_assignmenttests = load_assignment('project2.ok') =====================================================================Assignment: Project 2: Inference and Capital PunishmentOK, version v1.6.4===================================================================== 1.1 1. Murder rates Punishment for crime has many philosophical justifications. An important one is that fear of punishment may  deter  people from committing crimes.In the United States, some jurisdictions execute some people who are convicted of particularlyserious crimes, like murder. This punishment is called the  death penalty  or  capital punishment . Thedeath penalty is controversial, and deterrence has been one focal point of the debate. There areother reasons to support or oppose the death penalty, but in this project we’ll focus on deterrence.The key question about deterrence is:Does instituting a death penalty for murder actually reduce the number of murders?Youmighthaveastrongintuitioninonedirection,buttheevidenceturnsouttobesurprisinglycomplex. Different sides have variously argued that the death penalty has no deterrent effect andthat each execution prevents 8 murders, all using statistical arguments! We’ll try to come to ourown conclusion.Here is a road map for this project:1. In the rest of this section, we’ll investigate the main dataset we’ll be using.2. In section 2, we’ll see how to test null hypotheses like this: “For this set of U.S. states, themurder rate was equally likely to go up or down each year.”3. In section 3, we’ll apply a similar test to see whether U.S. states that suddenly ended orreinstituted the death penalty were more likely to see murder rates increase than decrease.2  4. In section 4, we will run some more tests to further claims we had been developing in previ-ous sections.5. In section 5, we’ll try to answer our question about deterrence using a visualization ratherthan a formal hypothesis test. The data  The main data source for this project comes from a paper by three researchers, Dezh- bakhsh, Rubin, and Shepherd. The dataset contains rates of various violent crimes for every year1960-2003 (44 years) in every US state. The researchers compiled their data from the FBI’s UniformCrime Reports.Since crimes are committed by people, not states, we need to account for the number of peoplein each state when we’re looking at state-level data. Murder rates are calculated as follows:murder rate for state X in year Y  = number of murders in state X in year Ypopulation in state X in year Y  ∗  100000 (Murder is rare, so we multiply by 100,000 just to avoid dealing with tiny numbers.) In [205]: murder_rates = Table.read_table('crime_rates.csv').select('State', 'Year murder_rates.set_format( Population , NumberFormatter) Out[205]: State | Year | Population | Murder RateAlaska | 1960 | 226,167 | 10.2Alaska | 1961 | 234,000 | 11.5Alaska | 1962 | 246,000 | 4.5Alaska | 1963 | 248,000 | 6.5Alaska | 1964 | 250,000 | 10.4Alaska | 1965 | 253,000 | 6.3Alaska | 1966 | 272,000 | 12.9Alaska | 1967 | 272,000 | 9.6Alaska | 1968 | 277,000 | 10.5Alaska | 1969 | 282,000 | 10.6... (2190 rows omitted) So far, this looks like a dataset that lends itself to an observational study. In fact, these dataaren’t even enough to demonstrate an  association  between the existence of the death penalty in astate in a year and the murder rate in that state and year! Question 1.1.  What additional information will we need before we can check for that associa-tion? Answer:  We need to know whether or not the respective state implemented the death penaltyor not.Murder rates vary over time, and different states exhibit different trends. The rates in somestates change dramatically from year to year, while others are quite stable. Let’s plot a couple, justto see the variety. Question 1.2.  Draw a line plot with years on the horizontal axis and murder rates on thevertical axis. Include two lines: one for Alaska murder rates and one for Minnesota murder rates.Create this plot using a single call,  ak_mn.plot(’Year’) .  Hint : To create two lines, you will need create the table  ak_mn  with two columns of murderrates, in addition to a column of years. You can use  join  to create this table, which will have thefollowing structure:3  Year Murder rate in Alaska Murder rate in Minnesota1960 10.2 1.21961 11.5 11962 4.5 0.9 In [206]:  # The next lines are provided for you. They create a table# containing only the Alaska information and one containing # only the Minnesota information. ak = murder_rates.where('State', 'Alaska').drop('State', 'Population').r mn = murder_rates.where('State', 'Minnesota').drop('State', 'Population') # Fill in this line to make a table like the one pictured above. ak_mn = ak.join( Year , mn,  Year ) ak_mn.plot('Year') In [207]: _  = tests.grade('q1_1_2') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Running tests---------------------------------------------------------------------Test summaryPassed: 1Failed: 0[ooooooooook] 100.0% passed 4
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks