<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ofir Shalev (@ofirdi) on Medium]]></title>
        <description><![CDATA[Stories by Ofir Shalev (@ofirdi) on Medium]]></description>
        <link>https://medium.com/@ofirdi?source=rss-4a16520a752a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VJF2KA2jSo1vWdV0.jpg</url>
            <title>Stories by Ofir Shalev (@ofirdi) on Medium</title>
            <link>https://medium.com/@ofirdi?source=rss-4a16520a752a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:00:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ofirdi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Causal Inference — What If]]></title>
            <link>https://medium.com/@ofirdi/causal-inference-what-if-d6b5e1e2c919?source=rss-4a16520a752a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6b5e1e2c919</guid>
            <category><![CDATA[causal-inference]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ofir Shalev (@ofirdi)]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 07:46:20 GMT</pubDate>
            <atom:updated>2020-06-23T08:05:02.479Z</atom:updated>
            <content:encoded><![CDATA[<h3>Causal Inference — What If</h3><p><a href="http://bayes.cs.ucla.edu/jp_home.html">Judea Pearl,</a> a pioneering figure in artificial intelligence, argues that AI has been stuck in a decades-long rut. His prescription for progress? Teach machines to understand the question why.</p><blockquote><em>All the impressive achievements of deep learning amount to just curve fitting</em></blockquote><blockquote><em>Judea Pearl</em></blockquote><p><a href="https://yoshuabengio.org/profile/">Yoshua Bengio</a> added in a recent interview</p><blockquote><em>Now, Bengio says deep learning needs to be fixed. He believes it won’t realize its full potential, and won’t deliver a true AI revolution, until it can go beyond pattern recognition and learn more about cause and effect. In other words, he says, deep learning needs to start asking </em>why<em> things happen.</em></blockquote><blockquote><a href="https://www.wired.com/story/ai-pioneer-algorithms-understand-why/"><em>https://www.wired.com/story/ai-pioneer-algorithms-understand-why/</em></a></blockquote><p>When we look at observational metrics, our Machine Learning models are doing great predicting a certain outcome given a treatment, but they are good exactly at that and not at the counterfactual — what would have been the outcome given no treatment</p><p><a href="https://www.hsph.harvard.edu/miguel-hernan/causal-inference-book/"><em>Causal Inference</em></a> by <a href="https://www.hsph.harvard.edu/miguel-hernan/">Miguel Hernán </a>and <a href="https://www.hsph.harvard.edu/james-robins/">James Robins </a>provides a great introduction to causal inference. You can download latest draft from their website:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*k_q6NkaDof1WYeJX" /><figcaption><em>Hernán MA, Robins JM (2020). Causal Inference: What If. Boca Raton: Chapman &amp; Hall/CRC</em></figcaption></figure><p>The book is divided in three parts of increasing difficulty: <strong>Part I </strong>is about causal inference <em>without models</em> (i.e., nonparametric identification of causal effects), <strong>Part II</strong> is about causal inference with <em>models</em> (i.e., estimation of causal effects with parametric models), and <strong>Part III </strong>is about causal inference from <em>complex longitudinal data</em> (i.e., estimation of causal effects of time-varying treatments).</p><p>Here are the top <em>four</em> reasons of why I think it’s a great book:</p><h4>Detailed introduction to the key concepts including many examples</h4><p>The first four chapters (a definition of causal effect, randomised experiments, observational studies and effect modification) cover key concepts such as potential outcomes (the outcome variable that <em>would have been observed</em> under a certain treatment value), individual and average causal effects, randomisation, identifiability conditions, exchangeability, positivity and consistency. You will get to know <em>Zeus’s extended family,</em> with many examples covering their various health conditions and treatment options. As an example, table 1.1 shows the counterfactual outcomes (die or not) under both treatment (a = 1 a heart transplant) and no treatment (a = 0). Providing practical examples along with the definition helps cement the learning by identifying the key attributes associated with the concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/0*9O1PaxXSWQKSnzy2" /></figure><h4>Practical approach</h4><p>Starting from the introduction, the authors are quite clear about their goals</p><blockquote><em>Importantly, this is not a philosophy book. We remain agnostic about metaphysical concepts like causality and cause. Rather, we focus on the identification and estimation of causal effects in populations, that is, numerical quantities that measure changes in the distribution of an outcome under different interventions. For example, we discuss how to estimate<br>in patients with serious heart failure if they received a heart transplant versus if they did not receive a heart transplant. Our main goal is to help decision makers make better decisions</em></blockquote><blockquote>Introduction: Towards less causal inferences</blockquote><p>On top of it, the book comes with a large number of code example in both R and Python, covering the first two part including chapters 11–17. It would be great to see additional code examples covering part three (causal inference from complex longitudinal data).</p><p>You should start with reading the book, and on parallel fire-up</p><pre>jupyter notebook</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MVztIEdx8ayxehCE" /></figure><p>and start playing with the code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vb9ylZOCfegszO_r" /></figure><h4>The validity of causal inferences models</h4><p>The authors discuss a large number of non-parametric and parametric techniques and algorithms to calculate causal effects. But they keep reminding us that all of these techniques rely on untestable assumptions and on expert knowledge. As an example:</p><blockquote><em>Unfortunately, no matter how many variables are included in L, there is no way to test that the assumption (conditional exchangeability) is correct, which makes causal inference from observational data a risky task. The validity of causal inferences requires that the investigators’ expert knowledge is correct</em></blockquote><p>and</p><blockquote><em>Causal inference generally requires expert knowledge and untestable assumptions about the causal network linking treatment, outcome, and other variables.</em></blockquote><h4>A (geeky) sense of humor</h4><p>Technical books tend to be concise and dry, telling an anecdote or adding a joke can make difficult content more enjoyable and understandable.</p><p>As an example, when discussing the potential outcomes of the heart transplant treatment in Zeus’s extended family, here is how the authors introduced the issue of sampling variability:</p><blockquote><em>At this point you could complain that our procedure to compute effect measures is somewhat implausible. </em><strong><em>Not only did we ignore the well known fact that the immortal Zeus cannot die</em></strong><em>, but more to the point — our population in Table 1.1 had only 20 individuals.</em></blockquote><blockquote><em>Chapter 1.4</em></blockquote><p>As another example, chapter 7 introduces the topic of confounding variables using an observational study which is designed to answer the causal question “does one’s looking up to the sky make other pedestrians look up too?”. The plot develops and new details are being shared in chapters 8 (selection bias), chapter 9 (measurement bias) and chapter 10 (random variability), till the authors announce the following</p><blockquote><em>Do not worry. No more chapter introductions around the effect of your looking up on other people’s looking up. We squeezed that example well beyond what seemed possible</em></blockquote><blockquote><em>Chapter 11</em></blockquote><p>I hope that you will find this book useful and that you will enjoy learning about Causal Inference as much as I did!</p><p><em>* originally published </em><a href="https://technofob.com/2020/06/23/causal-inference-what-if/"><em>here</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6b5e1e2c919" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recall, Precision, F1, ROC, AUC, and everything]]></title>
            <link>https://medium.com/swlh/recall-precision-f1-roc-auc-and-everything-542aedf322b9?source=rss-4a16520a752a------2</link>
            <guid isPermaLink="false">https://medium.com/p/542aedf322b9</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[recall]]></category>
            <category><![CDATA[model-evaluation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ofir Shalev (@ofirdi)]]></dc:creator>
            <pubDate>Mon, 27 May 2019 08:24:51 GMT</pubDate>
            <atom:updated>2019-05-31T22:54:02.334Z</atom:updated>
            <content:encoded><![CDATA[<p>Your boss asked you to build a fraud detection classifier, so you’ve created one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdI-8wph0XW816WtzUOykw.jpeg" /></figure><p>The output of your fraud detection model is the probability [0.0–1.0] that a transaction is <em>fraudulent</em>. If this probability is below <strong>0.5</strong>, you classify the transaction as <em>non-fraudulent; otherwise</em>, you classify the transaction as <em>fraudulent</em>.</p><p>To evaluate the performance of your model, you collect <strong>10,000 </strong>manually classified transactions, with <strong>300</strong> <em>fraudulent</em> transaction and <strong>9,700</strong> <em>non-fraudulent</em> transactions. You run your classifier on every transaction, predict the class label (<em>fraudulent</em> or non-<em>fraudulent</em>) and summarise the results in the following <em>confusion matrix</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*7-zkSjvB-QOqqD8u.png" /></figure><p>A<strong> True Positive</strong> <strong>(TP=100) </strong>is an outcome where the model <em>correctly</em> predicts the <em>positive</em> <em>(fraudulent) </em>class. Similarly, a <strong>True Negative</strong> <strong>(TN=9,000)</strong> is an outcome where the model <em>correctly</em> predicts the <em>negative</em> <em>(non-fraudulent) </em>class.</p><p>A <strong>False Positive</strong> <strong>(FP=700)</strong> is an outcome where the model <em>incorrectly</em> predicts the <em>positive</em> <em>(fraudulent) </em>class. And a <strong>False Negative</strong> <strong>(FN=200)</strong> is an outcome where the model <em>incorrectly</em> predicts the <em>negative</em> <em>(non-fraudulent) </em>class.</p><p>Asking yourself what percent of your predictions were correct, you calculate the <strong>accuracy</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*W7l6mq-CxFuQbOamuXJYIQ.png" /></figure><p>Wow, 91% accuracy! Just before sharing the great news with your boss, you notice that out of the 300 <em>fraudulent</em> transactions, only 100 <em>fraudulent</em> transactions are classified correctly. Your classifier missed 200 out of the 300 fraudulent transactions!</p><p>Your colleague, hardly hiding her simile, suggests a “better” classifier. Her classifier predicts every transaction as <em>non-fraudulent</em> (negative), with a staggering <strong>97%</strong> accuracy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*uRbByHZGGc3g5wuW.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*CDn7EGqZ-p-FDqLw5DAJjA.png" /></figure><p>While<em> 97%</em> <em>accuracy</em> may seem excellent at first glance, you’ve soon realized the catch: your boss asked you to build a fraud detection classifier, and with the always-return<em>-non-fraudulent</em> classifier you will miss <strong>all</strong> the fraudulent transactions.</p><blockquote><em>“Nothing travels faster than the speed of light, with the possible exception of bad news, which obeys its own special laws.”</em></blockquote><blockquote>Douglas Adams</blockquote><p>You learned the hard-way that accuracy can be misleading and that for problems like this, additional measures are required to evaluate your classifier.</p><p>You start by asking yourself <strong>what percent of the positive <em>(fraudulent) </em>cases did you catch</strong>? You go back to the confusion matrix and divide the True Positive (TP — blue oval) by the overall number of <strong>true</strong> fraudulent transactions (red rectangle)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*Yixk-bTd5V3w9qwi.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*NluETFtk71xnWPStB9-9tA.png" /></figure><p>So the classier <strong>caught 33.3% </strong>of the <em>fraudulent</em> transactions.</p><p>Next, you ask yourself <strong>what percent of positive <em>(fraudulent)</em> predictions were correct? </strong>You go back to the <em>confusion matrix</em> and divide the True Positive (TP — blue oval) by the overall number of <strong>predicted</strong> fraudulent transactions (red rectangle)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*_J54ss2iJO4HhXCm.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*2_Znl36tIqA_KRBDKLWn6A.png" /></figure><p>So now you know that when your classifier predicts that a transaction is <em>fraudulent</em><strong>, only 12.5% of the time your classifier is correct</strong>.</p><p><strong>F1 Score</strong> combines Recall and Precision to one performance metric. F1 Score is the weighted average of Precision and Recall. Therefore, this score takes both false positives and false negatives into account. F1 is usually more useful than Accuracy, especially if you have an uneven class distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*oo1-C74CC1i5wYkkzJv2Dw.png" /></figure><p>Finally, you ask yourself what percent of <strong>negative <em>(non-fraudulent)</em> predictions were incorrect? </strong>You go back to the <em>confusion matrix</em> and divide the False Positive (FP — blue oval) by the overall number of <strong>true</strong> <em>non-fraudulent </em>transactions (red rectangle)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*gH7mDTc-9DB33oqV.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*hE0SBmw_59Za7TfO69fB6A.png" /></figure><p><strong>7.2% of the non-fraudulent transactions</strong> were <strong>classified</strong> <strong>incorrectly</strong> as <strong>fraudulent</strong> transactions.</p><h3>ROC (Receiver Operating Characteristics)</h3><p>You soon learn that you must examine <strong>both</strong> Precision and Recall. Unfortunately, Precision and Recall are often in tension. That is, improving Precision typically reduces Recall and vice versa.</p><p>The overall performance of a classifier, summarized over all possible thresholds, is given by the Receiver Operating Characteristics (ROC) curve. The name “ROC” is historical and comes from communications theory. ROC Curves are used to see how well your classifier can separate positive and negative examples and to identify the best threshold for separating them.</p><p>To be able to use the ROC curve, your classifier should be able to rank examples such that the ones with higher rank are more likely to be positive (<em>fraudulent</em>). As an example, Logistic Regression outputs <em>probabilities</em>, which is a score that you can use for ranking.</p><p>You train a new model and you use it to predict the outcome of 10 new test transactions, summarizing the result in the following table: the values of the middle column (True Label) are either zero (0) for <em>non-fraudulent</em> transactions or one (1) for <em>fraudulent</em> transactions, and the last column (Fraudulent Prob) is the probability that the transaction is<em> fraudulent</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*59YdJR66Y35E7qE9.png" /></figure><p>Remember the <strong>0.5</strong> threshold? If you are concerned about missing the two <em>fraudulent</em> transactions (red circles), then you may consider lowering this threshold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*kc_DNOEiN0Eng78D.png" /></figure><p>For instance, you might lower the threshold and label any transaction with a probability below 0.1 to the <em>non-fraudulent</em> class, catching the two <em>fraudulent</em> transactions that you previously missed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*wNGHwyjxntli9yzd.png" /></figure><p>To derive the ROC curve, you calculate the <strong>True Positive Rate (TPR)</strong> and the <strong>False Positive Rate (FPR)</strong>, starting by setting the threshold to <strong>1.0</strong>, where every transaction with a Fraudulent Prob of less than<strong> 1.0</strong> iclassified as <em>non-fraudulent (0)</em>. The column “T=1.0” shows the predicted class labels when the threshold is 1.0:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/0*Ti7B147hc_rJR72n.png" /></figure><p>The confusion matrix for the Threshold=1.0 case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*PuO86v1WvkLngJqW.png" /></figure><p>The <strong>ROC</strong> curve is created by plotting the <strong>True Positive Pate (TPR)</strong> against the <strong>False Positive Rate (FPR) </strong>at various <strong>threshold</strong> settings, so you calculate both:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*Sr4qLO5eTJzEwE4mv4er7w.png" /></figure><p>You summarize it in the following table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/0*NPlNDffPE7hudzw4.png" /></figure><p>Now you can finally plot the first point on your ROC graph! A random guess would give a point along the dotted diagonal line (the so-called <em>line of no-discrimination</em>) from the left bottom to the top right corners</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*O8sf-OOeABuof4ZN.png" /></figure><p>You now lower the threshold to 0.9, and recalculate the FPR and the TPR:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*tBye0EVNKvFPsJRC.png" /></figure><p>The confusion matrix for Threshold=0.9:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*9WjLlHle5PqvQLiy.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*Yddv0ACIyeiTu-sXnDNbqg.png" /></figure><p>Adding a new row to your summary table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/0*78Nw9sNn5FGzIHIb.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*htN8bTncCjhmmgN-.png" /></figure><p>You continue and plot the <strong>True Positive Pate (TPR)</strong> against the <strong>False Positive Rate (FPR) </strong>at various <strong>threshold</strong> settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*1obrcm_IUzav-hnr.gif" /></figure><p>And voila, here is your ROC curve!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*ROnZr_WvzJ7zpoXH.png" /></figure><h3>AUC (Area Under the Curve)</h3><p>The model performance is determined by looking at the area under the ROC curve (or AUC). An excellent model has AUC near to the 1.0, which means it has a good measure of separability. For your model, the AUC is the combined are of the blue, green and purple rectangles, so the AUC = 0.4 x 0.6 + 0.2 x 0.8 + 0.4 x 1.0 = 0.80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*Hy9S987XTAgTz5NU.png" /></figure><p>You can validate this result by calling roc_auc_score, and the result is indeed 0.80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*ZJC24OHH1zfZqY7W.png" /></figure><h3>Conclusion</h3><ul><li>Accuracy will not always be the metric.</li><li>Precision and recall are often in tension. That is, improving precision typically reduces recall and vice versa.</li><li>AUC-ROC curve is one of the most commonly used metrics to evaluate the performance of machine learning algorithms.</li><li>ROC Curves summarize the trade-off between the true positive rate and false positive rate for a predictive model using different probability thresholds.</li><li>The ROC curve can be used to choose the best operating point.</li></ul><p>I hope that this blog was engaging and insightful, and I look forward to your feedback!</p><p>This blog was originally published <a href="https://technofob.com/2019/05/27/recall-precision-f1-roc-auc-and-everything/">here</a>; you can reach me at <a href="http://bit.ly/LinkedInOfir">LinkedIn</a> and <a href="http://bit.ly/TwitterOfir">Twitter</a></p><p>References:</p><p>[1] An Introduction to Statistical Learning [James, Witten, Hastie, and Tibshirani]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=542aedf322b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/recall-precision-f1-roc-auc-and-everything-542aedf322b9">Recall, Precision, F1, ROC, AUC, and everything</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MICE is Nice, but why should you care?]]></title>
            <link>https://medium.com/@ofirdi/mice-is-nice-but-why-should-you-care-e66698f245a3?source=rss-4a16520a752a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e66698f245a3</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Ofir Shalev (@ofirdi)]]></dc:creator>
            <pubDate>Tue, 12 Jun 2018 00:16:26 GMT</pubDate>
            <atom:updated>2018-06-12T00:16:26.163Z</atom:updated>
            <content:encoded><![CDATA[<h4>Multiple Imputation by Chained Equations (MICE)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VBt3FN_WNjM2ImClwfrc8A.jpeg" /><figcaption>photo credit <a href="https://www.flickr.com/photos/amberjol/26343929720">https://www.flickr.com/photos/amberjol/26343929720</a></figcaption></figure><p>As every data scientist will witness, it is rarely that your data is 100% complete. We are often taught to “ignore” missing data. In practice, however, ignoring or inappropriately handling the missing data may lead to biased estimates, incorrect standard errors and incorrect inferences.</p><p>But first we need to think about what led to this missing data, or what was the mechanism by which some values were missing and some were observed?</p><p>There are three different mechanisms to describe what led to the missing values:</p><ul><li>Missing Completely At Random (MCAR): the missing observations are just a random subset of all observations, so there are no systematic differences between the missing and observed data. In this case, analysis using only complete cases will not be biased, but may have lower power.</li><li><strong>Missing At Random (MAR):</strong> there might be systematic differences between the missing and observed data, but these can be entirely explained by other observed variables. For example, a case where you observe gender and you see that women are more likely to respond than men. Including a lot of predictors in the imputation model can make this assumption more plausible.</li><li>Not Missing At Random (NMAR): the probability of a variable being missing might depend on itself on other unobserved values. For example, the probability of someone reporting their income depends on what their income is.</li></ul><p>MICE operates under the assumption that given the variables used in the imputation procedure, the missing data are <strong>Missing At Random (MAR)</strong>, which means that the probability that a value is missing depends only on observed values and not on unobserved values</p><blockquote><em>Multiple imputation by chained equations (MICE) has emerged in the statistical literature as one principled method of addressing missing data. Creating multiple imputations, as opposed to single imputations, accounts for the statistical uncertainty in the imputations. In addition, the chained equations approach is very flexible and can handle variables of varying types (e.g., continuous or binary) as well as complexities such as bounds.</em></blockquote><p>The chained equation process can be broken down into the following general steps:</p><ul><li>Step 1: A simple imputation, such as imputing the mean, is performed for every missing value in the dataset. These mean imputations can be thought of as “place holders.”</li><li>Step 2: Start Step 2 with the variable with the fewest number of missing values. The “place holder” mean imputations for one variable (“var”) are set back to missing.</li><li>Step 3: “var” is the dependent variable in a regression model and all the other variables are independent variables in the regression model.</li><li>Step 4: The missing values for “var” are then replaced with predictions (imputations) from the regression model. When “var” is subsequently used as an independent variable in the regression models for other variables, both the observed and these imputed values will be used.</li><li>Step 5: Moving on to the next variable with the next fewest missing values, steps 2–4 are then repeated for each variable that has missing data. The cycling through each of the variables constitutes one iteration or “cycle.” At the end of one cycle all of the missing values have been replaced with predictions from regressions that reflect the relationships observed in the data.</li><li>Step 6: Steps 2 through 4 are repeated for a number of cycles, with the imputations being updated at each cycle. The idea is that by the end of the cycles the distribution of the parameters governing the imputations (e.g., the coefficients in the regression models) should have converged in the sense of becoming stable.</li></ul><p>To make the chained equation approach more concrete, imagine a simple example where we have 3 variables in our dataset: age, income, and gender, and all 3 have at least some missing values. I created this animation as a way to visualize the details of the following example, so let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SClvtvYMVhwi28pk.gif" /><figcaption>Multiple Imputation by Chained Equations (MICE) — Single Iteration</figcaption></figure><p>The initial dataset is given below, where missing values are marked as N.A.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*foZQ5-VUgYpHAaEQ.png" /></figure><p>In step 1 of the MICE process, each variable would first be imputed using, e.g., mean imputation, temporarily setting any missing value equal to the mean observed value for that variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*deSkkmUKOJ3gJG9k.png" /></figure><p>Then in the next step the imputed mean values of age would be set back to missing (N.A).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*rvBTuJ3gPEJicU5_.png" /></figure><p>In the next step Bayesian linear regression of age predicted by income and gender would be run using all cases where age was observed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*wLPtjxXEW538WAHz.png" /></figure><p>In the next step, prediction of the missing age value would be obtained from that regression equation and imputed. At this point, age does not have any missingness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*tswiYe6ubMrTpzhk.png" /></figure><p>The previous steps would then be repeated for the income variable. The originally missing values of income would be set back to missing (N.A).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/0*ZoF2Trmn6U9qvCIE.png" /></figure><p>A linear regression of income predicted by age and gender would be run using all cases with income observed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*j3CrtyDnVPhU7BuG.png" /></figure><p>Imputations (predictions) would be obtained from that regression equation for the missing income value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*pZqqMUR08qRvJNOC.png" /></figure><p>Then, the previous steps would again be repeated for the variable gender. The originally missing values of gender would be set back to missing and a logistic regression of gender on age and income would be run using all cases with gender observed. Predictions from that logistic regression model would be used to impute the missing gender values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/0*c_TWDERTH797dsrs.png" /></figure><p>This entire process of iterating through the three variables would be repeated until some measure of convergence, where the imputations are stable; the observed data and the final set of imputed values would then constitute one “complete” data set.</p><p>We then repeat this whole process multiple times in order to get multiple imputations.</p><p>* Originally published at <a href="http://bit.ly/technofob">https://technofob.com/2018/05/30/mice-is-nice-but-why-should-you-care/</a></p><h3>Resources</h3><p>What is the difference between missing completely at random and missing at random? Bhaskaran et al <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4121561/">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4121561/</a></p><p>A Multivariate Technique for Multiply Imputing Missing Values Using a Sequence of Regression Models, E. Raghunathan et al <a href="http://www.statcan.gc.ca/pub/12-001-x/2001001/article/5857-eng.pdf">http://www.statcan.gc.ca/pub/12-001-x/2001001/article/5857-eng.pdf</a></p><p>Multiple Imputation by Chained Equations: What is it and how does it work? Azur et al <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3074241/">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3074241/</a></p><p>Recent Advances in missing Data Methods: Imputation and Weighting — Elizabeth Stuart <a href="https://www.youtube.com/watch?v=xnQ17bbSeEk">https://www.youtube.com/watch?v=xnQ17bbSeEk</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e66698f245a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>