{"id":661,"date":"2020-07-08T07:16:15","date_gmt":"2020-07-08T06:16:15","guid":{"rendered":"http:\/\/www.billconnelly.net\/?p=661"},"modified":"2025-07-05T04:15:09","modified_gmt":"2025-07-05T03:15:09","slug":"exercises-in-data-a-tale-in-3-parts","status":"publish","type":"post","link":"https:\/\/www.billconnelly.net\/?p=661","title":{"rendered":"Exercises in Data: A tale in 3 parts."},"content":{"rendered":"\n<p>Some of you may have seen this graph. It was tweeted out, non-ironically by an economist from a prestigious US university, and at first glace it seems ridiculous:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"692\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/covid_mortality_raw-1024x692.png\" alt=\"\" class=\"wp-image-662\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/covid_mortality_raw-1024x692.png 1024w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/covid_mortality_raw-300x203.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/covid_mortality_raw-768x519.png 768w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/covid_mortality_raw.png 1027w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I&#8217;d like to talk about this graph, data, regression, causation and data analysis.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Before I get started I want to point out that I am not an epidemiologist or an expert in virology or public health. This post is not meant to be guidance on policy. I am using an unusual graph to illustrate problems in data analysis. That said, I also suspect there is a lot of truth in the final conclusion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 1: Things are not always what they seem.<\/h2>\n\n\n\n<p>This graph, it was suggested, showed that in US states where doctors are paid more have lower mortality rates from COVID-19. After all look at the trend line!<\/p>\n\n\n\n<p>Most &#8220;sensible&#8221; people, myself included, saw no relationship between these two measures. And needless to say, the replies to the tweet did not shy away from pointing that out. Thankfully, in a rare moment of wisdom, instead of joining the pile-on, I simply shared the image with my friend and collaborator, <a href=\"https:\/\/twitter.com\/mere_conjecture\">Dr Jack Auty<\/a>. He did the sensible thing and extracted the data using<a href=\"https:\/\/automeris.io\/WebPlotDigitizer\/\"> WebPlotDigitizer<\/a> and run the data through R. I&#8217;ve put my data extraction up online, so you can follow along<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat &lt;- read.csv(\"http:\/\/www.billconnelly.net\/uploads\/covid1.csv\")\nmdl &lt;- lm(dat$Mortality.Rate ~ dat$Salary)\nsummary(mdl)\n\nCall:\nlm(formula = dat$Mortality.Rate ~ dat$Salary)\n\nResiduals:\n    Min      1Q  Median      3Q     Max \n-39.860 -17.289  -8.606   7.373 131.549 \n\nCoefficients:\n            Estimate Std. Error t value Pr(>|t|)   \n(Intercept) 125.7330    41.7867   3.009   0.0042 **\ndat$Salary   -0.4352     0.1854  -2.347   0.0232 * \n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 32.81 on 47 degrees of freedom\nMultiple R-squared:  0.1049,\tAdjusted R-squared:  0.08584 \nF-statistic: 5.507 on 1 and 47 DF,  p-value: 0.0232<\/code><\/pre>\n\n\n\n<p>So, I have run a linear regression of salary against mortality, and the summary() function returns all the stuff you typically need to know. And what do we see: well the dat$Salary coefficient is statistically significantly different from zero, meaning the line of best fit is not horizontal. Furthermore it&#8217;s negative, meaning that the line of best fit suggests that in states where doctors are paid more, the COVID mortality rate is lower. Finally, the R-squared is around 0.1, meaning that about 10% of the variance in mortality can be explained by the changes in doctors salaries. So does that means the original tweeter was correct?<\/p>\n\n\n\n<p>Well hang on. We&#8217;ve run a linear regression, what are the assumptions of linear regression? That is to say, what conditions must we meet in order for the numbers that come out of the linear regression to mean what we think the mean. They are:<\/p>\n\n\n\n<ol><li> Linearity &#8211; In this case, that the relationship between salary and mortality rate is a line.<\/li><li> Independence &#8211; Typically, this is explained by saying that each observation must not be affected by any of the other observations. <\/li><li> Homoscedasticity &#8211; That that variance of Y doesn&#8217;t vary as you move along X. For instance, if we wanted to do a regression of height against weight for all the species in the animal kingdom we would be in trouble as the variances of small animals is certainly going to be less than the variance of large animals. Percentage-wise it might be the same, but in units of length, the variance of ants is going to be less than elephants. <\/li><li>Normality &#8211; That the residuals of fit, (that is the distance between the data and the line of best fit) are normally distributed. This is often misinterpreted as that the data itself needs to be normally distributed. But no, it is just the residuals. Though, if this data set was somehow much bigger, and we had thousands of states, if were were able to select a dozen states that almost the same doctor&#8217;s salary, we would expect the mortality rate of those dozen states to be normally distributed.<\/li><\/ol>\n\n\n\n<p>It is the last two assumptions that are often violated, especially when the data goes across more than an order of magnitude. So can we test if this data obeys the assumptions? Yes, we can. We simply say:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>plot(mdl)<\/code><\/pre>\n\n\n\n<p>This generates 4 graphs, two of which I want to focus on. The first one shows the residuals against the fitted value<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"534\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag1.png\" alt=\"\" class=\"wp-image-665\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag1.png 856w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag1-300x187.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag1-768x479.png 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/figure>\n\n\n\n<p>We don&#8217;t see anything that terrible, but it&#8217;s not perfect either. We would hope to see these data points in nice cloud, where you could draw a horizontal line of best fit. This graph shows us how the data regarding assumptions 1, 3 and 4. If the residuals appear to follow a smooth curve, chances are you&#8217;ve broken the assumption of linearity. If the absolute value of the residuals get larger as the fitted values get larger, you&#8217;d broken the assumption of  homoscedasticity  Finally, if the residuals don&#8217;t look evenly spread above and below the horizontal line, chances are, you&#8217;ve broken the assumption of normality. To my eyes, the data above the line is on average further away from the horizontal line than the data below it, and so I suspect the residuals aren&#8217;t normally distributed. Thankfully, the next graph will give us a much clearer answer<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"523\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag2.png\" alt=\"\" class=\"wp-image-666\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag2.png 866w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag2-300x181.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag2-768x464.png 768w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/figure>\n\n\n\n<p>This is a quantile-quantile (Q-Q) plot of our residuals (transformed into a Z-score) against where you would expect them to fall if they were normally distributed. The point here is that if our residuals were normally distributed, they should fall on this dashed line, which they clearly do not, and importantly, they appear to deviate in a predictable fashion. <\/p>\n\n\n\n<p>I suspect that if we log transform our mortality data, our data will be much more nicely behaved. Indeed, log-transforming data typically is necessary when it varies by more than an order of magnitude. So lets do that, and see what our graphs look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mdl.log &lt;- lm(log(dat$Mortality.Rate) ~ dat$Salary)\nplot(mdl.log)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"525\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag3.png\" alt=\"\" class=\"wp-image-667\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag3.png 866w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag3-300x182.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag3-768x466.png 768w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/figure>\n\n\n\n<p>Our plot of residuals against fitted values looks like a bit of an improvement, but it wasn&#8217;t that much of an abomination to begin with. But what about the Q-Q plot?<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"525\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag4.png\" alt=\"\" class=\"wp-image-668\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag4.png 866w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag4-300x182.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelDiag4-768x466.png 768w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/figure>\n\n\n\n<p>Well this is certainly an improvement. It looks like there is still a predictably deviation from normality, but it isn&#8217;t anywhere near as aggressive and it only involves maybe three data points (as opposed to six).<\/p>\n\n\n\n<p>So what does our regression actually say now<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>summary(mdl.log)\n\nCall:\nlm(formula = log(dat$Mortality.Rate) ~ dat$Salary)\n\nResiduals:\n    Min      1Q  Median      3Q     Max \n-4.5550 -0.9394  0.2459  0.7568  2.1001 \n\nCoefficients:\n             Estimate Std. Error t value Pr(>|t|)    \n(Intercept)  7.250797   1.629428   4.450 5.25e-05 ***\ndat$Salary  -0.020417   0.007231  -2.824  0.00694 ** \n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 1.279 on 47 degrees of freedom\nMultiple R-squared:  0.145,\tAdjusted R-squared:  0.1268 \nF-statistic: 7.973 on 1 and 47 DF,  p-value: 0.006942<\/code><\/pre>\n\n\n\n<p>So we have a very significant slope coefficient, which is still negative, and our R-squared value has gone up a bit. And what do our fits look like?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>par(mfrow=c(1,2))\nplot(dat$Salary, log(dat$Mortality.Rate))\nabline(mdl.log)\npar(mfrow=c(1,2))\nplot(dat$Salary, dat$Mortality.Rate)\nabline(mdl)\nplot(dat$Salary, log(dat$Mortality.Rate))\nabline(mdl.log)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"553\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/final_fits.png\" alt=\"\" class=\"wp-image-669\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/final_fits.png 866w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/final_fits-300x192.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/final_fits-768x490.png 768w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/figure>\n\n\n\n<p>What we really see from this is that if the original twitter post had been displayed with appropriate axis, the whole fit would look a lot more convincing. We also see that transforming the data reduced the P value 10 fold and increased our R-squared.  So the take away message here is:  <br>it&#8217;s a good idea to make your graphs so they show your point, and  but it&#8217;s a great idea to think about your data before you subject it to statistical methods. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 2:  The wise know their limitations; the foolish do not. <\/h2>\n\n\n\n<p>Despite the statistical relationship between these two sets of data, what should we take away from this? Does anyone expect that if we started paying doctors more today, that the mortality rate of COVID would drop in the next few weeks? I hope not. Perhaps though, states which pay doctors more have attracted better doctors who have, in turn, improved the health care sector in those states? Or perhaps doctors are paid more in states that value well being more, and those states also contain more people that wear masks? These seems like reasonable hypotheses. Here, the word hypothesis is important. Because the regressions we were performing are <em>hypothesis tests<\/em>. And every time we perform a hypothesis test, there is a chance that we will incorrectly support our hypothesis, or incorrectly reject it. And this is why we cannot just go around randomly investigating every possible pair of data we can think of, as eventually we will always find two variables that are related, but that doesn&#8217;t mean the relationships are causative, or even important, after all <a href=\"https:\/\/www.tylervigen.com\/spurious-correlations\">correlation does not imply causation<\/a>. To put it simply, this apparent significant relationship may be nothing more than coincidence.<\/p>\n\n\n\n<p>On the other hand, calling the result a coincidence may be being foolish as well. Another possibility is that states which pay doctor&#8217;s more are more wealthy, educated or sparsely populated, and is it those variables that are causative in effecting mortality rates. So the relationship we observed was real, but not causative. That is to say there is a variable that is co-linear with doctor&#8217;s salary that we have not observed, and this variable causally relates to mortality rates, otherwise known as the omitted variable bias.<\/p>\n\n\n\n<p>While a full analysis that attempts to control for these various variables may be warranted, the real point I want to get at is that no matter what kind of regression we do, establishing the true cause of why some states show much lower mortality rates will always be difficult without an (quasi) experimental approach. Using an evidence based hypothesis will always boost the validity of a finding, but there is always a chance of the omitted variable bias. Or more simply,  when performing regression on retrospective data, no matter how carefully it is performed, or how sensible the hypothesis is, it can never establish causation. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 3: Garbage in, Garbage out.<\/h2>\n\n\n\n<p>There was something missing from the first post, something I should have noticed the absence of: the data source. Where did the data come from? And what does it mean by mortality rate? Is that per patient with COVID, or across the whole population? <\/p>\n\n\n\n<p>So I went and got the best data I could find, I used the US Bureau of Labor Statistics for the salary information, and the CDC for the mortality rate (total deaths from COVID per 100,000). Because I was convinced this would be important, I got the GDP per capita from the Bureau of Economic Analysis. Finally, I had a strong feeling that wealth inequality would also be important, I included each states Gini coefficient taken from data from the US Census Bureau. Vermont was excluded as the Bureau of Labor Statistics didn&#8217;t have their data for physician salary. The data is available <a href=\"http:\/\/www.billconnelly.net\/uploads\/covid2.csv\">here<\/a>.<\/p>\n\n\n\n<p>I ran a simple model<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mdl &lt;- lm(log(mort.rate) ~ salary + gdp + gini, data = cov.dat)\nsummary(mdl)\n\nCall:\nlm(formula = log(mort.rate) ~ salary + gdp + gini, data = cov.dat)\n\nResiduals:\n     Min       1Q   Median       3Q      Max \n-2.08874 -0.61624  0.01062  0.68168  1.77905 \n\nCoefficients:\n              Estimate Std. Error t value Pr(>|t|)   \n(Intercept) -6.262e+00  4.056e+00  -1.544    0.129   \nsalary      -5.532e-06  6.502e-06  -0.851    0.399   \ngdp          7.384e-06  6.410e-06   1.152    0.255   \ngini         2.097e+01  7.111e+00   2.949    0.005 **\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 0.9405 on 46 degrees of freedom\nMultiple R-squared:  0.3398,\tAdjusted R-squared:  0.2968 \nF-statistic: 7.893 on 3 and 46 DF,  p-value: 0.0002369<\/code><\/pre>\n\n\n\n<p>We see that salary and GDP have no effect on mortality, but the Gini coefficient does: as the Gini coefficient goes up (wealth gets more unequal) the mortality rate rises. However, while coliniarity between a variable you include and one you exclude can lead to omitted variable bias mentioned above, colinarity is a problem when you include two variables that are colinear too. It leads to poor estimates of coefficients, and in fact, can even make them point in the wrong direction. <\/p>\n\n\n\n<p>In order to test for colinarity, we can import the mctest library and apply all the tests, the most important one being the Farrar \u2013 Glauber Test, which tells us some coliniarity exists.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>library(mctest)\nomcdiag(mdl)\n\nCall:\nomcdiag(mod = mdl)\n\n\nOverall Multicollinearity Diagnostics\n\n                       MC Results detection\nDeterminant |X'X|:         0.6306         0\nFarrar Chi-Square:        21.7442         1\nRed Indicator:             0.3721         0\nSum of Lambda Inverse:     4.0983         0\nTheil's Method:            0.0965         0\nCondition Number:         78.0226         1\n\n1 --> COLLINEARITY is detected by the test \n0 --> COLLINEARITY is not detected by the test<\/code><\/pre>\n\n\n\n<p>And when we investigate who is to blame, if we run linear regressions between the terms, we see that the relationship between doctor&#8217;s salary and Gini coefficient is significant. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>summary(lm(salary ~ gini, data = cov.dat))\n\nCall:\nlm(formula = salary ~ gini, data = cov.dat)\n\nResiduals:\n   Min     1Q Median     3Q    Max \n-42837 -12142    218  12401  37456 \n\nCoefficients:\n            Estimate Std. Error t value Pr(>|t|)    \n(Intercept)   447392      59221   7.555 1.04e-09 ***\ngini         -508096     126813  -4.007 0.000213 ***\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 20970 on 48 degrees of freedom\nMultiple R-squared:  0.2506,\tAdjusted R-squared:  0.235 \nF-statistic: 16.05 on 1 and 48 DF,  p-value: 0.0002135<\/code><\/pre>\n\n\n\n<p>Though curiously it appears that states that pay their doctors more have a lower Gini coefficient.<\/p>\n\n\n\n<p>When dealing with colinear data, there are a variety of approaches one can take, but the simplest is simply to simply remove the colinear variable with the least explanatory power, i.e. drop doctors salary. In doing so, we get another model, which suggests a very significant relationship between COVID mortality rates Gini coefficient, again, where states with unequal wealth distribution have high mortality rates. We also see that states with higher GDP per capita have higher mortality rates. Finally, we see an interaction, where states that have a high Gini coefficient and a high GDP. have a reduced morality rate.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> mdl &lt;- lm(formula = log(mort.rate) ~ gdp * gini, data = cov.dat)\n> summary(mdl)\n\nCall:\nlm(formula = log(mort.rate) ~ gdp * gini, data = cov.dat)\n\nResiduals:\n     Min       1Q   Median       3Q      Max \n-2.17381 -0.49555  0.06311  0.59163  1.39747 \n\nCoefficients:\n              Estimate Std. Error t value Pr(>|t|)    \n(Intercept) -2.831e+01  7.967e+00  -3.554 0.000891 ***\ngdp          2.781e-04  1.049e-04   2.652 0.010948 *  \ngini         6.232e+01  1.590e+01   3.919 0.000293 ***\ngdp:gini    -5.212e-04  2.012e-04  -2.591 0.012792 *  \n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 0.8855 on 46 degrees of freedom\nMultiple R-squared:  0.4148,\tAdjusted R-squared:  0.3767 \nF-statistic: 10.87 on 3 and 46 DF,  p-value: 1.618e-05<\/code><\/pre>\n\n\n\n<p>But again, we should check for coliniarity<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> omcdiag(mdl)\n\nCall:\nomcdiag(mod = mdl)\n\n\nOverall Multicollinearity Diagnostics\n\n                       MC Results detection\nDeterminant |X'X|:         0.0021         1\nFarrar Chi-Square:       291.1233         1\nRed Indicator:             0.6791         1\nSum of Lambda Inverse:   774.7488         1\nTheil's Method:            2.0518         1\nCondition Number:        221.7526         1\n\n1 --> COLLINEARITY is detected by the test \n0 --> COLLINEARITY is not detected by the test<\/code><\/pre>\n\n\n\n<p>And every test tells us our data is colinear. Because there are only two variables in our model, we know GDP and Gini coefficients must be coliniar, and a linear regression shows us that as GDP per capita goes up, so does the Gini coefficient.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> summary(lm(gdp ~ gini, data = cov.dat))\n\nCall:\nlm(formula = gdp ~ gini, data = cov.dat)\n\nResiduals:\n   Min     1Q Median     3Q    Max \n-29863 -12025  -1188   8563 110237 \n\nCoefficients:\n            Estimate Std. Error t value Pr(>|t|)   \n(Intercept)  -113477      60073  -1.889  0.06494 . \ngini          375494     128636   2.919  0.00533 **\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 21270 on 48 degrees of freedom\nMultiple R-squared:  0.1508,\tAdjusted R-squared:  0.1331 \nF-statistic: 8.521 on 1 and 48 DF,  p-value: 0.005331<\/code><\/pre>\n\n\n\n<p>So we are left with only one option, to run two models, one for the effect of the Gini coefficient, and one for the effect of GDP per capita, and we see exactly what the previous models told us, states with a higher GDP per capita or a more wealth inequality have high COVID mortality, but because we ran these models separately, we have no idea about how these variables interact.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> m1 &lt;- lm(log(mort.rate) ~ gini, data = cov.dat)\n> summary(m1)\n\nCall:\nlm(formula = log(mort.rate) ~ gini, data = cov.dat)\n\nResiduals:\n    Min      1Q  Median      3Q     Max \n-2.1904 -0.7170 -0.0506  0.7076  1.7694 \n\nCoefficients:\n            Estimate Std. Error t value Pr(>|t|)    \n(Intercept)   -9.574      2.652  -3.610  0.00073 ***\ngini          26.551      5.680   4.675 2.42e-05 ***\n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 0.9394 on 48 degrees of freedom\nMultiple R-squared:  0.3128,\tAdjusted R-squared:  0.2985 \nF-statistic: 21.85 on 1 and 48 DF,  p-value: 2.418e-05\n\n> m2 &lt;- lm(log(mort.rate) ~ gdp, data = cov.dat)\n> summary(m2)\n\nCall:\nlm(formula = log(mort.rate) ~ gdp, data = cov.dat)\n\nResiduals:\n     Min       1Q   Median       3Q      Max \n-2.72733 -0.58109  0.00395  0.72119  2.03738 \n\nCoefficients:\n             Estimate Std. Error t value Pr(>|t|)    \n(Intercept) 1.793e+00  4.383e-01   4.090 0.000164 ***\ngdp         1.649e-05  6.673e-06   2.471 0.017070 *  \n---\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\n\nResidual standard error: 1.067 on 48 degrees of freedom\nMultiple R-squared:  0.1129,\tAdjusted R-squared:  0.09438 \nF-statistic: 6.106 on 1 and 48 DF,  p-value: 0.01707<\/code><\/pre>\n\n\n\n<p>And what does out fits look like?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>> plot(log(mort.rate) ~ gdp, data = cov.dat)\n> abline(m2)\n> plot(log(mort.rate) ~ gini, data = cov.dat)\n> abline(m1)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"497\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/models-1.png\" alt=\"\" class=\"wp-image-684\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/models-1.png 871w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/models-1-300x171.png 300w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/models-1-768x438.png 768w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/figure>\n\n\n\n<p>Given the low R-squared for the GDP fit, I&#8217;m not particularly shocked to see the unconvincing fit. But the Gini coefficient explained about 30% of the variance in mortality rates.<\/p>\n\n\n\n<p>And do these two models appear to obey the assumptions of linear regression? Pretty much:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"834\" height=\"1024\" src=\"http:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelsDiag-834x1024.png\" alt=\"\" class=\"wp-image-685\" srcset=\"https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelsDiag-834x1024.png 834w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelsDiag-244x300.png 244w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelsDiag-768x943.png 768w, https:\/\/www.billconnelly.net\/wp-content\/uploads\/2020\/07\/modelsDiag.png 871w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p>Our final take away message? Make sure the data you&#8217;re using comes from somewhere you trust, use your brain before you even start creating models, and then check the models assumptions before making any claims.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overall&#8230;<\/h2>\n\n\n\n<p>So the original graph was a bad graph: it failed to tell the story it was intended to tell, simply due to the choice of range on the X axis. The analysis performed on it was bad because it failed to take into account even the simplest of covariates. Investigating the covariates opened a can of worms, and left me with data the strongly implicated wealth inequality in explaining why some states have much higher rates of mortality due to COVID than others. Though, of course, this analysis in no way can prove causation. As before, it could be some other causative variable that correlates with the Gini coefficient that is leading us to this conclusion.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some of you may have seen this graph. It was tweeted out, non-ironically by an economist from a prestigious US university, and at first glace it seems ridiculous: I&#8217;d like to talk about this graph, data, regression, causation and data analysis.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/posts\/661"}],"collection":[{"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=661"}],"version-history":[{"count":13,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/posts\/661\/revisions"}],"predecessor-version":[{"id":688,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=\/wp\/v2\/posts\/661\/revisions\/688"}],"wp:attachment":[{"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.billconnelly.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<br />
<b>Notice</b>:  ob_end_flush(): Failed to send buffer of zlib output compression (0) in <b>/home/public/wp-includes/functions.php</b> on line <b>5373</b><br />
