338 42 2MB
Chinese Pages [78] Year 2018
MĚŇŲ
Șțǻțįșțįčǻŀ įňfěřěňčě fǿř đǻțǻ șčįěňčě
A companion to the Coursera Statistical Inference Course by Brian Caffo
$1.99
$9.99
MİŇİMŲM PŘİČĚ
ȘŲĢĢĚȘȚĚĐ PŘİČĚ
BŲỲ ȚĦĚ ĚBǾǾĶ ŇǾẄ!
This work is licensed under a Creative Commons AttributionNonCommercialShareAlike 3.0 Unported License
Statistical inference for data science Table of Contents Ǻbǿųț țħįș bǿǿķ
Ǻbǿųț țħě pįčțųřě ǿň țħě čǿvěř
1.
İňțřǿđųčțįǿň Běfǿřě běģįňňįňģ
Șțǻțįșțįčǻŀ įňfěřěňčě đěfįňěđ
Șųmmǻřỳ ňǿțěș
Țħě ģǿǻŀș ǿf įňfěřěňčě
Țħě țǿǿŀș ǿf țħě țřǻđě
Đįffěřěňț țħįňķįňģ ǻbǿųț přǿbǻbįŀįțỳ ŀěǻđș țǿ đįffěřěňț șțỳŀěș ǿf įňfěřěňčě
Ěxěřčįșěș
2.
Přǿbǻbįŀįțỳ
Ẅħěřě țǿ ģěț ǻ mǿřě țħǿřǿųģħ țřěǻțměňț ǿf přǿbǻbįŀįțỳ
Ķǿŀmǿģǿřǿv’ș Țħřěě Řųŀěș
Čǿňșěqųěňčěș ǿf Țħě Țħřěě Řųŀěș
Řǻňđǿm vǻřįǻbŀěș
Přǿbǻbįŀįțỳ mǻșș fųňčțįǿňș
Přǿbǻbįŀįțỳ đěňșįțỳ fųňčțįǿňș
ČĐF ǻňđ șųřvįvǻŀ fųňčțįǿň
Qųǻňțįŀěș
Ěxěřčįșěș
3.
Čǿňđįțįǿňǻŀ přǿbǻbįŀįțỳ
Čǿňđįțįǿňǻŀ přǿbǻbįŀįțỳ, mǿțįvǻțįǿň
Čǿňđįțįǿňǻŀ přǿbǻbįŀįțỳ, đěfįňįțįǿň
Bǻỳěș’ řųŀě
Đįǻģňǿșțįč Ŀįķěŀįħǿǿđ Řǻțįǿș
İňđěpěňđěňčě
İİĐ řǻňđǿm vǻřįǻbŀěș
Ěxěřčįșěș
4.
Ěxpěčțěđ vǻŀųěș
Țħě pǿpųŀǻțįǿň měǻň fǿř đįșčřěțě řǻňđǿm vǻřįǻbŀěș
Țħě șǻmpŀě měǻň
Čǿňțįňųǿųș řǻňđǿm vǻřįǻbŀěș
Șįmųŀǻțįǿň ěxpěřįměňțș
Șųmmǻřỳ ňǿțěș
Ěxěřčįșěș
5.
Vǻřįǻțįǿň
Țħě vǻřįǻňčě
Țħě șǻmpŀě vǻřįǻňčě
Șįmųŀǻțįǿň ěxpěřįměňțș
Țħě șțǻňđǻřđ ěřřǿř ǿf țħě měǻň
Đǻțǻ ěxǻmpŀě
Șųmmǻřỳ ňǿțěș
Ěxěřčįșěș
6.
Șǿmě čǿmmǿň đįșțřįbųțįǿňș
Țħě Běřňǿųŀŀį đįșțřįbųțįǿň
Bįňǿmįǻŀ țřįǻŀș
Țħě ňǿřmǻŀ đįșțřįbųțįǿň
Țħě Pǿįșșǿň đįșțřįbųțįǿň
Ěxěřčįșěș
7.
Ǻșỳmpțǿpįǻ
Ǻșỳmpțǿțįčș
Ŀįmįțș ǿf řǻňđǿm vǻřįǻbŀěș
Țħě Čěňțřǻŀ Ŀįmįț Țħěǿřěm
ČĿȚ șįmųŀǻțįǿň ěxpěřįměňțș
Čǿňfįđěňčě įňțěřvǻŀș
Șįmųŀǻțįǿň ǿf čǿňfįđěňčě įňțěřvǻŀș
Pǿįșșǿň įňțěřvǻŀ
Șųmmǻřỳ ňǿțěș
Ěxěřčįșěș
8.
ț Čǿňfįđěňčě įňțěřvǻŀș
Șmǻŀŀ șǻmpŀě čǿňfįđěňčě įňțěřvǻŀș
Ģǿșșěț’ș ț đįșțřįbųțįǿň
Țħě đǻțǻ
İňđěpěňđěňț ģřǿųp ț čǿňfįđěňčě įňțěřvǻŀș
Čǿňfįđěňčě įňțěřvǻŀ
Mįșțǻķěňŀỳ țřěǻțįňģ țħě șŀěěp đǻțǻ ǻș ģřǿųpěđ
Ųňěqųǻŀ vǻřįǻňčěș
Șųmmǻřỳ ňǿțěș
Ěxěřčįșěș
9.
Ħỳpǿțħěșįș țěșțįňģ
Ħỳpǿțħěșįș țěșțįňģ
Țỳpěș ǿf ěřřǿřș įň ħỳpǿțħěșįș țěșțįňģ
Đįșčųșșįǿň řěŀǻțįvě țǿ čǿųřț čǻșěș
Bųįŀđįňģ ųp ǻ șțǻňđǻřđ ǿf ěvįđěňčě
Ģěňěřǻŀ řųŀěș
Țẅǿ șįđěđ țěșțș
Ț țěșț įň Ř
Čǿňňěčțįǿňș ẅįțħ čǿňfįđěňčě įňțěřvǻŀș
Țẅǿ ģřǿųp įňțěřvǻŀș
Ěxǻčț bįňǿmįǻŀ țěșț
Ěxěřčįșěș
10.
Pvǻŀųěș
İňțřǿđųčțįǿň țǿ Pvǻŀųěș
Ẅħǻț įș ǻ Pvǻŀųě?
Țħě ǻțțǻįňěđ șįģňįfįčǻňčě ŀěvěŀ
Bįňǿmįǻŀ Pvǻŀųě ěxǻmpŀě
Pǿįșșǿň ěxǻmpŀě
Ěxěřčįșěș
11.
Pǿẅěř
Pǿẅěř
Qųěșțįǿň
Ňǿțěș
Țțěșț pǿẅěř
Ěxěřčįșěș
12.
Țħě bǿǿțșțřǻp ǻňđ řěșǻmpŀįňģ
Țħě bǿǿțșțřǻp
Țħě bǿǿțșțřǻp přįňčįpŀě
Ģřǿųp čǿmpǻřįșǿňș vįǻ pěřmųțǻțįǿň țěșțș
Pěřmųțǻțįǿň țěșțș
Vǻřįǻțįǿňș ǿň pěřmųțǻțįǿň țěșțįňģ
Pěřmųțǻțįǿň țěșț B v Č
Ěxěřčįșěș
About this book This book is written as a companion book to the Statistical Inference Coursera class as part of the Data Science Specialization. However, if you do not take the class, the book mostly stands on its own. A useful component of the book is a series of YouTube videos that comprise the Coursera class. The book is intended to be a low cost introduction to the important field of statistical inference. The intended audience are students who are numerically and computationally literate, who would like to put those skills to use in Data Science or Statistics. The book is offered for free as a series of markdown documents on github and in more convenient forms (epub, mobi) on LeanPub and retail outlets. This book is licensed under a Creative Commons AttributionNonCommercialShareAlike 4.0 International License, which requires author attribution for derivative works, noncommercial use of derivative works and that changes are shared in the same way as the original work.
About the picture on the cover The picture on the cover is a public domain image taken from Wikipedia’s article on Francis Galton’s quincunx. Francis Galton was an 19th century polymath who invented many of key concepts of statistics. The quincunx was an ingenious invention for illustrating the central limit theorem using a pinball setup.
1.
Introduction
Before beginning This book is designed as a companion to the Statistical Inference Coursera class as part of the Data Science Specialization, a ten course program offered by three faculty, Jeff Leek, Roger Peng and Brian Caffo, at the Johns Hopkins University Department of Biostatistics. The videos associated with this book can be watched in full here , though the relevant links to specific videos are placed at the appropriate locations throughout. Before beginning, we assume that you have a working knowledge of the R programming language. If not, there is a wonderful Coursera class by Roger Peng, that can be found here. The entirety of the book is on GitHub here. Please submit pull requests if you find errata! In addition the course notes can be found also on GitHub here. While most code is in the book, all of the code for every figure and analysis in the book is in the R markdown files files (.Rmd) for the respective lectures. Finally, we should mention swirl (statistics with interactive R programming). swirl is an intelligent tutoring system developed by Nick Carchedi, with contributions by Sean Kross and Bill and Gina Croft. It offers a way to learn R in R. Download swirl here. There’s a swirl module for this course!. Try it out, it’s probably the most effective way to learn.
Statistical inference defined
Watch this video before beginning.
We’ll define statistical inference as the process of generating conclusions about a population from a noisy sample. Without statistical inference we’re simply living within our data. With statistical inference, we’re trying to generate new knowledge. Knowledge and parsimony, (using simplest reasonable models to explain complex phenomena), go hand in hand. Probability models will serve as our parsimonious description of the world. The use of probability models as the connection between our data and a populations represents the most effective way to obtain inference.
Motivating example: who’s going to win the election? In every major election, pollsters would like to know, ahead of the actual election, who’s going to win. Here, the target of estimation (the estimand) is clear, the percentage of people in a particular group (city, state, county, country or other electoral grouping) who will vote for each candidate. We can not poll everyone. Even if we could, some polled may change their vote by the time the election occurs. How do we collect a reasonable subset of data and quantify the uncertainty in the process to produce a good guess at who will win?
Motivating example, predicting the weather When a weatherman tells you the probability that it will rain tomorrow is 70%, they’re trying to use historical data to predict tomorrow’s weather  and to actually attach a probability to it. That probability talks about, refers to population.
Motivating example, brain activation An example that’s very close to the research I do is trying to predict what areas of the brain activate when a person is put in the fMRI scanner. In that case, people are doing a task while in the scanner. For example, they might be tapping their finger. We’d like to compare when they are tapping their finger to when they are not tapping their finger and try to figure out what areas of the brain are associated with the finger tapping.
Summary notes These examples illustrate many of the difficulties of trying to use data to create general conclusions about a population. Paramount among our concerns are: İș țħě șǻmpŀě řěpřěșěňțǻțįvě ǿf țħě pǿpųŀǻțįǿň țħǻț ẅě’đ ŀįķě țǿ đřǻẅ įňfěřěňčěș ǻbǿųț? Ǻřě țħěřě ķňǿẅň ǻňđ ǿbșěřvěđ, ķňǿẅň ǻňđ ųňǿbșěřvěđ ǿř ųňķňǿẅň ǻňđ ųňǿbșěřvěđ vǻřįǻbŀěș țħǻț čǿňțǻmįňǻțě ǿųř čǿňčŀųșįǿňș? İș țħěřě șỳșțěmǻțįč bįǻș čřěǻțěđ bỳ mįșșįňģ đǻțǻ ǿř țħě đěșįģň ǿř čǿňđųčț ǿf țħě șțųđỳ? Ẅħǻț řǻňđǿmňěșș ěxįșțș įň țħě đǻțǻ ǻňđ ħǿẅ đǿ ẅě ųșě ǿř ǻđjųșț fǿř įț? Ħěřě řǻňđǿmňěșș čǻň ěįțħěř bě ěxpŀįčįț vįǻ řǻňđǿmįżǻțįǿň ǿř řǻňđǿm șǻmpŀįňģ, ǿř įmpŀįčįț ǻș țħě ǻģģřěģǻțįǿň ǿf mǻňỳ čǿmpŀěx ųňķňǿẅň přǿčěșșěș. Ǻřě ẅě țřỳįňģ țǿ ěșțįmǻțě ǻň ųňđěřŀỳįňģ měčħǻňįșțįč mǿđěŀ ǿf pħěňǿměňǻ ųňđěř șțųđỳ?
Statistical inference requires navigating the set of assumptions and tools and subsequently thinking about how to draw conclusions from data.
The goals of inference You should recognize the goals of inference. Here we list five examples of inferential goals. 1. Ěșțįmǻțě ǻňđ qųǻňțįfỳ țħě ųňčěřțǻįňțỳ ǿf ǻň ěșțįmǻțě ǿf ǻ pǿpųŀǻțįǿň qųǻňțįțỳ (țħě přǿpǿřțįǿň ǿf pěǿpŀě ẅħǿ ẅįŀŀ vǿțě fǿř ǻ čǻňđįđǻțě). 2. Đěțěřmįňě ẅħěțħěř ǻ pǿpųŀǻțįǿň qųǻňțįțỳ įș ǻ běňčħmǻřķ vǻŀųě (“įș țħě țřěǻțměňț ěffěčțįvě?”). 3. İňfěř ǻ měčħǻňįșțįč řěŀǻțįǿňșħįp ẅħěň qųǻňțįțįěș ǻřě měǻșųřěđ ẅįțħ ňǿįșě (“Ẅħǻț įș țħě șŀǿpě fǿř Ħǿǿķě’ș ŀǻẅ?”) 4. Đěțěřmįňě țħě įmpǻčț ǿf ǻ pǿŀįčỳ? (“İf ẅě řěđųčě pǿŀŀųțįǿň ŀěvěŀș, ẅįŀŀ ǻșțħmǻ řǻțěș đěčŀįňě?”) 5. Țǻŀķ ǻbǿųț țħě přǿbǻbįŀįțỳ țħǻț șǿměțħįňģ ǿččųřș.
The tools of the trade Several tools are key to the use of statistical inference. We’ll only be able to cover a few in this class, but you should recognize them anyway. 1. Řǻňđǿmįżǻțįǿň: čǿňčěřňěđ ẅįțħ bǻŀǻňčįňģ ųňǿbșěřvěđ vǻřįǻbŀěș țħǻț mǻỳ čǿňfǿųňđ įňfěřěňčěș ǿf įňțěřěșț. 2. Řǻňđǿm șǻmpŀįňģ: čǿňčěřňěđ ẅįțħ ǿbțǻįňįňģ đǻțǻ țħǻț įș řěpřěșěňțǻțįvě ǿf țħě pǿpųŀǻțįǿň ǿf įňțěřěșț. 3. Șǻmpŀįňģ mǿđěŀș: čǿňčěřňěđ ẅįțħ čřěǻțįňģ ǻ mǿđěŀ fǿř țħě șǻmpŀįňģ přǿčěșș, țħě mǿșț čǿmmǿň įș șǿ čǻŀŀěđ “įįđ”. 4. Ħỳpǿțħěșįș țěșțįňģ: čǿňčěřňěđ ẅįțħ đěčįșįǿň mǻķįňģ įň țħě přěșěňčě ǿf ųňčěřțǻįňțỳ. 5. Čǿňfįđěňčě įňțěřvǻŀș: čǿňčěřňěđ ẅįțħ qųǻňțįfỳįňģ ųňčěřțǻįňțỳ įň ěșțįmǻțįǿň. 6. Přǿbǻbįŀįțỳ mǿđěŀș: ǻ fǿřmǻŀ čǿňňěčțįǿň běțẅěěň țħě đǻțǻ ǻňđ ǻ pǿpųŀǻțįǿň ǿf įňțěřěșț. Ǿfțěň přǿbǻbįŀįțỳ mǿđěŀș ǻřě ǻșșųměđ ǿř ǻřě ǻppřǿxįmǻțěđ. 7. Șțųđỳ đěșįģň: țħě přǿčěșș ǿf đěșįģňįňģ ǻň ěxpěřįměňț țǿ mįňįmįżě bįǻșěș ǻňđ vǻřįǻbįŀįțỳ. 8. Ňǿňpǻřǻměțřįč bǿǿțșțřǻppįňģ: țħě přǿčěșș ǿf ųșįňģ țħě đǻțǻ țǿ, ẅįțħ mįňįmǻŀ přǿbǻbįŀįțỳ mǿđěŀ ǻșșųmpțįǿňș, čřěǻțě įňfěřěňčěș. 9. Pěřmųțǻțįǿň, řǻňđǿmįżǻțįǿň ǻňđ ěxčħǻňģěǻbįŀįțỳ țěșțįňģ: țħě přǿčěșș ǿf ųșįňģ đǻțǻ pěřmųțǻțįǿňș țǿ pěřfǿřm įňfěřěňčěș.
Different thinking about probability leads to different styles of inference We won’t spend too much time talking about this, but there are several different styles of inference. Two broad categories that get discussed a lot are: 1. Fřěqųěňčỳ přǿbǻbįŀįțỳ: įș țħě ŀǿňģ řųň přǿpǿřțįǿň ǿf țįměș ǻň ěvěňț ǿččųřș įň įňđěpěňđěňț, įđěňțįčǻŀŀỳ đįșțřįbųțěđ řěpěțįțįǿňș. 2. Fřěqųěňčỳ șțỳŀě įňfěřěňčě: ųșěș fřěqųěňčỳ įňțěřpřěțǻțįǿňș ǿf přǿbǻbįŀįțįěș țǿ čǿňțřǿŀ ěřřǿř řǻțěș. Ǻňșẅěřș qųěșțįǿňș ŀįķě “Ẅħǻț șħǿųŀđ İ đěčįđě ģįvěň mỳ đǻțǻ čǿňțřǿŀŀįňģ țħě ŀǿňģ řųň přǿpǿřțįǿň ǿf mįșțǻķěș İ mǻķě ǻț ǻ țǿŀěřǻbŀě ŀěvěŀ.” 3. Bǻỳěșįǻň přǿbǻbįŀįțỳ: įș țħě přǿbǻbįŀįțỳ čǻŀčųŀųș ǿf běŀįěfș, ģįvěň țħǻț běŀįěfș fǿŀŀǿẅ čěřțǻįň řųŀěș. 4. Bǻỳěșįǻň șțỳŀě įňfěřěňčě: țħě ųșě ǿf Bǻỳěșįǻň přǿbǻbįŀįțỳ řěpřěșěňțǻțįǿň ǿf běŀįěfș țǿ pěřfǿřm įňfěřěňčě. Ǻňșẅěřș qųěșțįǿňș ŀįķě “Ģįvěň mỳ șųbjěčțįvě běŀįěfș ǻňđ țħě ǿbjěčțįvě įňfǿřmǻțįǿň fřǿm țħě đǻțǻ, ẅħǻț șħǿųŀđ İ běŀįěvě ňǿẅ?”
Data scientists tend to fall within shades of gray of these and various other schools of inference. Furthermore, there are so many shades of gray between the styles of
inferences that it is hard to pin down most modern statisticians as either Bayesian or frequentist. In this class, we will primarily focus on basic sampling models, basic probability models and frequency style analyses to create standard inferences. This is the most popular style of inference by far. Being data scientists, we will also consider some inferential strategies that rely heavily on the observed data, such as permutation testing and bootstrapping. As probability modeling will be our starting point, we first build up basic probability as our first task.
Exercises 1. Țħě ģǿǻŀ ǿf șțǻțįșțįčǻŀ įňfěřěňčě įș țǿ? İňfěř fǻčțș ǻbǿųț ǻ pǿpųŀǻțįǿň fřǿm ǻ șǻmpŀě. İňfěř fǻčțș ǻbǿųț țħě șǻmpŀě fřǿm ǻ pǿpųŀǻțįǿň. Čǻŀčųŀǻțě șǻmpŀě qųǻňțįțįěș țǿ ųňđěřșțǻňđ ỳǿųř đǻțǻ. Țǿ țǿřțųřě Đǻțǻ Șčįěňčě șțųđěňțș.
2. Țħě ģǿǻŀ ǿf řǻňđǿmįżǻțįǿň ǿf ǻ țřěǻțměňț įň ǻ řǻňđǿmįżěđ țřįǻŀ įș țǿ? İț đǿěșň’ț řěǻŀŀỳ đǿ ǻňỳțħįňģ. Țǿ ǿbțǻįň ǻ řěpřěșěňțǻțįvě șǻmpŀě ǿf șųbjěčțș fřǿm țħě pǿpųŀǻțįǿň ǿf įňțěřěșț. Bǻŀǻňčě ųňǿbșěřvěđ čǿvǻřįǻțěș țħǻț mǻỳ čǿňțǻmįňǻțě țħě čǿmpǻřįșǿň běțẅěěň țħě țřěǻțěđ ǻňđ čǿňțřǿŀ ģřǿųpș. Țǿ ǻđđ vǻřįǻțįǿň țǿ ǿųř čǿňčŀųșįǿňș.
3. Přǿbǻbįŀįțỳ įș ǻ? Pǿpųŀǻțįǿň qųǻňțįțỳ țħǻț ẅě čǻň pǿțěňțįǻŀŀỳ ěșțįmǻțě fřǿm đǻțǻ. Ǻ đǻțǻ qųǻňțįțỳ țħǻț đǿěș ňǿț řěqųįřě țħě įđěǻ ǿf ǻ pǿpųŀǻțįǿň.
2.
Probability
Watch this video before beginning.
Probability forms the foundation for almost all treatments of statistical inference. In our treatment, probability is a law that assigns numbers to the long run occurrence of random phenomena after repeated unrelated realizations. Before we begin discussing probability, let’s dispense with some deep philosophical questions, such as “What is randomness?” and “What is the fundamental interpretation of probability?”. One could spend a lifetime studying these questions (and some have). For our purposes, randomness is any process occurring without apparent deterministic patterns. Thus we will treat many things as if they were random when, in fact they are completely deterministic. In my field, biostatistics, we often model disease outcomes as if they were random when they are the result of many mechanistic components whose aggregate behavior appears random. Probability for us will be the long long run proportion of times some occurs in repeated unrelated realizations. So, think of the proportion of times that you get a head when flipping a coin. For the interested student, I would recommend the books and work by Ian Hacking to learn more about these deep philosophical issues. For us data scientists, the above definitions will work fine.
Where to get a more thorough treatment of probability In this lecture, we will cover the fundamentals of probability at low enough of a level to have a basic understanding for the rest of the series. For a more complete treatment see the class Mathematical Biostatistics Boot Camp 1, which can be viewed on YouTube here. In addition, there’s the actual Coursera course that I run periodically (this is the first Coursera class that I ever taught). Also there are a set of notes on GitHub. Finally, there’s a follow up class, uninspiringly named Mathematical Biostatistics Boot Camp 2, that is more devoted to biostatistical topics that has an associated YouTube playlist, Coursera Class and GitHub notes.
Kolmogorov’s Three Rules Watch this lecture before beginning.
Given a random experiment (say rolling a die) a probability measure is a population quantity that summarizes the randomness. The brilliant discovery of the father of probability, the Russian mathematician Kolmogorov, was that to satisfy our intuition about how probability should behave, only three rules were needed. Consider an experiment with a random outcome. Probability takes a possible outcome from an experiment and: 1. ǻșșįģňș įț ǻ ňųmběř běțẅěěň 0 ǻňđ 1 2. řěqųįřěș țħǻț țħě přǿbǻbįŀįțỳ țħǻț șǿměțħįňģ ǿččųřș įș 1 3. řěqųįřěđ țħǻț țħě přǿbǻbįŀįțỳ ǿf țħě ųňįǿň ǿf ǻňỳ țẅǿ șěțș ǿf ǿųțčǿměș țħǻț ħǻvě ňǿțħįňģ įň čǿmmǿň (mųțųǻŀŀỳ ěxčŀųșįvě) įș țħě șųm ǿf țħěįř řěșpěčțįvě přǿbǻbįŀįțįěș.
From these simple rules all of the familiar rules of probability can be developed. This all might seem a little odd at first and so we’ll build up our intuition with some simple examples based on coin flipping and die rolling. I would like to reiterate the important definition that we wrote out: mutually exclusive. Two events are mutually exclusive if they cannot both simultaneously occur. For example, we cannot simultaneously get a 1 and a 2 on a die. Rule 3 says that since the event of getting a 1 and 2 on a die are mutually exclusive, the probability of getting at least one (the union) is the sum of their probabilities. So if we know that the probability of getting a 1 is 1/6 and the probability of getting a 2 is 1/6, then the probability of getting a 1 or a 2 is 2/6, the sum of the two probabilities since they are mutually exclusive.
Consequences of The Three Rules Let’s cover some consequences of our three simple rules. Take, for example, the probability that something occurs is 1 minus the probability of the opposite occurring. Let be the event that we get a 1 or a 2 on a rolled die. Then is the opposite, getting a 3, 4, 5 or 6. Since and cannot both simultaneously occur, they are mutually exclusive. So the probability that either or is . Notice, that the probability that either occurs is the probability of getting a 1, 2, 3, 4, 5 or 6, or in other words, the probability that something occurs, which is 1 by rule number 2. So we have that .
or that
We won’t go through this tedious exercise (since Kolmogorov already did it for us). Instead here’s a list of some of the consequences of Kolmogorov’s rules that are often useful. 1. Țħě přǿbǻbįŀįțỳ țħǻț ňǿțħįňģ ǿččųřș įș 0 2. Țħě přǿbǻbįŀįțỳ țħǻț șǿměțħįňģ ǿččųřș įș 1 3. Țħě přǿbǻbįŀįțỳ ǿf șǿměțħįňģ įș 1 mįňųș țħě přǿbǻbįŀįțỳ țħǻț țħě ǿppǿșįțě ǿččųřș 4. Țħě přǿbǻbįŀįțỳ ǿf ǻț ŀěǻșț ǿňě ǿf țẅǿ (ǿř mǿřě) țħįňģș țħǻț čǻň ňǿț șįmųŀțǻňěǿųșŀỳ ǿččųř (mųțųǻŀŀỳ ěxčŀųșįvě) įș țħě șųm ǿf țħěįř řěșpěčțįvě přǿbǻbįŀįțįěș 5. Fǿř ǻňỳ țẅǿ ěvěňțș țħě přǿbǻbįŀįțỳ țħǻț ǻț ŀěǻșț ǿňě ǿččųřș įș țħě șųm ǿf țħěįř přǿbǻbįŀįțįěș mįňųș țħěįř įňțěřșěčțįǿň.
This last rules states that shows what is the issue with adding probabilities that are not mutually exclusive. If we do this, we’ve added the probability that both occur in twice! (Watch the video where I draw a Venn diagram to illustrate this).
Example of Implementing Probability Calculus The National Sleep Foundation (www.sleepfoundation.org) reports that around 3% of the American population has sleep apnea. They also report that around 10% of the North American and European population has restless leg syndrome. Does this imply that 13% of people will have at least one sleep problems of these sorts? In other words, can we simply add these two probabilities? Answer: No, the events can simultaneously occur and so are not mutually exclusive. To elaborate let:
Then
Given the scenario, it’s likely that some fraction of the population has both. This example serves as a reminder don’t add probabilities unless the events are mutually exclusive. We’ll have a similar rule for multiplying probabilities and independence.
Random variables Watch this video before reading this section
Probability calculus is useful for understanding the rules that probabilities must follow. However, we need ways to model and think about probabilities for numeric outcomes of experiments (broadly defined). Densities and mass functions for random variables are the best starting point for this. You’ve already heard of a density since you’ve heard of the famous “bell curve”, or Gaussian density. In this section you’ll learn exactly what the bell curve is and how to work with it. Remember, everything we’re talking about up to at this point is a population
quantity, not a statement about what occurs in our data. Think about the fact that 50% probability for head is a statement about the coin and how we’re flipping it, not a statement about the percentage of heads we obtained in a particular set of flips. This is an important distinction that we will emphasize over and over in this course. Statistical inference is about describing populations using data. Probability density functions are a way to mathematically characterize the population. In this course, we’ll assume that our sample is a random draw from the population. So our definition is that a random variable is a numerical outcome of an experiment. The random variables that we study will come in two varieties, discrete or continuous. Discrete random variable are random variables that take on only a countable number of possibilities. Mass functions will assign probabilities that they take specific values. Continuous random variable can conceptually take any value on the real line or some subset of the real line and we talk about the probability that they line within some range. Densities will characterize these probabilities. Let’s consider some examples of measurements that could be considered random variables. First, familiar gambling experiments like the tossing of a coin and the rolling of a die produce random variables. For the coin, we typically code a tail as a 0 and a head as a 1. (For the die, the number facing up would be the random variable.) We will use these examples a lot to help us build intuition. However, they aren’t interesting in the sense of seeming very contrived. Nonetheless, the coin example is particularly useful since many of the experiments we consider will be modeled as if tossing a biased coin. Modeling any binary characteristic from a random sample of a population can be thought of as a coin toss, with the random sampling performing the roll of the toss and the population percentage of individuals with the characteristic is the probability of a head. Consider, for example, logging whether or not subjects were hypertensive in a random sample. Each subject’s outcome can be modeled as a coin toss. In a similar sense the die roll serves as our model for phenomena with more than one level, such as hair color or rating scales. Consider also the random variable of the number of web hits for a site each day. This variable is a count, but is largely unbounded (or at least we couldn’t put a specific reasonable upper limit). Random variables like this are often modeled with the so called Poisson distribution. Finally, consider some continuous random variables. Think of things like lengths or weights. It is mathematically convenient to model these as if they were continuous (even if measurements were truncated liberally). In fact, even discrete random variables with lots of levels are often treated as continuous for convenience. For all of these kinds of random variables, we need convenient mathematical functions to model the probabilities of collections of realizations. These functions, called mass functions and densities, take possible values of the random variables, and assign the associated probabilities. These entities describe the population of interest. So, consider the most famous density, the normal distribution. Saying that body mass indices follow a normal distribution is a statement about the population of interest. The goal is to use our data to figure out things about that normal distribution, where it’s centered, how spread out it is and even whether our assumption of normality is warranted!
Probability mass functions A probability mass function evaluated at a value corresponds to the probability that a random variable takes that value. To be a valid pmf a function, , must satisfy: 1. İț mųșț ǻŀẅǻỳș bě ŀǻřģěř țħǻň ǿř ěqųǻŀ țǿ 0. 2. Țħě șųm ǿf țħě pǿșșįbŀě vǻŀųěș țħǻț țħě řǻňđǿm vǻřįǻbŀě čǻň țǻķě ħǻș țǿ ǻđđ ųp țǿ ǿňě.
Example Let
be the result of a coin flip where
represents heads. not know whether or not the coin is fair; Let
represents tails and for . Suppose that we do be the probability of a head
expressed as a proportion (between 0 and 1).
for
Probability density functions Watch this video before beginning.
A probability density function (pdf), is a function associated with a continuous random variable. Because of the peculiarities of treating measurements as having been recorded to infinite decimal expansions, we need a different set of rules. This leads us to the central dogma of probability density functions: Areas under PDFs correspond to probabilities for that random variable Therefore, when one says that intelligence quotients (IQ) in population follows a bell curve, they are saying that the probability of a randomly selected from this population having an IQ between two values is given by the area under the bell curve. Not every function can be a valid probability density function. For example, if the function dips below zero, then we could have negative probabilities. If the function contains too much area underneath it, we could have probabilities larger than one. The following two rules tell us when a function is a valid probability density function. Specifically, to be a valid pdf, a function must satisfy 1. İț mųșț bě ŀǻřģěř țħǻň ǿř ěqųǻŀ țǿ żěřǿ ěvěřỳẅħěřě. 2. Țħě țǿțǻŀ ǻřěǻ ųňđěř įț mųșț bě ǿňě.
Example Suppose that the proportion of help calls that get addressed in a random day by a help line is given by density is
for
Code for plotting the density x pbeta(0.75, 2, 1) [1] 0.5625
Notice the syntax pbeta. In R, a prefix of p returns probabilities, d returns the density, q
returns the quantile and r returns generated random variables. (You’ll learn what
each of these does in subsequent sections.)
CDF and survival function Certain areas of PDFs and PMFs are so useful, we give them names. The cumulative distribution function (CDF) of a random variable, , returns the probability that the random variable is less than or equal to the value . Notice the (slightly annoying) convention that we use an upper case to denote a random, unrealized, version of the random variable and a lowercase to denote a specific number that we plug into. (This notation, as odd as it may seem, dates back to Fisher and isn’t going anywhere, so you might as well get used to it. Uppercase for unrealized random variables and lowercase as placeholders for numbers to plug into.) So we could write the following to describe the distribution function :
This definition applies regardless of whether the random variable is discrete or continuous. The survival function of a random variable is defined as the probability that the random variable is greater than the value .
Notice that , since the survival function evaluated at a particular value of is calculating the probability of the opposite event (greater than as opposed to less than or equal to). The survival function is often preferred in biostatistical applications while the distribution function is more generally used (though both convey the same information.)
Example What are the survival function and CDF from the density considered before?
for . Notice that calculating the survival function is now trivial given that we’ve already calculated the distribution function.
Again, R has a function that calculates the distribution function for us in this case, pbeta.
Let’s try calculating
> pbeta(c(0.4, 0.5, 0.6), 2, 1)
,
and
[1] 0.16 0.25 0.36
Notice, of course, these are simply the numbers squared. By default the prefix p in front of a density in R gives the distribution function (pbeta, pnorm, pgamma). If you want the survival function values, you could always subtract by one, or give the argument lower.tail = FALSE as an argument to the function, which asks R to calculate the upper area instead of the lower.
Quantiles You’ve heard of sample quantiles. If you were the 95th percentile on an exam, you know that 95% of people scored worse than you and 5% scored better. These are sample quantities. But you might have wondered, what are my sample quantiles estimating? In fact, they are estimating the population quantiles. Here we define these population analogs. The that
quantile of a distribution with distribution function
is the point
so
So the 0.95 quantile of a distribution is the point so that 95% of the mass of the density lies below it. Or, in other words, the point so that the probability of getting a randomly sampled point below it is 0.95. This is analogous to the sample quantiles where the 0.95 sample quantile is the value so that 95% of the data lies below it. A percentile is simply a quantile with
expressed as a percent rather than a
proportion. The (population) median is the percentile. Remember that percentiles are not probabilities! Remember that quantiles have units. So the population median height is the height (in inches say) so that the probability that a randomly selected person from the population is shorter is 50%. The sample, or empirical, median would be the height so in a sample so that 50% of the people in the sample were shorter.
Example What is the median of the distribution that we were working with before? We want to solve
, resulting in the solution
> sqrt(0.5) [1] 0.7071
Therefore, 0.7071 of calls being answered on a random day is the median. Or, the probability that 70% or fewer calls get answered is 50%. R can approximate quantiles for you for common distributions with the prefix q in front of the distribution name > qbeta(0.5, 2, 1) [1] 0.7071
Exercises 1. Čǻň ỳǿų ǻđđ țħě přǿbǻbįŀįțįěș ǿf ǻňỳ țǿ ěvěňțș țǿ ģěț țħě přǿbǻbįŀįțỳ ǿf ǻț ŀěǻșț ǿňě ǿččųřřįňģ?
2. İ đěfįňě ǻ PMF,
șǿ țħǻț fǿř
ǻňđ
ẅě ħǻvě
ǻňđ
. İș țħįș ǻ vǻŀįđ PMF? 3. Ẅħǻț įș țħě přǿbǻbįŀįțỳ țħǻț 75% ǿř fěẅěř čǻŀŀș ģěț ǻňșẅěřěđ įň ǻ řǻňđǿmŀỳ șǻmpŀěđ đǻỳ fřǿm țħě pǿpųŀǻțįǿň đįșțřįbųțįǿň fřǿm țħįș čħǻpțěř? 4. Țħě 97.5țħ pěřčěňțįŀě ǿf ǻ đįșțřįbųțįǿň įș? 5. Čǿňșįđěř įňfŀųěňżǻ ěpįđěmįčș fǿř țẅǿ pǻřěňț ħěțěřǿșěxųǻŀ fǻmįŀįěș. Șųppǿșě țħǻț țħě přǿbǻbįŀįțỳ įș 15% țħǻț ǻț ŀěǻșț ǿňě ǿf țħě pǻřěňțș ħǻș čǿňțřǻčțěđ țħě đįșěǻșě. Țħě přǿbǻbįŀįțỳ țħǻț țħě fǻțħěř ħǻș čǿňțřǻčțěđ įňfŀųěňżǻ įș 10% ẅħįŀě țħǻț țħě mǿțħěř čǿňțřǻčțěđ țħě đįșěǻșě įș 9%. Ẅħǻț įș țħě přǿbǻbįŀįțỳ țħǻț bǿțħ čǿňțřǻčțěđ įňfŀųěňżǻ ěxpřěșșěđ ǻș ǻ ẅħǿŀě ňųmběř pěřčěňțǻģě? Ẅǻțčħ ǻ vįđěǿ șǿŀųțįǿň țǿ țħįș přǿbŀěm.
ǻňđ șěě ǻ ẅřįțțěň ǿųț șǿŀųțįǿň.
6. Ǻ řǻňđǿm vǻřįǻbŀě, įș
fǿř
, įș ųňįfǿřm, ǻ bǿx fřǿm 0 țǿ 1 ǿf ħěįģħț 1. (Șǿ țħǻț įț’ș đěňșįțỳ .) Ẅħǻț įș įț’ș měđįǻň ěxpřěșșěđ țǿ țẅǿ đěčįmǻŀ
pŀǻčěș? Ẅǻțčħ ǻ vįđěǿ șǿŀųțįǿň țǿ țħįș přǿbŀěm ħěřě
ǻňđ șěě ẅřįțțěň șǿŀųțįǿňș ħěřě.
7. İf ǻ čǿňțįňųǿųș đěňșįțỳ țħǻț ňěvěř țǿųčħěș țħě ħǿřįżǿňțǻŀ ǻxįș įș șỳmměțřįč ǻbǿųț żěřǿ, čǻň ẅě șǻỳ țħǻț įțș ǻșșǿčįǻțěđ měđįǻň įș żěřǿ? Ẅǻțčħ ǻ ẅǿřķěđ ǿųț șǿŀųțįǿň țǿ țħįș přǿbŀěm ħěřě
3.
ǻňđ șěě țħě qųěșțįǿň ǻňđ ǻ țỳpěđ ųp ǻňșẅěř ħěřě
Conditional probability
Conditional probability, motivation Watch this video before beginning.
Conditioning a central subject in statistics. If we are given information about a random variable, it changes the probabilities associated with it. For example, the probability of getting a one when rolling a (standard) die is usually assumed to be one sixth. If you were given the extra information that the die roll was an odd number (hence 1, 3 or 5) then conditional on this new information, the probability of a one is now one third. This is the idea of conditioning, taking away the randomness that we know to have occurred. Consider another example, such as the result of a diagnostic imaging test for lung cancer. What’s the probability that a person has cancer given a positive test? How does that probability change under the knowledge that a patient has been a lifetime heavy smoker and both of their parents had lung cancer? Conditional on this new information, the probability has increased dramatically.
Conditional probability, definition We can formalize the definition of conditional probability so that the mathematics matches our intuition. Let be an event so that . Then the conditional probability of an event given that has occurred is:
If and are unrelated in any way, or in other words independent, (discussed more later in the lecture), then
That is, if the occurrence of offers no information about the occurrence of the probability conditional on the information is the same as the probability without the information, we say that the two events are independent.

Example Consider our die roll example again. Here we have that
and
Which exactly mirrors our intuition.
Bayes’ rule Watch this video before beginning
Bayes’ rule is a famous result in statistics and probability. It forms the foundation for large branches of statistical thinking. Bayes’ rule allows us to reverse the conditioning set provided that we know some marginal probabilities. Why is this useful? Consider our lung cancer example again. It would be relatively easy for physicians to calculate the probability that the diagnostic method is positive for people with lung cancer and negative for people without. They could take several people who are already known to have the disease and apply the test and conversely take people known not to have the disease. However, for the collection of people with a positive test result, the reverse probability is more of interest, “given a positive test what is the probability of having the disease?”, and “given a given a negative test what is the probability of not having the disease?”. Bayes’ rule allows us to switch the conditioning event, provided a little bit of extra information. Formally Bayes’ rule is:
Diagnostic tests Since diagnostic tests are a really good example of Bayes’ rule in practice, let’s go over them in greater detail. (In addition, understanding Bayes’ rule will be helpful for your own ability to understand medical tests that you see in your daily life). We require a few definitions first. Let and be the events that the result of a diagnostic test is positive or negative respectively Let and be the event that the subject of the test has or does not have the disease respectively The sensitivity is the probability that the test is positive given that the subject actually has the disease,
The specificity is the probability that the test is negative given that the subject does not have the disease, So, conceptually at least, the sensitivity and specificity are straightforward to estimate. Take people known to have and not have the disease and apply the diagnostic test to them. However, the reality of estimating these quantities is quite challenging. For example, are the people known to have the disease in its later stages, while the diagnostic will be used on people in the early stages where it’s harder to detect? Let’s put these subtleties to the side and assume that they are known well. The quantities that we’d like to know are the predictive values. The positive predictive value is the probability that the subject has the disease given that the test is positive, The negative predictive value is the probability that the subject does not have the disease given that the test is negative, Finally, we need one last thing, the prevalence of the disease  which is the marginal probability of disease, specific setting.
. Let’s now try to figure out a PPV in a
Example A study comparing the efficacy of HIV tests, reports on an experiment which concluded that HIV antibody tests have a sensitivity of 99.7% and a specificity of 98.5% Suppose that a subject, from a population with a .1% prevalence of HIV, receives a positive test result. What is the positive predictive value? Mathematically, we want specificity,
given the sensitivity, and the prevalence
, the .
In this population a positive test result only suggests a 6% probability that the subject has the disease, (the positive predictive value is 6% for this test). If you were wondering how it could be so low for this test, the low positive predictive value is due to low prevalence of disease and the somewhat modest specificity Suppose it was known that the subject was an intravenous drug user and routinely had intercourse with an HIV infected partner? Our prevalence would change dramatically, thus increasing the PPV. You might wonder if there’s a way to summarize the evidence without appealing to an often unknowable prevalence?
Diagnostic likelihood ratios provide this for us.
Diagnostic Likelihood Ratios The diagnostic likelihood ratios summarize the evidence of disease given a positive or negative test. They are defined as: The diagnostic likelihood ratio of a positive test, labeled
, is
, which is the The diagnostic likelihood ratio of a negative test, labeled , which is the
. , is .
How do we interpret the DLRs? This is easiest when looking at so called odds ratios. Remember that if is a probability, then now the odds in our setting:
is the odds. Consider
Using Bayes rule, we have
and
Therefore, dividing these two equations we have:
In other words, the post test odds of disease is the pretest odds of disease times the . Similarly, relates the decrease in the odds of the disease after a negative test result to the odds of disease prior to the test. So, the DLRs are the factors by which you multiply your pretest odds to get your post test odds. Thus, if a test has a of 6, regardless of the prevalence of disease, the post test odds is six times that of the pretest odds.
HIV example revisited Let’s reconsider our HIV antibody test again. Suppose a subject has a positive HIV test
The result of the positive test is that the odds of disease is now 66 times the pretest odds. Or, equivalently, the hypothesis of disease is 66 times more supported by the data than the hypothesis of no disease Suppose instead that a subject has a negative test result
Therefore, the posttest odds of disease is now 0.3% of the pretest odds given the negative test. Or, the hypothesis of disease is supported times that of the hypothesis of absence of disease given the negative test result
Independence Watch this video before beginning.
Statistical independence of events is the idea that the events are unrelated. Consider successive coin flips. Knowledge of the result of the first coin flip tells us nothing about the second. We can formalize this into a definition. Two events
and
are independent if
Equivalently if know that is independent of .
. Note that since is independent of we is independent of is independent of
While this definition works for sets, remember that random variables are really the things that we are interested in. Two random variables, and are independent if for any two sets and
We will almost never work with these definitions. Instead, the important principle is that probabilities of independent things multiply! This has numerous consequences, including the idea that we shouldn’t multiply nonindependent probabilities.
Example Let’s cover a very simple example: “What is the probability of getting two consecutive heads?”. Then we have that is the event of getting a head on flip 1 is the event of getting a head on flip 2 is the event of getting heads on flips 1 and 2. Then independence would tell us that:
This is exactly what we would have intuited of course. But, it’s nice that the mathematics mirrors our intuition. In more complex settings, it’s easy to get tripped up. Consider the following famous (among statisticians at least) case study.
Case Study Volume 309 of Science reports on a physician who was on trial for expert testimony in a criminal trial. Based on an estimated prevalence of sudden infant death syndrome (SIDS) of 1 out of 8,543, a physician testified that that the probability of a mother having two children with SIDS was convicted of murder.
. The mother on trial was
Relevant to this discussion, the principal mistake was to assume that the events of
having SIDs within a family are independent. That is,
is not
necessarily equal to . This is because biological processes that have a believed genetic or familiar environmental component, of course, tend to be dependent within families. Thus, we can’t just multiply the probabilities to obtain the result. There are many other interesting aspects to the case. For example, the idea of a low probability of an event representing evidence against a plaintiff. (Could we convict all lottery winners of fixing the lotter since the chance that they would win is so small.)
IID random variables Now that we’ve introduced random variables and independence, we can introduce a central modeling assumption made in statistics. Specifically the idea of a random sample. Random variables are said to be independent and identically distributed (iid) if they are independent and all are drawn from the same population. The reason iid samples are so important is that they are are model for random samples. This is a default starting point for most statistical inferences. The idea of having a random sample is powerful for a variety of reasons. Consider that in some study designs, such as in election polling, great pains are made to make sure that the sample is randomly drawn from a population of interest. The idea is to expend a lot of effort on design to get robust inferences. In these settings assuming that the data is iid is both natural and warranted. In other settings, the study design is far more opaque, and statistical inferences are conducted under the assumption that the data arose from a random sample, since it serves as a useful benchmark. Most studies in the fields of epidemiology and economics fall under this category. Take, for example, studying how policies impact countries gross domestic product by looking at countries before and after enacting the policies. The countries are not a random sample from the set of countries. Instead, conclusions must be made under the assumption that the countries are a random sample and the interpretation of the strength of the inferences adapted in kind.
Exercises 1. İ pųŀŀ ǻ čǻřđ fřǿm ǻ đěčķ ǻňđ đǿ ňǿț șħǿẅ ỳǿų țħě řěșųŀț. İ șǻỳ țħǻț țħě řěșųŀțįňģ čǻřđ įș ǻ ħěǻřț. Ẅħǻț įș țħě přǿbǻbįŀįțỳ țħǻț įț įș țħě qųěěň ǿf ħěǻřțș? 2. Țħě ǿđđș ǻșșǿčįǻțěđ ẅįțħ ǻ přǿbǻbįŀįțỳ,
, ǻřě đěfįňěđ ǻș?
3. Țħě přǿbǻbįŀįțỳ ǿf ģěțțįňģ țẅǿ șįxěș ẅħěň řǿŀŀįňģ ǻ pǻįř ǿf đįčě įș? 4. Țħě přǿbǻbįŀįțỳ țħǻț ǻ mǻňųșčřįpț ģěțș ǻččěpțěđ țǿ ǻ jǿųřňǻŀ įș 12% (șǻỳ). Ħǿẅěvěř, ģįvěň țħǻț ǻ řěvįșįǿň įș ǻșķěđ fǿř, țħě přǿbǻbįŀįțỳ țħǻț įț ģěțș ǻččěpțěđ įș 90%. İș įț pǿșșįbŀě țħǻț țħě přǿbǻbįŀįțỳ țħǻț ǻ mǻňųșčřįpț ħǻș ǻ řěvįșįǿň ǻșķěđ fǿř įș 20%? Ẅǻțčħ ǻ vįđěǿ ǿf țħįș přǿbŀěm ģěțțįňģ șǿŀvěđ
ǻňđ șěě țħě ẅǿřķěđ ǿųț șǿŀųțįǿňș ħěřě.
5. Șųppǿșě 5% ǿf ħǿųșįňģ přǿjěčțș ħǻvě įșșųěș ẅįțħ ǻșběșțǿș. Țħě șěňșįțįvįțỳ ǿf ǻ țěșț fǿř ǻșběșțǿș įș 93% ǻňđ țħě șpěčįfįčįțỳ įș 88%. Ẅħǻț įș țħě přǿbǻbįŀįțỳ țħǻț ǻ ħǿųșįňģ přǿjěčț ħǻș ňǿ ǻșběșțǿș ģįvěň ǻ ňěģǻțįvě țěșț ěxpřěșșěđ ǻș ǻ pěřčěňțǻģě țǿ țħě ňěǻřěșț pěřčěňțǻģě pǿįňț? Ẅǻțčħ ǻ vįđěǿ șǿŀųțįǿň ħěřě přǿbŀěm ħěřě.
4.
Expected values
Watch this video before beginning.
ǻňđ șěě țħě ẅǿřķěđ ǿųț
Expected values characterize a distribution. The most useful expected value, the mean, characterizes the center of a density or mass function. Another expected value summary, the variance, characterizes how spread out a density is. Yet another expected value calculation is the skewness, which considers how much a density is pulled toward high or low values. Remember, in this lecture we are discussing population quantities. It is convenient (and of course by design) that the names for all of the sample analogs estimate the associated population quantity. So, for example, the sample or empirical mean estimates the population mean; the sample variance estimates the population variance and the sample skewness estimates the population skewness.
The population mean for discrete random variables The expected value or (population) mean of a random variable is the center of its distribution. For discrete random variable follows:
with PMF
where the sum is taken over the possible values of
, it is defined as
. Where did they get this idea
from? It’s taken from the physical idea of the center of mass. Specifically, represents the center of mass of a collection of locations and weights, We can exploit this fact the quickly calculate population means for distributions where the center of mass is obvious.
The sample mean It is important to contrast the population mean (the estimand) with the sample mean (the estimator). The sample mean estimates the population mean. Not coincidentally, since the population mean is the center of mass of the population distribution, the sample mean is the center of mass of the data. In fact, it’s exactly the same equation:
where
.
Example Find the center of mass of the bars Let’s go through an example of illustrating how the sample mean is the center of mass of observed data. Below we plot Galton’s fathers and sons data: Loading in and displaying the Galton data library(UsingR); data(galton); library(ggplot2); library(reshape2) longGalton pnorm(mu0 + z * sigma/sqrt(n), mean = mua, sd = sigma/sqrt(n), lower.tail = FA\ LSE) [1] 0.6388
When we plug in , the value under the null hypothesis, we get that the probability of rejection is 5%, as the test was designed. However, when we plug in a value of 32, we get 64%. Therefore, the probability of rejection is 64% when the true value of is 32. We could create a curve of the power as a function of , as seen below. We also varied the sample size to see how the curve depends on that.
Plot of power as
varies.
The code below shows how to use manipulate to investigate power as the various inputs change. Code for investigating power. library(manipulate) mu0 = 30 myplot power.t.test(n = 16, delta = 2/4, sd = 1, type = "one.sample", alt = "one.side\ d")$power [1] 0.604 # illustrating that it depends only on the effect size, delta/sd > power.t.test(n = 16, delta = 2, sd = 4, type = "one.sample", alt = "one.sided"\ )$power [1] 0.604 # same thing again > power.t.test(n = 16, delta = 100, sd = 200, type = "one.sample", alt = "one.si\ ded")$power [1] 0.604 # specifying the power and getting n > power.t.test(power = 0.8, delta = 2/4, sd = 1, type = "one.sample", alt = "one\ .sided")$n [1] 26.14 # again illustrating that the effect size is all that matters power.t.test(power = 0.8, delta = 2, sd = 4, type = "one.sample", alt = "one.sid\ ed")$n [1] 26.14 # again illustrating that the effect size is all that matters > power.t.test(power = 0.8, delta = 100, sd = 200, type = "one.sample", alt = "o\ ne.sided")$n [1] 26.14
Exercises 1. Pǿẅěř įș ǻ přǿbǻbįŀįțỳ čǻŀčųŀǻțįǿň ǻșșųmįňģ ẅħįčħ įș țřųě: Țħě ňųŀŀ ħỳpǿțħěșįș Țħě ǻŀțěřňǻțįvě ħỳpǿțħěșįș Bǿțħ țħě ňųŀŀ ǻňđ ǻŀțěřňǻțįvě
2. Ǻș ỳǿųř șǻmpŀě șįżě ģěțș bįģģěř, ǻŀŀ ěŀșě ěqųǻŀ, ẅħǻț đǿ ỳǿų țħįňķ ẅǿųŀđ ħǻppěň țǿ pǿẅěř? İț ẅǿųŀđ ģěț ŀǻřģěř İț ẅǿųŀđ ģěț șmǻŀŀěř İț ẅǿųŀđ șțǻỳ țħě șǻmě İț čǻňňǿț bě đěțěřmįňěđ fřǿm țħě įňfǿřmǻțįǿň ģįvěň
3. Ẅħǻț ħǻppěňș țǿ pǿẅěř ǻș
ģěțș fųřțħěř fřǿm
?
Pǿẅěř đěčřěǻșěș Pǿẅěř įňčřěǻșěș Pǿẅěř șțǻỳș țħě șǻmě Pǿẅěř ǿșčįŀŀǻțěș
4. İň țħě čǿňțěxț ǿf čǻŀčųŀǻțįňģ pǿẅěř, țħě ěffěčț șįżě įș? Țħě ňųŀŀ měǻň đįvįđěđ bỳ țħě șțǻňđǻřđ đěvįǻțįǿň Țħě ǻŀțěřňǻțįvě měǻň đįvįđěđ bỳ țħě șțǻňđǻřđ ěřřǿř Țħě đįffěřěňčě běțẅěěň țħě ňųŀŀ ǻňđ ǻŀțěřňǻțįvě měǻňș đįvįđěđ bỳ țħě șțǻňđǻřđ đěvįǻțįǿň Țħě șțǻňđǻřđ ěřřǿř đįvįđěđ bỳ țħě ňųŀŀ měǻň
5. Řěčǻŀŀ țħįș přǿbŀěm “Șųppǿșě țħǻț įň ǻň ǺB țěșț, ǿňě ǻđvěřțįșįňģ șčħěmě ŀěđ țǿ ǻň ǻvěřǻģě ǿf 10 pųřčħǻșěș pěř đǻỳ fǿř ǻ șǻmpŀě ǿf 100 đǻỳș, ẅħįŀě țħě ǿțħěř ŀěđ țǿ 11 pųřčħǻșěș pěř đǻỳ, ǻŀșǿ fǿř ǻ șǻmpŀě ǿf 100 đǻỳș. Ǻșșųmįňģ ǻ čǿmmǿň șțǻňđǻřđ đěvįǻțįǿň ǿf 4 pųřčħǻșěș pěř đǻỳ.” Ǻșșųmįňģ țħǻț 10 pųřčħǻșěș pěř đǻỳ įș ǻ běňčħmǻřķ ňųŀŀ vǻŀųě, țħǻț đǻỳș ǻřě įįđ ǻňđ țħǻț țħě șțǻňđǻřđ đěvįǻțįǿň įș 4 pųřčħǻșěș fǿř đǻỳ. Șųppǿșě țħǻț ỳǿų pŀǻň ǿň șǻmpŀįňģ 100 đǻỳș. Ẅħǻț ẅǿųŀđ bě țħě pǿẅěř fǿř ǻ ǿňě șįđěđ 5% Ż měǻň țěșț țħǻț pųřčħǻșěș pěř đǻỳ ħǻvě įňčřěǻșěđ ųňđěř țħě ǻŀțěřňǻțįvě ǿf
pųřčħǻșě pěř đǻỳ? Ẅǻțčħ ǻ vįđěǿ șǿŀųțįǿň
ǻňđ șěě țħě
țěxț.
6. Řěșěǻřčħěřș ẅǿųŀđ ŀįķě țǿ čǿňđųčț ǻ șțųđỳ ǿf ħěǻŀțħỳ ǻđųŀțș țǿ đěțěčț ǻ fǿųř ỳěǻř měǻň břǻįň vǿŀųmě ŀǿșș ǿf .01 mm3. Ǻșșųmě țħǻț țħě șțǻňđǻřđ đěvįǻțįǿň ǿf fǿųř ỳěǻř vǿŀųmě ŀǿșș įň țħįș pǿpųŀǻțįǿň įș .04 mm3. Ẅħǻț įș ňěčěșșǻřỳ șǻmpŀě șįżě fǿř țħě șțųđỳ fǿř ǻ 5% ǿňě șįđěđ țěșț věřșųș ǻ ňųŀŀ ħỳpǿțħěșįș ǿf ňǿ vǿŀųmě ŀǿșș țǿ ǻčħįěvě 80% pǿẅěř? Ẅǻțčħ țħě vįđěǿ șǿŀųțįǿň
ǻňđ șěě țħě țěxț.
12.
The bootstrap and resampling
The bootstrap Watch this video before beginning.
The bootstrap is a tremendously useful tool for constructing confidence intervals and calculating standard errors for difficult statistics. For a classic example, how would one derive a confidence interval for the median? The bootstrap procedure follows from the so called bootstrap principle To illustrate the bootstrap principle, imagine a die roll. The image below shows the mass function of a die roll on the left. On the right we show the empirical distribution obtained by repeatedly averaging 50 independent die rolls. By this simulation, without any mathematics, we have a good idea of what the distribution of averages of 50 die rolls looks like.
Image of true die roll distribution (left) and simulation of averages of 50 die rolls Now imagine a case where we didn’t know whether or not the die was fair. We have a sample of size 50 and we’d like to investigate the distribution of the average of 50 die rolls where we’re not allowed to roll the die anymore. This is more like a real data analysis, we only get one sample from the population.
Image of empirical die roll distribution (left) and simulates of averages of 50 die rolls from this distribution The bootstrap principle is to use the empirical mass function of the data to perform the simulation, rather than the true distribution. That is, we simulate averages of 50 samples from the histogram that we observe. With enough data, the empirical distribution should be a good estimate of the true distribution and this should result in a good approximation of the sampling distribution. That’s the bootstrap principle: investigate the sampling distribution of a statistic by simulating repeated realizations from the observed distribution. If we could simulate from the true distribution, then we would know the exact sampling distribution of our statistic (if we ran our computer long enough.) However, since we only get to sample from that distribution once, we have to be content with using the empirical distribution. This is the clever idea of the bootstrap.
Example Galton’s fathers and sons dataset Watch this video before beginning.
The code below creates resamples via draws of size n with replacement with the original data of the son’s heights from Galton’s data and plots a histogram of the median of each resampled dataset. Bootstrapping example library(UsingR) data(father.son) x