Think Stats: Probability and Statistics for Programmers Allen B. Downey Version 1.0.0 Contributor ListIf you have a suggestion or correction, please send email to downey@allendowney.com. If I make a change based on your feedback, I will add you to the contributor list (unless you ask to be omitted). If you include at least part of the sentence the error appears in, that makes it easy for me to search. Page and section numbers are fine, too, but not quite as easy to work with. Thanks! Chapter 0 Statistical thinking for programmersThis book is about turning data into knowledge. Data is cheap (at least relatively); knowledge is harder to come by. I will present three related pieces:
The thesis of this book is that if you know how to program, you can use that skill to help you understand probability and statistics. These topics are often presented from a mathematical perspective, and that approach works well for some people. But some important ideas in this area are hard to work with mathematically and relatively easy to approach computationally. Both approaches have merits, and the ideal might combine both, but the goal of this book is to explore the computational path. The rest of this chapter presents a case study motivated by a question I heard when my wife and I were expecting our first child: do first babies tend to arrive late? 0.1 Do first babies arrive late?If you Google this question, you will find plenty of discussion. Some people claim it’s true, others say it’s a myth, and some people say it’s the other way around: first babies come early. In many of these discussions, people provide data to support their claims. I found many examples like these:
Reports like these are called anecdotal evidence because they are based on data that is unpublished and usually personal. In casual conversation, there is nothing wrong with anecdotes, so I don’t mean to pick on the people I quoted. But we might want evidence that is more persuasive and an answer that is more reliable. By those standards, anecdotal evidence usually fails, because:
So how can we do better? 0.2 A statistical approachTo address the limitations of anecdotes, we will use the tools of statistics, which include:
By performing these steps with care to avoid common pitfalls, we can reach conclusions that are more justifiable and more likely to be correct. 0.3 The National Survey of Family GrowthSince 1973 the U.S. Centers for Disease Control and Prevention (CDC) have conducted the National Survey of Family Growth (NSFG), which is intended to gather “information on family life, marriage and divorce, pregnancy, infertility, use of contraception, and men’s and women’s health. The survey results are used ... to plan health services and health education programs, and to do statistical studies of families, fertility, and health.”1 We will use data collected by this survey to investigate whether first babies tend to come late, and other questions. In order to use this data effectively, we have to understand the design of the study. The NSFG is a cross-sectional study, which means that it captures a snapshot of a group at a point in time. The most common alternative is a longitudinal study, which observes a group repeatedly over a period of time. The NSFG has been conducted seven times; each deployment is called a cycle. We will be using data from Cycle 6, which was conducted from January 2002 to March 2003. The goal of the survey is to draw conclusions about a population; the target population of the NSFG is people in the United States aged 15-44. The people who participate in a survey are called respondents. In general, cross-sectional studies are meant to be representative, which means that every member of the target population has an equal chance of participating. Of course that ideal is hard to achieve in practice, but people who conduct surveys come as close as they can. The NSFG not representative; instead it is deliberately oversampled. The designers of the study recruited three groups—Hispanics, African-Americans and teenagers—at rates higher than their representation in the U.S. population. The reason for oversampling is to make sure that the number of respondents in each of these groups is large enough to draw valid statistical inferences. Of course, the drawback of oversampling is that it is not as easy to draw conclusions about the general population based on statistics from the survey. We will come back to this point later. Exercise 1 Although the NSFG has been conducted seven times, it is not a longitudinal study. Read the Wikipedia pages wikipedia.org/wiki/Cross-sectional_study and wikipedia.org/wiki/Longitudinal_study to make sure you understand why not. Exercise 2 In this exercise, you will download data from the NSFG and do some exploratory data analysis.
Exercise 3
The best way to learn about statistics is to work on a project you are interested in. Is there a question like, “Do first babies arrive late,” that you would like to investigate? Think about questions you find personally interesting, or items of conventional wisdom, or controversial topics, or questions that have political consequences, and see if you can formulate a question that lends itself to statistical inquiry. Now start looking for datasets to help you address the question. Governments are good sources because data from public research is often freely available. Another way to find data is Wolfram Alpha, which is a curated collection of good-quality datasets at wolframalpha.com. But results generated by Wolfram Alpha are subject to copyright restrictions; you might want to check the terms before you commit yourself. Google and other search engines can also help you find data, but it can be harder to evaluate the quality of resources on the web. If it seems like someone has answered your question, you should look closely to see whether the answer is justified. You might find flaws in the data or the analysis that make the conclusion unreliable. In that case you might perform a different analysis of the same dataset, or look for a better source of data. If you find a published paper that addresses your question, you should be able to get the raw data. Many authors make their data available on the web, but for sensitive data you might have to write to the authors, provide information about how you plan to use the data, or agree to certain terms of use. Be persistent!
Index
|
Are you using one of our books in a class?We'd like to know about it. Please consider filling out this short survey.
|
This document was translated from LATEX by HEVEA.