<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Win-Vector Blog &#187; Statistics</title>
	<atom:link href="http://www.win-vector.com/blog/tag/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.win-vector.com/blog</link>
	<description>The Applied Theorist&#039;s Point of View</description>
	<lastBuildDate>Sat, 04 Feb 2012 17:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Correlation and R-Squared</title>
		<link>http://www.win-vector.com/blog/2011/11/correlation-and-r-squared/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=correlation-and-r-squared</link>
		<comments>http://www.win-vector.com/blog/2011/11/correlation-and-r-squared/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 00:04:28 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[correlation]]></category>
		<category><![CDATA[goodness-of-fit]]></category>
		<category><![CDATA[linear regression]]></category>
		<category><![CDATA[R-squared]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1866</guid>
		<description><![CDATA[What is R2? In the context of predictive models (usually linear regression), where y is the true outcome, and f is the model&#8217;s prediction, the definition that I see most often is: In words, R2 is a measure of how much of the variance in y is explained by the model, f. Under &#8220;general conditions&#8221;, [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>What is R<sup>2</sup>? In the context of predictive models (usually linear regression), where <em>y</em> is the true outcome, and <em>f</em> is the model&#8217;s prediction, the definition that I see most often is: </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/4471BBA8-E9DB-4D30-A9AE-A74F8C773247.jpg" alt="4471BBA8-E9DB-4D30-A9AE-A74F8C773247.jpg" border="0" width="195" /></div>
<p></p>
<p>In words, R<sup>2</sup> is a measure of how much of the variance in <em>y</em> is explained by the model, <em>f</em>.  </p>
<p> Under &#8220;general conditions&#8221;, as Wikipedia says,<br />
R<sup>2</sup> is also the square of the correlation between the actual and predicted outcomes: </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/A4311540-8DFB-45FB-93F7-65E7B72AE6C8.jpg" alt="A4311540-8DFB-45FB-93F7-65E7B72AE6C8.jpg" border="0" width="336" /></div>
</p>
<p>I prefer the &#8220;squared correlation&#8221; definition, as it gets more directly at what is usually my primary concern: prediction. If R<sup>2</sup> is close to one, then the model&#8217;s predictions mirror true outcome, tightly. If R<sup>2</sup> is low, then either the model does not mirror true outcome, or it only mirrors it loosely: a &#8220;cloud&#8221; that — hopefully — is oriented in the right direction. Of course, looking at the graph always helps:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/R2_compare.png" alt="R2_compare.png" border="0" width="550" height="450" /></div>
</p>
<p>The question we will address here is : how do you get from R<sup>2</sup> to correlation?</p>
<p><span id="more-1866"></span>
<p>If you look at the two equations for correlation and R<sup>2</sup>, you can see that the relationship between them does not hold for general <em>f</em> and <em>y</em>. In particular, correlation is far more invariant to scaling. For correlation, all of the following relations are true: </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/3B8B7BE1-9E6B-4F6B-B1F7-7AFF3C2331BD.jpg" alt="3B8B7BE1-9E6B-4F6B-B1F7-7AFF3C2331BD.jpg" border="0" width="143"/></div>
<p>But only the last relation is true for R<sup>2</sup>. So in general, the two cannot be functions of each other.
</p>
<p>However, we are making a specific assumption about <em>f</em>: it is the output of a predictive model. In fact, we are actually making several specific assumptions;</p>
<p>1. <em>f</em> is the model that minimizes squared-error loss <br />
2. Because it is the optimum (in the sense of item 1), there is no shift of <em>f</em> that will improve the fit. <br />
3. Because it is the optimum (in the sense of item 1), there is no scaling of <em>f</em> that will improve the fit. 
</p>
<p>We can express the above assumptions as follows:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/B719DE1C-CE30-46BB-9B19-58111A5BEAD6.jpg" alt="B719DE1C-CE30-46BB-9B19-58111A5BEAD6.jpg" border="0" width="212" /></div>
<p>If we express the last line as</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/25988EED-3859-4732-837B-06106D0F9E90.jpg" alt="25988EED-3859-4732-837B-06106D0F9E90.jpg" border="0" width="210" /></div>
<p>Then loss is optimized at <em>g(1,0)</em>.
</p>
<p>Since <em>g(1,0)</em> is the optimum, then the derivatives of <em>g</em> are zero here: </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/4CA19B8A-E816-4F11-AC9B-6CA80AC5E961.jpg" alt="4CA19B8A-E816-4F11-AC9B-6CA80AC5E961.jpg" border="0" width="317" /></div>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/C2CDE5A4-0BBF-4AEC-9EA5-3B8767BBE33A.jpg" alt="C2CDE5A4-0BBF-4AEC-9EA5-3B8767BBE33A.jpg" border="0" width="290" /></div>
</p>
<p>From the partial with respect to <em>a</em>, we get that</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/787BDA81-F90A-475D-B546-68B931C7909E.jpg" alt="787BDA81-F90A-475D-B546-68B931C7909E.jpg" border="0" width="90" /></div>
<p>and from the partial with respect to <em>b</em>, we get that</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/47B35F40-060C-4284-B9B4-685A3A260F09.jpg" alt="47B35F40-060C-4284-B9B4-685A3A260F09.jpg" border="0" width="43"/></div>
<p>(since the mean is just the normalized sum).
</p>
<p>Now, let&#8217;s shift the coordinate system so that <span style="text-decoration:overline">y</span> (and <span style="text-decoration:overline">f</span>) are equal to zero. This makes the equations much simpler, and doesn&#8217;t affect the generality of the result.
</p>
<p>The equation for R<sup>2</sup> is now</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/6F70842F-4123-4A47-BF47-F5827D52607F.jpg" alt="6F70842F-4123-4A47-BF47-F5827D52607F.jpg" border="0" width="230" /></div>
<p>And the equation for correlation is now</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/BBB57FF2-F3A3-479D-8352-78E019AD2996.jpg" alt="BBB57FF2-F3A3-479D-8352-78E019AD2996.jpg" border="0" width="250" /></div>
<p>And we are done.
</p>
<p>Notice that this result is true for any model fit that meets the assumptions that we outlined above (squared-error loss, optimality under shifting and scaling). Linear regression (with an intercept) fits this criterion, but so can other model-fitting techniques — generalized additive models, polynomial fits, decision (regression) trees, ensemble methods — if the proper loss function is used.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/11/DecisionTree.png" alt="DecisionTree.png" border="0" width="550" height="450" /></div>
</p>
<p>To repeat: for optimal models (under squared-error loss, shift and scale invariance), R<sup>2</sup> is the square of the correlation between the true and predicted outcomes. This relationship is not true for general <em>f</em> and <em>y</em>.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2011/11/correlation-and-r-squared/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The equivalence of logistic regression and maximum entropy models</title>
		<link>http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-equivalence-of-logistic-regression-and-maximum-entropy-models</link>
		<comments>http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 16:21:09 +0000</pubDate>
		<dc:creator>John Mount</dc:creator>
				<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Calculus of Variations]]></category>
		<category><![CDATA[log-likelihood]]></category>
		<category><![CDATA[Logistic Regression]]></category>
		<category><![CDATA[Max-Ent]]></category>
		<category><![CDATA[Maximum Entropy]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1753</guid>
		<description><![CDATA[Nina Zumel recently gave a very clear explanation of logistic regression ( The Simpler Derivation of Logistic Regression ). In particular she called out the central role of log-odds ratios and demonstrated how the &#8220;deviance&#8221; (that mysterious quantity reported by fitting packages) is both a term in &#8220;the pseudo-R^2&#8243; (so directly measures goodness of fit) [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/' rel='bookmark' title='Learn Logistic Regression (and beyond)'>Learn Logistic Regression (and beyond)</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Nina Zumel recently gave a very clear explanation of logistic regression ( <a target="_blank" href="http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/">The Simpler Derivation of Logistic Regression</a> ).  In particular she called out the central role of log-odds ratios and demonstrated how the &#8220;deviance&#8221; (that mysterious<br />
quantity reported by fitting packages) is both a term in &#8220;the pseudo-R^2&#8243; (so directly measures goodness of fit) and is the quantity that is actually optimized during the fitting procedure.  One great point of the writeup was how simple everything is once you start thinking in terms of derivatives (and that it isn&#8217;t so much the functional form of the sigmoid that is special but its relation to its own derivative that is special).</p>
<p>We adapt these presentation ideas to make explicit the well known equivalence of logistic regression and maximum entropy models.<span id="more-1753"></span>In our new writeup: <a target="_blank" href="http://www.win-vector.com/dfiles/LogisticRegressionMaxEnt.pdf">The equivalence of logistic regression and maximum entropy models</a>  we move to multi-category modeling and demonstrate how one invents something as remarkable as logistic regression.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/' rel='bookmark' title='Learn Logistic Regression (and beyond)'>Learn Logistic Regression (and beyond)</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Simpler Derivation of Logistic Regression</title>
		<link>http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-simpler-derivation-of-logistic-regression</link>
		<comments>http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 15:36:37 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[likelihood]]></category>
		<category><![CDATA[log-likelihood]]></category>
		<category><![CDATA[Logistic Regression]]></category>
		<category><![CDATA[newton's method]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1740</guid>
		<description><![CDATA[Logistic regression is one of the most popular ways to fit models for categorical data, especially for binary response data. It is the most important (and probably most used) member of a class of models called generalized linear models. Unlike linear regression, logistic regression can directly predict probabilities (values that are restricted to the (0,1) [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/' rel='bookmark' title='Learn Logistic Regression (and beyond)'>Learn Logistic Regression (and beyond)</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Logistic regression is one of the most popular ways to fit models for categorical data, especially for binary response data. It is the most important (and probably most used) member of a class of models called generalized linear models. Unlike linear regression, logistic regression can directly predict probabilities (values that are restricted to the (0,1) interval); furthermore, those probabilities are well-calibrated when compared to the probabilities predicted by some other classifiers, such as Naive Bayes. Logistic regression preserves the marginal probabilities of the training data. The coefficients of the model also provide some hint of the relative importance of each input variable.</p>
<p> While you don&#8217;t have to know how to derive logistic regression or how to implement it in order to use it, the details of its derivation give important insights into interpreting and troubleshooting the resulting models. Unfortunately, most derivations (like the ones in [Agresti, 1990] or [Hastie, et.al, 2009]) are too terse for easy comprehension. Here, we give a derivation that is less terse (and less general than Agresti&#8217;s), and we&#8217;ll take the time to point out some details and useful facts that sometimes get lost in the discussion.<span id="more-1740"></span><br/><br/>To make the discussion easier, we will focus on the binary response case. We assume that the case of interest (or &#8220;true&#8221;) is coded to 1, and the alternative case (or &#8220;false&#8221;) is coded to 0.</p>
<p>The logistic regression model assumes that the log-odds of an observation <em>y</em> can be expressed as a linear function of the K input variables <strong>x</strong>:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/B437C723-50ED-4B7B-97B6-56D36C66CD3C.jpg" alt="B437C723-50ED-4B7B-97B6-56D36C66CD3C.jpg" border="0" width="189" /></div>
<p>Here, we add the constant term <em>b<sub>0</sub></em>, by setting <em>x<sub>0</sub></em> = 1. This gives us  K+1 parameters. The left hand side of the above equation is called the <em>logit</em><sun> of P (hence, the name logistic regression). </p>
<p>Let&#8217;s take the exponent of both sides of the logit equation.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/B4F430F4-5B17-4151-B7B9-AD0282034582.jpg" alt="B4F430F4-5B17-4151-B7B9-AD0282034582.jpg" border="0" width="200" /></div>
<p>This immediately tells us that logistic models are multiplicative in their inputs (rather than additive, like a linear model), and it gives us a way to interpret the coefficients. The value exp(<em>b<sub>j</sub></em>) tells us how the odds of the response being &#8220;true&#8221; increase (or decrease) as <em>x<sub>j</sub> </em>increases by one unit, all other things being equal. For example, suppose <em>b<sub>j</sub></em> = 0.693. Then exp(<em>b<sub>j</sub></em>) = 2. If <em>x<sub>j</sub></em> is a numerical variable (say, age in years), then every year&#8217;s increase in age doubles the odds of the response being true — all other things being equal. If <em>x<sub>j</sub> </em>is a binary variable (say, sex, with female coded as 1 and male as 0), then if the subject is female, then the response is two times more likely to be true than if the subject is male, all other things being equal.</p>
<p>We can also invert the logit equation to get a new expression for P(x):</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/9512CE26-F521-4F55-A9C7-2F951C8CD791.jpg" alt="9512CE26-F521-4F55-A9C7-2F951C8CD791.jpg" border="0" width="141" /></div>
<p><br/>The right hand side of the top equation is the sigmoid of <em>z</em>, which maps the real line to the interval (0, 1), and is approximately linear near the origin. A useful fact about P(<em>z</em>) is that the derivative P&#8217;(<em>z</em>) = P(<em>z</em>) (1 &#8211; P(<em>z</em>)). Here&#8217;s the derivation:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/B2F9E40A-5775-47FE-B582-28B62F19BE99.jpg" alt="B2F9E40A-5775-47FE-B582-28B62F19BE99.jpg" border="0" width="600" /></div>
<p>Later, we will want to take the gradient of P with respect to the set of coefficients <strong>b</strong>, rather than <em>z</em>. In that case, P&#8217;(<em>z</em>) = P(<em>z</em>) (1 &#8211; P(<em>z</em>))<em>z</em>&#8216;, where &#8216; is the gradient taken with respect to <strong>b</strong>.</p>
<p>The solution to a Logistic Regression problem is the set of parameters <strong>b</strong> that maximizes the likelihood of the data, which is expressed as the product of the predicted probabilities of the N individual observations.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/2FC8A9C0-D435-459A-8D58-5B183EF952F5.jpg" alt="2FC8A9C0-D435-459A-8D58-5B183EF952F5.jpg" border="0" width="340" /></div>
<p>(<em>X, y</em>) is the set of observations; <em>X</em> is a K+1 by N matrix of inputs, where each column corresponds to an observation, and the first row is <strong>1</strong>; <em>y</em> is an N-dimensional vector of responses; and (<strong>x</strong><sub>i</sub>, <em>y<sub>i</sub></em>) are the individual observations.</p>
<p>It&#8217;s generally easier to work with the log of this expression, known (of course) as the log-likelihood.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/B4A3F94A-D4B5-4391-ABFD-C872839F3CFC.jpg" alt="B4A3F94A-D4B5-4391-ABFD-C872839F3CFC.jpg" border="0" width="412" /></div>
<p>Maximizing the log-likelihood will maximize the likelihood. As a side note, the quantity −2*log-likelihood is called the <em>deviance</em> of the model. It is analogous to the residual sum of squares (RSS) of a linear model. Ordinary least squares minimizes RSS; logistic regression minimizes deviance. A useful goodness-of-fit heuristic for a logistic regression model is to compare the deviance of the model with the so-called <em>null deviance</em>: the deviance of the constant model that returns only the global response probability for every data point. One minus the ratio of deviance to null deviance is sometimes called <em>pseudo-R<sup>2</sup></em>, and is used the way one would use R<sup>2</sup> to evaluate a linear model.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/E5A7630A-2EA5-47A3-9A8A-10BF46B64F6A.jpg" alt="E5A7630A-2EA5-47A3-9A8A-10BF46B64F6A.jpg" border="0" width="241" /></div>
<p><br/>Traditional derivations of Logistic Regression tend to start by substituting the logit function directly into the log-likelihood equations, and expanding from there. The derivation is much simpler if we don&#8217;t plug the logit function in immediately. To maximize the log-likelihood, we take its gradient with respect to <strong>b</strong>:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/B2673255-4B13-4FF1-88F8-ACF004F28518.jpg" alt="B2673255-4B13-4FF1-88F8-ACF004F28518.jpg" border="0" width="260" /></div>
<p>where P<sub>i</sub> is shorthand for P(<string>x</strong><sub>i</sub>). The maximum occurs where the gradient is zero.</p>
<p>We can expand this equation further, when we remember that P&#8217; = P(1-P):</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/C6B59E85-25AB-4537-A1C1-3664A98EEE00.jpg" alt="C6B59E85-25AB-4537-A1C1-3664A98EEE00.jpg" border="0" width="352" /></div>
<p>The last line merges the two cases (<em>y<sub>i</sub></em> = 1 and <em>y<sub>i</sub></em> = 0) into a single sum. We can now cancel terms and set the gradient to zero. This gives us the set of simultaneous equations that are true at the optimum:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/9D60BD95-E4E0-40AF-9350-01DA19EFE845.jpg" alt="9D60BD95-E4E0-40AF-9350-01DA19EFE845.jpg" border="0" width="150" /></div>
<p>Notice that the equations to be solved are in terms of the probabilities P (which are a function of <strong>b</strong>), not directly in terms of the coefficients <strong>b</strong> themselves. This means that logistic models are coordinate-free: for a given set of input variables, the probabilities returned by the model will be the same even if the variables are shifted, combined, or rescaled. Only the values of the coefficients will change.</p>
<p>The other thing to notice from the above equations is that the sum of probability mass across each coordinate of the <strong>x</strong><sub>i</sub> vectors is equal to the count of observations with that coordinate value for which the response was true. For example, suppose the jth input variable is 1 if the subject is female, 0 if the subject is male. Then </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/2357AF36-1D0E-4EF1-88A9-8694220B62E4.jpg" alt="2357AF36-1D0E-4EF1-88A9-8694220B62E4.jpg" border="0" width="211" /></div>
<p>In other words, the summed probability mass for the female subjects equals the count of female subjects with the response &#8220;true&#8221;. It is also true that the sum of all the probability mass over the entire training set will equal the number of &#8220;true&#8221; responses in the training set. This is what we mean when we say that logistic regression preserves the marginal probabilities of the training data.</p>
<p><strong>Solving for the Coefficients</strong></p>
<p>The most straightforward way to solve for the coefficients <strong>b</strong> is Newton&#8217;s method. The Fisher scoring method that is used in most off-the-shelf implementations is a more general variation of Newton&#8217;s method; it works on the same principles. We will describe solving for the coefficients using Newton&#8217;s method.</p>
<p>Suppose you have a vector valued function <strong>f</strong>: <strong> y = f(b)</strong>.  You want to find the value <strong>b</strong><sub>opt</sub> such that  <strong>f(b)</strong><sub>opt</sub> = <strong>0</strong>. Assuming that we start with an initial guess <strong>b</strong><sub>0</sub>, we can take the Taylor expansion of <strong>f</strong> around <strong>b</strong><sub>0</sub>:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/DCAFCF7F-1991-4005-8CAD-39F5002B9C6C.jpg" alt="DCAFCF7F-1991-4005-8CAD-39F5002B9C6C.jpg" border="0" width="237" /></div>
<p>Here, <strong>f</strong>&#8216;  is a matrix; it is the Jacobean of first derivatives of <strong>f</strong> with respect to <strong>b</strong>. Setting the left hand side to zero, we can solve for &#916 as </p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/7447A740-4D4A-4BC5-AC66-45D9CF2665DD.jpg" alt="7447A740-4D4A-4BC5-AC66-45D9CF2665DD.jpg" border="0" width="176" /></div>
<p>We then update our estimate for <strong>b</strong>:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/6D54A73B-69F1-4B5B-9103-80AC40A0D08D.jpg" alt="6D54A73B-69F1-4B5B-9103-80AC40A0D08D.jpg" border="0" width="108" /></div>
<p>and iterate until convergence.</p>
<p>In our case, <strong>f</strong> is the gradient of the log-likelihood, and its Jacobean is the Hessian (the matrix of second derivatives) of the log-likelihood function.</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/F52762C7-618B-45AC-8396-01A228D0A54E.jpg" alt="F52762C7-618B-45AC-8396-01A228D0A54E.jpg" border="0" width="203" /></div>
<p>where <strong>W</strong> is a diagonal matrix of the derivatives P&#8217;<sub>i</sub>, and the ith column of <strong>X</strong> corresponds to the ith observation. So we can solve for &#916 at each iteration as</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/16E1E7D7-1EEF-43A6-BA5C-B77CBA2E2EED.jpg" alt="16E1E7D7-1EEF-43A6-BA5C-B77CBA2E2EED.jpg" border="0" width="239" /></div>
<p>where <strong>W</strong> is the current matrix of derivatives, <strong>y</strong> is the vector of observed responses, and <strong>P</strong><sub>k</sub> is the vector of probabilities as calculated by the current estimate of <strong>b</strong>.</p>
<p>Compare this to the solution of a linear regression:</p>
<div style="text-align:center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2011/09/2B73A3FE-3667-4BCF-BC67-B5A701014785.jpg" alt="2B73A3FE-3667-4BCF-BC67-B5A701014785.jpg" border="0" width="152"/></div>
<p>Comparing the two, we can see that at each iteration, &#916 is the solution of a weighted least square problem, where the &#8220;response&#8221; is the difference between the observed response and its current estimated probability of being true. This is why the technique for solving logistic regression problems is sometimes referred to as <em>iteratively re-weighted least squares</em>. Generally, the method does not take long to converge (about 6 or so iterations).</p>
<p>Thinking of logistic regression as a weighted least squares problem immediately tells you a few things that can go wrong, and how. For example, if some of the input variables are correlated, then the Hessian <strong>H</strong> will be ill-conditioned, or even singular. This will result in large error bars (or &#8220;loss of significance&#8221;) around the estimates of certain coefficients. It can also result in coefficients with excessively large magnitudes, and often the wrong sign. If an input perfectly predicts the response for some subset of the data (but not all), then the term P<sub>i</sub> (1 &#8211; P<sub>i</sub>) will be driven to zero for that subset, which will drive the coefficient for that input to infinity (if the input perfectly predicted all the data, then the residual (<strong>y</strong> &#8211; <strong>P</strong><sub>k</sub>) has already gone to zero, which means that you are already at the optimum).</p>
<p>On the other hand, the least squares analogy also gives us the solution to these problems: <em>regularized regression</em>, such as lasso or ridge. Regularized regression penalizes excessively large coefficients, and keeps them bounded. If you are implementing your own logistic regression procedure, rather than using a package, then it is straightforward to implement a regularized least squares for the iteration step (<a href="http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/">as Win-Vector has done</a>). But even if you are using an off-the-shelf implementation, the above discussion will help give you a sense of how to interpret the coefficients of your model, and how to recognize and troubleshoot some issues that might arise.</p>
<p><strong>Conclusion</strong></p>
<p>Here is what you should now know from going through the derivation of logistic regression step by step: </p>
<p>- Logistic regression models are multiplicative in their inputs. <br/></p>
<p>- The exponent of each coefficient tells you how a unit change in that input variable affects the odds ratio of the response being true. </p>
<p>- Logistic regression is coordinate-free: translations, rotations, and rescaling of the input variables will not affect the resulting probabilities. </p>
<p>- Logistic regression preserves the marginal probabilities of the training data. <br/></p>
<p>- Overly large coefficient magnitudes, overly large error bars on the coefficient estimates, and the wrong sign on a coefficient could be indications of correlated inputs. </br></p>
<p>- Coefficients that tend to infinity could be a sign that an input is perfectly correlated with a subset of your responses. Or put another way, it could be a sign that this input is only really useful on a subset of your data, so perhaps it is time to segment the data. </p>
<p>- Pseudo-R<sup>2</sup> is a useful goodness-of-fit heuristic. <br/></p>
<p><strong>References</strong></p>
<p>[Agresti, 1990] Agresti, A. (1990). Categorical Data Analysis.</p>
<p>[Hastie, et.al, 2009] Hastie, T., R. Tibshirani, and J. Friedman (2009). The Elements of Statistical Learning, 2nd Edition.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/' rel='bookmark' title='Learn Logistic Regression (and beyond)'>Learn Logistic Regression (and beyond)</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Your Data is Never the Right Shape</title>
		<link>http://www.win-vector.com/blog/2011/07/your-data-is-never-the-right-shape/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=your-data-is-never-the-right-shape</link>
		<comments>http://www.win-vector.com/blog/2011/07/your-data-is-never-the-right-shape/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 20:27:00 +0000</pubDate>
		<dc:creator>John Mount</dc:creator>
				<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Data Mining]]></category>
		<category><![CDATA[plyr]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[reshape]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1687</guid>
		<description><![CDATA[One of the recurring frustrations in data analytics is that your data is never in the right shape. Worst case: you are not aware of this and every step you attempt is more expensive, less reliable and less informative than you would want. Best case: you notice this and have the tools to reshape your [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/08/a-demonstration-of-data-mining/' rel='bookmark' title='A Demonstration of Data Mining'>A Demonstration of Data Mining</a></li>
<li><a href='http://www.win-vector.com/blog/2009/08/good-graphs-graphical-perception-and-data-visualization/' rel='bookmark' title='Good Graphs: Graphical Perception and Data Visualization'>Good Graphs: Graphical Perception and Data Visualization</a></li>
<li><a href='http://www.win-vector.com/blog/2009/04/the-data-enrichment-method/' rel='bookmark' title='The Data Enrichment Method'>The Data Enrichment Method</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>One of the recurring frustrations in data analytics is that your data is never in the right shape.  Worst case: you are not aware of this and every step you attempt is more expensive, less reliable and less informative than you would want.  Best case: you notice this and have the tools to reshape your data.  </p>
<p>There is no final &#8220;right shape.&#8221;  In fact even your data is never right. You will always be called to re-do your analysis (new variables, new data, corrections) so you should always understand you are on your &#8220;penultimate analysis&#8221; (always one more to come).  This is why we insist on using general methods and scripted techniques, as these methods are much much easier to reliably reapply on new data than GUI/WYSWYG techniques.</p>
<p>In this article we will work a small example and call out some <a target="_blank" href="http://cran.r-project.org/">R</a> tools that make reshaping your data much easier.  The idea is to think in terms of &#8220;relational algebra&#8221; (like SQL) and transform your data towards your tools (and not to attempt to adapt your tools towards the data in an ad-hoc manner).<span id="more-1687"></span>Take a simple example where you are designing a new score called &#8220;<code>score2</code>&#8221; to predict or track an already known value called &#8220;<code>score1</code>.&#8221;  The typical situation is <code>score1</code> is a future outcome (such as the number of dollars profit on a transaction) and <code>score2</code> is a prediction (such as the estimated profit before the transaction is attempted).  Training data is usually assembled by performing a large number of transactions, recording what was known before the transaction and then aligning or joining this data with measured results when they become available.  For this example we are not interested in the inputs driving the model (a rare situation, but we are trying to make our example as simple as possible) but only examining the quality of <code>score2</code> (which is defined as how well it tracks <code>score1</code>).</p>
<p>All of this example will be in R, but the principles are chosen apply more generally.  First let us enter some example data:</p>
<p><code><br />
<br/> &gt; d &lt;- data.frame(id=c(1,2,3,1,2,3),score1=c(17,5,6,10,13,7),score2=c(13,10,5,13,10,5))<br />
<br/> &gt; d<br />
</code></p>
<p>This gives us our example data.  Each row is numbered (1 through 6) has an <code>id</code> and both our scores:</p>
<pre>
  id score1 score2
1  1     17     13
2  2      5     10
3  3      6      5
4  1     10     13
5  2     13     10
6  3      7      5
</pre>
<p>We said our only task was to characterize how well <code>score2</code> works at predicting <code>score1</code> (or how good a substitute <code>score2</code> is for <code>score1</code>).  We could compute correlation, RMS error, info-gain or some such.  But instead lets look at this graphically.  We will prepare a graph showing how well <code>score1</code> is represented by <code>score2</code>.  For this we choose to place <code>score1</code> on the y-axis (as it is the outcome) and <code>score2</code> on the x-axis (as it is the driver).</p>
<p><code><br />
<br/> &gt; library(ggplot2)<br />
<br/> &gt; ggplot(d) + geom_point(aes(x=score2,y=score1))<br />
</code></p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2011/07/plot1.png" alt="plot1.png" border="0" width="525" height="525" /></p>
<p>Figure 1: <code>score1</code> as a function of  <code>score2</code>.</p>
<p></center></p>
<p>This does not look good.  We would liked to have seen all of the dots falling on the line &#8220;y=x.&#8221;  This plot shows <code>score2</code> is not predicting <code>score1</code> very well.  Part of this is that we missed an important feature of the data (and because we missed it the feature becomes a problem): the <code>id</code>s repeat.  First we re-order by <code>id</code> to make this more obvious.</p>
<p><code><br />
<br/> &gt; dsort &lt;- d[order(d$id),]<br />
<br/> &gt; dsort<br />
</code></p>
<pre>
  id score1 score2
1  1     17     13
4  1     10     13
2  2      5     10
5  2     13     10
3  3      6      5
6  3      7      5
</pre>
<p>This is a very common situation.  The original score is not completely a function of the known inputs.  We are using &#8220;<code>id</code>&#8221; to abstract represent all of the inputs, two rows in our example have the same <code>id</code> if and only if all known inputs are exactly the same.  The repeating <code>id</code>s are the same experiment run at different times (a good idea) and the variation in <code>score1</code> could be the effect of an un-modeled input that changed value or something simple like a &#8220;noise term&#8221; (a random un-modeled effect).   Notice that <code>score2</code> is behaving as a function of <code>id</code>- all rows with the same <code>id</code> have the same value for <code>score2</code>.  If <code>score2</code> is a model then it has to be a function of the inputs (or more precisely if it is not a function of the inputs you have done something wrong).  So any variation of <code>score1</code> between rows with identical <code>id</code> is &#8220;unexplainable variation&#8221; (unexplainable from the point of view of currently tracked inputs).  You should know about, characterize and report this variation (why it is good to have some repeated experiments).  But this variation is not the model&#8217;s fault, if we want to know how good a job we did constructing the model (which we now see can be a slightly different question than how well the model works at prediction) we need to see how much of the explainable variation the model accounts for.</p>
<p>If we assume (as is traditional) the unexplained variation is from a &#8220;unbiased noise source&#8221; then we can lessen the impact of the noise source by replacing <code>score1</code> with a value averaged over rows with the same <code>id</code>.  This assumption is traditional because an unbiased noise source is present in many problems and assuming anything more requires more research into the problem domain.   You would eventually fold such research into your model- so your goal is always have all effects or biases in your model and hope what is left over is unbiased.  This is usually not strictly true, but not accounting for the unexplained variation at all is in many cases even worse than modeling the unexplained variation as being bias-free.</p>
<p>And now we find our data is the &#8220;wrong shape.&#8221;  To replace <code>score1</code> with the appropriate averages we need to do some significant data manipulation.  We need to group sets of rows and add new columns. We could do this imperatively (write some loops and design some variables to track and manipulate state) or declaratively (find a path of operations from what you have to what you need through R&#8217;s data manipulation algebra).  Even though the declarative method is more work the first time (you could often write the code in less time than it takes to read the manuals) it is the right way to go (as it is more versatile and powerful in the end).</p>
<p>Luckily we don&#8217;t have to use raw R.  There are a number of remarkable packages (all by <a target="_blank" href="http://had.co.nz/">Hadley Wickham</a> who is also the author of the <a target="_blank" href="http://had.co.nz/ggplot2/">ggplot2</a> package we use to prepare our figures) that really improve R&#8217;s ability to coherently manage data.  The easiest (on us) way do fix up our data is to make the computer work hard and use the powerful melt/cast technique.  These functions are found in the libraries <a target="_blank" href="http://www.jstatsoft.org/v21/i12/paper">reshape</a> and <a target="_blank" href="http://www.jstatsoft.org/v40/i01/paper">plyr</a> (which were automatically loaded with we loaded ggplot2 library).</p>
<p>melt is a bit abstract.  What it does convert your data into a &#8220;narrow&#8221; format where rows are split into many rows each carrying just one result column of the original row.  For example we can melt our data by <code>id</code> as follows:</p>
<p><code><br />
<br/> &gt; dmelt &lt;- melt(d,id.vars=c('id'))<br />
<br/> &gt; dmelt<br />
</code></p>
<p>Which yields the following:</p>
<pre>
   id variable value
1   1   score1    17
2   1   score1    10
3   2   score1     5
4   2   score1    13
5   3   score1     6
6   3   score1     7
7   1   score2    13
8   1   score2    13
9   2   score2    10
10  2   score2    10
11  3   score2     5
12  3   score2     5
</pre>
<p>Each of the two facts (<code>score1</code>, <code>score2</code>) from our original row is split into its own row.  The <code>id</code> column plus the new variable column are now considered to be keys.  This format is not used directly but used because it is easy to express important data transformations in terms of it.  For instance we wanted our table to have duplicate rows collected and <code>score1</code> replaced by its average (to attempt to remove the unexplainable variation).  That is now easy:</p>
<p><code><br />
<br/> &gt; dmean &lt;- cast(dmelt,fun.aggregate=mean)<br />
<br/> &gt; dmean<br />
</code></p>
<pre>
  id score1 score2
1  1   13.5     13
2  2    9.0     10
3  3    6.5      5
</pre>
<p>We used <code>cast()</code> in its default mode, where it assumes all columns not equal to &#8220;value&#8221; are the keyset.  It then collects all rows with identical keying and combines them back into wide rows using mean or average as the function to deal with duplicates.  Notice <code>score1</code> is now the desired average, and <code>score2</code> is as before (as it was a function of the keys or inputs, so it is not affected by averaging).  With this new smaller data set we can re-try our original graph:</p>
<p><code><br />
<br/> &gt; ggplot(dmean) + geom_point(aes(x=score2,y=score1))<br />
</code></p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2011/07/plot2.png" alt="plot2.png" border="0" width="525" height="525" /></p>
<p>Figure 2: <code>mean(score1)</code> as a function of  <code>score2</code>.</p>
<p></center></p>
<p>This doesn&#8217;t look so bad.  A lot of the error or variation in the first plot was unexplainable variation.  <code>score2</code> isn&#8217;t bad given its inputs.  If you wanted to do better than <code>score2</code> you would be advised to find more modeling inputs (versus trying more exotic modeling techniques).</p>
<p>Of course a client or user is not interested if <code>score2</code> is &#8220;best possible.&#8221;  They want to know if it is any good.  To do this we should show them (either by graph or by quantitative summary statistics like we mentioned earlier) at least 3 things:</p>
<ol>
<li>How well the model predicts overall (the very first graph we presented).</li>
<li>How much of the explainable variation the model predicts (the second graph).</li>
<li>The nature of the unexplained variation (which we will explore next).</li>
</ol>
<p>We said earlier we are hoping the unexplained variation is noise (or if it is not noise it would be nice if it is a clue to new important modeling features).  So the unexplained variation must not go unexamined.  We will finish by showing how to characterize the unexplained variation.  As before will will just make a graph, but the data preparation steps would be exactly the same if we were using a quantitive summary (like correlation, or any other).  And, of course, our data is still not the right shape for this step.  Luckily there is another tool ready to fix this: <code>join()</code>.</p>
<p><code><br />
<br/> &gt; djoin &lt;- join(dsort,dsort,'id')<br />
<br/> &gt; fixnames &lt;- function(cn) {<br />
     n &lt;- length(cn);<br />
     for(i in 2:((n+1)/2)) { cn[i] &lt;- paste('a',cn[i],sep='') };<br />
     for(i in ((n+3)/2):n) { cn[i] &lt;- paste('b',cn[i],sep='') };<br />
     cn<br />
  }<br />
<br/> &gt; colnames(djoin) &lt;- fixnames(colnames(djoin))<br />
<br/> &gt; djoin<br />
</code></p>
<p>which produces:</p>
<pre>
   id ascore1 ascore2 bscore1 bscore2
1   1      17      13      17      13
2   1      17      13      10      13
3   1      10      13      17      13
4   1      10      13      10      13
5   2       5      10       5      10
6   2       5      10      13      10
7   2      13      10       5      10
8   2      13      10      13      10
9   3       6       5       6       5
10  3       6       5       7       5
11  3       7       5       6       5
12  3       7       5       7       5
</pre>
<p>All of the work was done by the single line &#8220;<code>djoin &lt;- join(dsort,dsort,'id')</code>&#8221; the rest was just fixing the column names (as self-join is not the central use case of join).  What we have now is a table that is exactly right for studying unexplained variation.  For each <code>id</code> we have each row with the same <code>id</code> matched.  This blows every <code>id</code> from having 2 rows in <code>dsort</code> to 4 rows in <code>djoin</code>.  Notices this gives us every pair of <code>score1</code> values seen for the same <code>id</code> (which will let us examine unexplained variation) and <code>score2</code> is still constant over all rows with the same <code>id</code> (as it has always been throughout our analysis).  With this table we can now plot how <code>score1</code> varies for rows with the same <code>id</code>:</p>
<p><code><br />
<br/> &gt; ggplot(djoin) + geom_point(aes(x=ascore1,y=bscore1))<br />
</code></p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2011/07/unex.png" alt="unex.png" border="0" width="525" height="525" /></p>
<p>Figure 3: <code>score1</code> as a function of  <code>score1</code>.</p>
<p></center></p>
<p>And we can see, as we expected, the unexplained variation in <code>score1</code> is about as large as the mismatch between <code>score1</code> and <code>score2</code> in our original plot.  The important thing is this is all about <code>score1</code> (<code>score2</code> is now literally out of the picture).  The analyst&#8217;s job would now be to try and tie bits of the unexplained variation to new inputs (that can be folded into a new <code>score2</code>) and/or characterize the noise term (so the customer knows how close they should expect repeated experiments to be).</p>
<p>What we are trying to encourage with the use of &#8220;big hammer tools&#8221; is an ability and willingness to look at and transform your data in meaningful steps.  It often seems easier and more efficient to build one more piece of data tubing, but a lot of data tubes become an unmanageable collection of spaghetti code.  The analyst should, in some sense, always be looking at data and not looking at coding details.  For these sort of analyses we encourage analysts to think in terms of &#8220;data shape&#8221; and transforms.  This discipline leaves more of the analysts energy and attention to think productively about the data and actual problem domain.</p>
<hr />
Note:</p>
<p>For the third plot showing the variation of <code>score1</code> across different rows (but same <code>id</code>s) it may be appropriate to use a slightly more complicated <code>join()</code> procedure than we showed.  The join shown produced rows of artificial agreement where both values of <code>score1</code> came from the same row (thus had no chance of being different, so in some sense deserve no credit).  This is also the only way any non-duplicated evaluations could make it to the plot.  To eliminate these uninteresting agreements from the plot do the following:</p>
<p><code><br />
<br/> &gt; d$rowNumber &lt;- 1:(dim(d)[1])<br />
<br/> &gt; djoin &lt;- join(d,d,'id')<br />
<br/> &gt; colnames(djoin) &lt;- fixnames(colnames(djoin))<br />
<br/> &gt; djoin &lt;- djoin[djoin$arowNumber!=djoin$browNumber,]<br />
<br/> &gt; djoin<br />
</code></p>
<p>This gives us a table that shows only values of <code>score1</code> from different rows:</p>
<pre>
   id ascore1 ascore2 arowNumber bscore1 bscore2 browNumber
2   1      17      13          1      10      13          4
4   2       5      10          2      13      10          5
6   3       6       5          3       7       5          6
7   1      10      13          4      17      13          1
9   2      13      10          5       5      10          2
11  3       7       5          6       6       5          3
</pre>
<p>And only plots points on the diagonal if &#8220;you have really earned them&#8221;:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2011/07/fig4.png" alt="fig4.png" border="0" width="525" height="525" /><br />
</center></p>
<p>So while the direct <code>join()</code> may not be the immediate perfect answer it is still a good intermediate to form as what you want is only simple data transformation away from it.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/08/a-demonstration-of-data-mining/' rel='bookmark' title='A Demonstration of Data Mining'>A Demonstration of Data Mining</a></li>
<li><a href='http://www.win-vector.com/blog/2009/08/good-graphs-graphical-perception-and-data-visualization/' rel='bookmark' title='Good Graphs: Graphical Perception and Data Visualization'>Good Graphs: Graphical Perception and Data Visualization</a></li>
<li><a href='http://www.win-vector.com/blog/2009/04/the-data-enrichment-method/' rel='bookmark' title='The Data Enrichment Method'>The Data Enrichment Method</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2011/07/your-data-is-never-the-right-shape/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learn Logistic Regression (and beyond)</title>
		<link>http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond</link>
		<comments>http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 06:18:33 +0000</pubDate>
		<dc:creator>John Mount</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Learn a Powerful Machine Learning Tool]]></category>
		<category><![CDATA[Logistic Regression]]></category>
		<category><![CDATA[Max-Ent]]></category>
		<category><![CDATA[Maximum Entropy]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Regularization]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1578</guid>
		<description><![CDATA[One of the current best tools in the machine learning toolbox is the 1930s statistical technique called logistic regression. We explain how to add professional quality logistic regression to your analytic repertoire and describe a bit beyond that.A statistical analyst working on data tends to deliberately start simple move cautiously to more complicated methods. When [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>One of the current best tools in the machine learning toolbox is the 1930s statistical technique called logistic regression.  We explain how to add professional quality logistic regression to your analytic repertoire and describe a bit beyond that.<span id="more-1578"></span>A statistical analyst working on data tends to deliberately start simple move cautiously to more complicated methods.  When first encountering data it is best to think in terms of visualization and exploratory data analysis (in the sense of Tukey).  But in the end the analyst is expected to deliver actionable decision procedures- not just pretty charts.  To get actionable advice the analyst will move up to more complicated tools like pivot tables and Naive Bayes.  Once the problem requires control of interactions and dependencies the analyst must move away from these tools and towards the more complicated statistical tools like standard regression, decision trees and logistic regression.  Beyond that we have machine learning tools such as: kernel methods, boosting, bagging, decision trees and support vector machines.  Which tool is best depends a lot on the situation- and the prepared analyst can quickly try many techniques.  Logistic regression is often a winning method and we will use this article to discuss logistic regression a bit deeper.  By the end of this writeup you should be able to use standard tools to perform a logistic regression and know some of the limitations you will want to work beyond.</p>
<p>Logistic regression was invented in the late 1930s by statisticians Ronald Fisher and Frank Yates.  The definitive resource on this (and other generalized linear models) is Alan Agresti &#8220;Categorical Data Analysis&#8221; 2002, New York, Wiley-Interscience.   Logistic regression is a &#8220;categorical&#8221; tool in that it is used to predict categories (fraud/not-fraud, good/bad &#8230;) instead of numeric scores (like standard regression).  For example: consider the &#8220;car&#8221; data set from the <a target="_blank" href="http://archive.ics.uci.edu/ml/">UCI machine learning database</a> ( <a  target="_blank" href="http://archive.ics.uci.edu/ml/machine-learning-databases/car/">data</a>, <a target="_blank" href="http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.names">description</a> ).  The data is taken from a consumer review of cars.  Each car is summarized by 6 attributes ( price, maintenance costs, doors, storage size, seating and safety ); there is also a conclusion column that contains the final overall recommendation (unacceptable, acceptable,  good, very good).  The machine learning problem is to infer the reviewer&#8217;s relative importance or weight of each feature.  This could be used to influence a cost constrained design of a future car.  This dataset was originally used to demonstrate hierarchical and decision tree based expert systems.  But logistic regression can quickly derive interesting results.</p>
<p>Let us perform a complete analysis together (at least in our imaginations if not with our actual computers).  First download and install the excellent free analysts workbench called <a target="_blan" href="http://www.R-project.org/">&#8220;R&#8221;</a>.  This software package is an implementation of John Chambers&#8217; S language (a statistical language designed to allow for self-service statistics to relieve some of Chambers&#8217; consulting responsibilities) and a near relative of the SPlus system.  This system is powerful and has a number of very good references (our current favorite being <a href="http://oreilly.com/catalog/9780596801717">Joseph Adler &#8220;R in a nutshell&#8221; 2009, O&#8217;Reilly Media</a>).  Using R  we can build an interesting model in 2 lines of code.</p>
<p>After installing R start the program and copy the following line into the R command shell.</p>
<pre>
CarData <- read.table(url('http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data'),
    sep=',',col.names=c('buying','maintenance','doors','persons','lug_boot','safety','rating'))
</pre>
<p>This has downloaded the car data directly from the UCI database and added a header line so we can refer to variables by name.  To see roll-ups or important summaries of our data we could just type in "summary(CarData)."  But we will move on with the promised modeling.  Now type in the following line:</p>
<pre>
logisticModel <- glm(rating!='unacc' ~ buying + maintenance + doors + persons + lug_boot +safety,
    family=binomial(link = "logit"),data=CarData)
</pre>
<p>We now have a complete logistic model.  To examine this model we type "summary(logisticModel)".  And see the following (rather intimidating) summary:</p>
<pre>
Coefficients:
                  Estimate Std. Error z value Pr(>|z|)
(Intercept)       -28.4255  1257.5255  -0.023    0.982
buyinglow           5.0481     0.5670   8.904  < 2e-16 ***
buyingmed           3.9218     0.4842   8.100 5.49e-16 ***
buyingvhigh        -2.0662     0.3747  -5.515 3.49e-08 ***
maintenancelow      3.4064     0.4692   7.261 3.86e-13 ***
maintenancemed      3.4064     0.4692   7.261 3.86e-13 ***
maintenancevhigh   -2.8254     0.4145  -6.816 9.36e-12 ***
doors3              1.8556     0.4042   4.591 4.41e-06 ***
doors4              2.4816     0.4278   5.800 6.62e-09 ***
doors5more          2.4816     0.4278   5.800 6.62e-09 ***
persons4           29.9652  1257.5256   0.024    0.981
personsmore        29.5843  1257.5255   0.024    0.981
lug_bootmed        -1.5172     0.3758  -4.037 5.40e-05 ***
lug_bootsmall      -4.4476     0.4750  -9.363  < 2e-16 ***
safetylow         -30.5045  1300.3428  -0.023    0.981
safetymed          -3.0044     0.3577  -8.400  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
</pre>
<p>We also saw the cryptic warning message "glm.fit: fitted probabilities numerically 0 or 1 occurred" which we will discuss later.  Returning to our result we see a left column that is formed by concatenating variable names and variable values (values are called "levels" when they are strings).  For example the label "buyinglow" is a combination of "buying" and "low" meaning a low purchase price.  The next column (and the last one we will dig into) is the score associated with this combination of variable and level.  The interpretation is that a care that has "buyinglow" is given a 5.0481 point score bonus.  Whereas a car with "safetylow" is given a -30.5045 scoring penalty.  In fact the complete prediction procedure for a new car is to look the levels specified for all 6 variables and add up the correct scores (plus the "(Intercept)" score of  -28.4255 which is used as an initial score).  Any value not found is assumed to be zero.  This summed-up score is called the "link" and is essentially the model prediction.  Positive link values are associated with acceptable cars and negative link values are associated with unacceptable cars.  For example the first car in our data set is:</p>
<pre>
  buying maintenance doors persons lug_boot safety rating
   vhigh       vhigh     2       2    small    low  unacc
</pre>
<p>According to the columns: we see above our scoring procedure assigns a very bad score of -68 to this car- correctly predicting the "unacc" rating.  We can examine the error rates of our model with the single line:</p>
<pre>
table(CarData$rating,predict(logisticModel,type='response')>=0.5)
</pre>
<p>While yields the result:</p>
<pre>
        FALSE TRUE
  acc      32  352
  good      0   69
  unacc  1166   44
  vgood     0   65
</pre>
<p>This diagram is called a "contingency table" and is a very powerful summary.  The rows are labeled with the ratings assigned at training time (unacceptable, acceptable, good and very good).  The columns FALSE and TRUE  denote the model predicted the car was unacceptable or at least acceptable.  From the row "unacc" we see that 1166 of the 1166+44 unacceptable cars were correctly predicted FALSE (or not at least acceptable).  Also notice the only face negatives are the 32 FALSEs in the "acc" row- none of the good or very good cars were predicted to be unacceptable.  We can also look at this graphically:</p>
<pre>
library(lattice)
densityplot(predict(logisticModel,type='link'),groups=CarData$rating!='unacc',auto.key=T)
</pre>
<p>Which yields the following graph:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/density1.png" alt="density1.png" border="0" width="525" height="525" /><br />
</center></p>
<p>This is an area density chart.  Each car that was defined as being unacceptable adds a single blue circle to the bottom of the chart.  Each car that was defined as being acceptable adds a single magenta circle to the bottom of the chart.  The left-right position of each circle is the link score the model assigned to the circle.  There are so many circles that they start to overlap into solid smudges.  To help with this charting software adds the density curves above the circles.  Density curves are a lot like histograms- the height of the curve indicates what fraction of the circles of the same color are under that region of the curve.  So we can see most of the blue circles are in 3 clusters centered at -55, -30 and -5 while the magenta circles are largely clustered around +5.  From a chart like this you can see that a decision procedure of saying a link score above zero is good and below zero is bad would be pretty accurate (most of the blue is to the left and most of the magenta is to the right).  In fact this rule would be over 95% accurate (though accuracy is not a be-all measure, see: <a target="_none" href="http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/">Accuracy Measures</a>).</p>
<p>So far so good.  We have built a model that accurately predicts conclusions based on inputs (so it could be used to generate new ratings) and furthermore our model has visible "Estimate" coefficients that report the relative strength of each feature (which we could use prescriptively in valuing trade-offs in designing a new car).  Except we need to go back to the warning message: "glm.fit: fitted probabilities numerically 0 or 1 occurred."  For a logistic regression the only way the model fitter can encounter "probabilities numerically 0 or 1" is if the link score was out of a reasonable range of zero (say +-20).  Remember we saw link scores as low as -68.  With a link score of -68 the probability of the car in question being acceptable is around 2*10^-16.  This from a training set that only included 1728 items (so really can not be expected to see events much rarer than one in a thousand. We are deliberately confusing two different types of probabilities here- but it is a good way to think). </p>
<p>What is the cause of these extreme link scores?  Extreme coefficient estimates.  The +29.96 preference for "persons4" (cars that seat 4) is a huge vote that swamps out effects from purchase price and maintenance cost.  The model has over fit and made some dangerous extreme assumptions.  What causes this are variable and level combinations that have no falsification in the data set.  For example: suppose only one car had the variable level "person4" and that car happened to be acceptable.  The logistic modeling package could always raise the link score of that single car by putting a bit more weight on the "person4" estimate.  Since this variable level shows up only in positive  examples (and in this case only one example) there is absolutely no penalty for increasing the coefficient.  Logistic regression models are built by an optimizer.  And when an optimizer finds a situation with no penalty- it abuses the situation to no end.  This is what the warning was reporting.  All link numbers map to probabilities between zero and one; only ridiculously large link values map to probabilities near one (and only ridiculously small values map to probabilities near zero).  The optimizer was caught trying to make some of the coefficients "run away" or "run to infinity."  There are some additional diagnostic signs (such as the large coefficients, large standard errors and low significant levels), but there is no advice offered by the system in how to deal with this.  The standard methods are to suppress problem variables and levels (or suppress data with the problem variables and levels present) from the model.  But this is inefficient in that the only way we have of preventing a variable from appearing to be too useful is not to use it.  These are exactly the variables we do not want to eliminate from the model, but they are unsafe to keep in the model (their presence can cause unreliable predictions on new data not seen during training).</p>
<p>What can we do to fix this?  We need to ensure that running a coefficient to infinity is not without cost.  One way to achieve this would be something like Laplace smoothing where we enter two made-up data items: one that has every level set on and is acceptable and one that has every level set on and is unacceptable.  Unfortunately there is no easy way to do this from the user-layer in R.  For example each datum can only have one value set for each categorical variable- so we can't define a datum that has all features on.  Another way to fix this would be to directly penalize large coefficients (like Tychonoff regularization in linear algebra).  Explicit regularization is a good idea and very much in the current style.  Again, unfortunately, the R user layer does not expose a regularization control to the user.  But one of the advantages of logistic regression is that it is relatively easy to implement (harder than Naive Bayes or standard regression in that it needs and optimizer, but easier than SVM in that the optimizer is fairly trivial).</p>
<p>The logistic regression optimizer works to find a model of probabilities p() that maximizes the sum:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/cost1.png" alt="cost1.png" border="0" width="644" height="56" /><br />
</center></p>
<p>Or in english: assign large probabilities to examples known to be positive and small probabilities to examples known to be negative.  Now the logistic model assigns probabilities using a function of the form:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/p.png" alt="p.png" border="0" width="244" height="83" /><br />
</center></p>
<p>The beta is the model parameters and the x is the data associated with a given example.  The dot product of beta and x is the link score we saw earlier.  The rest of the function is called the sigmoid (also used by neural nets) and its inverse is called the "logit" which is where logistic regression gets its name.  Now this particular function (and others have the so-called "canonical link") has the property that the gradient (the vector of derivative directions indicating the direction of most rapid score improvement) is particularly beautiful.  The gradient vector is:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/grad1.png" alt="grad1.png" border="0" width="410" height="56" /><br />
</center></p>
<p>This quantity is a vector because it is a weighted sum over the data_i (which are all vectors of feature values and value/level indicators).  As we expect the gradient to be zero at an optimal point we now have a set of equations we expect to be simultaneously satisfied at the optimal model parameters.  In fact these equations are enough to essentially determine the model- find parameter values that satisfy all of this vector equation and you have found the model (this is usually done by the Newton–Raphson method or by Fisher Scoring).  As an aside this is also the set of equations that the maximum entropy method must specify; which is why for probability problems maximum entropy and logistic regression models are essentially identical.  </p>
<p>If we directly add a penalty for large coefficients to our original scoring function as below:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/cost2.png" alt="cost2.png" border="0" width="731" height="56" /><br />
</center></p>
<p>Beta is (again) our model weights (laid out in the same order as the per-datum variables) and epsilon (>=0) is the new user control for regularization.  A small positive epsilon will cause regularization without great damage to model performance (for our example we used epsilon = 0.1). Now our optimal gradient equations (or set of conditions we must meet) become:</p>
<p><center><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2010/11/grad2b.png" alt="grad2b.png" border="0" width="485" height="56" /><br />
</center></p>
<p>Or- instead of the model having to reproduce all know feature summaries (if a feature is on in 30% of the positive training data then it must be on for 30% of the modeled positive probabilities) we now have a slop term of 2 epsilon beta.  To the extent a coefficient is large its matching summary is allowed slack (making it harder for the summary to drive the coefficient to infinity).  This system of equations is as easy to solve as the original system (a slightly different update is used in the Newton-Raphson method) and we get a solution as below:</p>
<pre>
variable	kind		level	value
		Intercept		-2.071592578277024
buying		Categorical	high	-1.8456895489650629
buying		Categorical	low	2.024816396087424
buying		Categorical	med	1.257553912038549
buying		Categorical	vhigh	-3.508273337437926
doors		Categorical	2	-1.8414721595612646
doors		Categorical	3	-0.391932359146582
doors		Categorical	4	0.08090597021546056
doors		Categorical	5more	0.08090597021546052
lug_boot	Categorical	big	0.8368739895290729
lug_boot	Categorical	med	-0.2858686820997001
lug_boot	Categorical	small	-2.62259788570632
maintenance	Categorical	high	-1.274387434600252
maintenance	Categorical	low	1.3677275941857292
maintenance	Categorical	med	1.3677275941857292
maintenance	Categorical	vhigh	-3.5326603320481342
persons		Categorical	2	-8.360699258777752
persons		Categorical	4	3.2937880724973065
persons		Categorical	more	2.9953186080035197
safety		Categorical	high	4.160122946359636
safety		Categorical	low	-8.028169713081502
safety		Categorical	med	1.7964541884449603
</pre>
<p>This model has essentially identical performance and much smaller coefficients.  From a performance point of view this is essentially the same model.  What has changed is the model no longer is able to pick up a small bonus by "piling on" a coefficient.  For example moving a link value to infinity moves the probabilities from 0.999 to 1.0 which in turn moves the data penalty (assuming the data point is positive) from log(0.999) to log(1.0) or from -0.001 to 0.0.  The approximate 1/1000 score improvement is offset by a penalty proportional to the size of the coefficient- making the useless "adding of nines" no longer worth it.  Or, as has become famous with large margin classifiers, it is important to improve what the model does on probability estimates near 0.5 not estimates already near 0 or 1.</p>
<p> As expected: the coefficients are significantly different than the standard logistic regression.  For example the original model has 3 variables with extreme levels (the intercept, number of passengers and safety) while the new model sees only extreme values (but much smaller) for number of persons and safety (which are likely correlated).  Also consider the difference between the buying levels low and very high in the original model (5 - -2 = 7) and in the new model (2 - -3.5 = 5.5) differ by 1.5 or around 3 of the reported standard deviations (indicating the significance summaries are not enough to certify the location of model parameters).  It is not just that all of the coefficients have shifted, many of the differences are smaller (and others are not- changing the emphasis of the model).  We don not want to overstate differences- we are not so much looking for something better than standard logistic regression as adding an automatic safety that saves us both the effort and loss of predictive power found in fixing models by suppressing unusually distributed (but useful) variables and levels.</p>
<p>An analyst is well served to have logistic regression (and the density plots plus contingency table summaries) as ready tools.  These methods will take you quite far.  And if you start hitting the limits of these tools you can, as we do, bring in custom tools that allow for explicit regularization yielding effective and reliable results.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2011/09/the-equivalence-of-logistic-regression-and-maximum-entropy-models/' rel='bookmark' title='The equivalence of logistic regression and maximum entropy models'>The equivalence of logistic regression and maximum entropy models</a></li>
<li><a href='http://www.win-vector.com/blog/2011/09/the-simpler-derivation-of-logistic-regression/' rel='bookmark' title='The Simpler Derivation of Logistic Regression'>The Simpler Derivation of Logistic Regression</a></li>
<li><a href='http://www.win-vector.com/blog/2010/12/large-data-logistic-regression-with-example-hadoop-code/' rel='bookmark' title='Large Data Logistic Regression (with example Hadoop code)'>Large Data Logistic Regression (with example Hadoop code)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2010/11/learn-a-powerful-machine-learning-tool-logistic-regression-and-beyond/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Living in A Lognormal World</title>
		<link>http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=living-in-a-lognormal-world</link>
		<comments>http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:46:37 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[customer value]]></category>
		<category><![CDATA[lognormal distribution]]></category>
		<category><![CDATA[long tail theory]]></category>
		<category><![CDATA[McPhee's Theory of Exposure]]></category>
		<category><![CDATA[median versus mean]]></category>
		<category><![CDATA[power law distribution]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1388</guid>
		<description><![CDATA[Recently, we had a client come to us with (among other things) the following question: Who is more valuable, Customer Type A, or Customer Type B? This client already tracked the net profit and loss generated by every customer who used his services, and had begun to analyze his customers by group. He was especially [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Recently, we had a client come to us with (among other things) the following question:<br />
Who is more valuable, Customer Type A, or Customer Type B?</p>
<p>This client already tracked the net profit and loss generated by every customer who used his services, and had begun to analyze his customers by group. He was especially interested in Customer Type A; his gut instinct told him that Type A customers were quite profitable compared to the others (Type B) and he wanted to back up this feeling with numbers.</p>
<p>He found that, on average, Type A customers generate about $92 profit per month, and Type B customers average about $115 per month (The data and figures that we are using in this discussion aren&#8217;t actual client data, of course, but a notional example). He also found that while Type A customers make up about 4% of the customer base, they generate less than 4% of the net profit per month. So Type A customers actually seem to be less profitable than Type B customers. Apparently, our client was mistaken.</p>
<p>Or was he? <span id="more-1388"></span></p>
<p>A little more elementary statistics revealed that the median profit generated by Type A customers is $65 — e.g., half the customers from group A generate more than $65 profit per month. The median for Type B customers is about $4.80 — so half the customers from group B generate less than five dollars profit every month. Maybe our client&#8217;s instincts aren&#8217;t completely off-base.</p>
<p>Let&#8217;s look at the distribution of net profit across both customer populations:</p>
<table border="0" align="center">
<tbody>
<tr>
<td>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/01/densityAll.png" border="0" alt="densityAll.png" width="500" /></div>
</td>
</tr>
</tbody>
<caption><em>Figure 1: Distribution of net profit for Type A customers (blue) and Type B customers (red). The x-axis gives the net profit or loss, and the y-axis gives the fraction of the population that generates a given net profit. </em><br />
</caption>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>This pattern is typical among the customers of many businesses. The majority of customers generate relatively moderate profit (or loss); but there is an important minority of large-profit and large-loss customers out on both tails. In this case, the monthly customer value actually ranges from losses in the tens of thousands to profits of several hundred thousands (I clipped the graph, for &#8220;clarity&#8221;).</p>
<p>I hesitate to call these large magnitude customers &#8220;outliers&#8221; because that term implies anomalous, possibly erroneous, data. In this case, the &#8220;outliers&#8221; are relatively rare, but important, customers who can potentially make the difference between a company that is in the black or in the red. Still, they are the exception and their behavior doesn&#8217;t necessarily tell you anything about the behavior of your typical customer. Knowing the mean profitability of a given customer group is important, of course, but the estimate will be dominated by your exceptionally profitable or lossy customers in that group, and as we&#8217;ve seen, that hides information about the majority of your customers.</p>
<p>You might remember from our <a href="http://www.win-vector.com/blog/2009/08/good-graphs-graphical-perception-and-data-visualization/">Good Graphs article</a> that if you have positive skewed data with a wide dynamic range, graphing the data on a log scale helps you see phenomena across the entire range of data that you might miss on the ordinary graph. Unfortunately, we have data here in the positive and negative range. So let&#8217;s split the customers into three groups: profitable, unprofitable, and break-even. About 5-6% of the customer base is break-even, roughly the same proportion in Groups A and B; we&#8217;ll ignore them for now, and look at the profitable customers first (over 80% of the customers, in both groups).</p>
<table border="0" align="center">
<tbody>
<tr>
<td>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/02/positiveCusts.png" border="0" alt="positiveCusts.png" width="500" /></div>
</td>
</tr>
</tbody>
<caption><em>Figure 2: Distribution of profit from profitable Type A customers (blue) and Type B customers (red). The x-axis gives net profit on a log 10 scale, so every labelled tick corresponds to a change by a factor of 100 (eg. 10^0 = $1, 10^2 = $100, and so on). The y-axis represents the fraction of the profitable customer base that generates a given profit.<br />
</em></caption>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>Now we can clearly see that (among profitable customers) the typical Type A customer is in fact more profitable than the typical Type B customer. The mean profit from profitable Type A customers is about $227, and the median profit is about $93 (shown by the dashed blue line). About 2/3 of the profitable Type A customers generate between $21 and $400 in profit, and over 95% of them generate between $5 and $1721 in profit. We can call that 95% the set of &#8220;typical&#8221; profitable Type A customers. That&#8217;s not a standard definition, but it&#8217;s an intuitive one, and useful for this discussion.</p>
<p>Approximately 2.5% of Type A customers generate profits greater than $1721; let&#8217;s call them the Type A &#8220;best-customers,&#8221; some of whom generate profits in the tens of thousands. They are responsible for 30% of the profit that comes from profitable Type A customers, and 3% of the profit that comes from all profitable customers (even though they only make up 0.2% of that population).</p>
<p>Profitable Type B customers generate $148 mean profit, and about $7.67 median profit (the red dashed line). A typical profitable Type B customer generates between six cents and $1031 in profit — a lower range than what the typical Type A customer generates, although the very highest-performing Type B customers are competitive with the highest-performing Type A customers (about 130 Type B customers outperform all the Type A customers).</p>
<p>Unfortunately, when Type A customers are unprofitable, they are typically more unprofitable than those of Type B. This is another reason why the mean profit from Type A customers overall was so low. Our client correctly perceived that Type A customers are typically quite profitable, but there is a small population of real clunkers in the group, too.</p>
<table border="0" align="center">
<tbody>
<tr>
<td>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/02/negativeCusts.png" border="0" alt="negativeCusts.png" width="500" /></div>
</td>
</tr>
</tbody>
<caption><em>Figure 3: Distribution of loss from unprofitable Type A customers (blue) and Type B customers (red). The x-axis gives loss on a log 10 scale; further to the right on the graph means a larger loss. An unprofitable Type A customer loses a median of $137 a month, and a mean of $1180. Unprofitable Type B customers lose a median of $4.80, and a mean of $210.<br />
</em></caption>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>We can do a similar analysis for the entire base of profitable customers. We would find that the typical profitable customer generates between six cents and $1200 in profit every month (median $8.65, mean $153), and that the 2.5% of best-customers generate over 60% of the profits.</p>
<p><strong>The Lognormal Distribution</strong></p>
<table border="0" align="center">
<tbody>
<tr>
<td>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/02/lognormalComp.png" border="0" alt="lognormalComp.png" width="536" height="270" /></div>
</td>
</tr>
</tbody>
<caption><em> Figure 4: (Left) Distribution of profitable customers (graph clipped at $10,000). The x-axis gives the net profit, and the y-axis gives the fraction of the population that generates a given net profit. (Right) Distribution of profitable customers plotted on a log scale.<br />
</em></caption>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>The distribution of highly skewed positive data, like the value of profitable customers, incomes, sales, or stock prices, can often be modelled as a <a href="http://en.wikipedia.org/wiki/Log-normal_distribution">lognormal distribution</a>: that is, the log of the data is distributed in a bell-shaped curve centered (in log space) at the median of the data (remember, for a normal curve, the median and the mean are the same). In our case, both the profits (seen above, in Figure 4) and the losses are distributed approximately lognormally. For lognormal populations, the mean is generally much higher than the median, and the bulk of the contribution towards the mean will be made by a small population of highest-valued data points. <em>If you use the mean as a stand-in for value, you will overstate the value of most of your customers.</em></p>
<p>If your customer value data is distributed approximately lognormally, then you can quickly estimate the range of values that 95% of your customers will fall into. About 95% of normally distributed data will fall within plus/minus two standard deviations of the mean, and taking logarithms converts multiplication into addition. So: if <em>sd</em> is the standard deviation of the natural log of your customer value data,  <em>M</em> is the median profit, and <em>k</em> = exp(<em>sd</em>), then 95% of your customers will fall in the value range (<em>M/(k*k)</em>, <em>M*k*k</em>). The 2.5% of customers who generate more than <em>M*k*k</em> profit are your best-customers, who often drive a majority of your profit.</p>
<p><strong>Long Tail Theory</strong></p>
<p>The distribution of customers above sounds a lot like Chris Anderson&#8217;s <a href="http://www.wired.com/wired/archive/12.10/tail.html">Long Tail Theory</a> of consumer goods. Most of the revenue of (for example) a bookseller or a music store comes from a few &#8220;hits&#8221;, or blockbusters, with the rest of the merchant&#8217;s inventory out along the tail of Figure 5, moving a relatively small volume per title.</p>
<table border="0" align="center">
<tbody>
<tr>
<td>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/01/LongTailComp.png" border="0" alt="LongTailComp.png" width="522" height="644" /></div>
</td>
</tr>
</tbody>
<caption><em> Figure 5: (Top) A notional long tail curve. The y-axis represents sales volume, and the x-axis represents goods ranked from most to least popular. The highest selling goods are to the left. Note that this figure represents the sales curve differently from how the distribution of customer value is represented on the left side of Figure 4. (Bottom) The customer value data (top 10,000 customers) from Figure 4, plotted in the style above. The y-axis has been limited to $50,000 for clarity.<br />
</em></caption>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>Anderson generally assumes that sales of such goods are distributed as a power law distribution, rather than a lognormal; the log of power law data isn&#8217;t distributed symmetrically, but actually has a longer tail to the right. This means that even for the log of the data, the mean is higher than the median. In fact, in some cases, the mean of a power law distribution can be infinite. If sales volume is power law distributed, then top-selling hits are responsible for an even larger percentage of total sales volume than would be the case with a lognormal.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Pareto_distribution">Pareto Distribution</a>, which is one form of a power distribution, has been proposed as an alternative to the lognormal for modelling income distribution and other similar phenomena. Researchers have debated whether lognormal or Pareto is a better model for income distribution since at least the 1950s. Qualitatively, the two distributions have similar behavior. There are certain estimation and forecasting tasks where it does make a difference if your data follows a power law rather than a lognormal, but for the purposes of this discussion, it doesn&#8217;t really matter. For those who are interested, Michael Mitzenmacher has a <a href="http://projecteuclid.org/DPubS?service=UI&amp;version=1.0&amp;verb=Display&amp;handle=euclid.im/1089229510">fairly approachable discussion</a> about the difference between power laws and lognormal distributions.</p>
<p>Back to Long Tail Theory. Historically, merchants tend to concentrate on high-volume items, due to space limitations and the cost of holding inventory. Overall, however, the sum total of tail-product sales will add up to a respectable volume, especially for web retailers who have unlimited &#8220;floor space&#8221; — or so the Long Tail theory goes. A retailer must then decide whether to follow the traditional &#8220;hits-oriented&#8221; strategy, or a more &#8220;tail-oriented&#8221; strategy that caters to the numerous niche markets.</p>
<p>If we draw an analogy with customer value, then best-customers are &#8220;hits.&#8221; Obviously, our client would like to &#8220;fire&#8221; his unprofitable customers while retaining his best-performing customers, and even attract more customers like them. But what about his little customers — the 95% of customers in the typical range? If his retention and growth strategy focuses primarily on attracting and retaining big customers, he is following a hits-oriented strategy. If his campaign also includes reaching out to little customers, then he is following something analogous to a tail strategy.</p>
<p>Not all business works like a music or book seller; the appropriate strategy will vary. Still, we can think of a few reasons why keeping little customers happy is a good idea.</p>
<p>For one thing, big customers are not only rare, but they are the ones that your competitors covet the most. Little customers, meanwhile, can still add up to a respectable chunk of change (close to 40% of net profit in our example above). A solid cushion of smaller customers may soften the blow to your profit margin, should a few of your bigger customers defect.</p>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/01/logos1.png" border="0" alt="logos.png" width="369" height="336" /></div>
<p>Consider computer sales. Microsoft and Dell serve both the corporate and consumer markets. To judge from their past marketing practices, they consider business customers to be the more valuable segment (see <a href="http://www.win-vector.com/blog/2009/07/microsoft-store-again/">here</a> for a rant somewhat related to this topic). But business IT sales have declined in the current moribund economic climate; analysts attribute the growth in computer sales for the last quarter of 2009 <a href="http://www.cultofmac.com/apple-saw-24-growth-in-q4-2009-as-computer-market-bounces-back/26184">primarily to consumer spending</a>. Dell&#8217;s market growth for that last quarter was much lower than that of HP, Acer, and Apple, which are more consumer-oriented companies. It&#8217;s also worth noting that Microsoft saw a 14% <a href="http://www.neowin.net/news/main/09/10/23/windows-and-xbox-help-microsoft-earnings-beat-predictions">decline in revenue</a> for the quarter ending September 30, 2009, compared to the year-ago quarter (and their earnings were in large part due to sales of the Xbox, a consumer product), while at the same time, consumer-oriented Apple saw a <a href="http://www.cultofmac.com/apple-saw-24-growth-in-q4-2009-as-computer-market-bounces-back/26184">24% increase in revenue</a> from its year-ago quarter.</p>
<p>Your pool of little customers is also a pool of potential future best-customers. And <a href="http://insight.kellogg.northwestern.edu/index.php/Kellogg/article/predicting_customer_lifetimevalue">you can&#8217;t always guess which ones</a>. So a wise strategy might be to allocate part of your retention and growth campaign to providing loyalty incentives to smaller customers, and educating them about how your higher-end services or products might benefit them. Those little customers who have the means or opportunity to move on to the next level might very well appreciate your efforts, and stay with you, rather than defecting to a competitor.</p>
<p><strong>Optimizing Sales vs. Optimizing Customers</strong></p>
<p>One last thought about retail hits and high-value customers. McPhee&#8217;s Theory of Exposure, which is cited by Anita Elberse in her Harvard Business Review article <a href="http://hbr.org/2008/07/should-you-invest-in-the-long-tail/ar/1">&#8220;Should You Invest in the Long Tail?&#8221;</a>, states that the popularity of music, film, TV or books is largely driven by &#8220;marginal audience participants&#8221; — the casual, or light, consumer. Casual consumers gravitate to already popular products because they have limited exposure to alternatives, and hence limited knowledge of them. Consumers of more obscure products, on the other hand, tend to be heavy (and knowledgable) consumers: voracious readers, dedicated music or film buffs, or enthusiasts of specific genres, like science-fiction or horror.</p>
<div style="text-align: center;"><img src="http://www.win-vector.com/blog/wp-content/uploads/2010/01/albums.png" border="0" alt="albums.png" width="300" /></div>
<p>McPhee&#8217;s research was done in 1963, using subjects who had a fairly small range of choices, compared to internet scale. Elberse found, however, that the phenomena McPhee described still held for the internet merchants that she studied. She uses this observation (along with McPhee&#8217;s companion theory of <a href="http://en.wikipedia.org/wiki/Double_jeopardy_(marketing)">Double Jeopardy</a>) to argue that retailers should not substantially alter their traditional hits-based strategies. There is an alternative interpretation:</p>
<p><em>If your business follows McPhee&#8217;s theory, then hit products disproportionately attract low-value (low-volume) customers, and vice-versa. </em></p>
<p>So an overly hits-oriented strategy will skew you towards a base of low-value customers. Indeed, <a href="http://sethgodin.typepad.com/seths_blog/2009/12/its-not-the-rats-you-need-to-worry-about.html">Seth Godin argues</a> that iTunes and Amazon, who are in a better position to implement a more tail-oriented strategy, are thriving at the expense of physical stores exactly because they have been able to steal the quality (high-volume) customers away.</p>
<p>The moral is that both sales and customer value live in a lognormal world, where blockbuster products are marketed to a large cloud of low revenue customers, and high revenue best-customers are supported by large catalogues of low volume products. Fail to serve one side of this relationship, and you risk losing the other side.</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistics to English Translation, Part 2b: Calculating Significance</title>
		<link>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=statistics-to-english-translation-part-2b-calculating-significance</link>
		<comments>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 07:02:40 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[ANOVA]]></category>
		<category><![CDATA[F-test]]></category>
		<category><![CDATA[significance]]></category>
		<category><![CDATA[t-test]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1281</guid>
		<description><![CDATA[In the previous installment of the Statistics to English Translation, we discussed the technical meaning of the term &#8221;significant&#8221;. In this installment, we look at how significance is calculated. This article will be a little more technically detailed than the last one, but our primary goal is still to help you decipher statements about significance [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-’significant’-doesn’t-always-mean-’important’/">previous installment</a> of the <a href="http://www.win-vector.com/blog/category/statistics-to-english-translation/">Statistics to English Translation</a>, we discussed the technical meaning of the term &#8221;significant&#8221;. In this installment, we look at how significance is calculated. This article will be a little more technically detailed than the last one, but our primary goal is still to help you decipher statements about significance in research papers: statements like &#8220;<!-- MATH  $(F(2, 864) = 6.6, p = 0.0014)$  --><br />
<img src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg4.png" border="0" alt="$ (F(2, 864) = 6.6, p = 0.0014)$" width="238" height="37" align="middle" /> &#8221;.</p>
<p>As in the <a href="http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-’significant’-doesn’t-always-mean-’important’/">last article</a>, we will concentrate on situations where we want to test the difference of means. You should read that previous article first, so you are familiar with the terminology that we use in this one.</p>
<p>A pdf version of this current article can be found <a href="http://win-vector.com/dfiles/ste2b_calculatesig.pdf">here</a>.<br />
<span id="more-1281"></span></p>
<h1><a name="SECTION00010000000000000000" id="SECTION00010000000000000000">How is Significance Determined?</a></h1>
<p>Generally speaking, we calculate significance by computing a <em>test statistic</em> from the data. If we assume a specific null hypothesis, then we know that this test statistic will be distributed in a certain way. We can then compute how likely it is to observe our value of the test statistic, if we assume that the null hypothesis is true.</p>
<p>We&#8217;ll explain the use of a test statistic with our Sneetch example from the last installment.</p>
<h1><a name="SECTION00020000000000000000" id="SECTION00020000000000000000">The t-test for Difference of Means</a></h1>
<p>Suppose that the test scores for both Star-Bellies and Plain-Bellies are normally distributed, with the means and standard deviations as given in the table below.</p>
<div align="center">
<table cellpadding="3" border="1">
<tr>
<td align="center">&nbsp;</td>
<td align="center"><img width="16" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg5.png" alt="$ n$"> (number of subjects)</td>
<td align="center"><img width="21" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg6.png" alt="$ m$"> (mean score)</td>
<td align="center"><img width="14" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg7.png" alt="$ s$"> (standard error)</td>
</tr>
<tr>
<td align="center">Star-Bellies</td>
<td align="center">50</td>
<td align="center">78</td>
<td align="center">7</td>
</tr>
<tr>
<td align="center">Plain-Bellies</td>
<td align="center">40</td>
<td align="center">74</td>
<td align="center">8</td>
</tr>
</table>
</div>
<p>Remember from the previous installment that we can estimate the true population means <img width="24" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg8.png" alt="$ \mu_1$"> and <img width="24" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg9.png" alt="$ \mu_2$"> as normally distributed around the empirical population means <img width="29" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg10.png" alt="$ m_1$"> and <img width="29" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg11.png" alt="$ m_2$"> respectively, with variances<br />
<img width="52" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg12.png" alt="$ \sigma^2/{n_1}$"> and<br />
<img width="52" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg13.png" alt="$ \sigma^2/{n_2}$"> . This is shown in Figure <a href="#fig:twomeans">1</a>. Informally speaking, there is no significant difference in the two populations if the shaded overlap area in Figure <a href="#fig:twomeans">1</a> is large.</p>
<div align="center"><a name="fig:twomeans" id="fig:twomeans"></a><a name="36"></a></p>
<table>
<caption align="bottom"><strong>Figure 1:</strong> The estimates of the means for two populations</caption>
<tr>
<td>
<div align="center"><img width="282" height="204" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./overlap.png" alt="Image overlap"></div>
</td>
</tr>
</table>
</div>
<p>Calculating this area is somewhat involved. Instead, we calculate the <em>t-statistic</em>:</p>
<div align="center">
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="126" height="62" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg14.png" alt="$\displaystyle t = \frac{(m_2 - m_1)}{s_D}$"></td>
<td nowrap width="10" align="right">(1)</td>
</tr>
</table>
</div>
<p><br clear="all"><br />
where <img width="26" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg15.png" alt="$ s_D$"> is called the <em>pooled variance</em> of the two populations.</p>
<div align="center">
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="325" height="64" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg16.png" alt="$\displaystyle {s_D}^2 = \frac{n_1\cdot {s_1}^2 + n_2\cdot {s_2}^2}{n_1 + n_2 - 2} \cdot (1/n_1 + 1/n_2)$"></td>
<td nowrap width="10" align="right">(2)</td>
</tr>
</table>
</div>
<p><br clear="all"></p>
<p>For our Sneetch example, <img width="75" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg17.png" alt="$ s_D = 1.6$"> , and <img width="79" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg18.png" alt="$ t=2.499$"> , or the negative of that, depending on which group is Group 1. There are<br />
<img width="142" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg19.png" alt="$ 50 + 40 - 2 = 88$"> degrees of freedom.</p>
<p>If the null hypothesis is true, and the two populations are identical, then <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"> is distributed according to <em>Student&#8217;s distribution with<br />
<img width="105" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg20.png" alt="$ N_1 + N_2 - 2$"> degrees of freedom</em>. Student&#8217;s distribution is sort of a &#8220;stretched out&#8221; bell curve; as the degrees of freedom increase (<br />
<img width="122" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg21.png" alt="$ N_1 + N_2 \rightarrow \infty$"> ), Student&#8217;s distribution approaches the standard normal distribution, <img width="63" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg22.png" alt="$ N(0, 1)$"> <a name="tex2html2" href="#foot209" id="tex2html2"><sup>1</sup></a>.</p>
<p>In other words, if the null hypothesis is true, <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"> should be near zero. The probability of seeing a <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"> of a certain magnitude or greater under the null hypothesis is given by the area under the tails of Student&#8217;s distribution:</p>
<div align="center"><a name="57"></a></p>
<table>
<caption align="bottom"><strong>Figure 2:</strong> The area under the tails for a given <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"></caption>
<tr>
<td>
<div align="center"><img width="514" height="365" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./twotailedtest.jpg" alt="Image twotailedtest"></div>
</td>
</tr>
</table>
</div>
<p>This area is <img width="14" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg27.png" alt="$ p$"> . For the Sneetch example, <img width="82" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg28.png" alt="$ p = 0.014$"> .</p>
<p>The further out on the tails <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"> is, the stronger the evidence that you should reject the null hypothesis. If you know for some reason that the mean of one population will be greater than or equal to the other, than you can use the <em>one-tailed test</em>:</p>
<div align="center"><a name="64"></a></p>
<table>
<caption align="bottom"><strong>Figure 3:</strong> The one-tailed test for a given <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"></caption>
<tr>
<td>
<div align="center"><img width="514" height="365" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./onetailedtest.jpg" alt="Image onetailedtest"></div>
</td>
</tr>
</table>
</div>
<p>This test halves the p-value as compared to the two-tailed test, making a given <img width="12" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg1.png" alt="$ t$"> value twice as significant. When in doubt about which to use, the two-tailed test is more conservative against false positives<a name="tex2html5" href="#foot210" id="tex2html5"><sup>2</sup></a>.</p>
<p>In discussions of t-tests, you will often see statements of the form:</p>
<blockquote><p>The t-test meets the hypothesis that two means are equal if</p></blockquote>
<div align="center">
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="88" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg31.png" alt="$\displaystyle \vert t\vert &gt; t_{\alpha/2, \nu}$"></td>
<td nowrap width="10" align="right">&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</div>
<p><br clear="all"></p>
<blockquote><p>for a two-tailed test, or</p></blockquote>
<div align="center">
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="64" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg32.png" alt="$\displaystyle t &gt; t_{\alpha, \nu}$"></td>
<td nowrap width="10" align="right">&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</div>
<p><br clear="all"></p>
<blockquote><p>for a (right-sided) one-tailed test.</p></blockquote>
<p>The quantities on the right hand side of the two equations above are called the <em>critical values</em> for a given significance level <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> (usually,<br />
<img width="75" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg34.png" alt="$ \alpha = 0.05$"> ) and <img width="15" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg35.png" alt="$ \nu$"> degrees of freedom. The critical values are the values for which the area of the right hand tail is equal to <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> .</p>
<div align="center"><a name="211"></a></p>
<table>
<caption align="bottom"><strong>Figure 4:</strong> Critical value for a one-tailed test. Reject the null hypothesis if<br />
<img width="66" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg2.png" alt="$ t &gt; t_{crit}$"></caption>
<tr>
<td>
<div align="center"><img width="385" height="252" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./onetailedcritval.png" alt="Image onetailedcritval"></div>
</td>
</tr>
</table>
</div>
<p>For a two-tailed test, you must halve the area under a single tail.</p>
<div align="center"><a name="212"></a></p>
<table>
<caption align="bottom"><strong>Figure 5:</strong> Critical value for a two-tailed test. Reject the null hypothesis if<br />
<img width="77" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg3.png" alt="$ \vert t\vert &gt; t_{crit}$"></caption>
<tr>
<td>
<div align="center"><img width="384" height="248" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./twotailedcritval.png" alt="Image twotailedcritval"></div>
</td>
</tr>
</table>
</div>
<p>This convention dates back to the time when computational resources were scarce, and researchers had to use pre-computed tables of critical values, rather than calculating <img width="14" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg27.png" alt="$ p$"> directly. Today, general statistical packages such as R or Matlab can compute the CDFs of any number of standard distributions; once you can compute the CDF, directly computing <img width="14" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg27.png" alt="$ p$"> (the area under the tails) is straightforward. Despite this, many tutorials of the t-test (and of the F-test, and other significance tests) still adhere to the convention of comparing test statistics to critical values. This tends to needlessly ritualize the whole process, and make it seem more complicated and mysterious than it actually is, at least in my opinion.</p>
<p>David Freedman was very much against the continued practice of using critical values, rather than reporting the actual p-value. The last chapter of Freedman, Pisani and Purves [<a href="#Freedman07">FPP07</a>] is worth reading for its discussion of this, and other potential pitfalls of significance tests.</p>
<p>Some standard packages for evaluating t-tests, F-tests, or the ANOVA also present analysis results in terms of critical values. Most of them do usually print the actual p value as well, along with the value of the test statistic and the degrees of freedom. Most researchers rightfully report the test statistics along with the actual significance levels: &#8220;we conclude that there is a significant difference in mathematical performance (t(88) = 2.499, p = 0.014)&#8230; .&#8221; Here, 88 gives the degrees of freedom, <img width="45" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg36.png" alt="$ t(88)$"> is the value of the t-statistic, and <img width="14" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg27.png" alt="$ p$"> is of course the p-value.</p>
<p>Similar comments apply to the F-test, discussed in more detail below.</p>
<h2><a name="SECTION00021000000000000000" id="SECTION00021000000000000000">Assumptions</a></h2>
<p>Strictly speaking, the t-test is only valid for normally distributed data where both populations have equal variance. However, the test is fairly robust to non-normal data [<a href="#Box53">Box53</a>]. You can verify that the sample variances are &#8220;equal enough&#8221; &#8211; that is, they could plausibly both be sampled observations from populations with the same variance, by using the <em>F-test</em>. The F-statistic</p>
<div align="center"><img width="102" height="40" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg37.png" alt="$\displaystyle F = {s_1}^2/{s_2}^2 $"></div>
<p>is distributed according to the <em>F distribution with<br />
<img width="131" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg38.png" alt="$ (n_1 - 1,n_2 - 1)$"> degrees of freedom</em></p>
<div align="center"><a name="104"></a></p>
<table>
<caption align="bottom"><strong>Figure 6:</strong> The F distribution</caption>
<tr>
<td>
<div align="center"><img width="514" height="365" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./Ftest.jpg" alt="Image Ftest"></div>
</td>
</tr>
</table>
</div>
<p>In practice, the larger variance is usually put in the numerator, so <img width="54" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg39.png" alt="$ F &gt; 1$"> . The test should still be two-tailed, so you should double the area under the right-hand tail<a name="tex2html9" href="#foot107" id="tex2html9"><sup>3</sup></a>. In this situation, you want to check if you ƒshould accept the null hypothesis (that<br />
<img width="54" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg44.png" alt="$ F \approx 1$"> ) at a given significance level. If so, then you can go ahead and apply the t-test.</p>
<p>There is a variation of the t-tests for distributions of unequal variance, called Welch&#8217;s t-test [<a href="#WikiWelch">Wikc</a>]. In this case, you are only checking if the means are equal, not that the distributions are the same.</p>
<h1><a name="SECTION00030000000000000000" id="SECTION00030000000000000000">The F-test for Analysis of Variance (ANOVA)</a></h1>
<p>ANOVA is an extension of the difference of means test above to the casae of more than two populations. The null hypothesis in this case is that all the sample means are equal &#8211; or more strictly, that all the treatment groups are drawn from the same population.</p>
<p>The simplest version of the ANOVA is the <em>one-way ANOVA</em>, where there are <img width="15" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg45.png" alt="$ k$"> <em>treatment groups</em> (populations) with <img width="21" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg46.png" alt="$ n_i$"> subjects (or repetitions, or replications) each, for a total of <img width="22" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg47.png" alt="$ N$"> subjects. Each population corresponds to a different single factor (a treatment or a condition: for example, a type of medicine, or a Star-Bellied Sneetch vs. a Plain-Bellied Sneetch vs. a Grinch). Two- or three- way ANOVAs correspond to varying two or three different factors combinatorially. For example, we could do a two-way ANOVA of Sneetch math performance by considering both the belly type and the gender of the Sneetchs.</p>
<div align="center"><a name="115"></a></p>
<table>
<caption align="bottom"><strong>Figure 7:</strong> Table for a Two-way ANOVA of Sneetch math performance</caption>
<tr>
<td>
<div align="center"><img width="203" height="243" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./twowayANOVA.png" alt="Image twowayANOVA"></div>
</td>
</tr>
</table>
</div>
<p>We will only discuss one-way ANOVA in this article, since that covers all the relevant ideas about calculating significance.</p>
<p>For a one-way ANOVA, we have the population means <img width="27" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg48.png" alt="$ m_i$"> and variances <img width="27" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg49.png" alt="$ {s_i}^2$"> . We can also calculate the overall mean <img width="29" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg50.png" alt="$ m_0$"> , over the entire aggregate population.</p>
<p>The <em>between-groups mean sum of squares</em>, which is an estimate of the <em>between-groups variance</em>, is given by</p>
<div align="center">
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="260" height="58" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg51.png" alt="$\displaystyle {s_B}^2 = \frac{1}{k-1} \sum_i {n_i \cdot (m_i - m_0)^2}$"></td>
<td nowrap width="10" align="right">(3)</td>
</tr>
</table>
</div>
<p><br clear="all"></p>
<p><img width="33" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg52.png" alt="$ {s_B}^2$"> is sometimes designated <img width="48" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg53.png" alt="$ MS_B$"> It is a measure of how the population means vary with respect to the grand mean.</p>
<p>The <em>within-group mean sum of squares</em> is an estimate of the <em>within-group variance</em>:</p>
<div align="center"><a name="eqn:varw" id="eqn:varw"></a></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="256" height="77" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg54.png" alt="$\displaystyle {s_W}^2 = \frac{1}{N-k} \sum_i^k \sum_j^{n_i} {x_{ij} - m_i}^2$"></td>
<td nowrap width="10" align="right">(4)</td>
</tr>
</table>
</div>
<p><br clear="all"></p>
<p><img width="37" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg55.png" alt="$ {s_W}^2$"> is sometimes designated <img width="52" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg56.png" alt="$ MS_W$"> . It is a measure of the &#8220;average population variance&#8221;.</p>
<div align="center"><a name="142"></a></p>
<table>
<caption align="bottom"><strong>Figure 8:</strong> Within-group and between-group variance</caption>
<tr>
<td>
<div align="center"><img width="322" height="214" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./sigmas.png" alt="Image sigmas"></div>
</td>
</tr>
</table>
</div>
<p>If the null hypothesis is true, then</p>
</p>
<div align="center"><img width="114" height="40" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg57.png" alt="$\displaystyle F = {s_B}^2/{s_W}^2 $"></div>
<p>is distributed according to the F distribution wiht<br />
<img width="116" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg58.png" alt="$ (k-1, n-k)$"> degrees of freedom.</p>
<div align="center"><a name="150"></a></p>
<table>
<caption align="bottom"><strong>Figure 9:</strong> p-value for the one-tailed F-test</caption>
<tr>
<td>
<div align="center"><img width="514" height="365" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./Ftest.jpg" alt="Image Ftest"></div>
</td>
</tr>
</table>
</div>
<p>That is, under the null hypothesis, the within-group and between-group variances should be about equal:<br />
<img width="54" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg44.png" alt="$ F \approx 1$"> . If <img width="54" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg59.png" alt="$ F &lt; 1$"> , then some of the treatment groups overlap other groups substantially, so practically speaking, one might as well accept the null hypothesis. Hence, a one-sided F test is good enough. As with the t-test, research papers usually give the value of the F statistic, the degrees of freedom, and the p-value: &#8220;<br />
<img width="238" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg4.png" alt="$ (F(2, 864) = 6.6, p = 0.0014)$"> &#8221;. In this example, the test statistic value is 6.6, and it was evaluated against the F distribution with (2, 864) degrees of freedom, which means that<br />
<img width="122" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg60.png" alt="$ k = 3, n = 866$"> . The p-value is 0.0014.</p>
<h2><a name="SECTION00031000000000000000" id="SECTION00031000000000000000">Assumptions</a></h2>
<p>Like the t-test, ANOVA assumes that the data is normally distributed with equal variances. According to Box [<a href="#Box53">Box53</a>], ANOVA is fairly robust to unequal variances when the population sizes are about the same, but you might want to check anyway. If all the populations are the same size (all the <img width="21" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg46.png" alt="$ n_i$"> are the same), the easiest way to check for equality of variances is an F-test of the statistic<br />
<img width="140" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg61.png" alt="$ F = {s_{max}}^2/{s_{min}}^2$"> with <img width="49" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg62.png" alt="$ n-1$"> degrees of freedom[<a href="#Sachs84">Sac84</a>]. In other cases, you can use Bartlett&#8217;s Test [<a href="#WikiBartlett">Wika</a>] or Levene&#8217;s Test [<a href="#WikiLevene">Wikb</a>]. Bartlett&#8217;s test uses a test statistic that is distributed as the <img width="24" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg63.png" alt="$ \chi^2$"> distribution, and Levene&#8217;s test uses one that is distributed as the F distribution. Levene&#8217;s test does not assume normally distributed data.</p>
<p>If the data are not normally distributed, or have unequal variance, often they can be transformed to a form that is closer to obeying the assumptions of ANOVA. The following table of transformations is based on [<a href="#Sachs84">Sac84</a>, p. 517], and other sources [<a href="#ndsu">Hor</a>].</p>
<div align="center"><a name="177"></a></p>
<table>
<caption align="bottom"><strong>Figure 10:</strong> Table of Transformations</caption>
<tr>
<td><img width="500" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg64.png" alt="\begin{figure}\begin{center} \begin{tabular}{\vert p{2.5in}\vert p{3.5in}\vert} ... ...} \ $\sigma \approx k\mu$\ &amp; \ \hline \end{tabular} \end{center}\end{figure}"></td>
</tr>
</table>
</div>
<p>Jim Deacon from the University of Edinburgh lists some suggestions as well [<a href="#deacon07">Dea</a>]. He also reminds us that running ANOVA on the transformed data will identify significant differences in the <em>transformed</em> data. This is <em>not</em> the same as saying there are significant differences in the original data!</p>
<h1><a name="SECTION00040000000000000000" id="SECTION00040000000000000000">Once the Null Hypothesis is Rejected</a></h1>
<p>If you are able to reject the ANOVA null hypothesis, you will usually want to know which population means are significantly different from the rest. Often, in fact, you are primarily interested in which population had the highest mean. For example, if you are comparing the efficacy of a new medicine A against existing medicines B and C, you are probably not too concerned about whether B and C perform significantly differently from each other, only about whether A is significantly better than both.</p>
<p>If all you care about is whether the highest mean is significantly higher than the others, you can simply test where the statistic</p>
</p>
<div align="center"><img width="211" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg65.png" alt="$\displaystyle (m_1 - m_2)/({s_W}^2 \frac{n_1 + n_2}{n_1\cdot n_2}) $"></div>
<p>falls on the Student-t distribution with <img width="50" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg66.png" alt="$ n-k$"> degrees of freedom. Here, <img width="37" height="38" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg55.png" alt="$ {s_W}^2$"> is the within-group variance, as calculated in Equation <a href="#eqn:varw">4</a>, <img width="29" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg10.png" alt="$ m_1$"> and <img width="29" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg11.png" alt="$ m_2$"> are the highest and second highest population means, <img width="16" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg5.png" alt="$ n$"> is the total number of samples (<br />
<img width="81" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg67.png" alt="$ n = \sum{n_i}$"> ), and <img width="15" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg45.png" alt="$ k$"> is the number of treatment groups.</p>
<p>This test is usually written</p>
</p>
<div align="center"><img width="409" height="67" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg68.png" alt="$\displaystyle m_1 - m_2 &gt; t_{(n-k, \alpha/2)} \cdot \sqrt{{s_W}^2 \cdot \frac{n_1 + n_2}{n_1\cdot n_2}} = LSD_{(1,2)} $"></div>
<p>where<br />
<img width="75" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg69.png" alt="$ t_{(n-k, \alpha/2)}$"> is the (two-sided) critical value for significance level <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> and <img width="50" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg66.png" alt="$ n-k$"> is the number of degrees of freedom to use. This quantity is called the <em>least significant difference (LSD)</em> between the highest and second highest means, and the test is usually called the <em>LSD test</em>.</p>
<p>If you want to test all the population differences <img width="73" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg70.png" alt="$ m_i - m_j$"> for significance, (or test the highest value against all of the others explicitly) then you need to take some care with the LSD test. Remember that a significance level of <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> means that with probability <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> you will make a false positive error. To test all possible population differences is <img width="22" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg71.png" alt="$ K$"> = (<img width="15" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg45.png" alt="$ k$"> choose <img width="14" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg72.png" alt="$ 2$"> ) comparisons, or <img width="90" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg73.png" alt="$ K = k-1$"> comparisons, if you sort all the means in descending order and compare adjacent ones. Testing the highest mean against all the lower values is also <img width="90" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg73.png" alt="$ K = k-1$"> comparisons. This means you have a<br />
<img width="48" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg74.png" alt="$ K \cdot \alpha$"> probability of making a false positive error. So if you want the overall significance level to be <img width="17" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg33.png" alt="$ \alpha$"> , each individual comparison should use a stricter significance threshold<br />
<img width="78" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg75.png" alt="$ p \leq \alpha/K$"> .</p>
<p>A preferred way to compare multiple means for significance (once the ANOVA null hypothesis has been rejected) is to use a <em>multiple range test</em> [<a href="#deacon07">Dea</a>] or <em>Tukey&#8217;s method</em> [<a href="#nistTukey">oST06</a>], rather than the LSD test. Tukey&#8217;s method tests all pairwise comparison simultaneously, and the multiple range test starts with the broadest range (the highest and the lowest means), and works its way in until significance is lost.</p>
<h1><a name="SECTION00050000000000000000" id="SECTION00050000000000000000">Conclusion</a></h1>
<p>We&#8217;ve skimmed over many complications in this discussion. Hopefully, though, what we have gone over is enough to demystify much of the statistical discussion in research papers. Perhaps, it will demystify the output of standard ANOVA and t-test packages for you, as well.</p>
<p>Chong-ho Yu&#8217;s site [<a href="#yu09">hY</a>] gives a brief discussion of some of the issues that I&#8217;ve skimmed over. It also lists a few common non-parametric tests. These are tests that do not make assumptions about how the data is distributed, and so they may be more appropriate for data that is very non-normal, or for discrete data. They tend to have less power than parametric tests (that is, they have a lower true positive rate); so if the data is at all normal-like, parametric tests are preferred.</p>
<p>Significance tests are used in other applications beyond testing the difference in means or variances. They are used for testing whether events follow an expected distribution, for testing if there is a correlation between two variables, and for evaluating the coefficients of a regression analysis. We hope to cover some of these applications in future installments of this series.</p>
<h2><a name="SECTION00060000000000000000" id="SECTION00060000000000000000">Bibliography</a></h2>
<dl compact>
<dt><a name="Box53" id="Box53">Box53</a></dt>
<dd>G.E.P. Box, <i>Non-normality and tests on variances</i>, Biometrika <b>40</b> (1953), no.&nbsp;3/4, 318-335.</dd>
<dt><a name="deacon07" id="deacon07">Dea</a></dt>
<dd>Jim Deacon, <i>A multiple range test for comparing means in an analysis of variance</i>, <a href="http://www.biology.ed.ac.uk/research/groups/jdeacon/statistics/tress7.html">http://www.biology.ed.ac.uk/research/groups/jdeacon/statistics/tress7.html</a>.</dd>
<dt><a name="Freedman07" id="Freedman07">FPP07</a></dt>
<dd>David Freedman, Robert Pisani, and Roger Purves, <i>Statistics</i>, 4th ed., W. W. Norton &amp; Company, New York, 2007.</dd>
<dt><a name="ndsu" id="ndsu">Hor</a></dt>
<dd>Rich Horsley, <i>Transformations</i>, <tt><a name="tex2html14" href="http://www.ndsu.nodak.edu/ndsu/horsley/Transfrm.pdf" id="tex2html14">http://www.ndsu.nodak.edu/ndsu/horsley/Transfrm.pdf</a></tt>, Class notes, Plant Sciences 724, North Dakota State University.</dd>
<dt><a name="yu09" id="yu09">hY</a></dt>
<dd>Chong ho&nbsp;Yu, <i>Parametric tests</i>, <a href="http://www.creative-wisdom.com/teaching/WBI/parametric_test.shtml">http://www.creative-wisdom.com/teaching/WBI/parametric_test.shtml</a>.</dd>
<dt><a name="nistTukey" id="nistTukey">oST06</a></dt>
<dd>National&nbsp;Institute of&nbsp;Standards and Technology, <i>Tukey&#8217;s method</i>, NIST/SEMATECH e-Handbook of Statistical Methods, 2006, <a href="http://itl.nist.gov/div898/handbook/prc/section4/prc471.htm">http://itl.nist.gov/div898/handbook/prc/section4/prc471.htm.</dd>
<dt><a name="Sachs84" id="Sachs84">Sac84</a></dt>
<dd>Lothar Sachs, <i>Applied statistics: A handbook of techniques</i>, 2nd ed., Springer-Verlag, New York, 1984.</dd>
<dt><a name="WikiBartlett" id="WikiBartlett">Wika</a></dt>
<dd>Wikipedia, <i>Bartlett&#8217;s test</i>, <tt><a name="tex2html15" href="http://en.wikipedia.org/wiki/Bartlett's_test" id="tex2html15">http://en.wikipedia.org/wiki/Bartlett's_test</a></tt>.</dd>
<dt><a name="WikiLevene" id="WikiLevene">Wikb</a></dt>
<dd>&#8212;&#8211;, <i>Levene&#8217;s test</i>, <tt><a name="tex2html16" href="http://en.wikipedia.org/wiki/Levene's_test" id="tex2html16">http://en.wikipedia.org/wiki/Levene's_test</a></tt>.</dd>
<dt><a name="WikiWelch" id="WikiWelch">Wikc</a></dt>
<dd>&#8212;&#8211;, <i>Welch&#8217;s t test</i>, <tt><a name="tex2html17" href="http://en.wikipedia.org/wiki/Welch's_t_test" id="tex2html17">http://en.wikipedia.org/wiki/Welch's_t_test</a></tt>.</dd>
</dl>
<p></p>
<hr />
<h4>Footnotes</h4>
<dl>
<dt><a name="foot209" id="foot209">&#8230;</a><a href="#tex2html2"><sup>1</sup></a></dt>
<dd>Remember from the last installment that when you are estimating the mean of a distribution with unknown mean <img width="16" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg23.png" alt="$ \mu$"> and unknown variance <img width="24" height="19" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg24.png" alt="$ \sigma^2$"> , the 95% confidence interval around your estimate is<br />
<img width="115" height="39" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg25.png" alt="$ m \pm 2\cdot \sigma/\sqrt{n}$"> . Intuitively speaking, Student&#8217;s distribution is what you get if you calculate confidence intervals using the estimated variance <img width="14" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg7.png" alt="$ s$"> instead of the true but unknown variance <img width="16" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg26.png" alt="$ \sigma$"> . The distribution is stretched out compared to the normal distribution to reflect this increased uncertainty.</dd>
<dt><a name="foot210" id="foot210">&#8230; positives</a><a href="#tex2html5"><sup>2</sup></a></dt>
<dd>In his textbook <em>Statistics</em>, Freedman tells an anecdote about a study that was published in the <em>Journal of the AMA</em>, claiming to demonstrate that cholesterol causes heart attacks. The treatment group that took a cholesterol reducing drug had &#8220;significantly fewer&#8221; heart attacks than the control group (<br />
<img width="82" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg29.png" alt="$ p \approx 0.035$"> ). A closer reading revealed that the researchers used a one-tailed test, which is equivalent to <em>assuming</em> that the treatment group was going to have fewer heart attacks. What if the drug had <em>increased</em> the risk of heart attack? The proper two-tailed significance of their results would have been<br />
<img width="73" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg30.png" alt="$ p \approx 0.07$"> , which is higher than <em>JAMA</em>&#8216;s strict significance threshold of 0.05. [<a href="#Freedman07">FPP07</a>, p. 550]</dd>
<dt><a name="foot107" id="foot107">&#8230; tail</a><a href="#tex2html9"><sup>3</sup></a></dt>
<dd>The area to the right of <img width="19" height="17" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg40.png" alt="$ F$"> with <img width="45" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg41.png" alt="$ (a,b)$"> degrees of freedom is equal to the area to the left of <img width="38" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg42.png" alt="$ 1/F$"> , with <img width="45" height="37" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2bimg43.png" alt="$ (b,a)$"> degrees of freedom.</dd>
</dl>
<p></p>
<hr />
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</title>
		<link>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=statistics-to-english-translation-part-2a-%25e2%2580%2599significant%25e2%2580%2599-doesn%25e2%2580%2599t-always-mean-%25e2%2580%2599important%25e2%2580%2599</link>
		<comments>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 20:39:20 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[effect size]]></category>
		<category><![CDATA[hypothesis testing]]></category>
		<category><![CDATA[significance]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1186</guid>
		<description><![CDATA[In this installment of our ongoing Statistics to English Translation series1, we will look at the technical meaning of the term &#8221;significant&#8221;. As you might expect, what it means in statistics is not exactly what it means in everyday language. As always, a pdf version of this article is available as well. Does too much [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
<li><a href='http://www.win-vector.com/blog/2011/12/why-you-can-not-to-use-statistics-to-dispute-magic/' rel='bookmark' title='Why you can not to use statistics to dispute magic'>Why you can not to use statistics to dispute magic</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this installment of our ongoing Statistics to English Translation series<a name="tex2html1" href="#foot133" id="tex2html1"><sup>1</sup></a>, we will look at the technical meaning of the term &#8221;significant&#8221;. As you might expect, what it means in statistics is not exactly what it means in everyday language.</p>
<p>As always, a <a href="http://www.win-vector.com/dfiles/ste2a_significance.pdf">pdf version of this article</a> is available as well.<span id="more-1186"></span></p>
<blockquote><p>Does too much salt cause high blood pressure, or doesn&#8217;t it? That debate has raged for decades, with a slew of studies finding &#8220;yes&#8221; and a slew of others finding &#8220;no.&#8221; Two new studies out today in the journal <em>Hypertension</em> tip the scales in favor of reducing sodium &#8211; particularly for those 1 in 4 Americans who have high blood pressure. One study found that reducing salt intake from 9,700 milligrams a day to 6,500 milligrams decreased blood pressure significantly in blacks, Asians, and whites who had untreated mild hypertension. Another study found that switching to a lower-salt diet helped lower blood pressure in folks with treatment-resistant hypertension.<br />
- &#8220;10 salt shockers that could make hypertension worse,&#8221; <em>U.S. News &amp; World Report</em> [<a href="#Kotz09">Kot09</a>]</p></blockquote>
<p>&#8220;Great!&#8221; you think. &#8220;Who needs to spend money on high-blood pressure meds? I can just cut down my salt!&#8221; Well, maybe so, maybe not. To come to that conclusion, you need more information than you were given in that paragraph. What was the &#8220;significant&#8221; decrease in blood pressure? What was the &#8220;before&#8221; and the &#8220;after&#8221;? Does &#8220;significant&#8221; mean important, or useful? And why has there been so much controversy over this?</p>
<p>Let&#8217;s discuss the important points with an example.</p>
<div align="center"><img width="211" height="236" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./sneetches.jpg" alt="Image sneetches"></div>
<p>Suppose that we wanted to test for a difference in intelligence between two groups, say Star-Bellied Sneetches and Plain-Bellied Sneetches<a name="tex2html3" href="#foot134" id="tex2html3"><sup>2</sup></a>. We take a group of 50 Star-Bellies and a group of 40 Plain-Bellies, and give them both a series of tests designed to measure their mathematical, linguistic, and problem-solving abilities. After evaluating the data, we conclude that there is &#8220;a significant difference in mathematical performance (t(88) = 2.499, p = 0.014) between the two groups&#8221;. The mean mathematics score of the Star-Bellies is 78, with a standard deviation of 7, and the mean mathematics score of the Plain-Bellies is 74, with a standard deviation of 8, for a difference of 4 points<a name="tex2html4" href="#foot135" id="tex2html4"><sup>3</sup></a>.</p>
<p>Should we interpret this result to mean that Star-Bellied Sneetches are better than Plain-Bellied ones at math? It depends.</p>
<h1><a name="SECTION00010000000000000000" id="SECTION00010000000000000000">How Hypothesis Tests Work</a></h1>
<p>The Sneetch example above and the blood-pressure study cited earlier are both examples of <em>hypothesis tests</em>. In hypothesis testing, researchers set their proposed hypothesis (that there is an effect or a relationship) against the <em>null hypothesis</em> that there is no effect or relationship. In this article, we consider proposed relationships of the form</p>
<blockquote><p>The mean value of X measured for group A is different from the mean value of X measured for group B.</p></blockquote>
<p>In this case, the null hypothesis is</p>
<blockquote><p>The mean value of X is the same for groups A and B, and any difference observed in the data is only by observational chance.</p></blockquote>
<p>In fact, we are actually testing the stricter null hypothesis:</p>
<blockquote><p>The distribution of X is the same for groups A and B, and any difference observed is only by observational chance.</p></blockquote>
<p>A and B are sometimes called <em>treatment groups</em>; this terminology comes from the original applications of hypothesis testing procedures, in agriculture and medicine. In the blood pressure study above, the treatment is daily salt intake. One group ingests about 9,700 milligrams of sodium a day, the other group about 6,500 milligrams a day. The question of interest is: does the difference in sodium intake make a difference in the average blood pressure of the two groups? The null hypothesis is &#8220;No.&#8221;</p>
<h2><a name="SECTION00011000000000000000" id="SECTION00011000000000000000">Significance</a></h2>
<p>We call an observed difference <em>significant</em> &#8211; meaning that a difference as large as we observed is probably not by chance &#8211; if the the value <img width="40" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg3.png" alt="$ 1-p$"> is &#8220;high enough.&#8221; In the Sneetch example, <img width="70" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg4.png" alt="$ p = 0.014$"> is the <em>significance level</em> of the result. To interpret the p-value, suppose the null hypothesis is true: there is truly no difference between Star-Bellied math scores and Plain-Bellied math scores. If this is so, then there is only a 0.014 (1.4%) chance that the difference in the average scores of the two groups will be 4 points or larger. In other words, if the null hypothesis is true, and we administer this same test to different groups of 50 Star-Bellies and 40 Plain-Bellies a hundred times, then the difference in scores will be 4 points or more only about once or twice.</p>
<p>We interpret the fact that we have seen a difference that should be rare to be evidence that the null hypothesis <em>isn&#8217;t</em> true. So we <em>reject the null hypothesis</em> and say that there is a &#8220;significant difference&#8221; in the performance of the two groups. Alternatively, we could say that Star-Bellied Sneetches performed &#8220;significantly better&#8221; than Plain-Bellied Sneetches on the math test.</p>
<h2><a name="SECTION00012000000000000000" id="SECTION00012000000000000000">Effect Size</a></h2>
<p>Four points (or about a 5% difference) is the <em>effect size</em> of the comparison. The effect size represents what might be called the &#8220;practical significance&#8221; of the result. In general, the larger the effect size, the better. In this example, Star-Bellies might truly outperform Plain-Bellies by about four points on average, but if we were to examine the relationship between math scores and real-life math performance (say, how well college-attending Sneetches do in their math and science courses), we might discover that it takes a test score difference of ten points or more to reliably predict which Sneetches will do better. In that case, a four point average difference would not be a practical difference.</p>
<h1><a name="SECTION00020000000000000000" id="SECTION00020000000000000000">Evaluating a Result</a></h1>
<p>When evaluating a result, you should look both for its significance and its effect size. In practice, researchers usually consider a finding to be significant if <!-- MATH<br />
 $p \leq 0.05$<br />
 --><br />
<img width="62" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg5.png" alt="$ p \leq 0.05$"> . This is actually a pretty large <img width="12" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg6.png" alt="$ p$"> ; it means even if the null hypothesis is true, you would still observe a difference as large as the one that you observed about five times out of every one hundred trials. In fact, Sachs noted that <!-- MATH<br />
 $p < 0.0027$<br />
 --><br />
<img width="77" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg7.png" alt="$ p &lt; 0.0027$"> used to be the commonly used threshold for significance ([<a href="#Sachs84">Sac84</a>, p. 114]).</p>
<p>Sometimes results are reported using an asterisk convention: (*) means <!-- MATH<br />
 $p \leq 0.05$<br />
 --><br />
<img width="62" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg5.png" alt="$ p \leq 0.05$"> , (**) means <!-- MATH<br />
 $p \leq<br />
0.01$<br />
 --><br />
<img width="62" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg8.png" alt="$ p \leq 0.01$"> , and (***) means <!-- MATH<br />
 $p \leq 0.001$<br />
 --><br />
<img width="70" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg9.png" alt="$ p \leq 0.001$"> . Hopefully, the actual significance level is reported (it isn&#8217;t always), as well as the actual effect size (it isn&#8217;t always).</p>
<div align="center"><img width="240" height="180" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./cup_of_coffee.jpg" alt="Image cup_of_coffee"></div>
<p>The effect size in medical studies is often reported in the popular press with statements like &#8220;those who abstained from coffee had triple the risk of contracting colon cancer compared to those who drank three or more cups a day.&#8221; Does that mean that all confirmed Lapsang Souchong drinkers and the uncaffeinated should run out and learn to embrace Starbucks? Well, no. First of all, ask yourself: what is the baseline risk of colon cancer? If abstaining from coffee triples the risk from 0.01% to 0.03%, well, it probably isn&#8217;t worth worrying about. On the other hand, if the risk triples from 5% to 15%, perhaps that is a reason to take up espressos. You should also see who were the subjects of the study, and how similar they are to you. Suppose the study was done on Caucasian males in the U.S., ages 55-65, with no family history of colon cancer. If you are a young white American male, it&#8217;s possible that this study says something about your future health. If you are female or non-Caucasian or not living in the U.S., the finding may or may not be relevant to you. It depends on the mechanism that drives the relationship, and whether or not it applies to you as well as to the subjects of the study.</p>
<h2><a name="SECTION00021000000000000000" id="SECTION00021000000000000000">&#8220;Significant&#8221; is not the same as &#8220;Important&#8221;</a></h2>
<blockquote><p>With a large sample, even a small difference can be &#8220;statistically significant&#8221;&#8230; . This doesn&#8217;t necessarily make it important. Conversely, an important difference may not be statistically significant if the sample size is too small.<br />
- Freedman, Pisani and Purves, <em>Statistics</em> [<a href="#Freedman07">FPP07</a>, p. 550]</p></blockquote>
<p>The ability of a study to detect a significant difference depends almost entirely on its size. When a researcher designs a study, she has to decide how much risk of error &#8211; and what type of error &#8211; she is willing to tolerate.</p>
<blockquote><p>How big a risk [of inventing a difference] between two indistinguishable treatments are we willing to put up with? This risk is known as the significance level <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg10.png" alt="$ \alpha$"> . [<a href="#Sachs84">Sac84</a>, p. 214]</p></blockquote>
<p><img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg10.png" alt="$ \alpha$"> is the probability of rejecting a null hypothesis that should be accepted. This is a Type I error (a false positive). <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg10.png" alt="$ \alpha$"> enters the design of the study as the threshold for p-values that the researcher will accept as significant.</p>
<blockquote><p>How big a risk do we allow of missing a substantial difference between two treatments? &#8230; This risk is called <img width="14" height="29" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg11.png" alt="$ \beta$"> . [<a href="#Sachs84">Sac84</a>, p. 214]</p></blockquote>
<p><img width="14" height="29" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg11.png" alt="$ \beta$"> is the probability of accepting a null hypothesis that should have been rejected. This is a Type II error (a false negative). The quantity <img width="41" height="29" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg12.png" alt="$ 1-\beta$"> is known as the <em>power</em> of the test: the probability that the test will correctly reject the null hypothesis when the alternative hypothesis is true.</p>
<blockquote><p>How small a difference should still be recognized as significant? This difference is called <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> . [<a href="#Sachs84">Sac84</a>, p. 214]</p></blockquote>
<p><img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> is the minimum effect size that we are willing to consider &#8220;practically significant.&#8221;</p>
<p>It is important to consider <em>all three</em> of <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg10.png" alt="$ \alpha$"> , <img width="14" height="29" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg11.png" alt="$ \beta$"> , and <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> when determining an appropriate sample size for a trial. The power of a test and the significance of a result both increase as the sample size <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> increases. So if <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> is not specified, <b>any difference can appear significant, with a large enough <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"></b> , even if the difference is really by chance.</p>
<h3><a name="SECTION00021100000000000000" id="SECTION00021100000000000000">The Central Limit Theorem</a></h3>
<p>To see why the above statement is true, we need a few more facts about estimating the mean. Suppose we have a random variable <img width="19" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg14.png" alt="$ X$"> that is normally (or nearly normally) distributed, with a true mean <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> and (unknown) variance <img width="21" height="16" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg15.png" alt="$ \sigma^2$"> . You want to estimate <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> by drawing <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> samples; the sample mean <img width="13" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg16.png" alt="$ \bar{x}$"> gives you an estimate of <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> . According to the <em>Central Limit Theorem</em>, if you were to repeat this experiment over and over again, you would see that the estimated <img width="13" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg16.png" alt="$ \bar{x}$"> has a normal distribution, with mean <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> and variance <!-- MATH<br />
 $\sigma^2/n$<br />
 --><br />
<img width="38" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg17.png" alt="$ \sigma^2/n$"> . So <img width="13" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg16.png" alt="$ \bar{x}$"> is a good estimate of <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> , one that improves with a larger sample size <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> .</p>
<p>Another fact about normal distributions is that a little over 95% of the probability mass is within <img width="24" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg18.png" alt="$ \pm 2$"> standard deviations of the mean. So, for a single experiment, we can reason that the true mean <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> is in the interval <!-- MATH<br />
 $\bar{x} \pm 2 \sigma/\sqrt{n}$<br />
 --><br />
<img width="81" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg19.png" alt="$ \bar{x} \pm 2 \sigma/\sqrt{n}$"> with 95% probability<a name="tex2html5" href="#foot136" id="tex2html5"><sup>4</sup></a>.</p>
<div align="center"><a name="86"></a></p>
<table>
<caption align="bottom"><strong>Figure 1:</strong> Confidence bounds on the estimate of <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> for different values of <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"></caption>
<tr>
<td>
<div align="center"><img width="370" height="183" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./fig1.png" alt="Image fig1"></div>
</td>
</tr>
</table>
</div>
<p>So, as <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> gets larger, we zoom in on <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> <a name="tex2html7" href="#foot89" id="tex2html7"><sup>5</sup></a>.</p>
<p>Now, back to the problem of checking for the difference of means. We&#8217;ll take <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> samples from population <img width="16" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg22.png" alt="$ A$"> and <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> from population <img width="17" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg23.png" alt="$ B$"> . Let&#8217;s assume for now that the variances are equal.</p>
<div align="center"><a name="93"></a></p>
<table>
<caption align="bottom"><strong>Figure 2:</strong> Confidence bounds overlap; means may not be truly different</caption>
<tr>
<td>
<div align="center"><img width="273" height="211" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./fig2.png" alt="Image fig2"></div>
</td>
</tr>
</table>
</div>
<p>With 95% probability, <!-- MATH<br />
 $\mu_A \in \bar{x}_A \pm 2\sigma/\sqrt{n}$<br />
 --><br />
<img width="131" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg24.png" alt="$ \mu_A \in \bar{x}_A \pm 2\sigma/\sqrt{n}$"> , and <!-- MATH<br />
 $\mu_B \in \bar{x}_B \pm 2\sigma/\sqrt{n}$<br />
 --><br />
<img width="132" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg25.png" alt="$ \mu_B \in \bar{x}_B \pm 2\sigma/\sqrt{n}$"> . If <!-- MATH<br />
 $|\bar{x}_A -<br />
\bar{x}_B|$<br />
 --><br />
<img width="72" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg26.png" alt="$ \vert\bar{x}_A - \bar{x}_B\vert$"> is small compared to <!-- MATH<br />
 $4 \sigma/\sqrt{n}$<br />
 --><br />
<img width="53" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg27.png" alt="$ 4 \sigma/\sqrt{n}$"> , then the two confidence intervals overlap substantially, and we cannot reject the null hypothesis that <!-- MATH<br />
 $\mu_A = \mu_B$<br />
 --><br />
<img width="66" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg28.png" alt="$ \mu_A = \mu_B$"> .</p>
<p>If, on the other hand, <!-- MATH<br />
 $|\bar{x}_A - \bar{x}_B|$<br />
 --><br />
<img width="72" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg26.png" alt="$ \vert\bar{x}_A - \bar{x}_B\vert$"> is wide compared to <!-- MATH<br />
 $4 \sigma/\sqrt{n}$<br />
 --><br />
<img width="53" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg27.png" alt="$ 4 \sigma/\sqrt{n}$"> :</p>
<div align="center"><a name="109"></a></p>
<table>
<caption align="bottom"><strong>Figure 3:</strong> Confidence bounds don&#8217;t overlap; means are significantly different</caption>
<tr>
<td>
<div align="center"><img width="331" height="193" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./fig3.png" alt="Image fig3"></div>
</td>
</tr>
</table>
</div>
<p>then the confidence intervals are well separated, and we can reject the null hypothesis.</p>
<p>So <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> , the minimum significant distance &#8211; the &#8220;resolution&#8221; of the experiment &#8211; is about the distance when the two confidence intervals touch: <!-- MATH<br />
 $4 \sigma/\sqrt{n}$<br />
 --><br />
<img width="53" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg27.png" alt="$ 4 \sigma/\sqrt{n}$"> , if our desired significance level is 0.05.</p>
<div align="center"><a name="116"></a></p>
<table>
<caption align="bottom"><strong>Figure 4:</strong> Minimum significant distance for a given sample size <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"></caption>
<tr>
<td>
<div align="center"><img width="304" height="229" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/./fig4.png" alt="Image fig4"></div>
</td>
</tr>
</table>
</div>
<p>If <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> is too large, the experiment may be unable to detect important differences because the confidence intervals overlap too soon. This means that the sample size was too small (the test didn&#8217;t have enough power), and the experiment should be repeated with a larger test population.</p>
<p>If <img width="12" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg13.png" alt="$ \delta$"> is too small, then the experiment will potentially detect statistically significant differences that are, for all practical intents and purposes, meaningless. To go back to the Sneetch example, if the math exam has one hundred questions, then an effect size of two points would correspond to one group answering two additional questions correctly, on average. Practically speaking, that&#8217;s probably not a very big difference. But if we made the experiment big enough, about 250 Sneetches in each group, it would be a <em>statistically</em> significant difference, to the 0.05 level. In theory, we could even make a difference of less than one point statistically significant! That is why knowing the effect size of a significant result is important.</p>
<h2><a name="SECTION00022000000000000000" id="SECTION00022000000000000000">&#8220;Significant&#8221; is not the same as &#8220;True&#8221;</a></h2>
<p>The power and significance level of a test play similar roles to the sensitivity and specificity of a diagnostic test. You&#8217;ll remember from Part 1 of this series<a name="tex2html11" href="#foot137" id="tex2html11"><sup>6</sup></a>that sensitivity and specificity are properties of the test, <em>not</em> how the test performs in a given population. To know the practical accuracy of a screening test, you must know the underlying prevalence of the condition that it is screening for. If it is crucial that the screening not miss any positive cases, then the test will be designed to be highly sensitive, possibly at the cost of specificity. In that case, the test will tend to have a high false positive rate if the condition is relatively rare. And yet, this same screening test will have a lower overall false positive rate when used in a population where the condition is more prevalent.</p>
<p>The same is true for hypothesis tests. The probability that a statistically significant result is actually <em>true</em> depends on the underlying probability that results &#8220;of that type&#8221; tend to be true in the domain of study. It also depends on whether the researcher was trying to minimize the chance of a false positive error, or a false negative error.</p>
<p>You should also be careful interpreting the results of exploratory work, where the researchers have run a series of several different studies, but only highlight the &#8220;significant&#8221; ones. Running twenty experiments and having one of them return a significant result to the <img width="62" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg29.png" alt="$ p=0.05$"> level is actually not significant at all.</p>
<p>John Ioannides discusses these points (and a few others) in his 2005 essay &#8220;Why Most Published Research Findings are False&#8221;[<a href="#Ion05">Ioa05</a>]. The essay made a few waves at the time of its publication, and it is still available online. We recommend that you read it, along with the 2007 followup article by Moonesinghe, et.al [<a href="#Moon07">MKJ07</a>]. Now that you&#8217;ve read the first two installments of the Statistics to English translation, both essays should be a breeze!</p>
<h1><a name="SECTION00030000000000000000" id="SECTION00030000000000000000">Some Points to Remember</a></h1>
<ul>
<li>&#8220;Significant&#8221; is a statistical statement that an observed relationship is unlikely to be by chance. It is not an necessarily a statement about the magnitude or the importance (or the truth!) of the relationship.</li>
<li>Knowing the effect size of a significant result will help you decide if the relationship is &#8220;practically significant.&#8221;</li>
<li>With a large enough sample size, any difference in means can appear significant, even when it is by chance.</li>
</ul>
<p>You now have a general idea what a &#8220;statistically significant result&#8221; is. The next installment will go into a little more technical detail of how significance is calculated. You should read that installment if you want to decipher statements in research papers like &#8220;<!-- MATH<br />
 $(F(2, 864) = 6.6, p = 0.0014)$<br />
 --><br />
<img width="202" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg30.png" alt="$ (F(2, 864) = 6.6, p = 0.0014)$"> &#8221; &#8212; or if you are simply curious.</p>
<h2><a name="SECTION00040000000000000000" id="SECTION00040000000000000000">Bibliography</a></h2>
<dl compact>
<dt><a name="Freedman07" id="Freedman07">FPP07</a></dt>
<dd>David Freedman, Robert Pisani, and Roger Purves, <i>Statistics</i>, 4th ed., W. W. Norton &amp; Company, New York, 2007.</dd>
<dt><a name="Ion05" id="Ion05">Ioa05</a></dt>
<dd>John P.&nbsp;A. Ioannidis, <i>Why most published research findings are false</i>, PLoS Med <b>2</b> (2005), no.&nbsp;8, e124, Available as <a href="http://www.plosmedicine.org/article/info:doi/10.1371/journal.pmed.0020124">http://www.plosmedicine.org/article/info:doi/10.1371/journal.pmed.0020124</a>.</dd>
<dt><a name="Kotz09" id="Kotz09">Kot09</a></dt>
<dd>Deborah Kotz, <i>10 salt shockers that could make hypertension worse</i>, U.S. News &amp; World Report (2009), Online as <a href="http://health.usnews.com/articles/health/heart/2009/07/20/10-salt-shockers-that-could-make-hypertension-worse.html"> http://health.usnews.com/articles/health/heart/2009/07/20/10-salt-shockers-that-could-make-hypertension-worse.html</a>.</dd>
<dt><a name="Moon07" id="Moon07">MKJ07</a></dt>
<dd>Ramal Moonesinghe, Muin&nbsp;J Khoury, and A.&nbsp;Cecile J.&nbsp;W Janssens, <i>Most published research findings are false &#8212; but a little replication goes a long way</i>, PLoS Med <b>4</b> (2007), no.&nbsp;2, e28, Available as <a href="http://www.plosmedicine.org/article/info%3Adoi%2F10.1371%2Fjournal.pmed.0040028">http://www.plosmedicine.org/article/info%3Adoi%2F10.1371%2Fjournal.pmed.0040028</a>.</dd>
<dt><a name="Sachs84" id="Sachs84">Sac84</a></dt>
<dd>Lothar Sachs, <i>Applied statistics: A handbook of techniques</i>, 2nd ed., Springer-Verlag, New York, 1984.</dd>
<dt><a name="Spiegel08" id="Spiegel08">SS99</a></dt>
<dd>Murray&nbsp;R. Spiegel and Larry&nbsp;J. Stephens, <i>Schaum&#8217;s outline of statistics</i>, 4th ed., McGraw-Hill, New York, 1999.</dd>
</dl>
<p></p>
<hr />
<h4>Footnotes</h4>
<dl>
<dt><a name="foot133" id="foot133">&#8230; series</a><a href="#tex2html1"><sup>1</sup></a></dt>
<dd><tt><a name="tex2html2" href="http://www.win-vector.com/blog/category/statistics-to-english-translation/" id="tex2html2">http://www.win-vector.com/blog/category/statistics-to-english-translation/</a></tt></dd>
<dt><a name="foot134" id="foot134">&#8230; Sneetches</a><a href="#tex2html3"><sup>2</sup></a></dt>
<dd>&#8220;The Sneetchs,&#8221; from <em>The Sneetches and Other Stories</em> by Dr. Seuss.<br />
<a href="http://www.youtube.com/watch?v=Ln3V0HgW4eM">http://www.youtube.com/watch?v=Ln3V0HgW4eM</a><br />
 and <a href="http://www.youtube.com/watch?v=s0LgMpfLD1Y">http://www.youtube.com/watch?v=s0LgMpfLD1Y</a>
</dd>
<dt><a name="foot135" id="foot135">&#8230; points</a><a href="#tex2html4"><sup>3</sup></a></dt>
<dd>This example is based on Exercise 10.17 in [<a href="#Spiegel08">SS99</a>]; the original exercise did not, unfortunately, involve Sneetches.</dd>
<dt><a name="foot136" id="foot136">&#8230; probability</a><a href="#tex2html5"><sup>4</sup></a></dt>
<dd>The correct way to state this is that for a given (unknown) <img width="14" height="28" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg1.png" alt="$ \mu $"> , the estimate <img width="13" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg16.png" alt="$ \bar{x}$"> falls in the interval <!-- MATH<br />
 $\mu<br />
\pm 2 \sigma/\sqrt{n}$<br />
 --><br />
<img width="82" height="33" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg20.png" alt="$ \mu \pm 2 \sigma/\sqrt{n}$"> just over 95% of the time. This gets awkward to reason about. Luckily, symmetry arguments let us center the appropriate confidence interval around <img width="13" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg16.png" alt="$ \bar{x}$"> instead.</dd>
<dt><a name="foot89" id="foot89">&#8230;</a><a href="#tex2html7"><sup>5</sup></a></dt>
<dd>Of course, we don&#8217;t actually know <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg21.png" alt="$ \sigma$"> , so we don&#8217;t know exactly how fast we zoom in. That doesn&#8217;t affect our argument, though, since only <img width="14" height="14" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/12/ste2aimg2.png" alt="$ n$"> changes</dd>
<dt><a name="foot137" id="foot137">&#8230; series</a><a href="#tex2html11"><sup>6</sup></a></dt>
<dd><a href="http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/">http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/</a></dd>
</dl>
<p></p>
<hr />
<address>Nina Zumel 2009-12-04</address>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/' rel='bookmark' title='&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures'>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</a></li>
<li><a href='http://www.win-vector.com/blog/2011/12/why-you-can-not-to-use-statistics-to-dispute-magic/' rel='bookmark' title='Why you can not to use statistics to dispute magic'>Why you can not to use statistics to dispute magic</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>&#8220;I don&#8217;t think that means what you think it means;&#8221; Statistics to English Translation, Part 1: Accuracy Measures</title>
		<link>http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures</link>
		<comments>http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 16:14:00 +0000</pubDate>
		<dc:creator>Nina Zumel</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Statistics To English Translation]]></category>
		<category><![CDATA[Accuracy Measures]]></category>
		<category><![CDATA[Classifiers]]></category>
		<category><![CDATA[Diagnostic Tests]]></category>
		<category><![CDATA[Precision and Recall]]></category>
		<category><![CDATA[ROC Curves]]></category>
		<category><![CDATA[Sensitivity and Specificity]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=1050</guid>
		<description><![CDATA[Scientists, engineers, and statisticians share similar concerns about evaluating the accuracy of their results, but they don&#8217;t always talk about it in the same language. This can lead to misunderstandings when reading across disciplines, and the problem is exacerbated when technical work is communicated to and by the popular media. The &#8220;Statistics to English Translation&#8221; [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Scientists, engineers, and statisticians share similar concerns about evaluating the accuracy of their results, but they don&#8217;t always talk about it in the same language. This can lead to misunderstandings when reading across disciplines, and the problem is exacerbated when technical work is communicated to and by the popular media.</p>
<p>The &#8220;Statistics to English Translation&#8221; series is a new set of articles that we will be posting from time to time, as an attempt to bridge the language gaps. Our goal is to increase statistical literacy: we hope that you will find it easier to read and understand the statistical results in research papers, even if you can&#8217;t replicate the analyses. We also hope that you will be able to read popular media accounts of statistical and scientific results more critically, and to recognize common misunderstandings when they occur.</p>
<p>The first installment discusses some different accuracy measures that are commonly used in various research communities, and how they are related to each other. There is also a more legible PDF version of the article <a href="http://win-vector.com/dfiles/StatisticsToEnglishPart1_Accuracy.pdf">here</a>.</p>
<p><span id="more-1050"></span></p>
<h2><a name="SECTION00020000000000000000" id="SECTION00020000000000000000">The Basics</a></h2>
<p>In informal language and in popular press articles, &#8220;accuracy&#8221; is often discussed as if it were a one-dimensional property of a diagnostic test or a classifier.</p>
<div align="center"><img width="613" height="454" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/MyMoney.png" alt="Image MyMoney"/></div>
<p>In general though, a single number is not enough. A test or classifier should detect what&#8217;s interesting, and ignore what&#8217;s not. How well it accomplishes these two tasks is related to the two kinds of mistakes that a test or classifier can make: false negatives, and false positives.</p>
<p>For a classification task, <em>positive</em> means that an instance is labeled as belonging to the class of interest: we may want to automatically gather all news articles about Microsoft out of a news feed, or identify fraudulent credit card transactions. For a screening test, positive means that the test detects whatever it was designed to look for: an HIV test detects the presence of human immunodeficiency virus, for example, while an allergy test detects the presence of an allergic reaction. A <em>negative</em> is obviously the opposite of a positive.</p>
<p>A <em>false positive</em> is concluding that something is positive when it is not. False positives are sometimes called <em>Type I errors</em>. A <em>false negative</em> is concluding that something is negative when it is not. False negatives are sometimes called <em>Type II errors</em>. The terms &#8220;Type I error&#8221; and &#8220;Type II error&#8221; are not terribly mnemonic, but they are commonly used, and therefore worth knowing.</p>
<p>For binary classification or binary test procedures, the <em>False Positive Rate</em>, <img width="45" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img1.png" alt="$ FPR$"/> , is the fraction of negative instances that are erroneously misclassified as positive.</p>
<div align="center"><a name="eqn:fp" id="eqn:fp"></a><!-- MATH<br />
 \begin{equation}<br />
FPR = \frac{\mbox{\#false positives}} {\mbox{all negative instances}}<br />
                     = \frac{\mbox{\#false positives}} {\mbox{\#false positives} + \mbox{\#true negatives}}<br />
\end{equation}<br />
 --></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="522" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img2.png" alt="$\displaystyle FPR = \frac{\mbox{\char93 false positives}} {\mbox{all negative i... ...se positives}} {\mbox{\char93 false positives} + \mbox{\char93 true negatives}}$"/></td>
<td nowrap width="10" align="right">(1)</td>
</tr>
</table>
</div>
<p><br clear="all"/></p>
<p>Likewise, the <em>False Negative Rate</em>, <img width="47" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img3.png" alt="$ FNR$"/> , is the fraction of positive instances that are erroneously misclassified as negative.</p>
<div align="center"><a name="eqn:fn" id="eqn:fn"></a><!-- MATH<br />
 \begin{equation}<br />
FNR = \frac {\mbox{\#false negatives}} {\mbox{all positive instances}}<br />
                     = \frac{\mbox{\#false negatives}} {\mbox{\#false negatives} + \mbox{\#true positives}}<br />
\end{equation}<br />
 --></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="520" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img4.png" alt="$\displaystyle FNR = \frac {\mbox{\char93 false negatives}} {\mbox{all positive ... ...se negatives}} {\mbox{\char93 false negatives} + \mbox{\char93 true positives}}$"/></td>
<td nowrap width="10" align="right">(2)</td>
</tr>
</table>
</div>
<p><br clear="all"/></p>
<p>The <em>True Positive Rate</em>, <img width="44" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img5.png" alt="$ TPR$"/> , is the fraction of positive instances that are correctly identified as such. It follows from the Definition <a href="#eqn:fn">2</a> above that <!-- MATH<br />
 $TPR = 1 - FNR$<br />
 --><br />
<img width="140" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img6.png" alt="$ TPR = 1 - FNR$"/> .</p>
<p>The <em>True Negative Rate</em>, <img width="46" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img7.png" alt="$ TNR$"/> , is the fraction of negative instances that are correctly identified as such. It follows from the Definition <a href="#eqn:fp">1</a> above that <!-- MATH<br />
 $TNR = 1 - FPR$<br />
 --><br />
<img width="140" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img8.png" alt="$ TNR = 1 - FPR$"/> .</p>
<h2><a name="SECTION00030000000000000000" id="SECTION00030000000000000000">Sensitivity and Specificity</a></h2>
<div align="center"><img width="180" height="180" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/screening.jpg" alt="Image screening"/></div>
<p>The terms sensitivity and specificity generally refer to diagnostic or screening procedures, such as an HIV or allergy tests. The <em>sensitivity</em> of a test is its true positive rate; the <em>specificity</em> is its true negative rate, although it can be more intuitive to think of specificity as the complement of the false positive rate: <em>Specificity</em> = <!-- MATH<br />
 $TNR = (1 - FPR)$<br />
 --><br />
<img width="153" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img9.png" alt="$ TNR = (1 - FPR)$"/> .</p>
<p>The Wikipedia entry on Sensitivity and Specificity [<a href="#wikiSS">Wik</a>] uses a nice example to illustrate the difference: think of a drug-sniffing dog as a screening test for illicit drugs. If the dog&#8217;s nose is highly <em>sensitive</em> to the smell of drugs, then it will detect all the hidden packets of drugs; if it is less sensitive, then it will fail to detect some of the packets. At the same time, the dog should react <em>specifically</em> to drugs, and not, say, jambalaya or doggie biscuits. If the dog is highly specific in its reactions, it will only react to drugs; if it is less specific, then it will react to the occasional care package of yummy home cooking from Mom.</p>
<p>Screening tests may trade off specificity for sensitivity (and vice-versa). To go back to our drug-sniffing example, we might treat every suitcase and bag that comes through the airport as if it contained drugs; this procedure is perfectly sensitive (it will detect every packet of drugs, for sure), but not specific at all. Or, we might assume that no one is carrying drugs. This is perfectly specific (we will never make a false accusation), but not sensitive at all.</p>
<p>A more realistic example, inspired by a discussion of mandatory AIDS testing by Joshua Rosenau [<a href="#Rosenau">Ros06</a>], is the use of the ELISA screening test to detect HIV-infected blood donations. The ELISA test is designed to be very sensitive: it detects 99.7% of the cases of HIV-infection, which gives a false negative rate of <!-- MATH<br />
 $3 \times 10^{-3}$<br />
 --><br />
<img width="70" height="39" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img10.png" alt="$ 3 \times 10^{-3}$"/> . On the other hand, it is not very specific: it has a 1.9% false positive rate<a name="tex2html2" href="#foot208" id="tex2html2"><sup>1</sup></a>. If you assume that the incidence of HIV-positive individuals in the general population is about 448 out of every 100,000 people [<a href="#CDC">Hig08</a>], then a positive test result is correct only about 19% of the time: one case of true infection out of every five positives. This error rate may be appropriate for screening blood donations, since it is better to discard four perfectly good pints of blood, &#8220;just in case&#8221;, than to allow a pint of HIV-infected blood into the blood bank. But it is <em>not</em> appropriate to assume that all five of those poor blood donors are HIV-positive, without followup tests to increase the specificity of the screening procedure.</p>
<h3><a name="SECTION00031000000000000000" id="SECTION00031000000000000000">Sensitivity, Specificity, and Prevalence</a></h3>
<p>The example above brings up an important point. Sensitivity and specificity are properties <em>of the test itself</em>, not <em>how the test performs in a given population</em>. <b>The absolute accuracy</b> (as the term is commonly understood) <b>of a screening test will change, depending on the prevalence of the condition that the test is screening for.</b></p>
<p>Let&#8217;s imagine the ELISA test described above as an HIV-screening daemon, who uses two coins to generate uncertainty. When the daemon is shown a pint of infected blood, she flips an unfair quarter. If the quarter comes up heads (which it does 3 times out of every 1000 flips), then she lies and says the blood is uninfected, otherwise she tells the truth. When the daemon is shown a pint of uninfected blood, she flips a silver dollar that comes up heads about 2 times out of every 100 flips. If the silver dollar comes up heads, she lies and says the blood is infected, or else she tells the truth. The quarter and the silver dollar encode ELISA&#8217;s sensitivity and specificity, respectively.</p>
<div align="center"><a name="76"></a></p>
<table>
<caption align="bottom"><strong>Figure 1:</strong> The ELISA daemon screening an uninfected pint of blood</caption>
<tr>
<td>
<div align="center"><img width="518" height="333" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ELISAflip.png" alt="Image ELISAflip"/></div>
</td>
</tr>
</table>
</div>
<p>Suppose ELISA looks at the blood of 1000 people a day, drawn from the general population. We can expect that about 5 of them are truly infected. That means that ELISA flips her silver dollar 995 times; it will come up heads about 20 times. That&#8217;s about twenty false positives a day. She&#8217;ll flip the quarter about 5 times, and with high probability, won&#8217;t ever see a head. That&#8217;s near zero false negatives a day. In total, ELISA will read positive for about 25 pints of blood every day, and she will be wrong for 80% of those cases.</p>
<p>But suppose ELISA looks at the blood of 1000 people from a high-risk population, where one out of four people are infected. Then ELISA flips her silver dollar about 750 times, and it will come up heads about 15 times: 15 false positives. She&#8217;ll also flip the quarter 250 times; the coin just might come up heads one time. Let&#8217;s say it does. Then ELISA will read positive for 249+15 = 264 pints of blood, and she&#8217;ll be wrong for only about 6% of those cases &#8211; plus that case of infection that she missed.</p>
<p><b>Same test, same sensitivity and specificity, but different overall accuracy.</b> The percentage of positives that are actually true positives in a given population is called the <em>positive predictive value</em> (<img width="45" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img11.png" alt="$ PPV$"/> ) of the test within that population; it is the probability <em>for that population</em> that a positive test result correctly predicts a positive instance.</p>
<div align="center"><!-- MATH<br />
 \begin{equation}<br />
PPV = \frac{TPR \times P(+)}{TPR \times P(+) + FPR \times P(-)}<br />
\end{equation}<br />
 --></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="298" height="58" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img12.png" alt="$\displaystyle PPV = \frac{TPR \times P(+)}{TPR \times P(+) + FPR \times P(-)}$"/></td>
<td nowrap width="10" align="right">(3)</td>
</tr>
</table>
</div>
<p><br clear="all"/><br />
where <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img13.png" alt="$ P(+)$"/> is the probability of a positive instance, or in other words the prevalence of the condition in the population. <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img14.png" alt="$ P(-)$"/> is the probability of a negative instance, and of course <!-- MATH<br />
 $P(+) + P(-) =<br />
1$<br />
 --><br />
<img width="139" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img15.png" alt="$ P(+) + P(-) = 1$"/> .<a name="tex2html4" href="#foot86" id="tex2html4"><sup>2</sup></a></p>
<h3><a name="SECTION00032000000000000000" id="SECTION00032000000000000000">Likelihood Ratios</a></h3>
<p>Likelihood ratios are another measure of diagnostic test accuracy. The <em>positive likelihood ratio</em> is the true positive rate over the false positive rate: <!-- MATH<br />
 $LR_P = TPR/FPR$<br />
 --><br />
<img width="152" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img16.png" alt="$ LR_P = TPR/FPR$"/> . For our example ELISA test, the positive likelihood ratio is 0.997/0.019 = 52.47. The <em>negative likelihood ratio</em> is the false negative rate over the true negative rate, <!-- MATH<br />
 $LR_N =FNR/TNR$<br />
 --><br />
<img width="159" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img17.png" alt="$ LR_N =FNR/TNR$"/> . For our ELISA example, the negative likelihood ratio is 0.003/.981 = 0.003058.</p>
<p>Likelihood ratios are a property of the screening test, independent of the prevalence of the condition in the population. If you know the odds of infection for the population of interest, <!-- MATH<br />
 $odds_{pop} =<br />
P(+)/P(-)$<br />
 --><br />
<img width="173" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img18.png" alt="$ odds_{pop} = P(+)/P(-)$"/> , then you can calculate the posterior odds of infection for someone who has tested positive:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
odds_{post}  =  LR_P \times odds_{pop}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="201" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img19.png" alt="$\displaystyle odds_{post} = LR_P \times odds_{pop} $"/></div>
<p>and the posterior odds of infection for someone who has tested negative:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
odds_{post} = LR_N \times odds_{pop}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="202" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img20.png" alt="$\displaystyle odds_{post} = LR_N \times odds_{pop} $"/></div>
<p>It&#8217;s been argued that likelihood ratios make it easier for non-statistically-minded practitioners to interpret the results of a test than sensitivity and specificity do [<a href="#JAMA94">JGS94</a>]. It&#8217;s also been argued the other way [<a href="#AIM05">PSBtR05</a>]. Which framework makes more sense depends on if you prefer thinking in odds or probabilities. In either case you should be leery of &#8220;guidelines&#8221; of the sort: &#8220;<img width="81" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img21.png" alt="$ LR_P &gt; 10$"/> indicates large and often conclusive increase in the likelihood of the disease.&#8221; There is certainly a large increase in the posterior likelihood of infection if <img width="81" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img21.png" alt="$ LR_P &gt; 10$"/> , but as the ELISA coin-flipping example should have made clear, this posterior likelihood can still be quite small, if the disease is sufficiently rare.</p>
<p>I occasionally see something called the <em>diagnostic odds ratio</em>. It was developed as &#8220;a single indicator of test performance,&#8221; and I&#8217;ve seen it described as &#8220;the odds of the true positive rate divided by the odds of the false positive rate&#8221; [<a href="#diagodds">HC07</a>]. I could give you the actual formula here, but frankly &#8211; it makes no sense. The whole point of having two measures for accuracy is that one is not enough, and if you absolutely must have one number, you are better off using something like the <img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> measure that we describe in the next section.</p>
<h2><a name="SECTION00040000000000000000" id="SECTION00040000000000000000">Precision and Recall</a></h2>
<div align="center"><img width="644" height="420" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/istock_library.jpg" alt="Image istock_library"/></div>
<p>Precision and recall are similar (but not identical) to sensitivity and specificity. The measures are popular in the information retrieval and machine learning communities.</p>
<p><em>Recall</em> is the same as sensitivity, or the true positive rate: the number of true examples correctly classified as such. <em>Precision</em> is defined as the fraction of instances classified as positive that really are positive:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
\mbox{precision} = \frac{\mbox{\# true positives}}{\mbox{\# true positives + \# false positives}}<br />
\end{displaymath}<br />
 --></p>
<div align="center">&nbsp; &nbsp;precision<img width="299" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img23.png" alt="$\displaystyle = \frac{\mbox{\char93 true positives}}{\mbox{\char93 true positives + \char93 false positives}} $"/></div>
<p>This is <em>not</em> the same as specificity; it is the same as the positive predictive value, and is a joint property of the classifier and the population that it was evaluated on.</p>
<p>Information retrieval research concerns itself with efficient discovery of relevant documents from document collections, and that domain motivates the definitions of precision and recall. A library patron queries the library catalog for books on a given topic; the catalog&#8217;s search engine should return all of the books relevant to her query, and only those books. Recall is a measure of how well the search delivers &#8220;all of the relevant books&#8221;, and precision is a measure of how well it delivers &#8220;only the relevant books&#8221;. If recall is poor, then the patron will miss finding many relevant books; if precision is poor, then she will be inundated with a bunch of book suggestions that have nothing to do with her search.</p>
<p>As with diagnostic procedures, classifiers may trade precision for recall, and vice-versa. Suppose our library patron is looking for novels about vampires. She could request all novels with the word &#8220;vampire&#8221; in the title. This search would have almost perfect precision, since presumably a novel with the word &#8220;vampire&#8221; in the title is going to be about vampires. It would not have perfect recall, since many novels about vampires &#8211; like <em>Dracula</em>, or the books from the <em>Twilight</em> series &#8211; don&#8217;t announce themselves quite that blatantly. Now suppose she is only interested in novels from Anne Rice&#8217;s <em>Vampire Chronicles</em> series. She could request all novels authored by Anne Rice. This search would have perfect recall, but not perfect precision, since Ms. Rice did in fact write several novels that are not about vampires.</p>
<p>These examples show that neither high precision nor high recall guarantee a useful classifier. It is the tension between achieving high precision and high recall that leads to good classifiers.</p>
<p>As we discussed above, the primary difference between precision and specificity is that precision is a property of <em>the algorithm and the population</em>. One could argue that precision is a more appropriate measure than specificity for many classification and machine learning tasks, especially those related to text or natural language. The fundamental assumption, after all, is that such algorithms are trained on data that is representative of the population that the classifier will be deployed in.</p>
<h3><a name="SECTION00041000000000000000" id="SECTION00041000000000000000">If you insist: Single Score Measures</a></h3>
<p>There is another measure called <img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> , the harmonic mean of precision and recall:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
F_1 = \frac{2}{(1/\mbox{precision} + 1/\mbox{recall})} =<br />
2 \times \frac{\mbox{precision} \times \mbox{recall}}{\mbox{precision + recall}}.<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="422" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img24.png" alt="$\displaystyle F_1 = \frac{2}{(1/\mbox{precision} + 1/\mbox{recall})} = 2 \times \frac{\mbox{precision} \times \mbox{recall}}{\mbox{precision + recall}}. $"/></div>
<p><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> is near one when both precision and recall are high, and near zero when they are both low. It is a convenient single score to characterize overall accuracy, especially for comparing the performance of different classifiers.</p>
<p>Using <img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> to compare classifiers assumes that precision and recall are equally important for the application. If one criterion is more important than the other, then one can also use the weighted geometric mean:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
F_\alpha = (1 + \alpha)(\mbox{precision} \times \mbox{recall})/(\alpha \mbox{precision +<br />
  recall}).<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="110" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img25.png" alt="$\displaystyle F_\alpha = (1 + \alpha)($"/>precision<img width="18" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img26.png" alt="$\displaystyle \times$"/>&nbsp; &nbsp;recall<img width="38" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img27.png" alt="$\displaystyle )/(\alpha$"/>&nbsp; &nbsp;precision + recall<img width="16" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img28.png" alt="$\displaystyle ). $"/></div>
<p><img width="15" height="18" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img29.png" alt="$ \alpha$"/> describes how much more important recall is than precision: use <img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img30.png" alt="$ F_2$"/> if recall is twice as important as precision, <img width="33" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img31.png" alt="$ F_{0.5}$"/> if precision is twice as important as recall.</p>
<p>It is still better to have separate target goals for precision and recall that a candidate classifier must meet. Still, <img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> and <img width="25" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img32.png" alt="$ F_\alpha$"/> are found in the literature, so they are presented here.</p>
<h2><a name="SECTION00050000000000000000" id="SECTION00050000000000000000">ROC Curves</a></h2>
<p>Not all diagnostic tests or classifiers return a simple &#8220;yes-or-no&#8221; answer. In fact, most probably don&#8217;t. Generally, a classification or diagnostic procedure will return a score along a continuum; ideally, the positive instances score towards one end of the scale, and the negative examples towards the other end. It is up to the scientist or the analyst to set a threshold on that score that separates what is considered a positive result from what is considered a negative result. The Receiver Operating Characteristic Curve, or <em>ROC Curve</em>, is a tool that helps set the best threshold.</p>
<div align="center"><a name="fig:densityplots" id="fig:densityplots"></a><a name="129"></a></p>
<table>
<caption align="bottom"><strong>Figure 2:</strong> Plot of score distributions for positive and negative instances (Class 10 is positive)</caption>
<tr>
<td>
<div align="center"><img width="525" height="525" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ScoreDensityplots.png" alt="Image ScoreDensityplots"/></div>
</td>
</tr>
</table>
</div>
<p>Suppose we are trying to classify a set of instances into one of two classes, positive and negative<a name="tex2html6" href="#foot133" id="tex2html6"><sup>3</sup></a>. We&#8217;ve gathered a test set of representative samples, and we&#8217;ve developed a scoring procedure to try to separate them. Positives tend to score on the high end of the scale, negatives toward the low end. We want to pick a threshold value.</p>
<p>Figure <a href="#fig:densityplots">2</a> shows what happens when score the test set. We can see that the scores of the positive instances (class 10) are in a cluster centered just above 7, and the scores of the negatives (class 0) are in a cluster centered near 5. Still, there is an interval where the two clusters overlap substantially. If we pick a threshold to the right of that interval (say, <img width="49" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img33.png" alt="$ T = 7$"/> ), almost everything that scores greater than <img width="17" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img34.png" alt="$ T$"/> will be truly positive (high precision/specificity), but we miss a lot of positives, too (low recall/sensitivity). If we pick a threshold to the left of that interval (say <img width="49" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img35.png" alt="$ T = 5$"/> ), we will catch almost all the positives (high recall/sensitivity), but we will also pick up a lot of negatives (low specificity/precision). So we want the threshold to be somewhere in the overlap interval, but where?</p>
<div align="center"><a name="fig:ROC" id="fig:ROC"></a><a name="214"></a></p>
<table>
<caption align="bottom"><strong>Figure 3:</strong> ROC Curve corresponding to Figure <a href="#fig:densityplots">2</a>. Selected thresholds are marked on the curve.</caption>
<tr>
<td>
<div align="center"><img width="525" height="525" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ROC.png" alt="Image ROC"/></div>
</td>
</tr>
</table>
</div>
<p>ROC curves plot the false positive rate on the x-axis and the true positive rate on the y-axis, as we vary the threshold. The point <img width="43" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img36.png" alt="$ (0,0)$"/> corresponds to rejecting everything; the point <img width="43" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img37.png" alt="$ (1,1)$"/> corresponds to accepting everything. The ideal point is <img width="43" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img38.png" alt="$ (0,1)$"/> : accept all positive instances and reject all negative instances. The line <img width="46" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img39.png" alt="$ x=y$"/> corresponds to random guessing: that is, a procedure that assigns each instance a score uniformly drawn from (in this example) the interval <img width="39" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img40.png" alt="$ [1,8]$"/> without even checking if the instance is positive or negative.</p>
<p>The ROC curve represents the tradeoff between true positives and false positives that we make as we increase the threshold from accepting everything to rejecting everything. Figure <a href="#fig:ROC">3</a> gives the ROC curve for our example, with a few example thresholds marked on the curve.</p>
<p>The area between the ROC curve and the <img width="46" height="31" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img39.png" alt="$ x=y$"/> line can be considered a measure of accuracy; the smaller that area, the more the scoring procedure is like random guessing. The larger the area, the better separated the two classes are. We can use the curve to help us decide how to set a threshold that will give us the most acceptable tradeoff between true positives and false positives. For this example, we would probably want to select a threshold somewhere between <img width="13" height="18" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img41.png" alt="$ 6$"/> and <img width="26" height="18" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img42.png" alt="$ 6.5$"/> .</p>
<h2><a name="SECTION00060000000000000000" id="SECTION00060000000000000000">In Conclusion</a></h2>
<p>Some points to remember:</p>
<ul>
<li>Classifier and diagnostic test performance are not one-dimensional.</li>
<li>Different fields use different (but related) measures of accuracy.</li>
<li>Classifier and diagnostic test performance depend on the relative cost of Type I and Type II errors, as well as on the proportion of positive and negative instances in the population of interest.</li>
</ul>
<h2><a name="SECTION00070000000000000000" id="SECTION00070000000000000000">Bibliography</a></h2>
<dl compact>
<dt><a name="diagodds" id="diagodds">HC07</a></dt>
<dd>Childrens&nbsp;Mercy Hospitals and Clinics, <i>Stats: Meta-analysis for a diagnostic test</i>, <tt><a name="tex2html8" href="http://www.childrens-mercy.org/stats/model/diagnostic.asp" id="tex2html8">http://www.childrens-mercy.org/stats/model/diagnostic.asp</a></tt>, 2007.</dd>
<dt><a name="CDC" id="CDC">Hig08</a></dt>
<dd>Liz Highleyman, <i>CDC updates estimates of HIV prevalence in the United States</i>, <tt><a name="tex2html9" href="http://www.hivandhepatitis.com/recent/2008/100708_a.html" id="tex2html9">http://www.hivandhepatitis.com/recent/2008/100708_a.html</a></tt>, 2008.</dd>
<dt><a name="JAMA94" id="JAMA94">JGS94</a></dt>
<dd>R.&nbsp;Jaeschke, GH&nbsp;Guyatt, and DL&nbsp;Sackett, <i>Users&#8217; guides to the medical literature. III. How to use an article about a diagnostic test. B. What are the results and will they help me in caring for my patients? The evidence-based medicine working group</i>, JAMA <b>271</b> (1994), no.&nbsp;6, 703-707.</dd>
<dt><a name="who" id="who">Org04</a></dt>
<dd>World&nbsp;Health Organization, <i>HIV assays: Operational characteristics (phase 1); Report 15 antigen/antibody ELISAs</i>, <tt><a name="tex2html10" href="http://whqlibdoc.who.int/publications/2004/9241592370.pdf" id="tex2html10">http://whqlibdoc.who.int/publications/2004/9241592370.pdf</a></tt>, 2004.</dd>
<dt><a name="AIM05" id="AIM05">PSBtR05</a></dt>
<dd>MA&nbsp;Puhan, J.&nbsp;Steurer, LM&nbsp;Bachmann, and G.&nbsp;ter Riet, <i>&#8220;A randomized trial of ways to describe test accuracy: the effect on physicians&#8217; post-test probability estimates&#8221;</i>, Annals of Internal Medicine <b>143</b> (2005), no.&nbsp;3, 184-&acirc;&Auml;&igrave;189.</dd>
<dt><a name="Rosenau" id="Rosenau">Ros06</a></dt>
<dd>Joshua Rosenau, <i>AIDS testing</i>, <tt><a name="tex2html11" href="http://scienceblogs.com/tfk/2006/08/aids_testing.php" id="tex2html11">http://scienceblogs.com/tfk/2006/08/aids_testing.php</a></tt>, 2006.</dd>
<dt><a name="wikiSS" id="wikiSS">Wik</a></dt>
<dd>Wikipedia, <i>Sensitivity and specificity</i>, <tt><a name="tex2html12" href="http://en.wikipedia.org/wiki/Sensitivity_and_specificity)" id="tex2html12">http://en.wikipedia.org/wiki/Sensitivity_and_specificity)</a></tt>.</dd>
</dl>
<h2><a name="SECTION00080000000000000000" id="SECTION00080000000000000000">Appendix: Glossary of Accuracy Terms</a></h2>
<h3><a name="SECTION00081000000000000000" id="SECTION00081000000000000000">Basic Terms</a></h3>
<dl>
<dt><strong>Accuracy</strong></dt>
<dd>
<p><!-- MATH<br />
 \begin{displaymath}<br />
\frac{\mbox{\#true positives} + \mbox{\#true negatives}}{\mbox{all instances}}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="267" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img43.png" alt="$\displaystyle \frac{\mbox{\char93 true positives} + \mbox{\char93 true negatives}}{\mbox{all instances}} $"/></div>
</dd>
<dt><strong>Type I error</strong></dt>
<dd>False Positive: to conclude something is a positive instance when it is not.</dd>
<dt><strong>Type II error</strong></dt>
<dd>False Negative: to conclude something is a negative instance when it is not.</dd>
<dt><strong>False Positive Rate (<img width="45" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img1.png" alt="$ FPR$"/> )</strong></dt>
<dd>The fraction of negative instances that are erroneously misclassified as positive.</p>
<div align="center"><!-- MATH<br />
 \begin{equation*}<br />
FPR = \frac{\mbox{\#false positives}} {\mbox{all negative instances}}<br />
                     = \frac{\mbox{\#false positives}} {\mbox{\#false positives} + \mbox{\#true negatives}}<br />
\end{equation*}<br />
 --></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="522" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img2.png" alt="$\displaystyle FPR = \frac{\mbox{\char93 false positives}} {\mbox{all negative i... ...se positives}} {\mbox{\char93 false positives} + \mbox{\char93 true negatives}}$"/></td>
<td nowrap width="10" align="right">&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</div>
<p><br clear="all"/></dd>
<dt><strong>False Negative Rate (<img width="47" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img3.png" alt="$ FNR$"/> )</strong></dt>
<dd>The fraction of positive instances that are erroneously misclassified as negative.</p>
<div align="center"><!-- MATH<br />
 \begin{equation*}<br />
FNR = \frac {\mbox{\#false negatives}} {\mbox{all positive instances}}<br />
                     = \frac{\mbox{\#false negatives}} {\mbox{\#false negatives} + \mbox{\#true positives}}<br />
\end{equation*}<br />
 --></p>
<table cellpadding="0" width="100%" align="center">
<tr valign="middle">
<td nowrap align="center"><img width="520" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img4.png" alt="$\displaystyle FNR = \frac {\mbox{\char93 false negatives}} {\mbox{all positive ... ...se negatives}} {\mbox{\char93 false negatives} + \mbox{\char93 true positives}}$"/></td>
<td nowrap width="10" align="right">&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</div>
<p><br clear="all"/></dd>
<dt><strong>True Positive Rate (<img width="44" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img5.png" alt="$ TPR$"/> )</strong></dt>
<dd>The fraction of positive instances that are correctly identified as such. <!-- MATH<br />
 $TPR = 1 - FNR$<br />
 --><br />
<img width="140" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img6.png" alt="$ TPR = 1 - FNR$"/> .</dd>
<dt><strong>True Negative Rate (<img width="46" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img7.png" alt="$ TNR$"/> )</strong></dt>
<dd>The fraction of negative instances that are correctly identified as such. <!-- MATH<br />
 $TNR = 1 - FPR$<br />
 --><br />
<img width="140" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img8.png" alt="$ TNR = 1 - FPR$"/> .</dd>
<dt><strong>Prevalence <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img13.png" alt="$ P(+)$"/></strong></dt>
<dd>The proportion of positive instances in the population, or the probability that someone drawn from the population at random in a positive instance. <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img14.png" alt="$ P(-)$"/> is the probability of drawing a negative instance from the population at random. The <em>odds of a positive</em> is the ratio of <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img13.png" alt="$ P(+)$"/> to <img width="45" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img14.png" alt="$ P(-)$"/> .</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
odds_{pop} = P(+)/P(-)<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="173" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img44.png" alt="$\displaystyle odds_{pop} = P(+)/P(-) $"/></div>
</dd>
</dl>
<h3><a name="SECTION00082000000000000000" id="SECTION00082000000000000000">Accuracy Terms</a></h3>
<p>Terms to describe the accuracy of diagnostic tests are conventionally given in terms of sensitivity and specificity. They have been rephrased here in terms of true positive rate, false positive rate, etc., for clarity.</p>
<dl>
<dt><strong><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/></strong></dt>
<dd>Single score measure of accuracy. The harmonic mean of precision and recall.</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
F_1 = \frac{2}{(1/\mbox{precision} + 1/\mbox{recall})} =<br />
2 \times \frac{\mbox{precision} \times \mbox{recall}}{\mbox{precision + recall}}.<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="422" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img24.png" alt="$\displaystyle F_1 = \frac{2}{(1/\mbox{precision} + 1/\mbox{recall})} = 2 \times \frac{\mbox{precision} \times \mbox{recall}}{\mbox{precision + recall}}. $"/></div>
<p><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> is near 1 for high accuracy, near 0 for low accuracy. Also see <em>Precision, Recall</em>.</dd>
<dt><strong><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img30.png" alt="$ F_2$"/></strong></dt>
<dd>Single score measure of accuracy when recall is twice as important as precision. Also see <em><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> , Precision, Recall</em>.</dd>
<dt><strong><img width="36" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img45.png" alt="$ F_0.5$"/></strong></dt>
<dd>Single score measure of accuracy when precision is twice as important as recall. Also see <em><img width="23" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img22.png" alt="$ F_1$"/> , Precision, Recall</em>.</dd>
<dt><strong>Likelihood-ratio (negative)</strong></dt>
<dd><!-- MATH<br />
 $LR_N = FNR/TNR$<br />
 --><br />
<img width="159" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img17.png" alt="$ LR_N =FNR/TNR$"/> . In diagnostic screening, used for calculating the posterior odds of a true positive for a subject who has tested positive:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
odds_{post}  =  LR_N \times odds_{pop}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="202" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img20.png" alt="$\displaystyle odds_{post} = LR_N \times odds_{pop} $"/></div>
</dd>
<dt><strong>Likelihood-ratio (positive)</strong></dt>
<dd><!-- MATH<br />
 $LR_P = TPR/FPR$<br />
 --><br />
<img width="152" height="36" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img16.png" alt="$ LR_P = TPR/FPR$"/> . In diagnostic screening, used for calculating the posterior odds of a positive for a subject who has tested negative:</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
odds_{post} = LR_P \times odds_{pop}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="201" height="34" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img19.png" alt="$\displaystyle odds_{post} = LR_P \times odds_{pop} $"/></div>
</dd>
<dt><strong>Positive Predictive Value</strong></dt>
<dd>Probability (with respect to a specific assumed prevalence rate) that a positive result from a diagnostic or screening procedure is a true positive. Same as precision.</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
PPV = \frac{TPR \times P(+)}{TPR \times P(+) + FPR \times P(-)}<br />
\end{displaymath}<br />
 --></p>
<div align="center"><img width="298" height="58" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img12.png" alt="$\displaystyle PPV = \frac{TPR \times P(+)}{TPR \times P(+) + FPR \times P(-)}$"/></div>
<p>Also see <em>Precision</em></dd>
<dt><strong>Precision</strong></dt>
<dd>In information retrieval, the fraction of returned documents that are actually relevant to the query. In classification, the fraction of all instances classified as class A that are truly in class A. The same as Positive Predictive Value.</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
\mbox{precision} = \frac{\mbox{\# true positives}}{\mbox{\# true positives + \# false positives}}<br />
\end{displaymath}<br />
 --></p>
<div align="center">&nbsp; &nbsp;precision<img width="299" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img23.png" alt="$\displaystyle = \frac{\mbox{\char93 true positives}}{\mbox{\char93 true positives + \char93 false positives}} $"/></div>
<p>Also see <em>Positive Predictive Value</em></dd>
<dt><strong>Recall</strong></dt>
<dd>In information retrieval, the fraction of relevant documents that are returned by the query. In classification, the fraction of all true instances of class A that are classified into class A. The same as sensitivity.</p>
<p><!-- MATH<br />
 \begin{displaymath}<br />
\mbox{recall} = \frac{\mbox{\# true positives}}{\mbox{\# true positives + \# false negatives}} = TPR<br />
\end{displaymath}<br />
 --></p>
<div align="center">&nbsp; &nbsp;recall<img width="366" height="56" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img46.png" alt="$\displaystyle = \frac{\mbox{\char93 true positives}}{\mbox{\char93 true positives + \char93 false negatives}} = TPR $"/></div>
<p>Also see <em>Sensitivity</em></dd>
<dt><strong>ROC Curve</strong></dt>
<dd>Plot of true positive rate versus false positive rate for a diagnostic test or binary classifier, as the decision threshold is varied.</dd>
<dt><strong>Sensitivity</strong></dt>
<dd>The true positive rate <img width="44" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img5.png" alt="$ TPR$"/> of a diagnostic or screening procedure. Also see <em>Recall</em>.</dd>
<dt><strong>Specificity</strong></dt>
<dd>The true negative rate <!-- MATH<br />
 $TNR = 1 - FPR$<br />
 --><br />
<img width="140" height="32" align="middle" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img8.png" alt="$ TNR = 1 - FPR$"/> (or the complement of the false positive rate) of a diagnostic or screening procedure.</dd>
</dl>
<p></p>
<hr />
<h4>Footnotes</h4>
<dl>
<dt><a name="foot208" id="foot208">&#8230; rate</a><a href="#tex2html2"><sup>1</sup></a></dt>
<dd>The ELISA sensitivity and specificity numbers are from WHO&#8217;s report on the operational characteristics of HIV Assays [<a href="#who">Org04</a>, p. 18], using the lower bounds of the confidence interval. They are slightly different from the numbers Rosenau uses</dd>
<dt><a name="foot86" id="foot86">&#8230;.</a><a href="#tex2html4"><sup>2</sup></a></dt>
<dd>The definition of <img width="45" height="15" align="bottom" border="0" src="http://www.win-vector.com/blog/wp-content/uploads/2009/11/ste1img11.png" alt="$ PPV$"/> is conventionally given in terms of sensitivity and specificity (similarly for the likelihood ratios discussed in the following section). The definitions in this article are given in terms of false positive rate, etc., since that is clearer for people reading outside their discipline.</dd>
<dt><a name="foot133" id="foot133">&#8230; negative</a><a href="#tex2html6"><sup>3</sup></a></dt>
<dd>We are using a classifier in our example, but a diagnostic test would work the same way.</dd>
</dl>
<p></p>
<hr />
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2a-%e2%80%99significant%e2%80%99-doesn%e2%80%99t-always-mean-%e2%80%99important%e2%80%99/' rel='bookmark' title='Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’'>Statistics to English Translation, Part 2a: ’Significant’ Doesn’t Always Mean ’Important’</a></li>
<li><a href='http://www.win-vector.com/blog/2009/12/statistics-to-english-translation-part-2b-calculating-significance/' rel='bookmark' title='Statistics to English Translation, Part 2b: Calculating Significance'>Statistics to English Translation, Part 2b: Calculating Significance</a></li>
<li><a href='http://www.win-vector.com/blog/2010/02/living-in-a-lognormal-world/' rel='bookmark' title='Living in A Lognormal World'>Living in A Lognormal World</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2009/11/i-dont-think-that-means-what-you-think-it-means-statistics-to-english-translation-part-1-accuracy-measures/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google AdSense Channels IDs and the Cramer Rao Inequality</title>
		<link>http://www.win-vector.com/blog/2009/10/google-adsense-channels-ids-and-the-cramer-rao-inequality/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-adsense-channels-ids-and-the-cramer-rao-inequality</link>
		<comments>http://www.win-vector.com/blog/2009/10/google-adsense-channels-ids-and-the-cramer-rao-inequality/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:07:07 +0000</pubDate>
		<dc:creator>John Mount</dc:creator>
				<category><![CDATA[Administrativia]]></category>
		<category><![CDATA[Expository Writing]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[AdSense]]></category>
		<category><![CDATA[AdSense Channel]]></category>
		<category><![CDATA[Channel ID]]></category>
		<category><![CDATA[Cramer-Rao]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.win-vector.com/blog/?p=898</guid>
		<description><![CDATA[&#8220;Comparing Apples and Oranges: Two Examples of the Limits of Statistical Inference, With an Application to Google Advertising Markets&#8221; is our analysis of Google AdSense Channel IDs and our use of the Cramer Rao bound to show that these IDs fundamentally limit what participants in the Google online advertising market can measure (and therefore in [...]
Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2008/06/yaygda-yet-another-yahoo-google-deal-article/' rel='bookmark' title='YAYGDA (Yet Another Yahoo Google Deal Article)'>YAYGDA (Yet Another Yahoo Google Deal Article)</a></li>
<li><a href='http://www.win-vector.com/blog/2009/07/should-your-mom-use-google-search/' rel='bookmark' title='Should your mom use Google search?'>Should your mom use Google search?</a></li>
<li><a href='http://www.win-vector.com/blog/2007/06/new-paper/' rel='bookmark' title='New Paper'>New Paper</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.win-vector.com/SelectedPapers/files/ComparingApplesAndOrangesProblemsWithAdsense.pdf">&#8220;Comparing Apples and Oranges: Two Examples of the Limits of Statistical Inference, With an Application to Google Advertising Markets&#8221;</a> is our analysis of Google AdSense Channel IDs and our use of the Cramer Rao bound to show that these IDs fundamentally limit what participants in the Google online advertising market can measure (and therefore in turn limit what these players can do).<br />
<span id="more-898"></span><br />
We also include a entry level exposition and examples of what the Cramer Rao Inequality is and how it works.</p>
<p>This is a repost of an older paper- but a few people have pointed out they were put off by the incredibly uninformative title of the original post &#8220;<a href="http://www.win-vector.com/blog/2007/06/new-paper/">New Paper</a>.&#8221;</p>
<p>Related posts:<ol>
<li><a href='http://www.win-vector.com/blog/2008/06/yaygda-yet-another-yahoo-google-deal-article/' rel='bookmark' title='YAYGDA (Yet Another Yahoo Google Deal Article)'>YAYGDA (Yet Another Yahoo Google Deal Article)</a></li>
<li><a href='http://www.win-vector.com/blog/2009/07/should-your-mom-use-google-search/' rel='bookmark' title='Should your mom use Google search?'>Should your mom use Google search?</a></li>
<li><a href='http://www.win-vector.com/blog/2007/06/new-paper/' rel='bookmark' title='New Paper'>New Paper</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.win-vector.com/blog/2009/10/google-adsense-channels-ids-and-the-cramer-rao-inequality/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

