Jekyll2023-03-23T14:33:36+00:00https://gabors-data-analysis.com/feed.xmlGabors Data AnalysisA comprehensive textbook on data analysis for business, applied economics and public policy students, that uses case studies with real-world data.Gábor Békés and Gábor KézdiData Chats Podcast2023-01-07T00:00:00+00:002023-01-07T00:00:00+00:00https://gabors-data-analysis.com/posts/2023/01/data-chats-podcast<p>I did a podcast with Chris Richardson of Pragmatic Institute, a California based data science education institute a while back, it is out now.
<a href="https://ds30.podbean.com/">Data Science in Action: Insights from a Leading Textbook Author</a>.</p>
<p>Also on <a href="https://podcasts.apple.com/us/podcast/data-science-in-action-insights-from-a-leading/id1507005455?i=1000592893701">Apple</a>, <a href="https://open.spotify.com/episode/0p8nrfxxhdKxp5Zm7tqcVx">Spotify</a></p>
<p>Pragmatic Institute‘s data podcast covers emerging and relevant topics in data science, data analytics, data engineering and pretty much all things data. They have some cool episodes with fellow book authors <a href="https://podcasts.apple.com/us/podcast/charles-wheelan-author-of-naked-statistics-why-data/id1507005455?i=1000571592075">Charles Wheelan</a> <a href="https://podcasts.apple.com/us/podcast/data-visualization-and-how-to-stop-your-charts-from-lying/id1507005455?i=1000576620853">Alberto Cairo</a> and <a href="https://podcasts.apple.com/us/podcast/strategies-to-tell-better-stories-with-data/id1507005455?i=1000579708479">Cole-Nussbaumer-Knaflic</a> as well as data scientits from <a href="https://podcasts.apple.com/us/podcast/godaddys-senior-data-scientist-on-evaluating-customer/id1507005455?i=1000585882813">GoDaddy</a> or <a href="https://podcasts.apple.com/us/podcast/beyond-recommendations-content-data-science-netflix/id1507005455?i=1000529859413">Netflix</a>.</p>
<h2 id="data-chats-summary">Data Chats summary</h2>
<p><em>“We also wanted to use the textbook to talk about important social issues, like, why do men make more than women? And so, one case study is about understanding the gender gap in the US and why is there a 15, 20% difference in earnings.” - Gábor Békés</em></p>
<p><strong>In this episode of Data Chats, Chris Richardson interviews Gábor Békés. They discuss:</strong></p>
<ul>
<li>Detailed process of data analysis</li>
<li>The most important methods, tools, and skills for future data analysts</li>
<li>Real life case-studies included in the book</li>
<li>Implications of data analysis on public policy</li>
<li>Humility required for the data interpretation process</li>
</ul>
<p><img src="/images/pragmatic.png" alt="Use to hold your laptop" height="80%" width="80%" /></p>
<h2 id="more-details">More details</h2>
<p>I talk about</p>
<ul>
<li>How we chose the topics to include.</li>
<li>Why he didn’t include code in the book.</li>
<li>
<p>Process of producing the code that is on the website.</p>
</li>
<li>Why we chose the case studies that he did.
<ul>
<li>One of the cases is around wage differences between men and women.</li>
<li>What happens when you fire your manager or coach mid-season? Do they improve in the short run?</li>
<li>Swimming pool tickets—prediction – how many people will come on a given day</li>
<li>Predict if a firm will default or not in the next two years based on data</li>
<li>Merger between two airlines in the US figure out the affect on consumers.</li>
<li>Football (soccer) case, English Premiere League, about changing coaches/managers mid-season.</li>
</ul>
</li>
</ul>
<p>Some other bits</p>
<ul>
<li>We thought long and hard about the first sentence of the book?</li>
<li>Data (without the theory the effects are silent) is silent without the analysis. You need to not just have the data, but you have to have the context and understanding of the environment of the problem.</li>
</ul>
<p>What a student who has read this book will be able to do this after reading the book: 95% of what an analyst needs (<em>as pointed out by Joshua Angrist</em>)</p>
<ul>
<li>How you start working with your data</li>
<li>How you find patterns</li>
<li>Have a prediction mind set—how do I predict outside my data?</li>
<li>Be able to analyze the causal effects of changes.</li>
<li>Understand that this is longer journey.</li>
<li>What one or two things I can do to better tomorrow.</li>
</ul>Gábor Békés and Gábor KézdiI did a podcast with Chris Richardson of Pragmatic Institute, a California based data science education institute a while back, it is out now. Data Science in Action: Insights from a Leading Textbook Author.Data Analysis for Business Analytics2022-07-15T00:00:00+00:002022-07-15T00:00:00+00:00https://gabors-data-analysis.com/posts/2022/07/data-analysis-business-analytics<h1 id="a-complete-data-analysis-package-for-business-analytics">A complete Data Analysis package for Business Analytics</h1>
<p>MS in Business Analytics, MS Applied Data Science – a variety of names exist for a relatively new breed of Master’s programs. They typically offer a one-year intensive curriculum to build up skills in coding: (#Rstats or #Python), engineering with #SQL, #cloud , #bigdata, #spark and many more as well as management and data analysis.</p>
<h2 id="data-analysis-for-business-economics-and-policy">Data Analysis for Business, Economics, and policy</h2>
<p>Data Analysis is a mix of statistics, econometrics, data science, machine learning with the aim of teaching practical skills that analysts may use in real life working in business. As instructor of Data Analysis and program director at <a href="https://economics.ceu.edu/program/master-science-business-analytics">CEU MS in Business Analytics</a> for years, I have experimented quite a bit with the curriculum. The experience gave rise to a textbook co-authored with Gabor Kezdi and published by Cambridge University Press. It is currently used in 80+ programs around the world, including a dozen <a href="https://gabors-data-analysis.com/courses-using/#business-analytics-data-science">Analytics</a> Master’s programs.</p>
<p>How can this <a href="https://gabors-data-analysis.com/">Data Analysis for Business, Economics, and Policy</a> textbook help instructors and students Business Analytics or related programs? We believe it can help in several different aspects.</p>
<p><img src="/images/cambridge-card.jpg" alt="Card" height="90%" width="90%" /></p>
<h2 id="four-benefits">Four benefits</h2>
<p>We think there are four key benefits of using the textbook in Business Analytics education: an approach that aims at highlighting the analytical process, curated content from exploration to machine learning <strong>and</strong> causal inference, focus on case studies and an ecosystem helping the learning process.</p>
<h3 id="data-analysis-is-a-process">Data analysis is a process</h3>
<p>First, it will help students understand that <strong>Data analysis is a process</strong>. It starts with formulating a question and collecting appropriate data or assessing whether the available data can help answer the question. Then come the tedious but essential tasks of data cleaning and organizing that affect the results of the analysis as much as any other step in the process. Exploratory data analysis gives context to the eventual results and helps deciding the details of the analytical method to be applied. The main analysis consists of choosing and implementing the method to answer the question, with potential robustness checks. Along the way, correct interpretation and effective presentation of the results are crucial. Carefully crafted data visualizations help summarize our findings and convey the key messages. The final task is to answer the original question, with potential qualifications and directions for future inquiries.</p>
<h3 id="four-parts-four-courses-on-data-exploration-regressions-prediction-and-causal-inference">Four parts, four courses on data exploration, regressions, prediction and causal inference</h3>
<p>Second, it will help you think about a course structure. In our view, a great way to teach the whole process is to organize it in four courses: data exploration, regression analysis, prediction with machine learning, and causal analysis.</p>
<ul>
<li>
<p><strong>Data Exploration</strong>: The first course starts with discussing (and possibly doing) data collection and thinking about data quality, followed by organizing and cleaning data, exploratory data analysis and data visualization. This first part must also include the key statistical knowledge needed for everything else: important distributions, statistical inference, correlation and hypothesis testing and some sampling methods. You may offer this as a bootcamp or a pre-session allowing more experienced students to exam out.</p>
</li>
<li>
<p><strong>Regression analysis</strong> Thorough introduction to regression analysis comes next, including probability models and time series regressions. It is vital for data analysis students to learn designing regression models and deeply understand their output. As part of the process, they may learn the role of selecting a functional form, dealing with uncertainty as well as different types of dependent variables.</p>
</li>
<li>
<p><strong>Prediction with Machine Learning</strong>: The third part covers <strong>predictive analytics</strong> and introduces cross-validation, LASSO, tree-based machine learning methods such as random forest, probability prediction, classification, and forecasting from time series data. This is where modern data science is presented in a prediction context focusing on the “do what works” approach. In this course, only a few methods are presented, but those are discussed in depth. Students may then take additional machine learning classes to master other models like deep learning.</p>
</li>
<li>
<p><strong>Causal effect of interventions</strong>: The fourth part covers <strong>causal analysis</strong>, starting with the potential outcomes framework as well as DAGs (causal maps). Students discuss the role of randomized experiments as well as practical issues doing them offline and online. Statistical methods include difference-in-differences analysis, various panel data methods and the event study approach.</p>
</li>
</ul>
<h3 id="a-case-study-focus">A case study focus</h3>
<p>Third, our approach focuses on explaining <strong>how to carry out an actual data analysis project from beginning to end</strong>. To cover all the steps that are necessary to carry out an actual data analysis project, we <strong>lean on a set of fully developed case studies</strong>. While each case study focuses on the method discussed in the chapter, they illustrate all elements of the process from question through analysis to conclusion. Our case studies cover a wide range of topics, with a potential appeal to a wide range of students. They include <strong>consumer decision, economic and social policy, finance, business and management, health, and sport</strong>. Their regional coverage is also wider than usual: one third is from the U.S.A., one third is from Europe and the U.K., and one third is from other countries or includes all parts of the world, from Australia to Thailand.</p>
<p><img src="/images/book-withpix1.jpg" alt="case studies" height="90%" width="90%" /></p>
<h3 id="the-ecosystem">The ecosystem</h3>
<p>Fourth, there is an ecosystem built into and around the textbook, consisting of</p>
<ul>
<li>online <a href="https://gabors-data-analysis.com/datasets/"><strong>datasets</strong></a>,</li>
<li>online <a href="https://github.com/gabors-data-analysis/da_case_studies"><strong>code in Stata, R, and Python</strong></a></li>
<li>in text practice questions (360)</li>
<li>in text data exercises (120)</li>
<li>online <a href="https://gabors-data-analysis.com/readings">reading recommendations</a></li>
<li>online <a href="https://gabors-data-analysis.com/data-source-ideas">suggested practice datasets</a></li>
<li>online suggestions <a href="https://gabors-data-analysis.com/code-learn/">to learn coding</a> ideas in R, Stata and Python</li>
<li>complete <a href="https://github.com/gabors-data-analysis/da-coding-rstats">coding course for Data Analysis in R </a> (<strong>NEW</strong>)</li>
<li>For instructors, <a href="https://www.cambridge.org/highereducation/books/data-analysis-for-business-economics-and-policy/D67A1B0B56176D6D6A92E27F3F82AA20/resources/instructor-resources/F57C5762D1593E72250729668A08A53B">lecture slides</a> at Cambridge UP website, also available in latex/overleaf</li>
</ul>
<h2 id="why-use-it">Why use it?</h2>
<p>In summary, analytic process orientation, comprehensive coverage of key topics, a focus on cases studies and a massive ecosystem (with data, code and even a coding course) makes this package a great value for instructors and students in Business analytics or applied data science programs.</p>
<p>The book is <a href="https://gabors-data-analysis.com/endorsements">endorsed</a> by two Nobel laureates (Angrist and Card), the dean of Yale School of Management (Charles) and many leading scholars. It is already adopted in over 80 courses globally, including Columbia, U Texas, U Michgan, Penn State, Pittsburgh, U of California, Simon Fraser, UCLondon, Cambridge Judge, Essex, ESSEC, Bocconi, Berlin, CEU Vienna, Budapest, Amsterdam, UC Dublin, UWA Perth, Kyoto.</p>
<p><strong>You may buy the book:</strong> <a href="https://www.amazon.com/Data-Analysis-Business-Economics-Policy-dp-1108716202/dp/1108716202/ref=mt_other?_encoding=UTF8&me=&qid=">Amazon.com</a>, or a great deal of <a href="/order">global options</a><br />
<a href="https://www.cambridge.org/highereducation/books/data-analysis-for-business-economics-and-policy/D67A1B0B56176D6D6A92E27F3F82AA20/examination-copy/login"><strong>Request an examination copy</strong></a> from the Publisher (or DM me)</p>
<p><a href="/contact-us/"><strong>Contact us</strong></a> <br />
<strong>Follow us on <a href="https://twitter.com/Gabors_Data">Twitter</a> and <a href="https://www.facebook.com/gaborsdata">Facebook</a></strong></p>
<p>As noted earlier, data analysis is a process. Hopefully we can help you enjoy the journey.</p>Gábor Békés and Gábor KézdiA complete Data Analysis package for Business AnalyticsInterpreting a coefficient in a simple OLS regression2021-11-29T00:00:00+00:002021-11-29T00:00:00+00:00https://gabors-data-analysis.com/posts/2021/11/ols-coeff-interpret<h2 id="interpreting-univariate-ols-coefficients">Interpreting univariate OLS coefficients</h2>
<p>Precise interpretation of a simple univariate, cross-sectional regression is not easy.</p>
<p>There are many good (precise) ways to do it, some that are not perfect and some that are not good. So let us offer an example, and a vareity of good, partially ok, but problematic and simply wrong answers. We also add some comments to explain why an asnwer is good or bad.</p>
<h3 id="the-question">The question</h3>
<p>You have a representative sample of 10,000 people in a country, aged 15-45. You are interested in the relationship between earning (USD /per year) and age. You run a simple linear regression estimated with OLS. Both \(y\) and \(x\) are in levels.</p>
\[y^{E} = \hat\alpha + \hat \beta \times age\]
<p>The estimated coefficients are: \(\hat \alpha = 7000, \hat\beta = 400\). The task is to interpret both of these coefficients.</p>
<h3 id="good-answers">Good answers</h3>
<p>Let us start with the constant (intercept) \(\hat\alpha\)</p>
<ul>
<li><strong>For people aged zero (when age=0), earnings is $7000, on average</strong></li>
<li>For people aged zero (when age=0), the expected earning is $7000
<ul>
<li><em>you may or may not add on average, “expected” includes it</em></li>
</ul>
</li>
<li>For people aged zero (when age=0), earning is $7000, on average</li>
<li>The constant cannot be interpreted in this context (because newborns make no money)</li>
<li>Intercept of the regression line, in this case has no realistic meaning, no earnings at age = 0</li>
</ul>
<p>Now let us look at the slope, \(\hat\beta\)</p>
<ul>
<li><strong>People who are one year older, earn $400 more, on average</strong></li>
<li>People who are one year older tend to earn $400 more (you may or may not add on average, “expected” kind of includes it)
<ul>
<li>… are expected to earn $400 more</li>
<li>…tend to have higher earnings by $400</li>
</ul>
</li>
<li>One additional year of age is associated with $400 higher earning, on average</li>
<li>One year age difference is associated with and an average of $400 extra earnings</li>
<li>One additional year in age corresponds to an average of $400 extra earnings</li>
<li>Earnings of people who are one year older, are (tend to be / is expected to be) on average $400 higher in the data</li>
<li>Comparing two people, the one who is one year older, is expected to (tend to have) have $400 higher earning</li>
</ul>
<h3 id="partial-credit-not-completely-bad-but-problematic">Partial credit, not completely bad but problematic</h3>
<p>For constant, \(\hat\alpha\)</p>
<ul>
<li>Newborn/Zero aged people earn $7000 ( missed: on average )</li>
<li>Average values of earning without considering the age is $7000 ( we consider it, but it’s zero )</li>
<li>The person earns 7000usd/year at least, no matter what is his age ( true but only because beta is positive )</li>
<li>7000 is the minimum income that has to be given irrespective of the age ( true but only because beta is positive )</li>
</ul>
<p>For slope, \(\hat\beta\)</p>
<ul>
<li>One additional year in age corresponds to $400 higher earning ( missed: on average )</li>
<li>One extra year means (implies) 400 more ( suggests causality, and missed on average )</li>
<li>any extra age adds up 400 to earnings ( suggests causality, and missed on average )</li>
<li>People who are one year older will have $400 higher earnings, on average ( “will have”: the data is about the past, we don’t know what the future brings. Yes, <em>will</em> can mean “likely” but should be avoided )</li>
</ul>
<h3 id="not-good-bad">Not good (bad)</h3>
<p>For constant, \(\hat\alpha\)</p>
<ul>
<li>The intercept is 7000 ( not interpretation )</li>
<li>Average earning is 7000 if age=15 ( not at the minimum age in the sample )</li>
<li>Average earning is 7000 ( no, 7000 is average earnings at age zero )</li>
</ul>
<p>For slope, \(\hat\beta\)</p>
<ul>
<li>for every unit change in age the change in earning on average is 400USD ( it’s about cross-section differences between people, not changes)</li>
<li>One year increase will get $400 increase in wage ( no time series or causality, no increase! )</li>
<li>Each year in the age increases earnings by $400 ( no time series or causality, no increase! )</li>
<li>The slope is 400 ( not interpretation )</li>
</ul>Gábor Békés and Gábor KézdiInterpreting univariate OLS coefficientsA simplified notation for OLS regression2021-07-11T00:00:00+00:002021-07-11T00:00:00+00:00https://gabors-data-analysis.com/posts/2021/07/ols-notation<h2 id="a-simplified-regression-notation">A simplified regression notation</h2>
<p>We introduced some new notation in the textbook, to make the formulae simpler and more focused. In particular, our formula for regressions is slightly different from the traditional formula. We think that it is good practice to write out the formula for each regression that is analyzed. For this reason, it important to use a notation for the regression formula that is as simple as possible and focuses only on what we care about. Our notation is intuitive, but it’s slightly different from traditional practice. Let us explain our reasons.</p>
<p>Our approach starts with the definition of the regression: it is a model for the conditional mean. The formulaic definition of the simple linear regression is \(E[y \mid x]= \alpha + \beta x\) .</p>
<p>The formulaic definition of a linear regression with three right-hand-side variables is</p>
\[E[y \mid x_1, x_2, x_3]= \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3\]
<p>The regression formula we use in the textbook is a simplified version of this formulaic definition. In particular, we have \(y^E\) on the left-hand side instead of \(E[y \mid ...]\). So \(y^E\) is just a shorthand for the expected value of \(y\) conditional on whatever is on the right-hand side of the regression.</p>
<p>Thus, the formula for the simple linear regression is \(y^E = \alpha + \beta x\), and \(y^E\) is the expected value of \(y\) conditional on \(x\). The formula for the linear regression with three right-hand-side variables is</p>
\[y^E= \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3\]
<p>and here \(y^E\) is the expected value of \(y\) conditional on \(x_1\), \(x_2\), and \(x_3\). Having \(y^E\) on the left-hand side makes notation much simpler than writing out the conditional expectation formula \(E[y \mid ...]\), especially when we have many right-hand-side variables.</p>
<p>In contrast, the traditional regression formula has the variable \(y\) itself on the left-hand side, and has an additional element, the error term. This different notation acknowledges the fact that the actual value of \(y\) is equal to its expected value (defined by the model) plus a deviation from it. For example, the traditional formula for the linear regression with three right-hand-side variables is</p>
\[y= \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3 + e\]
<p>Importantly, it does not imply, that the model is about the conditional mean.</p>
<p>Our notation is simpler, because it has fewer elements. More importantly, our notation makes it explicit that the regression is a model for the conditional mean. It focuses on the data that analysts care about (the right-hand-side variables and their coefficients), without adding anything else. Especially for introductory courses, we believe, it’s a better way.</p>
<p>Note that there are reasons to go beyond this notations. With causal analysis, we may come back to the traditional model and have a term capturing unobserved heterogeneity (often denoted by u not e.) For instance, when introducing potential outcomes, it may be useful. For prediction, we may also have a model with explicitly having a prediction error: the difference between actual and predicted value for a given \(y_i\).</p>
<p>But, well, for most uses of a regression model, we suggest building on the expected value as a starting point to push the idea of regression as a model of conditional mean, and using our shorthand to simplify notation.</p>Gábor Békés and Gábor KézdiA simplified regression notationOn picking the Viridis color scheme2020-10-18T00:00:00+00:002020-10-18T00:00:00+00:00https://gabors-data-analysis.com/posts/2020/10/viridis<h2 id="the-economist-meets-visual-arts">The economist meets visual arts</h2>
<p>About two years ago, we had to make final decision about how the graphs in the textbook will loook like. I am an economist, and well, I know about ten colors. I have had no idea what a <em>hue</em> means. I did not really know what a color scheme was.</p>
<p>Then, two things happen. First TV shows about interior design with their discussion of color schemes. My fav show has been <a href="https://www.bbc.co.uk/programmes/b04nj4d5" target="_blank">BBC’s The Great Interior Design Challenge</a>. This is when I first learnt that what I color blueish green is actually <em>teal</em>. And that there sooo many different shades of a color. Heard about the idea of color palettes and schemes, too.</p>
<p>Second, we had a serious discussion with Gabor K - he is partially color blind (as are about 6% of population) on what he may and may not see. Red and green, not an option. So we needed to decide on how we use colors, and we were set to pick two good looking, color-blind friendly colors. To get started, I talked to my dataviz mentor, <a href="http://albertocairo.com/" target="_blank">Alberto Cairo</a>, who showed me a great application, called <a href="https://colororacle.org/" target="_blank">Color Oracle</a> that will pinpoint if an image works for color blind folks.</p>
<p>Then, I visited my editors in Cambridge, and I also met technical people, who told me that there are no more 2 or 3-color books, it is either a single color or full color. So if we wanna have colors, we can have as many colors as we’d like. Awesome.</p>
<p>So the summary of all this is that we realized, we can have <em>many</em> colors, but not <em>any</em> colors. And we need a scheme. So we tried to pin down our needs:</p>
<ol>
<li>For some graphs, we would need many colors not just a few</li>
<li>We want to use colors to represent values on a less-more (few-many) scale</li>
<li>Color blind folks should see them all right</li>
<li>Bonus: a black and white copy shall work, ie light and dark instead of some colors.</li>
</ol>
<h2 id="viridis-to-the-rescue">Viridis to the rescue</h2>
<p>I searched around untill I found a wonderful <a href="https://www.youtube.com/watch?v=xAoljeRJ3lU" target="_blank">video on Viridis</a>. This is a conference talk at SciPy2015 by <a href="https://bids.berkeley.edu/people/nathaniel-smith" target="_blank">Nathaniel Smith</a> and <a href="https://bids.berkeley.edu/people/st%C3%A9fan-van-der-walt" target="_blank">Stéfan van der Walt</a>. In less than 20 minutes, it explained how vision works, what could go wrong and why viridis is a solution. Viridis is a scheme first developed for Matplotlib in Python, but now available in R and Stata as well.</p>
<p><img src="/images/viridis.png" alt="Viridis" /></p>
<p>When we needes a set of pre-defined colors for scatterplots or line graphs we picked 5 colors from the scheme (here with their HEX code)</p>
<p><img src="/images/5-colors.png" alt="Viridis 5 colors" /></p>
<p>And, well, that is basically it. We then went on and had the textbook key colors be also based on Viridis. But that will be another post…</p>
<h1 id="reference">reference</h1>
<p><a href="https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html" target="_blank">The viridis color palette in R</a> by Bob Rudis, Noam Ross and Simon Garnier
<a href="https://bids.github.io/colormap/" target="_blank">Matplotlib colormaps</a>, Option “D”.</p>Gábor Békés and Gábor KézdiThe economist meets visual artsGoalkeepers, random play and multiple testing2020-07-18T00:00:00+00:002020-07-18T00:00:00+00:00https://gabors-data-analysis.com/posts/2020/07/multiple-test-soccer<p>Random action may be a well thought out strategy. Sometimes you would want to act randomly to make your next action hard to predict. This is particularly important when there is an adverserial situation, and players must choose a strategy. In game theory, this idea of picking an action from a set randomly is called <a href="https://en.wikipedia.org/wiki/Strategy_(game_theory)">mixed stratgy</a> One such case is saving penalties.</p>
<p>How can we test if goalkeepers play mixed strategies? Well, we can test if they move randomly, and test randomness for a large set of goalkeepers.</p>
<h2 id="stats-and-the-beautiful-game">Stats and the beautiful game</h2>
<p>Testing the hypothesis of random action across goalkeepers is what Ignacio Palacios-Huerta carried out in his wonderful book (<a href="https://press.princeton.edu/books/paperback/9780691169255/beautiful-game-theory">Beautiful Game Theory: How Soccer Can Help Economics</a>.</p>
<p><img src="/images/messi_penalty_kick2.jpg" alt="image" style="float: left" /></p>
<p>In the very first chapter, the author looked at penalties, from the point of view of randomness. Goalkeepers often decide to move before the ball is shot. Having collected data on where the goalkeeper moved, he tests if moves (such as left and up or right and down) are random. Random action is mixed strategy. For 40 keepers, two of them are found to have non-random system of moving at 5%. This is exactly the number of falsely accepted $H_{A}$, we would expect based on chance.</p>
<p>Thus, finding two keepers not seemingly follow random action does not indeed prove that the do not play mixed strategy. Instead it shows, that for multiple testing, we should need a tigher confidence interval, maybe 1% or 0.05%. With such a tight CI set for multiple testing, we could not reject random action for either goalkeeper.</p>
<h1 id="reference">reference</h1>
<p><a href="https://commons.wikimedia.org/wiki/File:FWC_2018_-_Group_D_-_ARG_v_ISL_-_Messi_penalty_kick.jpg">Image</a></p>Gábor Békés and Gábor KézdiRandom action may be a well thought out strategy. Sometimes you would want to act randomly to make your next action hard to predict. This is particularly important when there is an adverserial situation, and players must choose a strategy. In game theory, this idea of picking an action from a set randomly is called mixed stratgy One such case is saving penalties.Selection bias – a war story2020-07-15T00:00:00+00:002020-07-15T00:00:00+00:00https://gabors-data-analysis.com/posts/2020/07/selection-war<p>During the Second World War, in a secret Manhattan building, statisticians and mathematicians were recruited from across the U.S.A. to carry out data analysis in order to save lives and help the U.S.A. win the war. One of the brightest of them was <a href="https://en.wikipedia.org/wiki/Abraham_Wald">Abraham Wald</a>, an emigré from Nazi occupied Central Europe.</p>
<h2 id="wald-im-action">Wald im action</h2>
<p>One of Abraham Wald’s tasks was to figure out where to put armor on fighter airplanes. A dataset was put together on airplanes from previous combats with bullet holes shown on various parts of the planes. For example, wings were hit in x% of the cases, vertical stabilizers in y%, etc. The data showed a very low percentage for engines: hardly any of the airplanes had their engines hit by bullets.</p>
<p><img src="/images/survivorship-bias.png" alt="image" style="float: left" /></p>
<p>Examining this data, Wald came to the conclusion that the extra armor should be fitted to protect engines. His superiors were stupefied: engines were in fact the least affected by bullets. But Wald’s argument convinced them in the end. What was that argument?</p>
<p>Wald realized that the data did not represent all fighter airplanes that fought combats. It included only airplanes that returned from combat so that their bodies could be examined for bullet holes. But the most important observations would have been those that did not return from combat: those were the airplanes that could have benefited the most from the extra armor.</p>
<h2 id="engines-of-selection">Engines of selection</h2>
<p>The fact that the airplanes that returned had no bullet holes in their engines could have had two reasons: engines were not hit, or the airplanes whose engines were hit were missing from the data. As the engines were exposed to bullets and had large enough surface the first reason was unlikely. In contrast, the second reason was very likely: airplanes whose engines were hit were lost almost certainly, while many of the airplanes whose other parts were hit were able come back. Therefore, although they were not in the data, there were airplanes whose engines were hit, and they suffered the most. Putting armor on the engines had the potential to save the most airplanes.</p>
<p>The essence of the issue here was <strong>sample selection</strong>: the sample of airplanes that returned from combat was not a representative sample of all airplanes that participated in the combats. Instead it was affected by severe selection bias: only surviving planes made it to the sample.</p>
<h2 id="references">References</h2>
<p>This is a well known story, told in several places. Source of the image: McGeddon from <a href="https://en.wikipedia.org/wiki/Survivorship_bias">Wikipedia
</a></p>Gábor Békés and Gábor KézdiDuring the Second World War, in a secret Manhattan building, statisticians and mathematicians were recruited from across the U.S.A. to carry out data analysis in order to save lives and help the U.S.A. win the war. One of the brightest of them was Abraham Wald, an emigré from Nazi occupied Central Europe.Some history of sampling2020-07-14T00:00:00+00:002020-07-14T00:00:00+00:00https://gabors-data-analysis.com/posts/2020/07/history-sampling<p>Statistical enumerations of land, people, and property have taken place in many of the better organized empires and states since Babylonian times. These all aimed to cover entire populations. The first recorded use of a sample to learn something about a population was John Graunt’s estimate of the population of London in 1662.</p>
<h2 id="early-methods-of-sampling">Early methods of sampling</h2>
<p>Gaunt found that in a subset of parishes with good records, 3 burials took place on average per year for 11 families, and average family size was about 8. He used these estimates together with a already known sum: the total number of burials in London. The result of his estimation was a total population of 384,000. Of course, as <a href="https://www.britannica.com/biography/John-Graunt">Graunt</a> himself recognized, the merits of this exercise rest on the quality of all ingredients in the calculation (burials per family, persons per family, total number of burials). In modern language, the first two are questions of representation: were those parishes that provided the estimates representative of all parishes? There was no way to answer that question with the data Graunt had, and the sampling method he had to use (parishes with good data) leaves room for severe selection bias.</p>
<p>The first publication of a sampling method that may be considered random was by Anders Kiaer, founder of Statistics Norway, in 1895. It described a data collection exercise using a sample that was selected using a complex and detailed rule, with a lot of stratification in the beginning but randomness in the end, to estimate statistics about the entire population. Most contemporary statisticians did not accept those estimates as they were not from the entire population. Kiaer also gave little detail on the random part of the selection; neither did he offer a systematic justification for why his method should work.</p>
<h2 id="fisher-and-neyman">Fisher and Neyman</h2>
<p>It took fifty years and many other statisticians, including Ronald A. Fisher and Jerzy Neyman, to develop a statistical theory that could be used to evaluate estimation from random samples. That theory convinced many statisticians that random samples may work after all, and many started to use relatively small random samples to estimate population statistics. The success of those examples, then, convinced users of statistics of the enormous value of random samples. Random samples proved to help learn orders of magnitude more about a population from the same budget than the previously used complete enumeration methods.</p>
<p><img src="/images/neymanfisher.jpg" alt="image" style="float: center" /></p>
<p>The initial distrust in random sampling is not that surprising. It is always better to have information on entire populations than samples. Perhaps one may think that we would need samples of a very large proportion, say, 50% or 20%, to get accurate estimates for the population – in which case the cost savings of sampling would not be that high. The fact that samples of a few thousand observations may give us a very good picture of entire populations is crucial for the practical value of random samples. It is also quite surprising.</p>
<p>There is something counterintuitive in the fact that it is the size of the sample that matters, not its proportion of the population. But it is true nevertheless. Leaving selection to a random rule may also run against our instincts. It amounts to giving up control over the process – and, as humans, we often think that we make better decisions when we are in control. In the end, it was the demonstrated success of random samples that showed our intuition wrong, and, together with the mathematical statistical theory, convinced most users of the merits of relatively small random samples.</p>
<h2 id="literary-digest-debacle">Literary Digest debacle</h2>
<p>One influential example was the 1936 poll conducted by the then popular magazine Literary Digest to predict whether the incumbent Democratic president Franklin D. Roosevelt or Alfred Landon, the Republican candidate, would win the presidential election. The Literary Digest asked 10 million people and received answers from over 2 million, by far the largest poll conducted to date. The poll predicted a landslide victory for Alfred Landon: 57% against Roosevelt’s 43%.</p>
<p>The actual results were 62% for Roosevelt versus 38% for Landon. The 2 million strong Literary Digest sample was not a random subsample of the entire electorate: the 10 million invitees were its own readers, augmented by a sample from the telephone directory (back then, only more affluent Americans had a telephone). Moreover, the 2 million that replied were not a random subsample of the 10 million.</p>
<p>At the same time, a substantially smaller but more representative sample conducted by a small company just started by <a href="https://en.wikipedia.org/wiki/George_Gallup">George Gallup</a> correctly predicted a victory for Roosevelt.</p>
<h2 id="references">References</h2>
<p>Peverille Squire: Why the 1936 literary digest poll failed, <em>Public Opinion Quarterly, 1988, 52, 125:133</em>. <a href="https://www.jstor.org/stable/2749114?seq=1#page_scan_tab_contents">LINK</a></p>Gábor Békés and Gábor KézdiStatistical enumerations of land, people, and property have taken place in many of the better organized empires and states since Babylonian times. These all aimed to cover entire populations. The first recorded use of a sample to learn something about a population was John Graunt’s estimate of the population of London in 1662.Variants of random sampling2020-07-13T00:00:00+00:002020-07-13T00:00:00+00:00https://gabors-data-analysis.com/posts/2020/07/sampling-variants<p>There are many variations on random sampling that aim to further improve representation or reduce the costs of data collection.</p>
<h2 id="3-variants-of-random-sampling">3 Variants of random sampling</h2>
<p><strong>Stratified sampling</strong> improves on the representative nature of a sample. It starts by specifying large groups in the population, and it applies random sampling within each group.</p>
<p><strong>Cluster sampling</strong> starts by specifying small groups, takes a random sample from each of those groups, and collects data from all observations within each selected group. It can greatly reduce data collection cost, for example for in-person interviews that require a lot of traveling. In exchange, cluster samples increase the uncertainty in the data because the number of clusters is a lot smaller than the number of people, thus the sample size is smaller from the point of view of representation.</p>
<p><strong>Multi-stage sampling</strong> mitigates this problem by selecting a somewhat larger number of clusters in a first stage and taking a random sample of observations within each cluster instead of including all observations. Some data collection requirements present specific circumstances that may call for further variations on random sampling.</p>
<p>One example for stratified sampling comes from the <code class="language-plaintext highlighter-rouge">Comparing online and offline prices</code> case study. People collecting data received instructions to sample a specified number of products (between 10 and 50) in each store, in a stratified manner (by department). To what extent the resulting samples ended up representing the population is an open question here. However, if the purpose of the analysis of comparing online and offline prices, it is this difference that has to be similar in the sample and in the population of all products. As long as these distributions are similar, other differences are not that important.</p>Gábor Békés and Gábor KézdiThere are many variations on random sampling that aim to further improve representation or reduce the costs of data collection.