<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CEEEQ3o-cSp7ImA9WhVTEU0.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257</id><updated>2012-02-24T08:56:42.459-08:00</updated><title>Probably Overthinking It</title><subtitle type="html">A blog by Allen Downey.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://allendowney.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/ProbablyOverthinkingIt" /><feedburner:info uri="probablyoverthinkingit" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>ProbablyOverthinkingIt</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;CEEEQ3o8eip7ImA9WhVTEU0.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1028680593186399708</id><published>2012-02-24T08:41:00.001-08:00</published><updated>2012-02-24T08:56:42.472-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-24T08:56:42.472-08:00</app:edited><title>Self-organized criticality and holistic models</title><content type="html">My new book,&amp;nbsp;&lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;, will&amp;nbsp;be published by&amp;nbsp;&lt;a href="http://shop.oreilly.com/product/0636920022480.do"&gt;O'Reilly Media&lt;/a&gt;&amp;nbsp;in March.&amp;nbsp;For people who can't stand to wait that long, I am publishing excerpts here. &amp;nbsp;If you really can't wait, you can read the free&amp;nbsp;version at&amp;nbsp;&lt;a href="http://thinkcomplex.com/"&gt;thinkcomplex.com&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity.html"&gt;Part One&lt;/a&gt;&amp;nbsp;I outline the topics in&amp;nbsp;&lt;i&gt;&lt;a href="http://thinkcomplex.com/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;&amp;nbsp;and contrasted a classical physical model of planetary orbits with an example&amp;nbsp;from complexity science: Schelling's model of racial segregation.&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity-part-two.html"&gt;Part Two&lt;/a&gt;&amp;nbsp;I outline some of the ways complexity differs from&amp;nbsp;classical science. &amp;nbsp;In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/02/think-complexity-part-three.html"&gt;Part Three&lt;/a&gt;, I describe differences in the ways complex models are used, and their effects in engineering and (of all things) epistemology.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://allendowney.blogspot.com/2012/02/think-complexity-part-four.html"&gt;Part Four&lt;/a&gt; pulls together discussions from two chapters: the Watts-Strogatz model of small world graphs, and the Barabasi-Albert model of scale free networks. &amp;nbsp;And now, Part Five: Self-organized criticality.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Sand piles&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In 1987 Bak, Tang and Wiesenfeld published a paper in &lt;i&gt;Physical Review&amp;nbsp;Letters&lt;/i&gt;, ``Self-organized criticality: an explanation of 1/&lt;i&gt;f&lt;/i&gt; noise.''&amp;nbsp;You can download it from&amp;nbsp;&lt;a href="http://prl.aps.org/abstract/PRL/v59/i4/p381_1"&gt;http://prl.aps.org/abstract/PRL/v59/i4/p381_1&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The title takes some explaining. &amp;nbsp;A system is ``critical'' if it is&amp;nbsp;in transition between two phases; for example, water at&amp;nbsp;its freezing point is a critical system. &amp;nbsp;A variety of critical systems demonstrate common behaviors:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Long-tailed distributions of some physical quantities: for&amp;nbsp;example, in freezing water the distribution of crystal sizes is&amp;nbsp;characterized by a power law.&lt;/li&gt;
&lt;li&gt;Fractal geometries: freezing water tends to form fractal&amp;nbsp;patterns---the canonical example is a snowflake. &amp;nbsp;Fractals&amp;nbsp;are characterized by self-similarity; that is, parts of the&amp;nbsp;pattern resemble scaled copies of the whole.&lt;/li&gt;
&lt;li&gt;Variations in time that exhibit pink noise: what we call&amp;nbsp;``noise'' is a time series with many frequency components. &amp;nbsp;In&amp;nbsp;``white'' noise, all of the components have equal power. &amp;nbsp;In&amp;nbsp;``pink'' noise, low-frequency components have more power than&amp;nbsp;high-frequency components. &amp;nbsp;Specifically, the power at frequency &lt;i&gt;f&lt;/i&gt;&amp;nbsp;is proportional to 1/&lt;i&gt;f&lt;/i&gt;. &amp;nbsp;Visible light with this power spectrum&amp;nbsp;looks pink, hence the name.&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Critical systems are usually unstable. &amp;nbsp;For example, to keep&amp;nbsp;water in a partially frozen state requires active control of&amp;nbsp;the temperature. &amp;nbsp;If the system is near the critical&amp;nbsp;temperature, a small deviation tends to move the system&amp;nbsp;into one phase or the other.&lt;br /&gt;
&lt;br /&gt;
Many natural systems exhibit characteristic behaviors of&amp;nbsp;criticality, but if critical points are unstable, they should&amp;nbsp;not be common in nature. &amp;nbsp;This is the puzzle Bak, Tang and&amp;nbsp;Wiesenfeld address. &amp;nbsp;Their solution is called self-organized&amp;nbsp;criticality (SOC), where ``self-organized'' means that from&amp;nbsp;any initial condition, the system tends to move toward a&amp;nbsp;critical state, and stay there, without external control.&lt;br /&gt;
&lt;br /&gt;
As an example, they propose a model of a sand pile. &amp;nbsp;The model is not&amp;nbsp;realistic, but it has become the standard example of self-organized&amp;nbsp;criticality.&lt;br /&gt;
&lt;br /&gt;
The model is a 2-D cellular automaton where the state of each cell&amp;nbsp;represents the slope of a part of a sand pile. &amp;nbsp;During each&amp;nbsp;time step, each cell is checked to see whether it exceeds some&amp;nbsp;critical value. &amp;nbsp;If so, an ``avalanche'' occurs that transfers&amp;nbsp;sand to neighboring cells; specifically, the cell's slope is decreased by 4,&amp;nbsp;and each of the 4 neighbors is increased by 1. &amp;nbsp;At the perimeter of the grid, all cells are kept at zero slope, so (in some sense)&amp;nbsp;the excess spills over the edge. &lt;br /&gt;
&lt;br /&gt;
Bak et al. let the system run until it is stable, then observe the effect of small perturbations;&amp;nbsp;they choose a cell at random, increment its value&amp;nbsp;by 1, and evolve the system, again, until it stabilizes.&lt;br /&gt;
&lt;br /&gt;
For each perturbation, they measure the total number&amp;nbsp;of cells that are affected by the resulting avalanche. &amp;nbsp;Most of&amp;nbsp;the time it is small, usually 1. &amp;nbsp;But occasionally&amp;nbsp;a large avalanche affects a substantial fraction&lt;br /&gt;
of the grid. &amp;nbsp;The distribution of &amp;nbsp;turns out to be long-tailed,&amp;nbsp;which supports the claim that the system is in a critical state.&lt;br /&gt;
&lt;br /&gt;
[&lt;i&gt;Think Complexity&lt;/i&gt; presents the details of this model and tests for long-tailed distributions, fractal geometry, and 1/f noise. &amp;nbsp;For this excerpt, I'll skip to the discussion at the end of the chapter.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Reductionism and Holism&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The original paper by Bak, Tang and Wiesenfeld is one of the most frequently-cited papers in the last few decades. Many new systems have been shown to be self-organized critical, and the sand-pile model, in particular, has been studied in detail.&lt;br /&gt;
&lt;br /&gt;
As it turns out, the sand-pile model is not a very good model of a sand pile. &amp;nbsp;Sand is dense and not very sticky, so momentum has a non-negligible effect on the behavior of avalanches. &amp;nbsp;As a result, there are fewer very large and very small avalanches than the model predicts, and the distribution is not long tailed.&lt;br /&gt;
&lt;br /&gt;
Bak has suggested that this observation misses the point. The sand pile model is not meant to be a realistic model of a sand pile; it is meant to be a simple example of a broad category of models.&lt;br /&gt;
&lt;br /&gt;
To understand this point, it is useful to think about two kinds of models, reductionist and holistic. &amp;nbsp;A reductionist model describes a system by describing its parts and their interactions. &amp;nbsp;When a reductionist model is used as an explanation, it depends on an analogy between the components of the model and the components of the system.&lt;br /&gt;
&lt;br /&gt;
For example, to explain why the ideal gas law holds, we can model the molecules that make up a gas with point masses, and model their interactions as elastic collisions. &amp;nbsp;If you simulate or analyze this model, you find that it obeys the ideal gas law. &amp;nbsp;This model is satisfactory to the degree that molecules in a gas behave like molecules in the model. &amp;nbsp;The analogy is between the parts of the system and the parts of the model.&lt;br /&gt;
&lt;br /&gt;
Holistic models are more focused on similarities between systems and less interested in analogous parts. &amp;nbsp;A holistic approach to modeling often consists of two steps, not necessarily in this order:&lt;br /&gt;
&lt;br /&gt;
1. Identify a kind of behavior that appears in a variety of systems.&lt;br /&gt;
&lt;br /&gt;
2. Find the simplest model that demonstrates that behavior.&lt;br /&gt;
&lt;br /&gt;
For example, in &lt;i&gt;The Selfish Gene&lt;/i&gt;, Richard Dawkins suggests that genetic evolution is just one example of an evolutionary system. &amp;nbsp;He identifies the essential elements of the category---discrete replicators, variability and differential reproduction---and proposes that any system that has these elements displays similar behavior, including complexity without design. &amp;nbsp; As another example of an evolutionary system, he proposes memes, which are thoughts or behaviors that are ``replicated'' by transmission from person to person. &amp;nbsp;As memes compete for the resource of human attention, they evolve in ways that are similar to genetic evolution.&lt;br /&gt;
&lt;br /&gt;
Critics of memetics have pointed out that memes are a poor analogy for genes. &amp;nbsp;Memes differ from genes in many obvious ways. &amp;nbsp;But Dawkins has argued that these differences are beside the point because memes are not supposed to be analogous to genes. Rather, memetics and genetics are examples of the same category---evolutionary systems. &amp;nbsp;The differences between them emphasize the real point, which is that evolution is a general model that applies to many seemingly disparate systems. &amp;nbsp;The logical structure of this argument is shown in this diagram:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-JYkW8hMeLeg/T0e8LMssipI/AAAAAAAAAsM/moVbEtMhDxg/s1600/model2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="101" src="http://2.bp.blogspot.com/-JYkW8hMeLeg/T0e8LMssipI/AAAAAAAAAsM/moVbEtMhDxg/s400/model2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Bak has made a similar argument that self-organized criticality is a general model for a broad category of systems. &amp;nbsp;According to Wikipedia, ``SOC is typically observed in slowly-driven non-equilibrium systems with extended degrees of freedom and a high level of nonlinearity.''&lt;br /&gt;
&lt;br /&gt;
Many natural systems demonstrate behaviors characteristic of critical systems. &amp;nbsp;Bak's explanation for this prevalence is that these systems are examples of the broad category of self-organized criticality. There are two ways to support this argument. &amp;nbsp;One is to build a realistic model of a particular system and show that the model exhibits SOC. &amp;nbsp;The second is to show that SOC is a feature of many diverse models, and to identify the essential characteristics those models have in common.&lt;br /&gt;
&lt;br /&gt;
The first approach, which I characterize as reductionist, can explain the behavior of a particular system. &amp;nbsp;The second, holistic, approach, explains the prevalence of criticality in natural systems. &amp;nbsp;They are different models with different purposes.&lt;br /&gt;
&lt;br /&gt;
For reductionist models, realism is the primary virtue, and simplicity is secondary. &amp;nbsp;For holistic models, it is the other way around.&lt;br /&gt;
&lt;br /&gt;
I am using "reductionism" and "holism" here is a descriptive sense, not as technical labels for these models. &amp;nbsp;For more general discussion of these terms, see&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Reductionism"&gt;http://en.wikipedia.org/wiki/Reductionism&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Holism"&gt;http://en.wikipedia.org/wiki/Holism&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SOC, causation and prediction&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If a stock market index drops by a fraction of a percent in a day, there is no need for an explanation. &amp;nbsp;But if it drops 10, people want to know why. &amp;nbsp;Pundits on television are willing to offer explanations, but the real answer may be that there is no explanation.&lt;br /&gt;
&lt;br /&gt;
Day-to-day variability in the stock market shows evidence of criticality: the distribution of value changes is long-tailed and the time series exhibits &amp;nbsp;noise. If the stock market is a self-organized critical system, we should expect occasional large changes as part of the ordinary behavior of the market.&lt;br /&gt;
&lt;br /&gt;
The distribution of earthquake sizes is also long-tailed, and there are simple models of the dynamics of geological faults that might explain this behavior. &amp;nbsp;If these models are right, they imply that large earthquakes are unexceptional; that is, they do not require explanation any more than small earthquakes do.&lt;br /&gt;
&lt;br /&gt;
Similarly, Charles Perrow has suggested that failures in large engineered systems, like nuclear power plants, are like avalanches in the sand pile model. &amp;nbsp;Most failures are small, isolated and harmless, but occasionally a coincidence of bad fortune yields a catastrophe. &amp;nbsp;When big accidents occur, investigators go looking for the cause, but if Perrow's ``normal accident theory'' is correct, there may be no cause.&lt;br /&gt;
&lt;br /&gt;
These conclusions are not comforting. &amp;nbsp;Among other things, they imply that large earthquakes and some kinds of accidents are fundamentally unpredictable. &amp;nbsp;It is impossible to look at the state of a critical system and say whether a large avalanche is ``due.'' &amp;nbsp;If the system is in a critical state, then a large avalanche is always possible. &amp;nbsp;It just depends on the next grain of sand.&lt;br /&gt;
&lt;br /&gt;
In a sand-pile model, what is the cause of a large avalanche? Philosophers sometimes distinguish the proximate cause, which is most immediately responsible, from the ultimate cause, which is, for whatever reason, considered the true cause.&lt;br /&gt;
&lt;br /&gt;
In the sand-pile model, the proximate cause of an avalanche is a grain of sand, but the grain that causes a large avalanche is identical to any other grain, so it offers no special explanation. The ultimate cause of a large avalanche is the structure and dynamics of the systems as a whole: large avalanches occur because they are a property of the system.&lt;br /&gt;
&lt;br /&gt;
Many social phenomena, including wars, revolutions, epidemics, inventions and terrorist attacks, are characterized by long-tailed distributions. &amp;nbsp;If the reason for these distributions is that social systems are critical, that suggests that major historical events may be fundamentally unpredictable and unexplainable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Questions&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
[Think Complexity can be used as a textbook, so it includes exercises and topics for class discussion. &amp;nbsp;Here are some ideas for discussion and further reading.]&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
1. In a 1996 paper in&amp;nbsp;&lt;i&gt;Nature&lt;/i&gt;, Frette et al report the results of experiments with rice piles (&lt;a href="http://www.nature.com/nature/journal/v379/n6560/abs/379049a0.html"&gt;http://www.nature.com/nature/journal/v379/n6560/abs/379049a0.html&lt;/a&gt;). They find that some kinds of rice yield evidence of critical behavior, but others do not. &lt;br /&gt;
&lt;br /&gt;
Similarly, Pruessner and Jensen studied large-scale versions of the forest fire model (using an algorithm similar to Newman and Ziff's). In their 2004 paper, ``Efficient algorithm for the forest fire model,'' they present evidence that the system is not critical after all (&lt;a href="http://pre.aps.org/abstract/PRE/v70/i6/e066707"&gt;http://pre.aps.org/abstract/PRE/v70/i6/e066707&lt;/a&gt;). &amp;nbsp; How do these results bear on Bak's claim that SOC explains the prevalence of critical phenomena in nature?&lt;br /&gt;
&lt;br /&gt;
2. In&amp;nbsp;&lt;i&gt;The Fractal Geometry of Nature&lt;/i&gt;, Benoit Mandelbrot proposes what he calls a ``heretical'' explanation for the prevalence of long-tailed distributions in natural systems (page 344). &amp;nbsp;It may not be, as Bak suggests, that many systems can generate this behavior in isolation. &amp;nbsp;Instead there may be only a few, but there may be interactions between systems that cause the behavior to propagate.&lt;br /&gt;
&lt;br /&gt;
To support this argument, Mandelbrot points out:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The distribution of observed data is often ``the joint &amp;nbsp; effect of a fixed underlying 'true distribution' and a highly &amp;nbsp; variable 'filter.'''&lt;/li&gt;
&lt;li&gt;Long-tailed distributions are robust to filtering; that is, &amp;nbsp; ``a wide variety of filters leave their asymptotic behavior &amp;nbsp; unchanged.''&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
What do you think of this argument? &amp;nbsp;Would you characterize it as reductionist or holist?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3. Read about the ``Great Man'' theory of history at &lt;a href="http://en.wikipedia.org/wiki/Great_man_theory"&gt;http://en.wikipedia.org/wiki/Great_man_theory&lt;/a&gt;. &amp;nbsp;What implication does self-organized criticality have for this theory?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1028680593186399708?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IL02VkzR8N8duh-3sO0KYdIVz08/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IL02VkzR8N8duh-3sO0KYdIVz08/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IL02VkzR8N8duh-3sO0KYdIVz08/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IL02VkzR8N8duh-3sO0KYdIVz08/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/MlZcM4StA2o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1028680593186399708/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/02/self-organized-criticality-and-holistic.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1028680593186399708?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1028680593186399708?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/MlZcM4StA2o/self-organized-criticality-and-holistic.html" title="Self-organized criticality and holistic models" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-JYkW8hMeLeg/T0e8LMssipI/AAAAAAAAAsM/moVbEtMhDxg/s72-c/model2.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/02/self-organized-criticality-and-holistic.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0IEQX4-eSp7ImA9WhRaEks.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-8232137973385805329</id><published>2012-02-14T08:55:00.000-08:00</published><updated>2012-02-14T16:25:00.051-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-14T16:25:00.051-08:00</app:edited><title>Think Complexity: Part Four</title><content type="html">My new book,&amp;nbsp;&lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;, will&amp;nbsp;be published by&amp;nbsp;&lt;a href="http://shop.oreilly.com/product/0636920022480.do"&gt;O'Reilly Media&lt;/a&gt;&amp;nbsp;in March.&amp;nbsp;For people who can't stand to wait that long, I am publishing excerpts here. &amp;nbsp;If you really can't wait, you can read the free&amp;nbsp;version at&amp;nbsp;&lt;a href="http://thinkcomplex.com/"&gt;thinkcomplex.com&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;And we need a blurb&lt;/b&gt;. &amp;nbsp;Think Complexity goes to press soon and we have a space on the back cover for a couple of endorsements. &amp;nbsp;If you like the book and have something quotable to say about it, let me know. &amp;nbsp;Thanks!&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity.html"&gt;Part One&lt;/a&gt;&amp;nbsp;I outline the topics in&amp;nbsp;&lt;i&gt;&lt;a href="http://thinkcomplex.com/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;&amp;nbsp;and contrasted a classical physical model of planetary orbits with an example&amp;nbsp;from complexity science: Schelling's model of racial segregation.&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity-part-two.html"&gt;Part Two&lt;/a&gt;&amp;nbsp;I outline some of the ways complexity differs from&amp;nbsp;classical science. &amp;nbsp;In &lt;a href="http://allendowney.blogspot.com/2012/02/think-complexity-part-three.html"&gt;Part Three&lt;/a&gt;, I describe differences in the ways complex models are used, and their effects in engineering and (of all things) epistemology.&lt;br /&gt;
&lt;br /&gt;
In this installment, I pull together discussions from two chapters: the Watts-Strogatz model of small world graphs, and the Barabasi-Albert model of scale free networks. &amp;nbsp;But it all starts with Stanley Milgram.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Stanley Milgram&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Stanley Milgram was an American social psychologist who conducted two of the most famous experiments in social science, the Milgram experiment, which studied people's obedience to authority (&lt;a href="http://en.wikipedia.org/wiki/Milgram_experiment"&gt;http://en.wikipedia.org/wiki/Milgram_experiment&lt;/a&gt;) and the Small World Experiment (&lt;a href="http://en.wikipedia.org/wiki/Small_world_phenomenon"&gt;http://en.wikipedia.org/wiki/Small_world_phenomenon&lt;/a&gt;), which studied the structure of social networks.&lt;br /&gt;
&lt;br /&gt;
In the Small World Experiment, Milgram sent a package to several randomly-chosen people in Wichita, Kansas, with instructions asking them to forward an enclosed letter to a target person, identified by name and occupation, in Sharon, Massachusetts (which is the town near Boston where I grew up). &amp;nbsp;The subjects were told that they could mail the letter directly to the target person only if they knew him personally; otherwise they were instructed to send it, and the same instructions, to a relative or friend they thought would be more likely to know the target person.&lt;br /&gt;
&lt;br /&gt;
Many of the letters were never delivered, but of the ones that were it turned out that the average path length---the number of times the letters were forwarded---was about six. &amp;nbsp;This result was taken to confirm previous observations (and speculations) that the typical distance between any two people in a social network is about ``six degrees of separation.''&lt;br /&gt;
&lt;br /&gt;
This conclusion is surprising because most people expect social networks to be localized---people tend to live near their friends---and in a graph with local connections, path lengths tend to increase in proportion to geographical distance. &amp;nbsp;For example, most of my friends live nearby, so I would guess that the average distance between nodes in a social network is about 50 miles. &amp;nbsp;Wichita is about 1600 miles from Boston, so if Milgram's letters traversed typical links in the social network, they should have taken 32 hops, not six.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Watts and Strogatz&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In 1998 Duncan Watts and Steven Strogatz published a paper in &amp;nbsp;&lt;i&gt;Nature&lt;/i&gt;, ``Collective dynamics of 'small-world' networks,'' that proposed an explanation for the small world phenomenon. &amp;nbsp;You can download it from &lt;a href="http://www.nature.com/nature/journal/v393/n6684/abs/393440a0.html"&gt;http://www.nature.com/nature/journal/v393/n6684/abs/393440a0.html&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Watts and Strogatz started with two kinds of graph that were well understood: random graphs and regular graphs. &amp;nbsp;They looked at two properties of these graphs, clustering and path length.&lt;br /&gt;
&lt;br /&gt;
Clustering is a measure of the ``cliquishness'' of the graph. In a graph, a clique is a subset of nodes that are all connected to each other; in a social network, a clique is a set of friends who all know each other. &amp;nbsp;Watts and Strogatz defined a clustering coefficient that quantifies the likelihood that two nodes that are connected to the same node are also connected to each other.&lt;br /&gt;
&lt;br /&gt;
Path length is a measure of the average distance between two nodes, which corresponds to the degrees of separation in a social network.&lt;br /&gt;
&lt;br /&gt;
Their initial result is what you might expect: regular graphs have high clustering and high path lengths; random graphs with the same size tend to have low clustering and low path lengths. &amp;nbsp;So neither of these is a good model of social networks, which seem to combine high clustering with short path lengths.&lt;br /&gt;
&lt;br /&gt;
Their goal was to create a generative model of a social network. &amp;nbsp;A generative model tries to explain a phenomenon by modeling the process that builds or leads to the phenomenon. &amp;nbsp;In this case Watts and Strogatz proposed a process for building small-world graphs:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Start with a regular graph with n nodes and degree k. &amp;nbsp;Watts and Strogatz start with a ring lattice, which is a kind of regular graph. &amp;nbsp;You could replicate their experiment or try instead a graph that is regular but not a ring lattice.&lt;/li&gt;
&lt;li&gt;Choose a subset of the edges in the graph and ``rewire'' them by replacing them with random edges. &amp;nbsp;Again, you could replicate the procedure described in the paper or experiment with alternatives. &amp;nbsp; The proportion of edges that are rewired is a parameter, p, that controls how random the graph is. &amp;nbsp;With p=0, the graph is regular; with p=1 it is random.&lt;/li&gt;
&lt;/ol&gt;Watts and Strogatz found that small values of p yield graphs with high clustering, like a regular graph, and low path lengths, like a random graph.&lt;br /&gt;
&lt;ol&gt;&lt;/ol&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Barabasi and Albert&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In 1999 Barabasi and Albert published a paper in Science, ``Emergence of Scaling in Random Networks,'' that characterizes the structure (also called ``topology'') of several real-world networks, including graphs that represent the interconnectivity of movie actors, world-wide web (WWW) pages, and elements in the electrical power grid in the western United States. &amp;nbsp;You can download the paper from &lt;a href="http://www.sciencemag.org/content/286/5439/509"&gt;http://www.sciencemag.org/content/286/5439/509&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
They measure the degree (number of connections) of each node and compute P(k), the probability that a vertex has degree k; then they plot P(k) versus k on a log-log scale. &amp;nbsp;The tail of the plot fits a straight line, so they conclude that it obeys a power &amp;nbsp; law; that is, as k gets large, P(k) is asymptotic to k^(-&lt;span style="background-color: #f9f9f9; font-family: serif; line-height: 17px; text-align: left;"&gt;γ)&lt;/span&gt;, where&amp;nbsp;&lt;span style="background-color: #f9f9f9; font-family: serif; line-height: 17px; text-align: left;"&gt;γ&lt;/span&gt;&amp;nbsp;is a parameter that determines the rate of decay.&lt;br /&gt;
&lt;br /&gt;
They also propose a model that generates random graphs with the same property. &amp;nbsp;The essential features of the model, which distinguish it from the model and the Watts-Strogatz model, are:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Growth&lt;/b&gt;: &amp;nbsp;Instead of starting with a fixed number of vertices, Barabasi and Albert start with a small graph and add vertices gradually.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Preferential attachment&lt;/b&gt;: When a new edge is created, it is more likely to connect to a vertex that already has a large number of edges. &amp;nbsp;This ``rich get richer'' effect is characteristic of the growth patterns of some real-world networks.&lt;br /&gt;
&lt;br /&gt;
Finally, they show that graphs generated by this model have a distribution of degrees that obeys a power law. &amp;nbsp;Graphs that have this property are sometimes called scale-free networks; see &lt;a href="http://en.wikipedia.org/wiki/Scale-free_network"&gt;http://en.wikipedia.org/wiki/Scale-free_network&lt;/a&gt;. That name can be confusing because it is the distribution of degrees that is scale-free, not the network.&lt;br /&gt;
&lt;br /&gt;
In order to maximize confusion, distributions that obey a power law are sometimes called scaling distributions because they are invariant under a change of scale. &amp;nbsp;That means that if you change the units the quantities are expressed in, the slope parameter,&amp;nbsp;&lt;span style="background-color: #f9f9f9; font-family: serif; line-height: 17px; text-align: left;"&gt;γ&lt;/span&gt;, doesn't change. &amp;nbsp;You can read &lt;a href="http://en.wikipedia.org/wiki/Power_law"&gt;http://en.wikipedia.org/wiki/Power_law&lt;/a&gt; for the details, but it is not important for what we are doing here.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Explanatory models&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-m30qHbngXYA/TzqNW9NEXPI/AAAAAAAAArU/pSrfp6L3a9o/s1600/model.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-m30qHbngXYA/TzqNW9NEXPI/AAAAAAAAArU/pSrfp6L3a9o/s1600/model.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
We started the discussion of networks with Milgram's Small World Experiment, which shows that path lengths in social networks are surprisingly small; hence, ``six degrees of separation''. &amp;nbsp; When we see something surprising, it is natural to ask ``Why?'' &amp;nbsp;but sometimes it's not clear what kind of answer we are looking for.&lt;br /&gt;
&lt;br /&gt;
One kind of answer is an explanatory model. &amp;nbsp;The logical structure of an explanatory model is: &lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;In a system, S, we see something observable, O, that warrants explanation.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;We construct a model, M, that is analogous to the system; that is, there is a correspondence between the elements of the model and the elements of the system.&lt;/li&gt;
&lt;li&gt;By simulation or mathematical derivation, we show that the model exhibits a behavior, B, that is analogous to O. &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;We conclude that S exhibits O because S is similar to M, M exhibits B, and B is similar to O.&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
At its core, this is an argument by analogy, which says that if two things are similar in some ways, they are likely to be similar in other ways. &amp;nbsp;Argument by analogy can be useful, and explanatory models can be satisfying, but they do not constitute a proof in the mathematical sense of the word.&lt;br /&gt;
&lt;br /&gt;
Remember that all models leave out, or ``abstract away'' details that we think are unimportant. &amp;nbsp;For any system there are many possible models that include or ignore different features. And there might be models that exhibit different behaviors, B, B' and B'', that are similar to O in different ways. In that case, which model explains O?&lt;br /&gt;
&lt;br /&gt;
The small world phenomenon is an example: the Watts-Strogatz (WS) model and the (BA) model both exhibit small world behavior, but they offer different explanations:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;The WS model suggests that social networks are ``small'' because they include both strongly-connected clusters and ``weak ties'' that connect clusters.&lt;/li&gt;
&lt;li&gt;The BA model suggests that social networks are small because they include nodes with high degree that act as hubs, and that &amp;nbsp; hubs grow, over time, due to preferential attachment.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
As is often the case in young areas of science, the problem is not that we have no explanations, but too many.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Questions&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
[Think Complexity can be used as a textbook, so it includes exercises and topics for class discussion. &amp;nbsp;Here are some ideas for discussion and further reading.]&lt;br /&gt;
&lt;br /&gt;
Are these explanations compatible; that is, can they both be right? Which do you find more satisfying as an explanation, and why? &amp;nbsp;Is there data you could collect, or an experiment you could perform, that would provide evidence in favor of one model over the other?&lt;br /&gt;
&lt;br /&gt;
Choosing among competing models is the topic of Thomas Kuhn's essay, ``Objectivity, Value Judgment, and Theory Choice.'' &amp;nbsp;You can download it &lt;a href="http://commonsenseatheism.com/wp-content/uploads/2010/04/Kuhn-Objectivity-Value-Judgment-and-Theory-Choice.pdf"&gt;here&lt;/a&gt; in PDF. &amp;nbsp;What criteria does Kuhn propose for choosing among competing models? Do these criteria influence your opinion about the WS and BA models? Are there other criteria you think should be considered?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-8232137973385805329?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/h9dzfC10d3d74nWfKHtI7Rtb2K8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h9dzfC10d3d74nWfKHtI7Rtb2K8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/h9dzfC10d3d74nWfKHtI7Rtb2K8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h9dzfC10d3d74nWfKHtI7Rtb2K8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/mHB0wtRt1RM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/8232137973385805329/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/02/think-complexity-part-four.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8232137973385805329?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8232137973385805329?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/mHB0wtRt1RM/think-complexity-part-four.html" title="Think Complexity: Part Four" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-m30qHbngXYA/TzqNW9NEXPI/AAAAAAAAArU/pSrfp6L3a9o/s72-c/model.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/02/think-complexity-part-four.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EESHY9cCp7ImA9WhRbFUk.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-5850683576521043061</id><published>2012-02-06T08:23:00.000-08:00</published><updated>2012-02-06T08:26:49.868-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-06T08:26:49.868-08:00</app:edited><title>Think Complexity: Part Three</title><content type="html">My new book,&amp;nbsp;&lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;, will&amp;nbsp;be published by&amp;nbsp;&lt;a href="http://shop.oreilly.com/product/0636920022480.do"&gt;O'Reilly Media&lt;/a&gt;&amp;nbsp;in March.&amp;nbsp;For people who can't stand to wait that long, I am publishing excerpts here. &amp;nbsp;If you really can't wait, you can read the free&amp;nbsp;version at&amp;nbsp;&lt;a href="http://thinkcomplex.com/"&gt;thinkcomplex.com&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity.html"&gt;Part One&lt;/a&gt;&amp;nbsp;I outline the topics in&amp;nbsp;&lt;i&gt;&lt;a href="http://thinkcomplex.com/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;&amp;nbsp;and contrasted a classical physical model of planetary orbits with an example&amp;nbsp;from complexity science: Schelling's model of racial segregation. &lt;br /&gt;
&lt;br /&gt;
In &lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity-part-two.html"&gt;Part Two&lt;/a&gt; I outline some of the ways complexity differs from&amp;nbsp;classical science. &amp;nbsp;In this installment, I describe differences in the ways complex models are used, and their effects in engineering and (of all things) epistemology.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A new kind of model&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Complex models are often appropriate for different purposes and interpretations:&lt;br /&gt;
&lt;br /&gt;
Predictive&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;explanatory: Schelling's model of segregation might shed light on a complex social phenomenon, but it is not useful for prediction. &amp;nbsp;On the other hand, a simple model of celestial mechanics can predict solar eclipses, down to the second, years in the future.&lt;br /&gt;
&lt;br /&gt;
Realism&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;instrumentalism: Classical models lend themselves to a realist interpretation; for example, most people accept that electrons are real things that exist. &amp;nbsp;Instrumentalism is the view that models can be useful even if the entities they postulate don't exist. George Box wrote what might be the motto of instrumentalism: ``All models are wrong, but some are useful."&lt;br /&gt;
&lt;br /&gt;
Reductionism&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;holism: Reductionism is the view that the behavior of a system can be explained by understanding its components. For example, the periodic table of the elements is a triumph of reductionism, because it explains the chemical behavior of elements with a simple model of the electrons in an atom. &amp;nbsp;Holism is the view that some phenomena that appear at the system level do&amp;nbsp;not exist at the level of components, and cannot be explained in&amp;nbsp;component-level terms.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A new kind of engineering&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I have been talking about complex systems in the context of science, but complexity is also a cause, and effect, of changes in engineering and the organization of social systems:&lt;br /&gt;
&lt;br /&gt;
Centralized&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;decentralized: Centralized systems are conceptually simple and easier to analyze, but decentralized systems can be more robust. &amp;nbsp;For example, in the World Wide Web clients send requests to centralized servers; if the servers are down, the service is unavailable. &amp;nbsp;In peer-to-peer networks, every node is both a client and a server. &amp;nbsp;To take down the service, you have to take down every node.&lt;br /&gt;
&lt;br /&gt;
Isolation&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;interaction: In classical engineering, the complexity of large systems is managed by isolating components and minimizing interactions. &amp;nbsp;This is still an important engineering principle; nevertheless, the availability of cheap computation makes it increasingly feasible to design systems with complex interactions between components.&lt;br /&gt;
&lt;br /&gt;
One-to-many&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;many-to-many: In many communication systems, broadcast services are being augmented, and sometimes replaced, by services that allow users to communicate with each other and create, share, and modify content.&lt;br /&gt;
&lt;br /&gt;
Top-down&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;bottom-up: In social, political and economic systems, many activities that would normally be centrally organized now operate as grassroots movements. &amp;nbsp;Even armies, which are the canonical example of hierarchical structure, are moving toward devolved command and control.&lt;br /&gt;
&lt;br /&gt;
Analysis&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;computation: In classical engineering, the space of feasible designs is limited by our capability for analysis. &amp;nbsp;For example, designing the Eiffel Tower was possible because Gustave Eiffel developed novel analytic techniques, in particular for dealing with wind load. &amp;nbsp;Now tools for computer-aided design and analysis make it possible to build almost anything that can be imagined. &amp;nbsp;Frank Gehry's Guggenheim Museum Bilbao is my favorite example.&lt;br /&gt;
&lt;br /&gt;
Design&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;search: Engineering is sometimes described as a search for solutions in a landscape of possible designs. &amp;nbsp;Increasingly, the search process can be automated. &amp;nbsp;For example, genetic algorithms explore large design spaces and discover solutions human engineers would not imagine (or like). &amp;nbsp;The ultimate genetic algorithm, evolution, notoriously generates designs that violate the rules of human engineering.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A new kind of thinking&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We are getting farther afield now, but the shifts I am postulating in the criteria of scientific modeling are related to 20th Century developments in logic and epistemology.&lt;br /&gt;
&lt;br /&gt;
Aristotelian logic&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;many-valued logic: In traditional logic, any proposition is either true or false. This system lends itself to math-like proofs, but fails (in dramatic ways) for many real-world applications. &amp;nbsp;Alternatives include many-valued logic, fuzzy logic, and other systems designed to handle indeterminacy, vagueness, and uncertainty. &amp;nbsp;Bart Kosko discusses some of these systems in &lt;i&gt;&lt;a href="http://amzn.to/AtuLnR"&gt;Fuzzy Thinking&lt;/a&gt;&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Frequentist probability&amp;nbsp;&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;Bayesianism: Bayesian probability has been around for centuries, but was not widely used until recently, facilitated by the availability of cheap computation and the reluctant acceptance of subjectivity in probabilistic claims. &amp;nbsp;Sharon Bertsch McGrayne presents this history in &lt;i&gt;&lt;a href="http://amzn.to/wgae9c"&gt;The Theory That Would Not Die&lt;/a&gt;&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Objective&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;&amp;nbsp;subjective: The Enlightenment, and philosophic modernism, are based on belief in objective truth; that is, truths that are independent of the people that hold them. &amp;nbsp;20th Century developments including quantum mechanics, Godel's Incompleteness Theorem, and Kuhn's study of the history of science called attention to seemingly unavoidable subjectivity in even ``hard sciences'' and mathematics. &amp;nbsp;Rebecca Goldstein presents the historical context of Godel's proof in &lt;i&gt;&lt;a href="http://amzn.to/xV2IeX"&gt;Incompleteness&lt;/a&gt;&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Physical law&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;theory&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;model: Some people distinguish between laws, theories, and models, but I think they are the same thing. &amp;nbsp;People who use ``law'' are likely to believe that it is objectively true and immutable; people who use ``theory'' concede that it is subject to revision; and ``model'' concedes that it is based on simplification and approximation.&lt;br /&gt;
&lt;br /&gt;
Some concepts that are called ``physical laws'' are really definitions; others are, in effect, the assertion that a model predicts or explains the behavior of a system particularly well. I discuss the nature of physical models later in &lt;i&gt;Think Complexity&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Determinism&lt;span style="background-color: #f9f9f9; color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: medium; line-height: 20px;"&gt;→&lt;/span&gt;indeterminism: Determinism is the view that all events are caused, inevitably, by prior events. &amp;nbsp;Forms of indeterminism include randomness, probabilistic causation, and fundamental uncertainty. We come back to this topic later in the book.&lt;br /&gt;
&lt;br /&gt;
These trends are not universal or complete, but the center of opinion is shifting along these axes. &amp;nbsp;As evidence, consider the reaction to Thomas Kuhn's The Structure of Scientific Revolutions, which was reviled when it was published and now considered almost uncontroversial.&lt;br /&gt;
&lt;br /&gt;
These trends are both cause and effect of complexity science. &amp;nbsp;For example, highly abstracted models are more acceptable now because of the diminished expectation that there should be unique correct model for every system. &amp;nbsp;Conversely, developments in complex systems challenge determinism and the related concept of physical law.&lt;br /&gt;
&lt;br /&gt;
The excerpts so far have been from Chapter 1 of &lt;i&gt;Think Complexity&lt;/i&gt;. &amp;nbsp;Future excerpts will go into some of these topics in more depth. &amp;nbsp;In the meantime, you might be interested in this timeline of complexity science (from Wikipedia):&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://upload.wikimedia.org/wikipedia/en/5/5a/Complexity-map-overview.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="396" src="http://upload.wikimedia.org/wikipedia/en/5/5a/Complexity-map-overview.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-5850683576521043061?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PUGVhweegzX0R34_4u3mUZGXF_M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PUGVhweegzX0R34_4u3mUZGXF_M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PUGVhweegzX0R34_4u3mUZGXF_M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PUGVhweegzX0R34_4u3mUZGXF_M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/8EtKTzO2zxk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/5850683576521043061/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/02/think-complexity-part-three.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5850683576521043061?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5850683576521043061?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/8EtKTzO2zxk/think-complexity-part-three.html" title="Think Complexity: Part Three" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/02/think-complexity-part-three.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkAFRno-eip7ImA9WhRUGEg.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-3812367456227674137</id><published>2012-01-29T09:38:00.000-08:00</published><updated>2012-01-29T09:38:37.452-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-29T09:38:37.452-08:00</app:edited><title>Freshman hordes even more godless!</title><content type="html">[This is an update of an article I wrote last year, "&lt;a href="http://allendowney.blogspot.com/2011/03/freshman-hordes-more-godless-than-ever.html"&gt;Freshman hordes more godless than ever&lt;/a&gt;."]&lt;br /&gt;
&lt;br /&gt;
For several years I have been following one of the most under-reported stories of the decade: the fraction of college freshmen who report no religious preference has more than tripled since 1985, from 8% to 25%, and the trend is accelerating.&lt;br /&gt;
&lt;br /&gt;
Similarly, students reporting that in the last year they have never attended a religious service has grown from 8% to more than 27%.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;My analysis is based on survey results from the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;a href="http://www.gseis.ucla.edu/heri/cirpoverview.php"&gt;Cooperative Institutional Research Program (CIRP)&lt;/a&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&amp;nbsp;of the&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;a href="http://www.gseis.ucla.edu/heri/index.php"&gt;Higher Education Research Insitute (HERI)&lt;/a&gt;. &amp;nbsp;In 2011, more than 200,000 students at 270 colleges and universities completed the CIRP Freshman Survey, which&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: inherit;"&gt;includes questions about students’ backgrounds, activities, and attitudes.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;In one question, students select their “current religious preference,” from a choice of seventeen common religions, “Other religion,” or “None.”&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;Another question asks students how often they “attended a religious service” in the last year. The choices are “Frequently,” “Occasionally,” and “Not at all.” Students are instructed to select “Occasionally” if they attended one or more times.&lt;/span&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;Thi&lt;span style="font-family: inherit;"&gt;s&amp;nbsp;figure shows students' responses over the history of the survey:&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-DvbbO2qotjw/TyVlV7EMj3I/AAAAAAAAAqk/8CVIC4k7vQA/s1600/heri2.3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://2.bp.blogspot.com/-DvbbO2qotjw/TyVlV7EMj3I/AAAAAAAAAqk/8CVIC4k7vQA/s400/heri2.3.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: inherit;"&gt;It's clear that both measurements are increasing, and it looks like they might be accelerating. &amp;nbsp;To make that more precise&lt;/span&gt;&lt;span style="font-family: inherit;"&gt;, I fit a parabola to each curve. &amp;nbsp;&lt;/span&gt;&lt;span style="font-family: inherit;"&gt;This figure shows the data for "No religion" and a least squares fit:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-kpVt6EMi3Bg/TyVlm9KMEKI/AAAAAAAAAqs/OyRpK6cAkKI/s1600/heri.1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-kpVt6EMi3Bg/TyVlm9KMEKI/AAAAAAAAAqs/OyRpK6cAkKI/s400/heri.1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: inherit;"&gt;The red line shows the fitted model; the dark gray area shows the sample error of the model. &amp;nbsp;The lighter gray area shows the sum of the sampling error and the residual error. &amp;nbsp;R&lt;/span&gt;&lt;span style="background-color: white;"&gt;²&lt;/span&gt;&lt;span style="font-family: inherit;"&gt;&amp;nbsp;for this model is 0.95; the p-values for the model and the parameters are &amp;lt; 0.001.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;Similarly, here is the data for "No attendance" and a least squares fit:&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ZeLUmPmkuRk/TyVmmscfLrI/AAAAAAAAAq0/Gddn6zgLRNg/s1600/heri.2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-ZeLUmPmkuRk/TyVmmscfLrI/AAAAAAAAAq0/Gddn6zgLRNg/s400/heri.2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: inherit;"&gt;R&lt;/span&gt;&lt;span style="background-color: white;"&gt;²&lt;/span&gt;&lt;span style="font-family: inherit;"&gt;&amp;nbsp;for this model is 0.89, and again the p-values are effectively 0. [Note for stats geeks: as it happens, the coefficient of the linear term is close to zero, so it is not statistically significant. &amp;nbsp;My first thought was to remove it from the model, but if I did that, I would understate the sampling error of the model. &amp;nbsp;In this case, it is correct to keep an "insignificant" variable in the model; the fact that it is near zero doesn't mean we can ignore it, or the error associated with it.]&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;To test more explicitly whether the growth is accelerating, I computed the change from one year to the next in percentage points. &amp;nbsp;The following figure shows these changes and a least squares fit:&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-I-hCh0R2GOM/TyVoTF2H9rI/AAAAAAAAAq8/P8LEOU0d4Ak/s1600/heri.0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-I-hCh0R2GOM/TyVoTF2H9rI/AAAAAAAAAq8/P8LEOU0d4Ak/s400/heri.0.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: inherit;"&gt;Subtraction amplifies noise, so for this model R&lt;/span&gt;&lt;span style="background-color: white;"&gt;²&lt;/span&gt;&lt;span style="font-family: inherit;"&gt;&amp;nbsp;is only 0.24, but the p-value of the slope is 0.002, so this data provides strong evidence of acceleration. &amp;nbsp;The slope is 0.035 percentage points per year.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;Based on this model, the predicted change for next year is 1 percentage point, so we expect the fraction of freshmen reporting no religious preference to be 26%.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;b&gt;The gender gap&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;Since the beginning of the CIRP survey, more men than women have reported no religious preference:&lt;/span&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-3wKhByBu6PU/TyVr2sIqE6I/AAAAAAAAArE/waGVnhqyIww/s1600/heri2.1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-3wKhByBu6PU/TyVr2sIqE6I/AAAAAAAAArE/waGVnhqyIww/s400/heri2.1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;And the gender gap seems to be growing. &amp;nbsp;Here is the difference between men and women, in percentage points, and a least squares fit:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-KT4uSHMdwYM/TyVsHADNwPI/AAAAAAAAArM/QhitSVjfOmI/s1600/heri2.2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-KT4uSHMdwYM/TyVsHADNwPI/AAAAAAAAArM/QhitSVjfOmI/s400/heri2.2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: inherit;"&gt;R&lt;span style="background-color: white;"&gt;²&lt;/span&gt;&lt;/span&gt;&amp;nbsp;for this model is 0.44; the slope is 0.035 percentage points per year, with p-value &amp;lt; 0.0001.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Discussion&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;I first wrote about this in&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&amp;nbsp;2007, in&amp;nbsp;&lt;a href="http://www.secularhumanism.org/index.php?section=library&amp;amp;page=downey_27_5"&gt;this article&lt;/a&gt;&amp;nbsp;for&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;a href="http://www.secularhumanism.org/index.php"&gt;Free Inquiry&lt;/a&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&amp;nbsp;magazine. &amp;nbsp;There I wrote:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;College students are hardly a random sample of the population. People with more education are less likely to believe in heaven, the devil, miracles, and the literal truth of the Christian Bible. However, contrary to many people’s expectations, educated people are more likely to attend services. So, we expect the students in this sample to be less believing than the general population but also more observant.&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;There is reason to think that the rate of secularization in the general population is faster than what we see in this sample. Over the lifetime of the CIRP survey, college education has democratized; the percentage of high-school graduates who enter college immediately after graduation has increased from roughly 50 percent in 1970 to 65 percent in 2003. Over this time, CIRP has included more poor students, more racial minorities, and more students from families with less education. These groups tend to be more religious than the general population, so we expect their participation to increase the religiosity in the sample. Thus, the observed decrease probably underestimates the trend in the general population.&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;The theory of secularization—that there is a global, long-term trend away from religion—is controversial. Early sociologists, notably Max Weber, hypothesized that secularization is a predictable effect of rationalization—the increasing tendency for social actions to be based on reason rather than emotion or tradition.&lt;i&gt;&lt;div style="display: inline !important;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;In the 1950s and 1960s, many sociologists of religion defended strong theories of secularization, but, since then, several of them—including Peter Berger and Harvey Cox—have reversed their positions, arguing that religion is resurging in some areas, including the United States.&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;i&gt;The data presented here speak directly to this debate. The CIRP survey has posed almost the same questions to a large sample of a consistently defined group for almost forty years, and the results show a clear and consistent trend away from both identification with religious sects and participation in religious services. These data make a strong case for secularization in the United States that has, if anything, accelerated in the last decade.&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;span style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;Data Source&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Data from the 2011 CIRP Survey are reported&lt;span style="background-color: white;"&gt; i&lt;span style="font-family: inherit;"&gt;n&amp;nbsp;&lt;i style="text-decoration: none;"&gt;&lt;a href="http://www.heri.ucla.edu/PDFs/pubs/TFS/Norms/Monographs/TheAmericanFreshman2011.pdf"&gt;The American Freshman: National Norms for Fall 2011&lt;/a&gt;,&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: white; font-family: inherit;"&gt;Pryor, J. H., DeAngelo, L., Palucki Blake, L., Hurtado, S., &amp;amp; Tran, S&lt;/span&gt;&lt;i style="background-color: white; font-family: inherit;"&gt;.,&amp;nbsp;&lt;/i&gt;&lt;span style="background-color: white; font-family: inherit;"&gt;Jan 2012.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: white; font-family: inherit;"&gt;This and all previous reports are available from the &lt;a href="http://www.heri.ucla.edu/tfsPublications.php"&gt;HERI publications page&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-3812367456227674137?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zbla9vriOEUFWV1VCS6q1jC2oUA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zbla9vriOEUFWV1VCS6q1jC2oUA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zbla9vriOEUFWV1VCS6q1jC2oUA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zbla9vriOEUFWV1VCS6q1jC2oUA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/WE6CpbLyBA4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/3812367456227674137/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/01/freshman-hordes-even-more-godless.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3812367456227674137?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3812367456227674137?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/WE6CpbLyBA4/freshman-hordes-even-more-godless.html" title="Freshman hordes even more godless!" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-DvbbO2qotjw/TyVlV7EMj3I/AAAAAAAAAqk/8CVIC4k7vQA/s72-c/heri2.3.png" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/01/freshman-hordes-even-more-godless.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUERng5fyp7ImA9WhRUFks.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1987200698901322045</id><published>2012-01-27T04:43:00.000-08:00</published><updated>2012-01-27T04:43:27.627-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-27T04:43:27.627-08:00</app:edited><title>Think Complexity, Part Two</title><content type="html">My new book,&amp;nbsp;&lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;, will&amp;nbsp;be published by&amp;nbsp;&lt;a href="http://shop.oreilly.com/product/0636920022480.do"&gt;O'Reilly Media&lt;/a&gt;&amp;nbsp;in March.&amp;nbsp;For people who can't stand to wait that long, I am publishing excerpts here. &amp;nbsp;If you really can't wait, you can read the free&amp;nbsp;version at&amp;nbsp;&lt;a href="http://thinkcomplex.com/"&gt;thinkcomplex.com&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In &lt;a href="http://allendowney.blogspot.com/2012/01/think-complexity.html"&gt;the previous installment&lt;/a&gt; I outlined the topics in &lt;i&gt;&lt;a href="http://thinkcomplex.com/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt; and contrasted a classical physical model of planetary orbits with an example&amp;nbsp;from complexity science: Schelling's model of racial segregation. &amp;nbsp;In&amp;nbsp;this installment I outline some of the ways complexity differs from&amp;nbsp;classical science.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Paradigm shift? &amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When I describe this book to people, I am often asked if this new kind of science is a paradigm shift. &amp;nbsp;I don't think so, and here's why. &amp;nbsp; Thomas Kuhn introduced the term ``paradigm shift'' in &lt;i&gt;The Structure of Scientific Revolutions&lt;/i&gt; in 1962. &amp;nbsp;It refers to a process in the history of science where the basic assumptions of a field change, or where one theory is replaced by another. He presents as examples the Copernican revolution, the displacement of phlogiston by the oxygen model of combustion, and the emergence of relativity. &lt;br /&gt;
&lt;br /&gt;
The development of complexity science is not the replacement of an older model, but (in my opinion) a gradual shift in the criteria models are judged by, and in the kinds of models that are considered acceptable. &amp;nbsp;For example, classical models tend to be law-based, expressed in the form of equations, and solved by mathematical derivation. &amp;nbsp;Models that fall under the umbrella of complexity are often rule-based, expressed as computations, and simulated rather than analyzed. &amp;nbsp;Not everyone finds these models satisfactory. &lt;br /&gt;
&lt;br /&gt;
For example, in &lt;i&gt;Sync&lt;/i&gt;, Steven Strogatz writes about his model of spontaneous synchronization in some species of fireflies. &amp;nbsp;He presents a simulation that demonstrates the phenomenon, but then writes: &lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;I repeated the simulation dozens of times, for other random initial conditions and for other numbers of oscillators. &amp;nbsp;Sync every time. [...] The challenge now was to prove it. &amp;nbsp;Only an ironclad proof would demonstrate, in a way that no computer ever could, that sync was inevitable; and the best kind of proof would clarify why it was inevitable. &lt;/i&gt;&amp;nbsp;&lt;/blockquote&gt;Strogatz is a mathematician, so his enthusiasm for proofs is understandable, but his proof doesn't address what is, to me, the most interesting part the phenomenon. &amp;nbsp;In order to prove that ``sync was inevitable,'' Strogatz makes several simplifying assumptions, in particular that each firefly can see all the others.&lt;br /&gt;
&lt;br /&gt;
In my opinion, it is more interesting to explain how an entire valley of fireflies can synchronize despite the fact that they cannot all see each other. &amp;nbsp;&lt;i&gt;Think Complexity&lt;/i&gt; discusses how this kind of global behavior emerges from local interactions. Explanations of these phenomena often use agent-based models, which explore (in ways that would be difficult or impossible with mathematical analysis) the conditions that allow or prevent synchronization. &lt;br /&gt;
&lt;br /&gt;
I am a computer scientist, so my enthusiasm for computational models is probably no surprise. &amp;nbsp;I don't mean to say that Strogatz is wrong, but rather that people disagree about what questions to ask and what tools to use to answer them. &amp;nbsp;These decisions are based on value judgments, so there is no reason to expect agreement. &amp;nbsp;Nevertheless, there is rough consensus among scientists about which models are considered good science, and which others are fringe science, pseudoscience, or not science at all. &lt;br /&gt;
&lt;br /&gt;
I claim, and this is a central thesis of the book, that the criteria this consensus is based on change over time, and that the emergence of complexity science reflects a gradual shift in these criteria. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The axes of scientific models&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I have described classical models as based on physical laws, expressed in the form of equations, and solved by mathematical analysis; conversely, models of complexity systems are often based on simple rules and implemented as computations. &amp;nbsp;We can think of this trend as a shift over time along two axes:&lt;br /&gt;
&lt;br /&gt;
Equation-based&lt;span style="background-color: #f9f9f9; line-height: 20px;"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: large;"&gt;→&lt;/span&gt;&lt;/span&gt;&amp;nbsp;simulation-based&lt;br /&gt;
Analysis&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;computation&lt;br /&gt;
&lt;br /&gt;
The new kind of science is different in several other ways:&lt;br /&gt;
&lt;br /&gt;
Continuous&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;discrete: Classical models tend to be based on continuous mathematics, like calculus; models of complex&amp;nbsp;systems are often based on discrete mathematics, including graphs and&amp;nbsp;cellular automata.&lt;br /&gt;
&lt;br /&gt;
Linear&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;non-linear: Classical models are often&amp;nbsp;linear, or use linear approximations to non-linear systems;&amp;nbsp;complexity science is more friendly to non-linear models. &amp;nbsp;One example&amp;nbsp;is chaos theory, which explores the dynamics of systems of non-linear equations.&lt;br /&gt;
&lt;br /&gt;
Deterministic&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;stochastic: Classical models are&amp;nbsp;usually deterministic, which may reflect underlying philosophical&amp;nbsp;determinism; complex models&amp;nbsp;often feature randomness.&lt;br /&gt;
&lt;br /&gt;
Abstract&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;detailed: In classical models, planets are&amp;nbsp;point masses, planes are frictionless, and cows are&amp;nbsp;spherical (see &lt;a href="http://en.wikipedia.org/wiki/Spherical_cow"&gt;http://en.wikipedia.org/wiki/Spherical_cow&lt;/a&gt;). &amp;nbsp;Simplifications like these are often necessary for analysis,&amp;nbsp;but computational models can be more realistic.&lt;br /&gt;
&lt;br /&gt;
One, two&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;many: In celestial mechanics, the&amp;nbsp;two-body problem can be solved analytically; the three-body problem&amp;nbsp;cannot. &amp;nbsp;Where classical models are often limited to&amp;nbsp;small numbers of interacting elements, complexity science works with&amp;nbsp;larger complexes (which is where the name comes from).&lt;br /&gt;
&lt;br /&gt;
Homogeneous&lt;span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; font-size: large; line-height: 20px;"&gt;→&lt;/span&gt;composite: In classical models, the&amp;nbsp;elements tend to be interchangeable; complex models more often&amp;nbsp;include heterogeneity.&lt;br /&gt;
&lt;br /&gt;
These are generalizations, so we should not take them too seriously. And I don't mean to deprecate classical science. &amp;nbsp;A more complicated model is not necessarily better; in fact, it is usually worse. &lt;br /&gt;
&lt;br /&gt;
Also, I don't mean to say that these changes are abrupt or complete. Rather, there is a gradual migration in the frontier of what is considered acceptable, respectable work. &amp;nbsp;Some tools that used to be regarded with suspicion are now common, and some &amp;nbsp;models that were widely accepted are now regarded with scrutiny. &amp;nbsp;For example, when Appel and Haken proved the four-color theorem in 1976, they used a computer to enumerate 1,936 special cases that were, in some sense, lemmas of their proof. &amp;nbsp;At the time, many mathematicians did not consider the theorem truly proved. &amp;nbsp;Now computer-assisted proofs are common and generally (but not universally) accepted.&lt;br /&gt;
&lt;br /&gt;
Conversely, a substantial body of economic analysis is based on a model of human behavior called ``Economic man,'' or, with tongue in cheek, &lt;i&gt;Homo economicus&lt;/i&gt;. &amp;nbsp;Research based on this model was highly-regarded for several decades, especially if it involved mathematical virtuosity. &amp;nbsp;More recently, this model is treated with more skepticism, and models that include imperfect information and bounded rationality are hot topics.&lt;br /&gt;
&lt;br /&gt;
At this point I have laid out a lot of ideas for one article, and&amp;nbsp;explained them very briefly. &amp;nbsp;&lt;i&gt;&lt;a href="http://thinkcomplex.com/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt; gets into these topics&amp;nbsp;in more detail, but I will stop here for now. &amp;nbsp;Next time I will talk about related shifts in engineering and (a little&amp;nbsp;farther afield) in ways of thinking.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1987200698901322045?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/I7CWytWm69W8QPX_GCvutu7BbgU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I7CWytWm69W8QPX_GCvutu7BbgU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/I7CWytWm69W8QPX_GCvutu7BbgU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/I7CWytWm69W8QPX_GCvutu7BbgU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/pDBCbIcXqoc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1987200698901322045/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/01/think-complexity-part-two.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1987200698901322045?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1987200698901322045?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/pDBCbIcXqoc/think-complexity-part-two.html" title="Think Complexity, Part Two" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/01/think-complexity-part-two.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUACSXYzeyp7ImA9WhRUE0k.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-5221337829151532586</id><published>2012-01-23T11:42:00.000-08:00</published><updated>2012-01-23T11:42:48.883-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-23T11:42:48.883-08:00</app:edited><title>Think Complexity</title><content type="html">&lt;i&gt;&lt;b&gt;Think Complexity&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
On Friday I turned in the manuscript for &lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt;, which will&amp;nbsp;be published by &lt;a href="http://shop.oreilly.com/product/0636920022480.do"&gt;O'Reilly Media&lt;/a&gt; in March (or, at least, that's the schedule).&amp;nbsp;For people who can't stand to wait that long, I am going to publish&amp;nbsp;excerpts here. &amp;nbsp;And if you really can't wait, you can read the free&amp;nbsp;version at &lt;a href="http://thinkcomplex.com/"&gt;thinkcomplex.com&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The book is about data structures and algorithms, intermediate&amp;nbsp;programming in Python, computational modeling and the philosophy of&amp;nbsp;science:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Data structures and algorithms: A data structure is a&amp;nbsp;collection of data elements organized in a way that supports&amp;nbsp;particular operations. &amp;nbsp;For example, a Python dictionary organizes&amp;nbsp;key-value pairs in a way that provides fast mapping from keys to&amp;nbsp;values, but mapping from values to keys is slower.&amp;nbsp;An algorithm is a mechanical process for performing a computation.&amp;nbsp;Designing efficient programs often involves the co-evolution of data&amp;nbsp;structures and the algorithms that use them. &amp;nbsp;For example, in the&amp;nbsp;first few chapters I present graphs, data structures that&amp;nbsp;implement graphs, and graph algorithms based on those data structures.&lt;/li&gt;
&lt;li&gt;Python programming: &lt;i&gt;&lt;a href="http://greenteapress.com/complexity/"&gt;Think Complexity&lt;/a&gt;&lt;/i&gt; picks up where &lt;i&gt;&lt;a href="http://greenteapress.com/thinkpython/thinkpython.html"&gt;Think Python&lt;/a&gt;&lt;/i&gt;&amp;nbsp;leaves off. &amp;nbsp;I assume that you have read that book or have&amp;nbsp;equivalent knowledge of Python. &amp;nbsp;I try to emphasize fundamental ideas&amp;nbsp;that apply to programming in many languages, but along the way I present some useful features that are specific to Python.&lt;/li&gt;
&lt;li&gt;Computational modeling: A model is a simplified&amp;nbsp;description of a system used for simulation or analysis.&amp;nbsp;Computational models are designed to take advantage of cheap, fast&amp;nbsp;computation.&lt;/li&gt;
&lt;li&gt;Philosophy of science: The experiments and results in this book&amp;nbsp;raise questions relevant to the philosophy of science,&amp;nbsp;including the nature of scientific laws, theory choice, realism and&amp;nbsp;instrumentalism, holism and reductionism, and epistemology.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
The book is also about complexity science, which is an&amp;nbsp;interdisciplinary field---at the intersection of mathematics, computer&amp;nbsp;science and natural science---that focuses on discrete models of&amp;nbsp;physical systems. &amp;nbsp;In particular, it focuses on complex systems, which are&amp;nbsp;systems with many interacting components. &lt;br /&gt;
&lt;br /&gt;
Complex systems include networks and graphs, cellular automata,&amp;nbsp;agent-based models and swarms, fractals and self-organizing&amp;nbsp;systems, chaotic systems and cybernetic systems. &amp;nbsp;Here is a&amp;nbsp;framework for these topics (from&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Complex_systems"&gt;http://en.wikipedia.org/wiki/Complex_systems&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://upload.wikimedia.org/wikipedia/commons/d/de/Complex_systems_organizational_map.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Complex_systems_organizational_map.jpg" width="319" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A new kind of science?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In 2002 Stephen Wolfram published &lt;i&gt;&lt;a href="http://www.wolframscience.com/"&gt;A New Kind of Science&lt;/a&gt;&lt;/i&gt; where he&amp;nbsp;presents his and others' work on cellular automata and describes a&amp;nbsp;scientific approach to the study of computational systems. &amp;nbsp;There's a chapter about cellular automata in the book, but for now I'm going to borrow his&amp;nbsp;title for something a little broader.&lt;br /&gt;
&lt;br /&gt;
I think complexity is a ``new kind of science'' not because&amp;nbsp;it applies the tools of science to a new subject, but because it&amp;nbsp;uses different tools, allows different kinds of work, and ultimately&amp;nbsp;changes what we mean by ``science.''&lt;br /&gt;
&lt;br /&gt;
To demonstrate the difference, I'll start with an example of classical&amp;nbsp;science: suppose someone asked you why planetary orbits are&amp;nbsp;elliptical. &amp;nbsp;You might invoke Newton's law of universal&amp;nbsp;gravitation and use it to write a differential equation that describes&amp;nbsp;planetary motion. &amp;nbsp;Then you could solve the differential equation and&amp;nbsp;show that the solution is an ellipse. &amp;nbsp;Voila!&lt;br /&gt;
&lt;br /&gt;
Most people find this kind of explanation satisfying. &amp;nbsp;It includes a&amp;nbsp;mathematical derivation---so it has some of the rigor of a proof---and&amp;nbsp;it explains a specific observation, elliptical orbits, by appealing to&amp;nbsp;a general principle, gravitation.&lt;br /&gt;
&lt;br /&gt;
Let me contrast that with a different kind of explanation. &amp;nbsp;Suppose&amp;nbsp;you move to a city like Detroit that is racially segregated, and you&amp;nbsp;want to know why it's like that. &amp;nbsp;If you do some research, you might&amp;nbsp;find a paper by Thomas Schelling called ``Dynamic Models of&amp;nbsp;Segregation,'' which proposes a simple model of racial segregation&amp;nbsp;(you can download the paper&amp;nbsp;&lt;a href="http://statistics.berkeley.edu/~aldous/157/Papers/Schelling_Seg_Models.pdf"&gt;here&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
Here is an outline of the paper's primary experiment:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The Schelling model of the city is an array of cells where each cell&amp;nbsp;represents a house. &amp;nbsp;The houses are occupied by two kinds of &lt;i&gt;agents&lt;/i&gt;, labeled red and blue, in roughly equal numbers. &amp;nbsp;About&amp;nbsp;10% of the houses are empty. &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;At any point in time, an agent might be happy or unhappy, depending&amp;nbsp;on the other agents in the neighborhood. &amp;nbsp;In one version of the model, agents are happy if they have at least&amp;nbsp;two neighbors like themselves, and unhappy if they have one or zero.&lt;/li&gt;
&lt;li&gt;The simulation proceeds by choosing an agent at random and checking&amp;nbsp;to see whether it is happy. &amp;nbsp;If so, nothing happens; if not,&amp;nbsp;the agent chooses one of the unoccupied cells at&amp;nbsp;random and moves.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
If you start with a simulated city that is entirely unsegregated and&amp;nbsp;run the model for a short time, clusters of similar agents appear. &amp;nbsp;As&amp;nbsp;time passes, the clusters grow and coalesce until there are a small&amp;nbsp;number of large clusters and most agents live in homogeneous&amp;nbsp;neighborhoods. &lt;br /&gt;
&lt;br /&gt;
The degree of segregation in the model is surprising, and it suggests&amp;nbsp;an explanation of segregation in real cities. &amp;nbsp;Maybe Detroit is&amp;nbsp;segregated because people prefer not to be greatly outnumbered and&amp;nbsp;will move if the composition of their neighborhoods makes them&amp;nbsp;unhappy. &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
Is this explanation satisfying in the same way as the explanation of&amp;nbsp;planetary motion? &amp;nbsp;Most people would say not, but why?&lt;br /&gt;
&lt;br /&gt;
Most obviously, the Schelling model is highly abstract, which is to&amp;nbsp;say not realistic. &amp;nbsp;It is tempting to say that people are more complex&amp;nbsp;than planets, but when you think about it, planets are just as complex&amp;nbsp;as people (especially the ones that have people).&lt;br /&gt;
&lt;br /&gt;
Both systems are complex, and both models are based on&amp;nbsp;simplifications; for example, in the model of planetary motion we&amp;nbsp;include forces between the planet and its sun, and ignore interactions&amp;nbsp;between planets.&lt;br /&gt;
&lt;br /&gt;
The important difference is that, for planetary motion, we can defend&amp;nbsp;the model by showing that the forces we ignore are smaller than the&amp;nbsp;ones we include. &amp;nbsp;And we can extend the model to include other&amp;nbsp;interactions and show that the effect is small. &amp;nbsp;For Schelling's model&amp;nbsp;it is harder to justify the simplifications.&lt;br /&gt;
&lt;br /&gt;
To make matters worse, Schelling's model doesn't appeal to any&amp;nbsp;physical laws, and it uses only simple computation, not mathematical&amp;nbsp;derivation. &amp;nbsp;Models like Schelling's don't look like classical&amp;nbsp;science, and many people find them less compelling, at least at first.&amp;nbsp;But as I will try to demonstrate, these models do useful work,&amp;nbsp;including prediction, explanation, and design. &amp;nbsp;One of the goals of&amp;nbsp;&lt;i&gt;Think Complexity&lt;/i&gt; is to explain how.&lt;br /&gt;
&lt;br /&gt;
In the next excerpt, I will present some of the ways I think complexity science differs from classical science. &amp;nbsp;But in the meantime I welcome comments on Part One.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-5221337829151532586?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/92hcFNN2oxmfRUJAr0evL283AwA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/92hcFNN2oxmfRUJAr0evL283AwA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/92hcFNN2oxmfRUJAr0evL283AwA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/92hcFNN2oxmfRUJAr0evL283AwA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/noP1jZYQBcs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/5221337829151532586/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/01/think-complexity.html#comment-form" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5221337829151532586?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5221337829151532586?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/noP1jZYQBcs/think-complexity.html" title="Think Complexity" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>6</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/01/think-complexity.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkANQHwzfyp7ImA9WhRUEEs.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-3735925895027847767</id><published>2012-01-20T06:13:00.000-08:00</published><updated>2012-01-20T06:13:11.287-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-20T06:13:11.287-08:00</app:edited><title>Some of my best friends are crackpots</title><content type="html">I have a soft spot for crank science. &amp;nbsp;Recently I visited &lt;a href="http://en.wikipedia.org/wiki/Norumbega_Tower"&gt;Norumbega Tower&lt;/a&gt;, which is an enduring monument to the crackpot theories of &lt;a href="http://en.wikipedia.org/wiki/Eben_Norton_Horsford"&gt;Eben Norton Horsford&lt;/a&gt;, inventor of double-acting baking powder and faux history. &amp;nbsp;But that's not what this article is about.&lt;br /&gt;
&lt;br /&gt;
This article is about the &lt;a href="http://en.wikipedia.org/wiki/Variability_hypothesis"&gt;Variability Hypothesis&lt;/a&gt;, which (quoth Wikipedia):&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;"originated in the early nineteenth century with Johann Meckel, who argued that males have a greater range of ability than females, especially in intelligence. In other words, he believed that most geniuses and most mentally retarded people are men. Because he considered males to be the 'superior animal,' Meckel concluded that females' lack of variation was a sign of inferiority."&lt;/blockquote&gt;I particularly like the last part, because I suspect that if it turns out that women are actually &lt;i&gt;more&lt;/i&gt; variable, Meckel would take that as a sign of inferiority, too. &amp;nbsp;Anyway, you will not be surprised to hear that evidence for the Variability Hypothesis is mixed at best.&lt;br /&gt;
&lt;br /&gt;
Nevertheless, it came up in my class recently when we looked at data from the CDC's &lt;a href="http://www.cdc.gov/brfss/"&gt;Behavioral Risk Factor Surveillance System&lt;/a&gt; (BRFSS), specifically the self-reported height of adult American men and women. &amp;nbsp;The dataset includes responses from&amp;nbsp;154407 men and&amp;nbsp;254722 women. &amp;nbsp;Here's what we found:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The average height for men is 178 cm; the average height for women is 163 cm. &amp;nbsp;So men are taller, on average. &amp;nbsp;No surprises so far.&lt;/li&gt;
&lt;li&gt;For men the standard deviation is 7.7 cm; for women is it 7.3 cm. &amp;nbsp;So in absolute terms, men's heights are more variable.&lt;/li&gt;
&lt;li&gt;But to compare variability between groups, it is more meaningful to use the &lt;a href="http://en.wikipedia.org/wiki/Coefficient_of_variation"&gt;coefficient of variation&lt;/a&gt;&amp;nbsp;(CV), which is the standard deviation divided by the mean. &amp;nbsp;It is a dimensionless measure of variability relative to scale. &amp;nbsp;For men CV is&amp;nbsp;0.0433; for women it is&amp;nbsp;0.0444.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
That's very close, so we could conclude that this dataset provides no support for the Variability Hypothesis. &amp;nbsp;But in keeping with the theme of this blog, I won't be happy until I have overthought the question. &amp;nbsp;And along the way I want to use this problem to demonstrate Bayesian estimation in 2 dimensions.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b&gt;Bayesian estimation in 2-D&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In previous articles I have presented Bayesian estimation for the &lt;a href="http://allendowney.blogspot.com/2011/06/hierarchical-bayesian-model-of-pond.html"&gt;number of species in a biological sample&lt;/a&gt; and the &lt;a href="http://allendowney.blogspot.com/2011/11/estimating-age-of-renal-tumors.html"&gt;age of a renal tumor&lt;/a&gt;. &amp;nbsp;But those are both 1-D problems. &amp;nbsp;Estimating the mean and variance of a sample is a 2-D problem. &amp;nbsp;There are analytic solutions for several forms of the prior distribution, but as usual I will demonstrate a computational approach.&lt;br /&gt;
&lt;br /&gt;
I'll present the code for the update first, and get back to the prior. &amp;nbsp;Here's what the update looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;def LogUpdate(suite, evidence):&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for hypo in suite.Values():&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; likelihood = LogLikelihood(evidence, hypo)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; suite.Incr(hypo, likelihood)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;suite&lt;/span&gt; is a Pmf object that maps from each hypothesis to its probability. &amp;nbsp;While we're performing the update, the probabilities are unnormalized, which is why they are called likelihoods. &amp;nbsp;And the whole thing happens under a log transform, because otherwise the likelihoods get so small they get rounded off to zero (see &lt;a href="http://en.wikipedia.org/wiki/Arithmetic_underflow"&gt;underflow&lt;/a&gt;).&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Here's the function that computes likelihoods:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;def LogLikelihood(evidence, hypo):&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; t = evidence&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; mu, sigma = hypo&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; total = Summation(t, mu)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return -len(t) * math.log(sigma) - total / 2 / sigma**2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;evidence&lt;/span&gt; is the tuple of heights in centimeters; &lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;hypo&lt;/span&gt; is a tuple of hypothetical values for mu and sigma. &amp;nbsp;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;Summation&lt;/span&gt; computes the sum of the squared deviations from mu; the return value is the log likelihood of getting this sample from a Gaussian distribution with the hypothetical parameters.&lt;br /&gt;
&lt;br /&gt;
I pulled &lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;Summation&lt;/span&gt; out into a separate function because it gets called repeatedly with the same parameters, so I can improve the run time (a lot) by caching previous results:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;def Summation(t, mu, cache={}):&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; try:&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return cache[t, mu]&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; except KeyError:&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; total = sum((x-mu)**2 for x in t)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cache[t, mu] = total&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return total&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
That's it for the update. &amp;nbsp;Now we need a prior. &amp;nbsp;One option is a uniform prior where mu can be any value and sigma can be any positive value. &amp;nbsp;In practice, there is no point in evaluating values far from the true parameters, because their likelihoods will be vanishingly small. &amp;nbsp;So we'll use the data to choose the range for the prior, then use the data to update the prior.&lt;br /&gt;
&lt;br /&gt;
That might sound completely bogus, because we are using the same data twice. &amp;nbsp;But choosing the range for the prior is just a computational convenience; it has no effect on the result, as long as the range is wide enough that the likelihood for values outside the range is effectively zero.&lt;br /&gt;
&lt;br /&gt;
To choose the prior range for mu and sigma, I use the conventional estimators and their standard errors. &amp;nbsp;Here's the code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def MakeUniformPrior(t, num_points, label, spread=3.0):&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; # estimate mean and stddev of t&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; n = len(t)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; xbar, S2 = thinkstats.MeanVar(t)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; sighat = math.sqrt(S2)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; # compute standard error for mu and the range of ms&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; stderr_xbar = sighat / math.sqrt(n)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; mspread = spread * stderr_xbar&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; ms = numpy.linspace(xbar-mspread, xbar+mspread, num_points)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; # compute standard error for sigma and the range of ss&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; stderr_sighat = sighat / math.sqrt(2 * (n-1))&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; sspread = spread * stderr_sighat&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; ss = numpy.linspace(sighat-sspread, sighat+sspread, num_points)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; # populate the PMF&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; pmf = Pmf.Pmf(name=label)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; for m in ms:&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for s in ss:&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pmf.Set((m, s), 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; return ms, ss, pmf&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Finally, here's the code that makes the prior, updates it, and normalizes the posterior:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;def EstimateParameters(t, label, num_points=31):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; xs, ys, suite = MakeUniformPrior(t, num_points, label)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; suite.Log()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; LogUpdate(suite, tuple(t))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; suite.Exp()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; suite.Normalize()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return xs, ys, suite&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Ok, that was more code than I usually put in these articles. &amp;nbsp;You can download it all from &lt;a href="http://thinkcomplex.com/bayes_height.py"&gt;thinkcomplex.com/bayes_height.py&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;Results&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The result is a map from pairs of mu and sigma to probabilities; one simple way to display the map is a contour plot. &amp;nbsp;Here is the result for men:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-7cLdBbdhAIY/TxiBEPEpD1I/AAAAAAAAAps/J0xQ2fI64vc/s1600/bayes_height_posterior_male.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-7cLdBbdhAIY/TxiBEPEpD1I/AAAAAAAAAps/J0xQ2fI64vc/s320/bayes_height_posterior_male.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;And for women:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-k_OTUlf45fA/TxiBJIJPzMI/AAAAAAAAAp0/Ameox0WdvXM/s1600/bayes_height_posterior_female.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-k_OTUlf45fA/TxiBJIJPzMI/AAAAAAAAAp0/Ameox0WdvXM/s320/bayes_height_posterior_female.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;As expected, the central location is near the estimated parameters. &amp;nbsp;But with this result in numerical form is that it is easy to compute the marginal distributions for mu and sigma, or their confidence intervals. &amp;nbsp;We can also compute posterior distributions for CV, and compare the distributions CV for men and women:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-K-Oz8cfOmIE/TxiBqEkzXZI/AAAAAAAAAp8/0Xec7_NKUG8/s1600/bayes_height_cv.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-K-Oz8cfOmIE/TxiBqEkzXZI/AAAAAAAAAp8/0Xec7_NKUG8/s320/bayes_height_cv.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Since there is no overlap between the distributions, we can conclude that the small observed difference is statistically significant; or, if we want to be more Bayesian about it, we can compute the probability that the CV for women is higher, which is pretty close to 1.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Finally we conclude:&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;The standard deviation of height for men is higher.&lt;/li&gt;
&lt;li&gt;But the coefficient of variation is slightly lower.&lt;/li&gt;
&lt;li&gt;Even though the difference is tiny, it is very unlikely to be due to chance.&lt;/li&gt;
&lt;li&gt;And therefore women are inferior.&lt;/li&gt;
&lt;/ul&gt;&lt;div&gt;Hey, I told you I have a soft spot for crank science.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-3735925895027847767?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PeS7zaGx71r0O2TR1eqwYwhkkB0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PeS7zaGx71r0O2TR1eqwYwhkkB0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PeS7zaGx71r0O2TR1eqwYwhkkB0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PeS7zaGx71r0O2TR1eqwYwhkkB0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/LzXynAT2YoI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/3735925895027847767/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/01/some-of-my-best-friends-are-crackpots.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3735925895027847767?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3735925895027847767?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/LzXynAT2YoI/some-of-my-best-friends-are-crackpots.html" title="Some of my best friends are crackpots" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-7cLdBbdhAIY/TxiBEPEpD1I/AAAAAAAAAps/J0xQ2fI64vc/s72-c/bayes_height_posterior_male.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/01/some-of-my-best-friends-are-crackpots.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YFRXszfip7ImA9WhRVE0U.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1982258704914428066</id><published>2012-01-05T09:44:00.000-08:00</published><updated>2012-01-12T09:25:14.586-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-12T09:25:14.586-08:00</app:edited><title>Frank is a scoundrel, probably</title><content type="html">My friend Ted Bunn wrote an article, "&lt;a href="http://blog.richmond.edu/physicsbunn/2012/01/05/who-knows-what-evil-lurks-in-the-hearts-of-men-the-bayesian-doesnt-care/"&gt;Who knows what evil lurks in the hearts of men? The Bayesian doesn’t care&lt;/a&gt;," inspired in part by one of my posts, "&lt;a href="http://allendowney.blogspot.com/2011/10/repeated-tests-how-bad-can-it-be.html"&gt;Repeated tests: how bad can it be?&lt;/a&gt;"&lt;br /&gt;
&lt;br /&gt;
He presents this scenario:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;Frank and Betsy are wondering whether a particular coin is a fair coin (i.e., comes up heads and tails equally often when flipped). &amp;nbsp;Frank, being a go-getter type, offers to do some tests to find out. He takes the coin away, flips it a bunch of times, and eventually comes back to Betsy to report his results.&amp;nbsp;&lt;/i&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;i&gt;“I flipped the coin 3022 times,” he says, “and it came up heads 1583 times. That’s 72 more heads than you’d expect with a fair coin. I worked out the p-value — that is, the probability of this large an excess occurring if the coin is fair — and it’s under 1%. So we can conclude that the coin is unfair at a significance level of &amp;nbsp;1% (or ’99% confidence’ as physicists often say).”&lt;/i&gt;&lt;/blockquote&gt;And suggests that there are two ways Betsy can interpret this report (again, quoting Ted):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;i&gt;Frank is an honest man, who has followed completely orthodox (frequentist) statistical procedure. To be specific, he decided on the exact protocol for his test (including, for some reason, the decision to do 3022 trials) in advance.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;Frank is a scoundrel who, for some reason, wants to reach the conclusion that the coin is unfair. He comes up with a nefarious plan: he keeps flipping the coin for as long as it takes to reach that 1% significance threshold, and then he stops and reports his results.&lt;/i&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
Finally, Ted asks, "What should Betsy conclude on the basis of the information Frank has given her?" &amp;nbsp;If you want to know Ted's answer, you have to read &lt;a href="http://blog.richmond.edu/physicsbunn/2012/01/05/who-knows-what-evil-lurks-in-the-hearts-of-men-the-bayesian-doesnt-care/"&gt;his article&lt;/a&gt; (and you should -- it is very interesting).&lt;br /&gt;
&lt;br /&gt;
But I'm going to give you my answer: Frank is a scoundrel. &amp;nbsp;Well, probably.&lt;br /&gt;
&lt;br /&gt;
I'll follow Ted by making one more assumption: "Suppose that Betsy’s initial belief is that 95% of coins are fair — that is, the probability P that they come up heads is exactly 0.5." &amp;nbsp;Now we can evaluate the evidence that Frank is a scoundrel.&lt;br /&gt;
&lt;br /&gt;
If Frank is a scoundrel, the probability that he reports a positive result is 1, provided that he is willing to keep flipping long enough, or 1-x, for small x, if we put a bound on the number of flips he is willing to do. &amp;nbsp;So&lt;br /&gt;
&lt;br /&gt;
P(positive test | Frank is a scoundrel) = 1-x&lt;br /&gt;
&lt;br /&gt;
If Frank is honest, then the probability of a positive result is&lt;br /&gt;
&lt;br /&gt;
P(fair coin) P(false positive | fair coin) + P(biased coin) * P(true positive | biased coin)&lt;br /&gt;
&lt;br /&gt;
Betsy believes that P(fair coin) is 95% and P(biased coin) is 5%. &amp;nbsp;Since Frank's significance level is 1%, P(false positive | fair coin) is 1%.&lt;br /&gt;
&lt;br /&gt;
The probability of a true positive is the power of the test, which depends on how biased the coin actually is. &amp;nbsp;But I will make the approximation that 3022 flips is enough to detect any substantial bias, so I'll take P(true positive | biased coin) = 1-y, for small y. &amp;nbsp;So,&lt;br /&gt;
&lt;br /&gt;
P(positive test | Frank is honest) = (0.95)(0.01) + (0.05)(1-y)&lt;br /&gt;
&lt;br /&gt;
As x and y get small, the likelihood ratio is (1 / 0.0595), which is about 17. &amp;nbsp;So that is fairly strong evidence that Frank is a scoundrel.&lt;br /&gt;
&lt;br /&gt;
I don't know about Betsy's prior beliefs about Frank, so you will have to fill in your own punchline about her posterior.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1982258704914428066?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1A79ifE99xichqvOlnU7YkMHGk0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1A79ifE99xichqvOlnU7YkMHGk0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1A79ifE99xichqvOlnU7YkMHGk0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1A79ifE99xichqvOlnU7YkMHGk0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/wZ3HdF8M9jw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1982258704914428066/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2012/01/frank-is-scoundrel-probably.html#comment-form" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1982258704914428066?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1982258704914428066?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/wZ3HdF8M9jw/frank-is-scoundrel-probably.html" title="Frank is a scoundrel, probably" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>6</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2012/01/frank-is-scoundrel-probably.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUAMR30zfyp7ImA9WhRRFkU.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-2103279562654342252</id><published>2011-11-30T07:29:00.000-08:00</published><updated>2011-11-30T12:09:46.387-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-30T12:09:46.387-08:00</app:edited><title>Are first babies more likely to be light?</title><content type="html">Way back in February I analyzed data from the National Survey of Family Growth (NSFG) and answered the question "&lt;a href="http://allendowney.blogspot.com/2011/02/are-first-babies-more-likely-to-be-late.html"&gt;Are first babies more likely to be late?&lt;/a&gt;" &amp;nbsp;Now I am getting back to that data to look at the related question, "Are first babies more likely to be &lt;i&gt;light&lt;/i&gt;?"&lt;br /&gt;
&lt;br /&gt;
In &lt;i&gt;&lt;a href="http://greenteapress.com/thinkstats/"&gt;Think Stats&lt;/a&gt;&lt;/i&gt; (Chapter 7), I showed that the mean birth weight for first babies is lower than the mean for others by about 2 ounces, and that difference is statistically significant. &amp;nbsp;But there is also a relationship between birth weight and mother's age, and the mothers of first babies tend to be younger. &amp;nbsp;So the question is: &lt;b&gt;if we control for the age of the mother, are first babies still lighter?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Several students in my class are working on projects involving multivariate regression, so I want to use this question as an example. &amp;nbsp;I will follow the steps I recommend to my students:&lt;br /&gt;
&lt;br /&gt;
1) Before looking at relationships between variables, look at each variable in isolation. &amp;nbsp;In particular, characterize the distributions and identify issues like outliers or long tails.&lt;br /&gt;
&lt;br /&gt;
2) Look at the variables pairwise. &amp;nbsp;For each pair, look at CDFs and scatterplots, and compute correlations and/or least squares fits.&lt;br /&gt;
&lt;br /&gt;
3) If there seem to be relationships among the variables, look for ways to separate the effects, either by breaking the data into subsets or doing multivariate regression.&lt;br /&gt;
&lt;br /&gt;
So let's proceed.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;One variable at a time&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The variables I'll use are&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Mother's age in years,&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Birth weight in ounces, and&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt;, which is a &lt;a href="http://en.wikipedia.org/wiki/Dummy_variable_(statistics)"&gt;dummy variable&lt;/a&gt;, 1 for first babies and 0 for others.&lt;/li&gt;
&lt;/ol&gt;For live births we have 9148 records with valid ages; here is the distribution:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-gogQHhCvgMs/TtVPYtf7DeI/AAAAAAAAAoc/AuorqD3_iSQ/s1600/agemodel_age_cdf.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-gogQHhCvgMs/TtVPYtf7DeI/AAAAAAAAAoc/AuorqD3_iSQ/s320/agemodel_age_cdf.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;It looks like there is a little skew to the right, but other than that, nothing to worry about.&lt;br /&gt;
&lt;br /&gt;
We have 9038 records with valid weights, with this distribution:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-krq_h1VKkEU/TtVPuEpj_ZI/AAAAAAAAAok/LDo2MR3-C_I/s1600/agemodel_weight_cdf.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-krq_h1VKkEU/TtVPuEpj_ZI/AAAAAAAAAok/LDo2MR3-C_I/s320/agemodel_weight_cdf.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;The middle of the distribution is approximately normal, with some jaggies due to round-off. &amp;nbsp;In the tails there are some values that are are certainly errors, but it is hard to draw a clear line between exceptional cases and bad data. &amp;nbsp;It might be a good idea to exclude some extreme values, but for the analysis below I did not.&lt;br /&gt;
&lt;br /&gt;
There are only two values for&amp;nbsp;&lt;span class="Apple-style-span" style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt;, so it's not much of a distribution, but with categorical data, we should check that we have enough values in each bin. &amp;nbsp;As it turns out, there are 4413 first babies and 4735 others, so that's just fine.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;One pair at a time&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To characterize the relationship between weight and&amp;nbsp;&lt;span class="Apple-style-span" style="color: #6aa84f; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt;, we compare the CDF of weights for first babies and others:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-fqRIFW2eamE/TtVSQIhhTQI/AAAAAAAAAos/OuKslNXR7RM/s1600/agemodel_weight_cdfs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-fqRIFW2eamE/TtVSQIhhTQI/AAAAAAAAAos/OuKslNXR7RM/s320/agemodel_weight_cdfs.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;There is some space between the distributions, and the difference in means is 2 ounces. &amp;nbsp;It's not obvious whether that difference is statistically significant, but it is, with p &amp;lt; 0.001.&lt;br /&gt;
&lt;br /&gt;
Similarly we can compare the CDF of mother's age for first babies and others:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-3ZyaTWxpe6U/TtVSzsGS77I/AAAAAAAAAo0/0dVi0-JNMXw/s1600/agemodel_age_cdfs.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-3ZyaTWxpe6U/TtVSzsGS77I/AAAAAAAAAo0/0dVi0-JNMXw/s320/agemodel_age_cdfs.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Here there is clearly space between the distributions. &amp;nbsp;The difference in means is 3.6 years, which is significant (no surprise this time).&lt;br /&gt;
&lt;br /&gt;
It is not as easy to see the relationship between age and birthweight. &amp;nbsp;I often tell my students to start with a scatterplot:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-iBI2ucBe03c/TtVTZjftWOI/AAAAAAAAAo8/CqUgFL48MQQ/s1600/agemodel_scatter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-iBI2ucBe03c/TtVTZjftWOI/AAAAAAAAAo8/CqUgFL48MQQ/s400/agemodel_scatter.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;But in this case it's not much help. &amp;nbsp;If there is a relationship there, it is hard to see. &amp;nbsp;An alternative is to break the age range into bins and compute the mean in each bin. &amp;nbsp;Here's what that looks like with 2-year bins:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Gjsz5RLsTMw/TtVT7cbo3cI/AAAAAAAAApE/c34pEZJVDxU/s1600/agemodel_line.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://2.bp.blogspot.com/-Gjsz5RLsTMw/TtVT7cbo3cI/AAAAAAAAApE/c34pEZJVDxU/s320/agemodel_line.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;We can't take the first and last points too seriously; there are not many cases in those bins. &amp;nbsp;And ideally I should represent the variability in each bin so we have a sense of whether the apparent differences are real. &amp;nbsp;Based on this figure, it looks like there is a relationship, but it might be nonlinear.&lt;br /&gt;
&lt;br /&gt;
Pearson's coefficient of correlation between age and birthweight is 0.07, which is small but statistically significant. &amp;nbsp;Spearman's coefficient of correlation is 0.10; the difference between the two coefficients is another warning that the relationship is nonlinear.&lt;br /&gt;
&lt;br /&gt;
If we ignore the non-linearity for now, we can compute a least squares fit for birthweight as a function of age. &amp;nbsp;The slope is 0.28, which means that we expect an additional 0.28 ounces per year of age. &amp;nbsp;Since first mothers are 3.6 years younger than others, we expect their babies to be 1.0 ounces lighter. &amp;nbsp;In fact, they are 2.0 ounces lighter, so the linear model of weight vs age accounts for 50% of the observed difference.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Multiple regression&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So far I have been using the &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;thinkstats&lt;/span&gt; libraries to compute correlation coefficients and least squares fits. &amp;nbsp;But for multiple regression I am going to break out &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;rpy&lt;/span&gt;, which is the Python interface to &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt;,&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&amp;nbsp;a "language and environment for statistical computing and graphics. It is a&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.gnu.org/" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; color: blue;" target="_top"&gt;GNU project&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&amp;nbsp;which is similar to the S language and environment which was developed at Bell Laboratories." &amp;nbsp;&lt;/span&gt;To see how it works, you can download the code I used in this section: &lt;a href="http://greenteapress.com/thinkstats/age_lm.py"&gt;age_lm.py&lt;/a&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;The first model I ran is the same linear model we were just looking at:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;weight = intercept + slope * age&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;In R's shorthand, that's:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;weights ~ ages&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
Here are the results:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;(Intercept) 109.28635 &amp;nbsp; &amp;nbsp;1.08775 100.470 &amp;nbsp;&amp;lt; 2e-16 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.27926 &amp;nbsp; &amp;nbsp;0.04258 &amp;nbsp; 6.559 5.72e-11 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;Multiple R-squared: 0.004738,&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Adjusted R-squared: 0.004628&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
The intercept is 109 ounces; the slope is 0.28 ounces per year, which what we saw before---comparing my implementation to R makes me more confident that R is correct :)&lt;br /&gt;
&lt;br /&gt;
The standard error provides a confidence interval for the estimates; plus or minus 2 standard errors is (roughly) a 95% confidence interval.&lt;br /&gt;
&lt;br /&gt;
The last column is the p-value, which is very small, indicating that the slope and intercept are significantly different from 0. &amp;nbsp;The t-value is the test statistic used to compute the p-value, but I don't know why it gets reported; it doesn't mean much.&lt;br /&gt;
&lt;br /&gt;
Since the p-values are so small, it might be surprising that&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;&amp;nbsp;is so low, only 0.0047. &amp;nbsp;But there is no contradiction. &amp;nbsp;We can say with high confidence that there is a relationship between these variables; nevertheless, birth weight is highly variable, and even if you know the age of the mother, that does not reduce the variability by much.&lt;br /&gt;
&lt;br /&gt;
To understand adjusted&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;, consider this:&amp;nbsp;if you add more explanatory variables to a model,&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;&amp;nbsp;usually goes up even if there is no real relationship. &amp;nbsp;The adjusted&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;&amp;nbsp;takes this into account, which makes it more meaningful to compare models with a different number of variables.&lt;br /&gt;
&lt;br /&gt;
Now let's add &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt; as an explanatory variable, so the model looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;weights ~ first + ages&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here are the results:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;(Intercept) 110.62791 &amp;nbsp; &amp;nbsp;1.24198 &amp;nbsp;89.073 &amp;nbsp;&amp;lt; 2e-16 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;first &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-1.11688 &amp;nbsp; &amp;nbsp;0.49940 &amp;nbsp;-2.236 &amp;nbsp; 0.0253 * &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.24708 &amp;nbsp; &amp;nbsp;0.04493 &amp;nbsp; 5.499 3.93e-08 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;Multiple R-squared: 0.005289,&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Adjusted R-squared: 0.005069&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The coefficient for &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt; is -1.1, which means that we expect first babies to be 1.1 ounces lighter, controlling for age. &amp;nbsp;The p-value for this estimate is 2.5%, which I consider borderline significant.&lt;br /&gt;
&lt;br /&gt;
The coefficient for &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages&lt;/span&gt; is about the same as before, and significant. &amp;nbsp;And&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;&amp;nbsp;is a little higher, but still small.&lt;br /&gt;
&lt;br /&gt;
But remember that the relationship between weight and age is non-linear. &amp;nbsp;We can explore that by introducing a new variable:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages2 = ages^2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now if we run this model:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;weights ~ ages + ages2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We are effectively fitting a parabola to the weight vs age curve.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;(Intercept) 89.151237 &amp;nbsp; 4.407677 &amp;nbsp;20.226 &amp;nbsp;&amp;lt; 2e-16 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.898151 &amp;nbsp; 0.346071 &amp;nbsp; 5.485 4.25e-08 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages2 &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.031002 &amp;nbsp; 0.006577 &amp;nbsp;-4.714 2.47e-06 ***&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;Multiple R-squared: 0.00718,&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Adjusted R-squared: 0.00696&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Estimates for both variables are significant. &amp;nbsp;The coefficient for &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages2&lt;/span&gt; is negative, which means that the parabola has downward curvature, as expected. &amp;nbsp;And&amp;nbsp;&lt;i style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;R&lt;/i&gt;&lt;sup style="background-color: white; font-family: sans-serif; line-height: 1em;"&gt;2&lt;/sup&gt;&amp;nbsp;is a little bigger.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Finally, we can bring it all together:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;weights ~ first + ages + ages2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;With this model we get:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Estimate Std. Error t value Pr(&amp;gt;|t|) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;(Intercept) 91.07627 &amp;nbsp; &amp;nbsp;4.56813 &amp;nbsp;19.937 &amp;nbsp;&amp;lt; 2e-16 ***&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;first &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.80708 &amp;nbsp; &amp;nbsp;0.50373 &amp;nbsp;-1.602 &amp;nbsp; &amp;nbsp;0.109 &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.79807 &amp;nbsp; &amp;nbsp;0.35163 &amp;nbsp; 5.113 3.23e-07 ***&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;ages2 &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.02953 &amp;nbsp; &amp;nbsp;0.00664 &amp;nbsp;-4.447 8.80e-06 ***&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;Multiple R-squared: 0.007462,&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;Adjusted R-squared: 0.007132&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;When we include the parabolic model of weight and age, the coefficient for &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;first&lt;/span&gt; gets smaller, and the p-value is 11%.&lt;br /&gt;
&lt;br /&gt;
I conclude that the difference in weight for first babies is explained by the difference in mothers' ages. &amp;nbsp;When we control for age, the difference between first babies and others is no longer statistically significant. &amp;nbsp;It is possible that there is a small difference in weight for first babies, but this dataset provides little evidence for it.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-2103279562654342252?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XmcHpSdKZPSEaxJwKp6bKICSgE4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XmcHpSdKZPSEaxJwKp6bKICSgE4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XmcHpSdKZPSEaxJwKp6bKICSgE4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XmcHpSdKZPSEaxJwKp6bKICSgE4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/9dIR0SUpwxY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/2103279562654342252/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/are-first-babies-more-likely-to-be.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2103279562654342252?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2103279562654342252?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/9dIR0SUpwxY/are-first-babies-more-likely-to-be.html" title="Are first babies more likely to be light?" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-gogQHhCvgMs/TtVPYtf7DeI/AAAAAAAAAoc/AuorqD3_iSQ/s72-c/agemodel_age_cdf.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/are-first-babies-more-likely-to-be.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYMQXY7fip7ImA9WhRRFkU.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-5529920471360202074</id><published>2011-11-28T05:11:00.000-08:00</published><updated>2011-11-30T11:59:40.806-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-30T11:59:40.806-08:00</app:edited><title>Estimating the age of renal tumors</title><content type="html">A few weeks ago I read this post on &lt;a href="http://www.reddit.com/r/statistics/comments/lzwl7/is_it_possible_to_determine_when_i_developed/"&gt;reddit.com/r/statistics&lt;/a&gt;:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;"I have Stage IV Kidney Cancer and am trying to determine if the cancer formed before I retired from the military. ...&amp;nbsp;Given the dates of retirement and detection is it possible to determine when there was a 50/50 chance that I developed the disease? Is it possible to determine the probability on the retirement date?&amp;nbsp;&amp;nbsp;My tumor was 15.5 cm x 15 cm at detection. Grade II."&lt;/i&gt;&lt;/blockquote&gt;I contacted the original poster and got more information; I learned that veterans get different benefits if it is "more likely than not" that a tumor formed while they were in military service (among other considerations).&lt;br /&gt;
&lt;br /&gt;
Because renal tumors grow slowly, and often do not cause symptoms, they are often left untreated. &amp;nbsp;As a result, we can observe the rate of growth for untreated tumors by comparing scans from the same patient at different times. &amp;nbsp;Several papers have reported these growth rates.&lt;br /&gt;
&lt;br /&gt;
I collected data from &lt;a href="http://radiology.rsna.org/content/250/1/137.full"&gt;a paper by Zhang et al&lt;/a&gt;. &amp;nbsp;I contacted the authors to see if I could get raw data, but they refused on grounds of medical privacy. &amp;nbsp;Nevertheless, I was able to extract the data I needed by printing one of their graphs and measuring it with a ruler. &amp;nbsp;It's silly, but it works.&lt;br /&gt;
&lt;br /&gt;
They report growth rates in reciprocal doubling time (RDT), which is in units of doublings per year. &amp;nbsp;So a tumor with RDT=1 doubles in volume each year; with RDT=2 it quadruples in the same time, and with RDT=-1, it halves. &amp;nbsp;The following figure shows the distribution of RDT for 53 patients:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-uVDXs4bWEuA/Ts1IF7eUgcI/AAAAAAAAAn8/YAicXweLRsc/s1600/kidney2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-uVDXs4bWEuA/Ts1IF7eUgcI/AAAAAAAAAn8/YAicXweLRsc/s400/kidney2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The squares are the data points from the paper; the line is a model I fit to the data. &amp;nbsp;The positive tail fits an exponential distribution well, so I used a mixture of two exponentials.&lt;br /&gt;
&lt;br /&gt;
As a simple model of tumor growth, I chose the median value of RDT, which is 0.45, and used that to estimate the age of a tumor with maximum dimension 15.5 cm. &amp;nbsp;Here's what I wrote in my letter to the Veterans Benefits Administration:&lt;br /&gt;
&lt;div style="background-color: transparent;"&gt;&lt;ol id="internal-source-marker_0.7386314519681036"&gt;&lt;li style="background-color: transparent; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;In the largest study I reviewed (53 patients) the median volume doubling time is 811 days. By definition of median, 50% of observed tumors grew faster and 50% slower. &amp;nbsp;By geometry, the doubling time for the maximum linear dimension is approximately (811)(3) = 2433 days or 6.7 years. &amp;nbsp;Therefore, for a tumor with maximum linear dimension 15.5 cm on [diagnosis date], &lt;/span&gt;&lt;span style="background-color: transparent; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;it is as likely as not that the size on [discharge date] was 6 cm&lt;/span&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style="background-color: transparent; list-style-type: decimal; text-decoration: none; vertical-align: baseline;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;If the diameter of the tumor on [discharge date] were 1 mm and it grew to 15.5 cm by [diagnosis date], the effective volume doubling time would be 150 days. &amp;nbsp;Fewer than half of the tumors in the studies I reviewed grew at this rate or faster, so &lt;/span&gt;&lt;span style="background-color: transparent; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;it is more likely than not that the tumor grew more slowly&lt;/span&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;blockquote class="tr_bq"&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Based on this analysis, I conclude that &lt;/span&gt;&lt;span style="background-color: transparent; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;it is more likely than not that this tumor formed prior to [discharge date]&lt;/span&gt;&lt;span style="background-color: transparent; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;/div&gt;I think this model is sufficient to answer the question as posed, but it occurred to me later (in the shower, where all good ideas come from) that we can do better. &amp;nbsp;By sampling from the distribution of growth rates and generating simulated tumor histories, we can estimate the distribution of size as a function of time and then, using Bayes's Theorem, get the distribution of age as a function of size.&lt;br /&gt;
&lt;br /&gt;
Here's how. &amp;nbsp;The simulation starts with a small tumor (0.3 cm) and runs these steps:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Choose a growth rate from the distribution of RDT.&lt;/li&gt;
&lt;li&gt;Compute the size of the tumor at the end of an 8 month interval (that's the median interval between &amp;nbsp;measurements in the data source).&lt;/li&gt;
&lt;li&gt;Repeat until the tumor is 20 cm in diameter.&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;This figure shows 100 simulated growth trajectories:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--a17ZyWImMs/Ts1K7TNn2jI/AAAAAAAAAoE/wc1Tjcs9IQg/s1600/kidney4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/--a17ZyWImMs/Ts1K7TNn2jI/AAAAAAAAAoE/wc1Tjcs9IQg/s400/kidney4.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;The line at 10 cm shows the range of ages for tumors at that size: the fastest-growing tumor gets there in 8 years; the slowest takes more than 35.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;By drawing the line at different sizes, we can estimate the distribution of age as a function of size. &amp;nbsp;There's an implicit use of Bayes's Theorem in there, but because I did everything discretely, I didn't have to think too hard. &amp;nbsp;This figure shows the distribution of age for a few different sizes:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ERt4Yzg7zp0/Ts1LosQ9ElI/AAAAAAAAAoM/xDXRq0r_jNs/s1600/kidney6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-ERt4Yzg7zp0/Ts1LosQ9ElI/AAAAAAAAAoM/xDXRq0r_jNs/s400/kidney6.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Not surprisingly, bigger tumors are likely to be older. &amp;nbsp;For any size, we can generate the CDF and compute the median, interquartile range, and 90% confidence interval. &amp;nbsp;Here's what that looks like (with size on a log scale):&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GCt2V-91MVM/Ts1ME3RVCII/AAAAAAAAAoU/k4d8lSNbLyE/s1600/kidney7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-GCt2V-91MVM/Ts1ME3RVCII/AAAAAAAAAoU/k4d8lSNbLyE/s400/kidney7.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;The points are data from simulation, which produces some variability due&amp;nbsp;to discrete approximation. &amp;nbsp;The lines are fitted to the data.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;With these results, doctors can look up the size of a tumor and get the distribution of ages; for example,&amp;nbsp;the median age of a 15 cm tumor is 27 years, with&amp;nbsp;interquartile range 22-31 and 90% confidence interval 16-39 years.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;This model yields more detail than the simple model I started with, but the results are qualitatively similar; a tumor this size is more likely than not to have formed prior to the original poster's date of discharge. &amp;nbsp;It looks like there is also a good chance that it formed prior to enlistment, but I don't know what the VBA makes of that.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
I think this model makes the best use of the available data, but there are several&amp;nbsp;limitations:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;1) The factors that limit tumor growth are different for very small tumors, so the observed data doesn't apply. &amp;nbsp;We can extrapolate back to when the tumor was small (I chose 0.3 cm, a bit smaller than the smallest tumor in the study). &amp;nbsp;That gives us a lower bound on the age of the tumor, but we can't say much about when the first cancer cell appeared.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;2) The distribution of growth rates is based on a sample of 53 patients. &amp;nbsp;A different sample would yield a different distribution. &amp;nbsp;I could use resampling to characterize this source of error, but haven't.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;3)&amp;nbsp;The growth model does not take into&amp;nbsp;account tumor subtype or grade, which is consistent with the conclusion of Zhang et al:&amp;nbsp;“Growth rates in renal tumors of different&amp;nbsp;sizes, subtypes and grades represent a wide range and overlap&amp;nbsp;substantially.” &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;4)&amp;nbsp;In our model of tumor growth, the growth rate during each interval is&amp;nbsp;independent of previous growth rates. &amp;nbsp;It is plausible that, in reality, tumors that have grown quickly in&amp;nbsp;the past are more likely to grow quickly.&lt;br /&gt;
&lt;br /&gt;
If this correlation exists, it affects the location and spread of the results. &amp;nbsp;For example, running simulations with&amp;nbsp;&lt;span style="background-color: white; line-height: 20px;"&gt;&lt;span style="font-family: inherit;"&gt;ρ&lt;/span&gt;&lt;/span&gt;&amp;nbsp;= 0.4 increases&amp;nbsp;the estimated median age by about a year, and the interquartile range&lt;br /&gt;
by about 3 years. &amp;nbsp;However, if there were a strong serial correlation in growth rate,&amp;nbsp;there would be also be a correlation between tumor volume and growth&amp;nbsp;rate, and prior work has shown no such relationship.&lt;br /&gt;
&lt;br /&gt;
There could still be a weak serial correlation, but since there is&amp;nbsp;currently no evidence for it, I ran these simulations&amp;nbsp;with&amp;nbsp;&lt;span style="background-color: white; line-height: 20px;"&gt;&lt;span style="font-family: inherit;"&gt;ρ&lt;/span&gt;&lt;/span&gt;&amp;nbsp; = 0.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-5529920471360202074?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ikgxgb3IyoVnLB1mCjO8uPkiGZI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ikgxgb3IyoVnLB1mCjO8uPkiGZI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ikgxgb3IyoVnLB1mCjO8uPkiGZI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ikgxgb3IyoVnLB1mCjO8uPkiGZI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/7PnSZeK2qPU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/5529920471360202074/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/estimating-age-of-renal-tumors.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5529920471360202074?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5529920471360202074?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/7PnSZeK2qPU/estimating-age-of-renal-tumors.html" title="Estimating the age of renal tumors" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-uVDXs4bWEuA/Ts1IF7eUgcI/AAAAAAAAAn8/YAicXweLRsc/s72-c/kidney2.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/estimating-age-of-renal-tumors.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEMMQHw9eCp7ImA9WhRVE0o.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1785006629775744896</id><published>2011-11-21T11:39:00.000-08:00</published><updated>2012-01-12T05:54:41.260-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-12T05:54:41.260-08:00</app:edited><title>Comment on "Racism and Meritocracy"</title><content type="html">WARNING: &amp;nbsp;This article is on a topic that elicits emotional reactions. &amp;nbsp;I welcome comments, but please make them thoughtful and keep them civil.&lt;br /&gt;
&lt;br /&gt;
Eric Ries wrote an &lt;a href="http://techcrunch.com/2011/11/19/racism-and-meritocracy/"&gt;article for TechCrunch&lt;/a&gt;&amp;nbsp;last week, talking about racism and meritocracy among Silicon Valley entrepreneurs. &amp;nbsp;It's a good article; you should read it and then come back.&lt;br /&gt;
&lt;br /&gt;
Although I mostly agree with him, Ries undermines his argument with a statistical bait-and-switch: he starts out talking about race, but most of the article (and the &lt;a href="http://www.slideshare.net/terriko/how-does-biology-explain-the-low-numbers-of-women-in-cs-hint-it-doesnt"&gt;slide deck&lt;/a&gt; he refers to) are about gender. &amp;nbsp;Unfortunately, for both his argument and the world, the race gap is bigger than the gender gap, and it is compounded because racial minorities, unlike women, are minorities.&lt;br /&gt;
&lt;br /&gt;
To quantify the size of the gap, I use data from &lt;i&gt;&lt;a href="http://www.amazon.com/gp/product/0226028569/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399369&amp;amp;creativeASIN=0226028569"&gt;Academically Adrift&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=greenteapre01-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0226028569&amp;amp;camp=217145&amp;amp;creative=399369" style="border: none !important; margin: 0px !important;" width="1" /&gt;&lt;/i&gt;, a recent book that reports the results from &lt;span class="Apple-style-span" style="font-family: inherit;"&gt;the &lt;span class="Apple-style-span" style="background-color: white; line-height: 15px;"&gt;&lt;a href="http://www.collegiatelearningassessment.org/"&gt;Collegiate Learning Assessment&lt;/a&gt; (CLA) database, collected by the &lt;a href="http://www.cae.org/content/about.htm"&gt;Council for Aid to Education&lt;/a&gt;, "&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;a national nonprofit organization ...&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; text-align: -webkit-left;"&gt;&amp;nbsp;established in 1952 to advance corporate support of education and to conduct policy research on higher education..."&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="background-color: white; text-align: -webkit-left;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: -webkit-left;"&gt;Here is a &lt;a href="http://www.collegiatelearningassessment.org/files/Architecture_of_the_CLA_Tasks.pdf"&gt;description of the CLA&lt;/a&gt;:&lt;/div&gt;&lt;span class="Apple-style-span" style="background-color: white; text-align: -webkit-left;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;"The CLA consists of three types of prompts within two types of task: the Performance Task and the&amp;nbsp;Analytic Writing Task...The Analytic Writing Task includes a pair of prompts called Make-an-Argument and Critique-an-Argument.&amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;"The CLA uses direct measures of skills in which students perform cognitively demanding tasks... All CLA measures are administered online and contain open-ended&amp;nbsp;prompts that require constructed responses. There are no multiple-choice questions. The CLA tasks require that students integrate critical thinking and written communication skills. The holistic&amp;nbsp;integration of these skills on the CLA tasks mirrors the requirements of serious thinking and writing&amp;nbsp;tasks faced in life outside of the classroom. "&lt;/blockquote&gt;This is not your father's SAT. &amp;nbsp;The exam simulates realistic workplace tasks and assesses skills that are relevant to many jobs, including (maybe especially) entrepreneurship.&lt;br /&gt;
&lt;br /&gt;
On this assessment, the measured differences between black and white college students are stark. &amp;nbsp;For white college students, the mean and standard deviation are&amp;nbsp;1170&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;±&lt;/span&gt;&amp;nbsp;179. &amp;nbsp;For black students, they are&amp;nbsp;995&amp;nbsp;&lt;span class="Apple-style-span" style="font-family: sans-serif; font-size: 13px; line-height: 20px;"&gt;±&amp;nbsp;&lt;/span&gt;167. &lt;br /&gt;
&lt;br /&gt;
To get a sense of what that difference looks like, suppose there are just two groups, which I call "blue" and "green" as a reminder that I am presenting an abstract model and not a realistic description. &amp;nbsp;This figure shows Gaussian distributions with the parameters reported in&amp;nbsp;&lt;i&gt;&lt;a href="http://www.amazon.com/gp/product/0226028569/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399369&amp;amp;creativeASIN=0226028569"&gt;Academically Adrift&lt;/a&gt;&lt;img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=greenteapre01-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=0226028569&amp;amp;camp=217145&amp;amp;creative=399369" style="border-bottom-style: none !important; border-color: initial !important; border-left-style: none !important; border-right-style: none !important; border-top-style: none !important; border-width: initial !important; margin-bottom: 0px !important; margin-left: 0px !important; margin-right: 0px !important; margin-top: 0px !important;" width="1" /&gt;&lt;/i&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-_TeNZMa_8QM/Tsp8AWerFYI/AAAAAAAAAnk/ZQKLUVo8lNM/s1600/normal1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-_TeNZMa_8QM/Tsp8AWerFYI/AAAAAAAAAnk/ZQKLUVo8lNM/s400/normal1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
The difference in means is 175 points, which is about one standard deviation. &amp;nbsp;If we select people from the upper tail, the majority are blue. &amp;nbsp;But the situation is even worse if greens are a minority. &amp;nbsp;If greens make up 20% of the population, the picture looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-1jC9V3v_hc8/Tsp8I08w7WI/AAAAAAAAAns/xVXlFJpg1Oo/s1600/normal2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-1jC9V3v_hc8/Tsp8I08w7WI/AAAAAAAAAns/xVXlFJpg1Oo/s400/normal2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
The fraction of greens in the upper tail is even smaller. &amp;nbsp;If, as Rie&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;s suggests, "&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;Here in Silicon Valley, we’re looking for the absolute best and brightest, the people far out on the tail end of aptitude," the number of greens in that tail is very small.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;How small? &amp;nbsp;That depends on where we draw the line. &amp;nbsp;If we select people who score above 1200, which includes 37% of the population, we get 6% greens (remember that they are 20% of the hypothetical population). &amp;nbsp;Above 1300 the proportion of greens is 3%, and above 1400 only 2%.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;And that's not very "far out on the tail end of aptitude." &amp;nbsp;Above 1500, we are still talking about 3% of the general population, but more than 99% of them are blue. &amp;nbsp;So in this hypothetical world of blues and greens, perfect meritocracy does not lead to proportional representation.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Ries suggests that blind screening of applicants might help. &amp;nbsp;I think the system he proposes is a good idea, because it improves fairness and also the perception of fairness. &amp;nbsp;But if the racial gap in Y Combinator's applicant pool is similar to the racial gap in&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;CLA scores, making the selection process more meritocratic won't make a big difference.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;These numbers are bad. &amp;nbsp;I'm sorry to be reporting them, and if I know the Internet, some people are going to call me a racist for doing it. &amp;nbsp;But I didn't make them up, and I'm pretty sure I did the math right. &amp;nbsp;Of course, you are welcome to disagree with my conclusions.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Here are some of the objections I expect:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;1) The CLA does not capture the full range of skills successful entrepreneurs need.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Of course it doesn't; no test could. &amp;nbsp;But I chose the CLA because I think it assesses thinking skills better than other standardized tests, and because the database include&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;s "&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;over 200,000 student results across&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;hundreds of colleges." &amp;nbsp;I can't think of a better way to estimate the magnitude of the racial gap in the applicant pool.&lt;/span&gt;&lt;br /&gt;
&lt;div style="text-align: -webkit-auto;"&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: -webkit-auto;"&gt;&lt;span class="Apple-style-span" style="line-height: 15px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;2) The application process is biased against racial minorities and women.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;The statistics I am reporting here, and my analysis of them, don't say anything about whether or not the application process is biased. &amp;nbsp;But they do suggest (&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;a) We should not assume that because racial minorities are underrepresented among Silicon Valley entrepreneurs, racial bias explains a large part of the effect, and (&lt;/span&gt;&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;b) We should not assume that eliminating bias from the process will have a large effect.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;Of course, trying to eliminate bias is the right thing to do, whether the effect is big or small.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;-----&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;NOTE: The range of scores for the CLA was capped at 1600 until 2007, which changed the shape of the distribution at the high end. &amp;nbsp;For those years, the Gaussian distributions in the figures are not exactly right, but I don't think it affects my analysis much. &amp;nbsp;Since 2007, scores are no longer capped, but I don't know what the tail of the distribution looks like now.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;EDIT 11-28-11: I revised a few sentences to clarify whether I was talking about representation or absolute numbers. &amp;nbsp;The fraction of greens in the population affects the absolute numbers in the tail but not their representation.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1785006629775744896?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fFdw5lsmfZtZhVzxZF-l_Rg_mN0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fFdw5lsmfZtZhVzxZF-l_Rg_mN0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fFdw5lsmfZtZhVzxZF-l_Rg_mN0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fFdw5lsmfZtZhVzxZF-l_Rg_mN0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/cljpH0w7E-0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1785006629775744896/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/comment-on-racism-and-meritocracy.html#comment-form" title="11 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1785006629775744896?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1785006629775744896?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/cljpH0w7E-0/comment-on-racism-and-meritocracy.html" title="Comment on &quot;Racism and Meritocracy&quot;" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-_TeNZMa_8QM/Tsp8AWerFYI/AAAAAAAAAnk/ZQKLUVo8lNM/s72-c/normal1.png" height="72" width="72" /><thr:total>11</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/comment-on-racism-and-meritocracy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A04BQ30-cSp7ImA9WhRSEE8.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-2637712193305576870</id><published>2011-11-10T11:09:00.000-08:00</published><updated>2011-11-11T08:45:52.359-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-11T08:45:52.359-08:00</app:edited><title>Girl Named Florida solutions</title><content type="html">In&amp;nbsp;&lt;i&gt;&lt;a href="http://books.google.com/books?id=7NH5yNWMCFEC&amp;amp;pg=PA114&amp;amp;lpg=PA114&amp;amp;dq=mlodinow+florida&amp;amp;source=bl&amp;amp;ots=4x9knNtrqL&amp;amp;sig=WwSte9JBwV9pQR4aAL4pCB2PN0I&amp;amp;hl=en&amp;amp;ei=sEa4TufeEI714QTEsZn7Aw&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CDEQ6AEwAw#v=onepage&amp;amp;q=florida&amp;amp;f=false"&gt;The Drunkard's Walk&lt;/a&gt;&lt;/i&gt;, Leonard Mlodinow presents "The Girl Named Florida Problem":&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;"In a family with two children, what are the chances, if one of the children is a girl named Florida, that both children are girls?"&lt;/i&gt;&lt;/blockquote&gt;I like this problem, and I use it on the first day of my class to introduce the topic of conditional probability. &amp;nbsp;But I've decided that it's too easy. &amp;nbsp;To give it a little more punch, I've decided to combine it with the&amp;nbsp;&lt;a href="http://allendowney.blogspot.com/2011/11/somebody-bet-on-bayes.html"&gt;Red-Haired Problem&lt;/a&gt;&amp;nbsp;from last week:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;In a family with two children, what are the chances, if at least one of the children is a girl with red hair, that both children are girls?&lt;/i&gt;&lt;/blockquote&gt;Just like last week, you can make some simplifying assumptions:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;About 2% of the world population has&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Red_hair" style="background-color: white; color: #213abb; text-decoration: none;"&gt;red hair&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;You can assume that the alleles for red hair are&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Dominance_(genetics)" style="background-color: white; color: #213abb; text-decoration: none;"&gt;purely recessive&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;Also, you can assume that the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Red_hair#Extinction_hoax" style="background-color: white; color: #213abb; text-decoration: none;"&gt;Red Hair Extinction&lt;/a&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white;"&gt;theory is false, so you can apply the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle" style="background-color: white; color: #213abb; text-decoration: none;"&gt;Hardy–Weinberg principle&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;And you can ignore the effect of identical twins.&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;Before I present my solution, I want to sneak up on it with a series of warm-up problems.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;P[GG | two children]: if a family has two children, what is the chance that they have two girls?&lt;/li&gt;
&lt;li&gt;P[GG | two children, at least one girl]: if we know they have at least one girl, what is the chance that they have two girls?&lt;/li&gt;
&lt;li&gt;P[GG | two children, older child is a girl]: if the older child is a girl, what is the chance that they have two girls?&lt;/li&gt;
&lt;li&gt;P[GG | two children, at least one is a girl named Florida].&lt;/li&gt;
&lt;li&gt;P[GG | two children, at least one is a girl with red hair, and the parents have brown hair].&lt;/li&gt;
&lt;li&gt;P[GG | two children, at least one is a girl with red hair].&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Problem 1:&amp;nbsp;P[GG | two children]&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;If we assume that the probability that each child is a girl is 50%, then&amp;nbsp;P[GG | two children] = 1/4.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Problem 2:&amp;nbsp;P[GG | two children, at least one girl]&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;There are four equally-likely kinds of two child families: &amp;nbsp;BB, BG, GB and GG. &amp;nbsp;We know that BB is out, so the conditional probability is&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;P[GG | at least one girl] = P[GG and at least one girl] / P[at least one girl] = 1/3.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Problem 3: P[GG | two children, older child is a girl]&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now there are only two possible families, GB and GG, so the conditional probability is 1/2. &amp;nbsp;Informally we can argue that once we know about the older child we can treat the younger child as independent. &amp;nbsp;But if there's one thing we learn from this problem, it's that our intuition for independence is not reliable.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Problem 4: P[GG | two children, at least one girl named Florida]&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Here's the one that makes people's head hurt. &amp;nbsp;For each child, there are three possibilities, boy, girl not named Florida, and girl named Florida, with these probabilities:&lt;br /&gt;
&lt;br /&gt;
B: 1/2&lt;br /&gt;
G: 1/2 - x&lt;br /&gt;
GF: x&lt;br /&gt;
&lt;br /&gt;
where x is the unknown percentage of people who are girls named Florida. &amp;nbsp;Of families with at least one girl named Florida, there are these possible combinations, with these probabilities&lt;br /&gt;
&lt;br /&gt;
B GF: 1/2 x&lt;br /&gt;
GF B: 1/2 x&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: yellow;"&gt;G GF: x (1/2 - x)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: yellow;"&gt;GF G: x (1/2 - x)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: yellow;"&gt;GF GF: x^2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The highlighted cases have two girls, so the probability we want is the sum of the highlighted cases over the sum of all cases. &amp;nbsp;With a little algebra, we get:&lt;br /&gt;
&lt;br /&gt;
P(GG | at least one girl named Florida) = (1 - x) / (2 - x)&lt;br /&gt;
&lt;br /&gt;
Assuming that Florida is not a common name, x approaches 0 and the answer approaches 1/2. &amp;nbsp;So it turns out, surprisingly, that the name of the girl is relevant information.&lt;br /&gt;
&lt;br /&gt;
As x approaches 1/2, the answer converges on 1/3. &amp;nbsp;For example, if we know that at least one child is a girl with two X chromosomes, x is close to 1/2 and the problem reduces to Problem 2.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
If this problem is still making your head hurt, this figure might help:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://docs.google.com/drawings/pub?id=1nBpRJOvkPwHAKiffPJ8lEDMru-OF5VSm9XXL57pgno0&amp;amp;w=310&amp;amp;h=305" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="197" src="https://docs.google.com/drawings/pub?id=1nBpRJOvkPwHAKiffPJ8lEDMru-OF5VSm9XXL57pgno0&amp;amp;w=310&amp;amp;h=305" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;Here B a boy, Gx is a girl with some property X, and G is a girl who doesn't have that property. &amp;nbsp;If we select all families with at least one Gx, we get the five blue squares (light and dark). &amp;nbsp;The families with two girls are the three dark blue squares.&lt;br /&gt;
&lt;br /&gt;
If property X is common, the ratio of dark blue to all blue approaches 1/3. &amp;nbsp;If X is rare, the same ratio approaches 1/2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 5: P[GG | two children, at least one girl with red hair, parents have brown hair]&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
If the parents have brown hair and one of their children has red hair, we know that both parents are heterozygous, so their chance of having a red-haired girl is 1/8.&lt;br /&gt;
&lt;br /&gt;
Using the girl-named-Florida formula, we get&lt;br /&gt;
&lt;br /&gt;
P[GG | two children, at least one girl with red hair, parents have brown hair] = (1 - 1/8) / (2 - 1/8) = 7/15.&lt;br /&gt;
&lt;br /&gt;
And finally:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 6: P[GG | two children, at least one girl with red hair]&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
In this case we don't know the genotype of the parents. &amp;nbsp;There are three possibilities: Aa Aa, Aa aa, and aa aa.&lt;br /&gt;
&lt;br /&gt;
We follow these steps:&lt;br /&gt;
&lt;br /&gt;
1) Use the prevalence of red hair to compute the prior probabilities of each parental genotype.&lt;br /&gt;
&lt;br /&gt;
2) Use the evidence (at least one girl with red hair) to compute the posteriors.&lt;br /&gt;
&lt;br /&gt;
3) For each combination, compute the conditional probability. &amp;nbsp;We have already computed&lt;br /&gt;
&lt;br /&gt;
P(GG | two children, at least one with red hair, Aa Aa) = 7/15&lt;br /&gt;
&lt;br /&gt;
The others are&lt;br /&gt;
&lt;br /&gt;
P(GG | two children, at least one with red hair, Aa aa) = 3/7&lt;br /&gt;
P(GG | two children, at least one with red hair, aa aa) = 1/3&lt;br /&gt;
&lt;br /&gt;
4) Apply the law of total probability to get the answer.&lt;br /&gt;
&lt;br /&gt;
I'm too lazy to do the algebra, so I got Mathematica to do it for me. &amp;nbsp;Here is&lt;a href="http://greenteapress.com/thinkstats/red.htm"&gt;&amp;nbsp;the notebook with the answer&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
In general, if p is the prevalence of red hair alleles,&lt;br /&gt;
&lt;br /&gt;
P(GG | two children, at least one with red hair) = (p^2 + 2p - 7) / (p^2 + 2p - 15)&lt;br /&gt;
&lt;br /&gt;
If the prevalence of red hair is 0.02, then p = sqrt(0.02) = &amp;nbsp;0.141, and&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;P(GG | two children, at least one with red hair) = 45.6%&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Congratulations to Professor Ted Bunn at the University of Richmond, the only person who submitted a correct answer before the deadline!&lt;br /&gt;
&lt;br /&gt;
At least, I think it's the right answer. &amp;nbsp;Maybe we both made the same mistake.&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; line-height: 21px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;For more fun with probability, see Chapter 5 of my book,&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Think Stats&lt;/span&gt;&lt;/i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;, which you can&amp;nbsp;&lt;/span&gt;&lt;a href="http://thinkstats.com/" style="color: #888888; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;read here&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;, or&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.amazon.com/gp/product/1449307116/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399373&amp;amp;creativeASIN=1449307116" style="color: #888888; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;buy here&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-2637712193305576870?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tz1CFRmSg1TMQbvmxwmVg222T4g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz1CFRmSg1TMQbvmxwmVg222T4g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tz1CFRmSg1TMQbvmxwmVg222T4g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tz1CFRmSg1TMQbvmxwmVg222T4g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/Vk54DFqQH_Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/2637712193305576870/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/girl-named-florida-solutions.html#comment-form" title="19 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2637712193305576870?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2637712193305576870?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/Vk54DFqQH_Q/girl-named-florida-solutions.html" title="Girl Named Florida solutions" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>19</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/girl-named-florida-solutions.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMCRX8yeSp7ImA9WhRTGUg.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1092356477851929362</id><published>2011-11-07T13:12:00.000-08:00</published><updated>2011-11-10T11:14:24.191-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-10T11:14:24.191-08:00</app:edited><title>The red-haired girl named Florida</title><content type="html">In &lt;i&gt;&lt;a href="http://books.google.com/books?id=7NH5yNWMCFEC&amp;amp;pg=PA114&amp;amp;lpg=PA114&amp;amp;dq=mlodinow+florida&amp;amp;source=bl&amp;amp;ots=4x9knNtrqL&amp;amp;sig=WwSte9JBwV9pQR4aAL4pCB2PN0I&amp;amp;hl=en&amp;amp;ei=sEa4TufeEI714QTEsZn7Aw&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=4&amp;amp;ved=0CDEQ6AEwAw#v=onepage&amp;amp;q=florida&amp;amp;f=false"&gt;The Drunkard's Walk&lt;/a&gt;&lt;/i&gt;, Leonard Mlodinow presents "The Girl Named Florida Problem":&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;"In a family with two children, what are the chances, if one of the children is a girl named Florida, that both children are girls?"&lt;/i&gt;&lt;/blockquote&gt;I like this problem, and I use it on the first day of my class to introduce the topic of conditional probability. &amp;nbsp;But I've decided that it's too easy. &amp;nbsp;To give it a little more punch, I've decided to combine it with the &lt;a href="http://allendowney.blogspot.com/2011/11/somebody-bet-on-bayes.html"&gt;Red-Haired Problem&lt;/a&gt; from last week:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;In a family with two children, what are the chances, if at least one of the children is a girl with red hair, that both children are girls?&lt;/i&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;i&gt;[Edit: I clarified the wording to say that &lt;/i&gt;at least&lt;i&gt; one of the children is a girl with red hair. &amp;nbsp;To be even more precise, I am looking for the conditional probability P(two girls | at least one girl with red hair).]&amp;nbsp;&lt;/i&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;/blockquote&gt;&lt;br /&gt;
Just like last week, you can make some simplifying assumptions:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;About 2% of the world population has&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Red_hair" style="background-color: white; color: #213abb; text-decoration: none;"&gt;red hair&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;You can assume that the alleles for red hair are&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Dominance_(genetics)" style="background-color: white; color: #213abb; text-decoration: none;"&gt;purely recessive&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;Also, you can assume that the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Red_hair#Extinction_hoax" style="background-color: white; color: #213abb; text-decoration: none;"&gt;Red Hair Extinction&lt;/a&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white;"&gt;theory is false, so you can apply the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle" style="background-color: white; color: #213abb; text-decoration: none;"&gt;Hardy–Weinberg principle&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;. &amp;nbsp;And you can ignore the effect of identical twins.&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;Here is &lt;a href="http://allendowney.blogspot.com/2011/11/girl-named-florida-solutions.html"&gt;my solution&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; line-height: 21px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;For more fun with probability, see Chapter 5 of my book,&amp;nbsp;&lt;/span&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Think Stats&lt;/span&gt;&lt;/i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;, which you can&amp;nbsp;&lt;/span&gt;&lt;a href="http://thinkstats.com/" style="color: #888888; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;read here&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;, or&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.amazon.com/gp/product/1449307116/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399373&amp;amp;creativeASIN=1449307116" style="color: #888888; text-decoration: none;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;buy here&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1092356477851929362?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CKbSg_ez66n98h44vq9ApF5rax0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CKbSg_ez66n98h44vq9ApF5rax0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CKbSg_ez66n98h44vq9ApF5rax0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CKbSg_ez66n98h44vq9ApF5rax0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/mWs5iG5twvI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1092356477851929362/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/red-haired-girl-named-florida.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1092356477851929362?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1092356477851929362?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/mWs5iG5twvI/red-haired-girl-named-florida.html" title="The red-haired girl named Florida" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>4</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/red-haired-girl-named-florida.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0ENSH89eip7ImA9WhRTE0o.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-4017272812034612144</id><published>2011-11-03T08:55:00.000-07:00</published><updated>2011-11-03T18:54:59.162-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-11-03T18:54:59.162-07:00</app:edited><title>Somebody bet on the Bayes</title><content type="html">In &lt;a href="http://allendowney.blogspot.com/2011/10/all-your-bayes-are-belong-to-us.html"&gt;last week's post&lt;/a&gt; I wrote solutions to some of my favorite Bayes's Theorem problems, and posed this new problem:&lt;br /&gt;
&lt;blockquote class="tr_bq" style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If you meet a man with (naturally) red hair, what is the probability that neither of his parents has red hair?&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;&lt;blockquote class="tr_bq"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;Hints: About 2% of the world population has&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Red_hair" style="background-color: white; color: #213abb; line-height: 18px; text-decoration: none;"&gt;red hair&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;. &amp;nbsp;You can assume that the alleles for red hair are&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Dominance_(genetics)" style="background-color: white; color: #213abb; line-height: 18px; text-decoration: none;"&gt;purely recessive&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;. &amp;nbsp;Also, you can assume that the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Red_hair#Extinction_hoax" style="background-color: white; color: #213abb; line-height: 18px; text-decoration: none;"&gt;Red Hair Extinction&lt;/a&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;theory is false, so you can apply the&amp;nbsp;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle" style="background-color: white; color: #213abb; line-height: 18px; text-decoration: none;"&gt;Hardy–Weinberg principle&lt;/a&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;.&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;Given the prevalence of red hair, we know what fraction of the population is homozygous recessive. &amp;nbsp;To solve the problem, we also need to know how many are heterozygous and homozygous dominant.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt;I'll use &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;a&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; to represent the recessive allele (or alleles) for red hair, and &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;A&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; for the dominant alleles that code for other colors. &amp;nbsp;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;p&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; is the prevalence of &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;a&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; and &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;q&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; is the prevalence of &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;A&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt;, so &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;p+q = 1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;If these prevalences are not changing over time, and they don't affect people's mating decisions, we can invoke the Hardy-Weinberg principle to get:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(AA)&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; = prevalence of homozygous dominant = &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;q**2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(Aa)&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; = prevalence of heterozygous =&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #38761d; font-family: inherit;"&gt; &lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;2 * p * q&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(aa)&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222; font-family: inherit;"&gt; = prevalence of homozygous recessive = &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;p**2&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;And &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(AA) + P(Aa) + P(aa) = 1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;Given &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;(aa)&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;, we can compute &lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;p&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;, &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;q&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt; and:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(Aa) = 0.243&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(AA) = 0.737&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;Now if a child has red hair, both parents have at least one recessive allele, so the possible combinations are (Aa Aa), (Aa aa), and (aa aa). &amp;nbsp;If we assume, again, that mating decisions are not based on hair color, we can get the prevalence of each parental pair:&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(Aa Aa) = Aa**2&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(Aa aa) = 2 Aa aa&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(aa aa) = aa**2&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;And we can use those as the priors. &amp;nbsp;The evidence is&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;E: the child has red hair&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;To get the likelihoods, we apply Mendelian genetics:&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(E | Aa Aa) = 0.25&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(E | Aa aa) = 0.5&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(E | aa aa) = 1.0&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;Finally, applying Bayes's Theorem, we have&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;P(Aa Aa | E) = P(Aa Aa) P(E | Aa Aa) / P(E)&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;And the answer is 0.737. &amp;nbsp;With a little algebra we can show that&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; line-height: 18px;"&gt;P(Aa Aa | E) = P(AA)&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;That is, the probability that neither parent has red hair is exactly the fraction of the population that is homozygous dominant.&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;Almost 75% of red-haired people come from parents with non-red hair, which might explain why a "red haired child" is a metaphor for a child that doesn't resemble his parents. In the expression, "&lt;a href="http://wiki.answers.com/Q/Where_did_the_phrase_'beat_you_like_a_red-headed_stepchild'_come_from_and_what_does_it_mean"&gt;beat like a red haired step child&lt;/a&gt;," some of the humor (for people who find child abuse funny) comes from the suggestion that the parentage of a red haired child is suspect.&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;But why should red hair be funnier than blue eyes or blonde hair? &amp;nbsp;It turns out that we can answer this question mathematically. If the prevalence of red hair were higher, say 10%, most red haired people would have at least one red-haired parent, and that would be less funny.&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;In general, as the prevalence of the recessive phenotype increases, the potential for amusing insinuations of infidelity decreases; near 0 it drops off steeply, as shown in this figure:&lt;/div&gt;&lt;div style="color: #222222; line-height: 18px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-8-4VW5ca6pM/TrKnkDmNhBI/AAAAAAAAAnU/Mss2QdX96XM/s1600/red.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-8-4VW5ca6pM/TrKnkDmNhBI/AAAAAAAAAnU/Mss2QdX96XM/s400/red.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;Since I believe I am the first person to quantify this effect, I humbly submit that it should be called "Downey's inverse law of mailman jokes."&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;For more fun with probability, see Chapter 5 of my book,&amp;nbsp;&lt;i&gt;Think Stats&lt;/i&gt;, which you can &lt;a href="http://thinkstats.com/"&gt;read here&lt;/a&gt;, or &lt;a href="http://www.amazon.com/gp/product/1449307116/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399373&amp;amp;creativeASIN=1449307116"&gt;buy here&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;-----&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;If you don't get the title of this post, it is a play on "Somebody bet on the bay," a lyric from the minstrel song "Camptown Races." &amp;nbsp;A bay is a horse with a reddish-brown coat, so I thought it was a pretty good fit.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222;"&gt;&lt;span class="Apple-style-span" style="line-height: 18px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-4017272812034612144?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/F1-Izeck6UnqP0Pz7ezu4Q7LosI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F1-Izeck6UnqP0Pz7ezu4Q7LosI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/F1-Izeck6UnqP0Pz7ezu4Q7LosI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/F1-Izeck6UnqP0Pz7ezu4Q7LosI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/u1wm5T1KGro" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/4017272812034612144/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/11/somebody-bet-on-bayes.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/4017272812034612144?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/4017272812034612144?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/u1wm5T1KGro/somebody-bet-on-bayes.html" title="Somebody bet on the Bayes" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-8-4VW5ca6pM/TrKnkDmNhBI/AAAAAAAAAnU/Mss2QdX96XM/s72-c/red.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/11/somebody-bet-on-bayes.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkENQH4-eyp7ImA9WhRXFU0.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-1352062729055702719</id><published>2011-10-27T07:45:00.000-07:00</published><updated>2011-12-21T12:51:31.053-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-21T12:51:31.053-08:00</app:edited><title>All your Bayes are belong to us!</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Bayes'_Theorem_MMB_01.jpg/800px-Bayes'_Theorem_MMB_01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="205" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Bayes'_Theorem_MMB_01.jpg/800px-Bayes'_Theorem_MMB_01.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
This week's post contains solutions to &lt;a href="http://allendowney.blogspot.com/2011/10/my-favorite-bayess-theorem-problems.html"&gt;My Favorite Bayes's Theorem Problems&lt;/a&gt;, and one new problem. &amp;nbsp;If you missed &lt;a href="http://allendowney.blogspot.com/2011/10/my-favorite-bayess-theorem-problems.html"&gt;last week's post&lt;/a&gt;, go back and read the problems before you read the solutions!&lt;br /&gt;
&lt;br /&gt;
If you don't understand the title of this post, &lt;a href="http://en.wikipedia.org/wiki/All_your_base_are_belong_to_us"&gt;brush up on your memes&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
1) The first one is a warm-up problem. &amp;nbsp;I got it from Wikipedia (but it's no longer there):&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;i&gt;Suppose there are two full bowls of cookies. Bowl #1 has 10 chocolate chip and 30 plain cookies, while bowl #2 has 20 of each. Our friend Fred picks a bowl at random, and then picks a cookie at random. We may assume there is no reason to believe Fred treats one bowl differently from another, likewise for the cookies. The cookie turns out to be a plain one. How probable is it that Fred picked it out of Bowl #1?&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;First the hypotheses:&lt;br /&gt;
A: the cookie came from Bowl #1&lt;br /&gt;
B: the cookie came from Bowl #2&lt;br /&gt;
&lt;br /&gt;
And the priors:&lt;br /&gt;
P(A) = P(B) = 1/2&lt;br /&gt;
&lt;br /&gt;
The evidence:&lt;br /&gt;
E: the cookie is plain&lt;br /&gt;
&lt;br /&gt;
And the likelihoods:&lt;br /&gt;
P(E|A) = prob of a plain cookie from Bowl #1 = 3/4&lt;br /&gt;
P(E|B) = prob of a plain cookie from Bowl #2 = 1/2&lt;br /&gt;
&lt;br /&gt;
Plug in Bayes's theorem and get&lt;br /&gt;
P(A|E) = 3/5&lt;br /&gt;
&lt;br /&gt;
You might notice that when the priors are equal they drop out of the BT equation, so you can often skip a step.&lt;br /&gt;
&lt;br /&gt;
2) This one is also an urn problem, but a little trickier.&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;The blue M&amp;amp;M was introduced in 1995. &amp;nbsp;Before then, the color mix in a bag of plain M&amp;amp;Ms was (30% Brown, 20% Yellow, 20% Red, 10% Green, 10% Orange, 10% Tan). &amp;nbsp;Afterward it was (24% Blue , 20% Green, 16% Orange, 14% Yellow, 13% Red, 13% Brown).&lt;/i&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;i&gt; A friend of mine has two bags of M&amp;amp;Ms, and he tells me that one is from 1994 and one from 1996. &amp;nbsp;He won't tell me which is which, but he gives me one M&amp;amp;M from each bag. &amp;nbsp;One is yellow and one is green. &amp;nbsp;What is the probability that the yellow M&amp;amp;M came from the 1994 bag?&lt;/i&gt;&lt;/blockquote&gt;Hypotheses:&lt;br /&gt;
A: Bag #1 from 1994 and Bag #2 from 1996&lt;br /&gt;
B: Bag #2 from 1994 and Bag #1 from 1996&lt;br /&gt;
&lt;br /&gt;
Again, P(A) = P(B) = 1/2.&lt;br /&gt;
&lt;br /&gt;
The evidence is:&lt;br /&gt;
E: yellow from Bag #1, green from Bag #2&lt;br /&gt;
&lt;br /&gt;
The likelihoods are&lt;br /&gt;
P(E|A) = (0.2)(0.2)&lt;br /&gt;
P(E|B) = (0.1)(0.14)&lt;br /&gt;
&lt;br /&gt;
So P(A|E) = 40 / 54 ~ 0.74&lt;br /&gt;
&lt;br /&gt;
By introducing the terms Bag #1 and Bag #2, rather than "the bag the yellow M&amp;amp;M came from" and "the bag the green came from," I avoided the part of this problem that can be tricky: keeping the hypotheses and the evidence straight.&lt;br /&gt;
&lt;br /&gt;
3) This one is from one of my favorite books, David MacKay's &lt;i&gt;&lt;a href="http://www.inference.phy.cam.ac.uk/mackay/itila/"&gt;Information Theory, Inference, and Learning Algorithms&lt;/a&gt;&lt;/i&gt;:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Elvis Presley had a twin brother who died at birth. &amp;nbsp;What is the probability that Elvis was an identical twin?&lt;/i&gt;&lt;/blockquote&gt;To answer this one, you need some background information:&amp;nbsp;According to the Wikipedia article on twins: &amp;nbsp;``Twins are estimated to be approximately 1.9% of the world population,&amp;nbsp;with monozygotic twins making up 0.2% of the total---and 8% of all&amp;nbsp;twins.''&lt;br /&gt;
&lt;br /&gt;
There are several ways to set up this problem; I think the easiest is to think about twin birth events, rather than individual twins, and to take the fact that Elvis was a twin as background information.&lt;br /&gt;
&lt;br /&gt;
So the hypotheses are&lt;br /&gt;
A: Elvis's birth event was an identical birth event&lt;br /&gt;
B: Elvis's birth event was a fraternal twin event&lt;br /&gt;
&lt;br /&gt;
If identical twins are 8% of all twins, then identical birth events are 8% of all twin birth events, so the priors are&lt;br /&gt;
&lt;br /&gt;
P(A) = 8%&lt;br /&gt;
P(B) = 92%&lt;br /&gt;
&lt;br /&gt;
The relevant evidence is&lt;br /&gt;
E: Elvis's twin was male&lt;br /&gt;
&lt;br /&gt;
So the likelihoods are&lt;br /&gt;
P(E|A) = 1&lt;br /&gt;
P(E|B) = 1/2&lt;br /&gt;
&lt;br /&gt;
Because identical twins are necessarily the same sex, but fraternal twins are equally likely to be opposite sex (or, at least, I assume so). &amp;nbsp;So&lt;br /&gt;
&lt;br /&gt;
P(A|E) = 8/54 ~ 0.15.&lt;br /&gt;
&lt;br /&gt;
The tricky part of this one is realizing that the sex of the twin provides relevant information!&lt;br /&gt;
&lt;br /&gt;
4) Also from MacKay's book:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Two people have left traces of their own blood at the scene of a crime. &amp;nbsp;A suspect, Oliver, is tested and found to have type O blood. &amp;nbsp;The blood groups of the two traces are found to be of type O (a common type in the local population, having frequency 60%) and of type AB (a rare type, with frequency 1%). &amp;nbsp;Do these data (the blood types found at the scene) give evidence in favour [sic] of the proposition that Oliver was one of the two people whose blood was found at the scene?&lt;/i&gt;&lt;/blockquote&gt;For this problem, we are not asked for a posterior probability; rather we are asked whether the evidence is incriminating. &amp;nbsp;This depends on the likelihood ratio, but not the priors.&lt;br /&gt;
&lt;br /&gt;
The hypotheses are&lt;br /&gt;
X: Oliver is one of the people whose blood was found&lt;br /&gt;
Y: Oliver is not one of the people whose blood was found&lt;br /&gt;
&lt;br /&gt;
The evidence is&lt;br /&gt;
E: two blood samples, one O and one AB&lt;br /&gt;
&lt;br /&gt;
We don't need priors, so we'll jump to the likelihoods. &amp;nbsp;If X is true, then Oliver accounts for the O blood, so we just have to account for the AB sample:&lt;br /&gt;
&lt;br /&gt;
P(E|X) = 0.01&lt;br /&gt;
&lt;br /&gt;
If Y is true, then we assume the two samples are drawn from the general population at random. &amp;nbsp;The chance of getting one O and one AB is&lt;br /&gt;
&lt;br /&gt;
P(E|Y) = 2(0.6)(0.01) = 0.012&lt;br /&gt;
&lt;br /&gt;
Notice that there is a factor of two here because there are two permutations that yield E.&lt;br /&gt;
&lt;br /&gt;
So the evidence is slightly more likely under Y, which means that it is actually exculpatory! &amp;nbsp;This problem is a nice reminder that evidence that is &lt;i&gt;consistent&lt;/i&gt; with a hypothesis does not necessarily &lt;i&gt;support&lt;/i&gt; the hypothesis.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) I like this problem because it doesn't provide all of the information. &amp;nbsp;You have to figure out what information is needed and go find it.&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;According to the CDC, ``Compared to nonsmokers, men who smoke&amp;nbsp;are about 23 times more likely to develop lung cancer and women who&amp;nbsp;smoke are about 13 times more likely.''&lt;/i&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;i&gt;If you learn that a woman has been diagnosed with lung cancer, and&amp;nbsp;you know nothing else about her, what is the probability that she&amp;nbsp;is a smoker?&lt;/i&gt;&lt;/blockquote&gt;I find it helpful to draw a tree:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-uQT3C5WHqiM/TqBE9TjNFrI/AAAAAAAAAm0/FDlattML3D8/s1600/DiagramforthelungcancerBayesproblem+%25281%2529.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="253" src="http://4.bp.blogspot.com/-uQT3C5WHqiM/TqBE9TjNFrI/AAAAAAAAAm0/FDlattML3D8/s320/DiagramforthelungcancerBayesproblem+%25281%2529.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;If y is the fraction of women who smoke, and x is the fraction of nonsmokers who get lung cancer, the number of smokers who get cancer is proportional to 13xy, and the number of nonsmokers who get lung cancer is proportional to x(1-y).&lt;br /&gt;
&lt;br /&gt;
Of all women who get lung cancer, the fraction who smoke is 13xy / (13xy + x(1-y)).&lt;br /&gt;
&lt;br /&gt;
The x's cancel, so it turns out that we don't actually need to know the absolute risk of lung cancer, just the relative risk. &amp;nbsp;But we do need to know y, the fraction of women who smoke. &amp;nbsp;According to the &lt;a href="http://www.cdc.gov/tobacco/data_statistics/fact_sheets/adult_data/cig_smoking/index.htm"&gt;CDC&lt;/a&gt;, y was 17.9% in 2009. &amp;nbsp;So we just have to compute&lt;br /&gt;
&lt;br /&gt;
13y / (13y + 1-y) ~ 74%&lt;br /&gt;
&lt;br /&gt;
This is higher than many people guess.&lt;br /&gt;
&lt;br /&gt;
6) Next, a mandatory Monty Hall Problem. &amp;nbsp;First, here's the general description of the scenario, from Wikipedia:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say Door A [but the door is not opened], and the host, who knows what's behind the doors, opens Door B, which has a goat. He then says to you, "Do you want to pick Door C?" Is it to your advantage to switch your choice?&lt;/i&gt;&lt;/blockquote&gt;The answer depends on the behavior of the host when the car is behind Door A. &amp;nbsp;In this case the host can open either B or C. &amp;nbsp;Suppose he chooses B with probability&amp;nbsp;&lt;i&gt;p&lt;/i&gt;&amp;nbsp;and C otherwise. &amp;nbsp;What is the probability that the car is behind Door A (as a function of&amp;nbsp;&lt;i&gt;p&lt;/i&gt;)?&lt;br /&gt;
&lt;br /&gt;
The hypotheses are&lt;br /&gt;
A: the car is behind Door A&lt;br /&gt;
B: the car is behind Door B&lt;br /&gt;
C: the car is behind Door C&lt;br /&gt;
&lt;br /&gt;
And the priors are&lt;br /&gt;
P(A) = P(B) = P(C) = 1/3&lt;br /&gt;
&lt;br /&gt;
The likelihoods are&lt;br /&gt;
P(E|A) = p, because in this case Monty has a choice and chooses B with probability p,&lt;br /&gt;
P(E|B) = 0, because if the car were behind B, Monty would not have opened B, and&lt;br /&gt;
P(E|C) = 1, because in this case Monty has no choice.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
Applying Bayes's Theorem,&lt;br /&gt;
P(A|E) = p / (1+p)&lt;br /&gt;
&lt;br /&gt;
In the canonical scenario, p=1/2, so P(A|E) = 1/3, which is the canonical solution. &amp;nbsp;If p=0, P(A|E) = 0, so you can switch and win every time (when Monty opens B, that it). &amp;nbsp;If p=1,&amp;nbsp;P(A|E) = 1/2, so in that case it doesn't matter whether you stick or switch.&lt;br /&gt;
&lt;br /&gt;
When Monty opens C,&amp;nbsp;P(A|E) = (1-p) / (1+p).&lt;br /&gt;
&lt;br /&gt;
7) And finally, here is a new problem I just came up with:&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;&lt;i&gt;If you meet a man with (naturally) red hair, what is the probability that neither of his parents has red hair?&lt;/i&gt;&lt;/blockquote&gt;Hints: About 2% of the world population has &lt;a href="http://en.wikipedia.org/wiki/Red_hair"&gt;red hair&lt;/a&gt;. &amp;nbsp;You can assume that the alleles for red hair are&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Dominance_(genetics)"&gt;purely recessive&lt;/a&gt;. &amp;nbsp;Also, you can assume that the &lt;a href="http://en.wikipedia.org/wiki/Red_hair#Extinction_hoax"&gt;Red Hair Extinction&lt;/a&gt; theory is false, so you can apply the &lt;a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle"&gt;Hardy–Weinberg principle&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Solution to this one next week!&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Please let me know if you have suggestions for more problems. An ideal problem should meet at least some of these criteria:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;1) It should be based on a context that is realistic or at least interesting, and not too contrived.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;2) It should make good use of Bayes's Theorem -- that is, it should be easier to solve with BT than without.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;3) It should involve some real data, which the solver might have to find.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;4) It might involve a trick, but should not be artificially hard.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; color: #222222; line-height: 18px; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If you send me something that is not under copyright, or is usable under fair use, I will include it in the next edition of&amp;nbsp;&lt;i&gt;&lt;a href="http://thinkstats.com/" style="color: #213abb; text-decoration: none;"&gt;Think Stats&lt;/a&gt;&lt;/i&gt;&amp;nbsp;and add you to the contributors list.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-1352062729055702719?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/G7UoP5W5Y-9qSQPm6WiBtAvQx4k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/G7UoP5W5Y-9qSQPm6WiBtAvQx4k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/G7UoP5W5Y-9qSQPm6WiBtAvQx4k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/G7UoP5W5Y-9qSQPm6WiBtAvQx4k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/EgzJ-9hPuCc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/1352062729055702719/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/10/all-your-bayes-are-belong-to-us.html#comment-form" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1352062729055702719?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/1352062729055702719?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/EgzJ-9hPuCc/all-your-bayes-are-belong-to-us.html" title="All your Bayes are belong to us!" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-uQT3C5WHqiM/TqBE9TjNFrI/AAAAAAAAAm0/FDlattML3D8/s72-c/DiagramforthelungcancerBayesproblem+%25281%2529.png" height="72" width="72" /><thr:total>9</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/10/all-your-bayes-are-belong-to-us.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkIBRXwzeSp7ImA9WhdaEk4.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-3907083582945814725</id><published>2011-10-20T07:17:00.000-07:00</published><updated>2011-10-21T13:55:54.281-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-21T13:55:54.281-07:00</app:edited><title>My favorite Bayes's Theorem problems</title><content type="html">This week: some of my favorite problems involving Bayes's Theorem. &amp;nbsp;Next week: solutions.&lt;br /&gt;
&lt;br /&gt;
1) The first one is a warm-up problem. &amp;nbsp;I got it from Wikipedia (but it's no longer there):&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;i&gt;Suppose there are two full bowls of cookies. Bowl #1 has 10 chocolate chip and 30 plain cookies, while bowl #2 has 20 of each. Our friend Fred picks a bowl at random, and then picks a cookie at random. We may assume there is no reason to believe Fred treats one bowl differently from another, likewise for the cookies. The cookie turns out to be a plain one. How probable is it that Fred picked it out of Bowl #1?&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;This is a thinly disguised &lt;a href="http://en.wikipedia.org/wiki/Urn_problem"&gt;urn problem&lt;/a&gt;. &amp;nbsp;It is simple enough to solve without Bayes's Theorem, but good for practice.&lt;br /&gt;
&lt;br /&gt;
2) This one is also an urn problem, but a little trickier.&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;The blue M&amp;amp;M was introduced in 1995. &amp;nbsp;Before then, the color mix in a bag of plain M&amp;amp;Ms was (30% Brown, 20% Yellow, 20% Red, 10% Green, 10% Orange, 10% Tan). &amp;nbsp;Afterward it was (20% Blue , 20% Green, 16% Orange, 14% Yellow, 13% Red, 13% Brown).&lt;/i&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;i&gt; A friend of mine has two bags of M&amp;amp;Ms, and he tells me that one is from 1994 and one from 1996. &amp;nbsp;He won't tell me which is which, but he gives me one M&amp;amp;M from each bag. &amp;nbsp;One is yellow and one is green. &amp;nbsp;What is the probability that the yellow M&amp;amp;M came from the 1994 bag?&lt;/i&gt;&lt;/blockquote&gt;3) This one is from one of my favorite books, David MacKay's "Information Theory, Inference, and Learning Algorithms":&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Elvis Presley had a twin brother who died at birth. &amp;nbsp;What is the probability that Elvis was an identical twin?&lt;/i&gt;&lt;/blockquote&gt;To answer this one, you need some background information:&amp;nbsp;According to the Wikipedia article on twins: &amp;nbsp;``Twins are estimated to be approximately 1.9% of the world population,&amp;nbsp;with monozygotic twins making up 0.2% of the total---and 8% of all&amp;nbsp;twins.''&lt;br /&gt;
&lt;br /&gt;
4) Also from MacKay's book:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Two people have left traces of their own blood at the scene of a crime. &amp;nbsp;A suspect, Oliver, is tested and found to have type O blood. &amp;nbsp;The blood groups of the two traces are found to be of type O (a common type in the local population, having frequency 60%) and of type AB (a rare type, with frequency 1%). &amp;nbsp;Do these data (the blood types found at the scene) give evidence in favour [sic] of the proposition that Oliver was one of the two people whose blood was found at the scene?&lt;/i&gt;&lt;/blockquote&gt;5) I like this problem because it doesn't provide all of the information. &amp;nbsp;You have to figure out what information is needed and go find it.&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;According to the CDC, ``Compared to nonsmokers, men who smoke&amp;nbsp;are about 23 times more likely to develop lung cancer and women who&amp;nbsp;smoke are about 13 times more likely.''&lt;/i&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;i&gt;If you learn that a woman has been diagnosed with lung cancer, and&amp;nbsp;you know nothing else about her, what is the probability that she&amp;nbsp;is a smoker?&lt;/i&gt;&lt;/blockquote&gt;6) And finally, a mandatory Monty Hall Problem. &amp;nbsp;First, here's the general description of the scenario, from Wikipedia:&lt;br /&gt;
&lt;blockquote&gt;&lt;i&gt;Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say Door A [but the door is not opened], and the host, who knows what's behind the doors, opens another door, say Door B, which has a goat. He then says to you, "Do you want to pick Door C?" Is it to your advantage to switch your choice?&lt;/i&gt;&lt;/blockquote&gt;The answer depends on the behavior of the host if the car is behind Door A. &amp;nbsp;In this case the host can open either B or C. &amp;nbsp;Suppose he chooses B with probability &lt;i&gt;p&lt;/i&gt; and C otherwise. &amp;nbsp;What is the probability that the car is behind Door A (as a function of &lt;i&gt;p&lt;/i&gt;)?&lt;br /&gt;
&lt;br /&gt;
If you like this problem, you might also like the &lt;a href="http://allendowney.blogspot.com/2011/10/blinky-monty-problem.html"&gt;Blinky Monty Problem&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Solutions next week!&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Please let me know if you have suggestions for more problems. An ideal problem should meet at least some of these criteria:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;1) It should be based on a context that is realistic or at least interesting, not too contrived.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;2) It should make good use of Bayes's Theorem -- that is, it should be easier to solve with BT than without.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;3) It should involve some real data, which the solver might have to find.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;4) It might involve a trick, but should not be artificially hard.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: white; margin-bottom: 5px; margin-top: 5px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If you send me something that is not under copyright, or is usable under fair use, I will include it in the next edition of &lt;i&gt;&lt;a href="http://thinkstats.com/"&gt;Think Stats&lt;/a&gt;&lt;/i&gt; and add you to the contributors list.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-3907083582945814725?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FwJeKm1dTlXWJi9PVQy2Al9jBtc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FwJeKm1dTlXWJi9PVQy2Al9jBtc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FwJeKm1dTlXWJi9PVQy2Al9jBtc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FwJeKm1dTlXWJi9PVQy2Al9jBtc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/__umqle_TQ0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/3907083582945814725/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/10/my-favorite-bayess-theorem-problems.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3907083582945814725?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3907083582945814725?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/__umqle_TQ0/my-favorite-bayess-theorem-problems.html" title="My favorite Bayes's Theorem problems" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/10/my-favorite-bayess-theorem-problems.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYFRX85fSp7ImA9WhRUFk4.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-8059000893542088957</id><published>2011-10-17T13:02:00.000-07:00</published><updated>2012-01-26T18:58:34.125-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-01-26T18:58:34.125-08:00</app:edited><title>The Blinky Monty Problem</title><content type="html">I read Jason Rosenhouse's book about &lt;a href="http://www.amazon.com/gp/product/0195367898/ref=as_li_qf_sp_asin_tl?ie=UTF8&amp;amp;tag=greenteapre01-20&amp;amp;linkCode=as2&amp;amp;camp=217145&amp;amp;creative=399369&amp;amp;creativeASIN=0195367898"&gt;The Monty Hall Problem&lt;/a&gt; recently, and I use the problem as an example in my statistics class. &amp;nbsp;Last semester I wrote a variation of the problem that turns out to be challenging, and a motivating problem for Bayesian estimation. &amp;nbsp;Here's what I call the "Blinky Monty Problem."&lt;br /&gt;
&lt;blockquote style="font-size: 13px;"&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;Suppose you are on&amp;nbsp;&lt;/i&gt;Let's Make a Deal&lt;i&gt;&amp;nbsp;and you are playing the&amp;nbsp;Monty Hall Game, with one twist. &amp;nbsp;Before you went on the show you analyzed tapes of&amp;nbsp;previous shows and discovered that Monty has a&amp;nbsp;tell: when the contestant picks the correct&amp;nbsp;door, Monty is more likely to blink.&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote style="font-size: 13px;"&gt;&lt;span class="Apple-style-span" style="color: #444444;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;Of the 18 shows you watched, the contestant chose&amp;nbsp;the correct door 5 times, and Monty blinked three of those times. &amp;nbsp;Of the other 13 times, Monty blinked three times.&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote style="font-size: 13px;"&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;Assume that you choose Door A. &amp;nbsp;Monty opens door B&amp;nbsp;and blinks. &amp;nbsp;What should you do, and what is your chance of winning?&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;
To get started, let's review the standard version of the Monty Hall problem (from Wikipedia):&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="background-color: white; line-height: 20px;"&gt;&lt;span class="Apple-style-span" style="color: #444444; font-family: inherit;"&gt;&lt;i&gt;"Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say A [but the door is not opened], and the host, who knows what's behind the doors, opens another door, say B, which has a goat. He then says to you, "Do you want to pick door C?" Is it to your advantage to switch your choice?"&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;We can solve this problem using Bayes's Theorem. &amp;nbsp;There are two relevant hypotheses:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;A: the car is behind door A&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;C: the car is behind door C&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before Monty opens door B, the prior probability for both hypotheses is 1/3. &amp;nbsp;Now the evidence is&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;E: Monty opened door B.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To compute the posterior probabilities, we need the likelihoods P(E|A) and P(E|C).&lt;br /&gt;
&lt;br /&gt;
P(E|A) is the probability of the evidence if the car is behind door A. &amp;nbsp;In this case Monty has a choice; he could have opened door B or C. &amp;nbsp;In the canonical version of the problem, he chooses at random, so&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(E|A) = 1/2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
P(E|C)&amp;nbsp;is the probability of the evidence if the car is behind door C. &amp;nbsp;In this case Monty has no choice, so&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(E|A) = 1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Applying Bayes's Theorem yields:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(A|E) = 1/3&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(C|E) = 2/3&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So if you switch to Door C, you increase the chances of winning from 1/3 to 2/3. &amp;nbsp;This is the standard answer to the standard version of the problem. &amp;nbsp;If you are not familiar with the Monty Hall problem and this answer comes as a shock to you, please don't take it out on me. &amp;nbsp;Go read about it, &lt;a href="http://en.wikipedia.org/wiki/Monty_Hall_problem"&gt;starting here&lt;/a&gt;, and come back when you have calmed down.&lt;br /&gt;
&lt;br /&gt;
Are you ready to go on? &amp;nbsp;Ok. &amp;nbsp;We can do a similar analysis for the Blinky Monty problem, but now we have more evidence to consider:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;E: Monty opens Door B and blinks.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
According to the scouting report, the probability that Monty blinks if the car is behind A is 3/5, so&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(E|A) = (1/2)(3/5) = 3/10&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If the car is behind C, Monty blinks 3/13 of the time, so&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;P(E|C) = (1)(3/13) = 3/13&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Plugging in Bayes' Theorem, we get P(A|E) = 0.51, so in this scenario you are slightly better off sticking with Door A.&lt;br /&gt;
&lt;br /&gt;
But is that all there is to it? &amp;nbsp;No! &amp;nbsp;And here's where this blog earns the name "Probably Overthinking It." Remember that the probabilities for Monty's blinking are estimates based on a sample, so we have some uncertainty about them.&lt;br /&gt;
&lt;br /&gt;
To take that uncertainty into account, we have to&lt;br /&gt;
&lt;br /&gt;
1) Use the scouting report to estimate the distribution of P(blink|A) and P(blink|C).&lt;br /&gt;
&lt;br /&gt;
2) For each pair of values from those distributions, compute P(A|E).&lt;br /&gt;
&lt;br /&gt;
3) Apply the law of total probability to get the overall P(A|E).&lt;br /&gt;
&lt;br /&gt;
That might sound complicated, but it is straightforward to estimate computationally.&lt;br /&gt;
&lt;br /&gt;
First, let me take a minute to make fun of frequentists. &amp;nbsp;According to conventional hypothesis testing, the data from the scouting report is not statistically significant. &amp;nbsp;If the null hypothesis is that Monty has the same chance of blinking regardless of the location of the car, the p-value of the sample we saw is 0.27 (I used Fisher's exact test, computed using this &lt;a href="http://www.graphpad.com/quickcalcs/contingency1.cfm"&gt;online calculator&lt;/a&gt;). &amp;nbsp;We can't reject the null hypothesis, so if we play by the rules of&amp;nbsp;conventional hypothesis testing, I guess that means we can't take advantage of Monty's tell. &amp;nbsp;If you are a committed frequentist, you should stop reading now.&lt;br /&gt;
&lt;br /&gt;
Good. &amp;nbsp;Now that the riff-raff are gone, let's proceed. &amp;nbsp;Here's how we make the posterior distribution for P(blink|doorA):&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; doorA = MakeUniformSuite(0.0, 1.0, 101, name='Door A')&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; evidence = 3, 2&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; Update(doorA, evidence)&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;MakeUniformSuite() makes a Pmf of 101 values equally spaced between 0 and 1, with equal probability. Update() does the usual Bayesian update:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def Update(suite, evidence):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """Updates a suite of hypotheses based on new evidence.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; Modifies the suite directly; if you want to keep the original, make&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; a copy.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; Args:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; suite: Pmf object&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; evidence: whatever kind of object Likelihood expects&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; for hypo in suite.Values():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; likelihood = Likelihood(evidence, hypo)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; suite.Mult(hypo, likelihood)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; suite.Normalize()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def Likelihood(evidence, hypo):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """Computes the likelihood of the evidence assuming the hypothesis is true.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; Args:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; evidence: a tuple of (number of heads, number of tails)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hypo: float probability of heads&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; Returns:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; probability of tossing the given number of heads and tails with a&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; coin that has p probability of heads&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; heads, tails = evidence&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; p = hypo&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; return pow(p, heads) * pow(1-p, tails)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;If you are not familiar with that, you can read Chapter 8 of &lt;a href="http://greenteapress.com/thinkstats/"&gt;Think Stats&lt;/a&gt;, or see &lt;a href="http://allendowney.blogspot.com/2011/02/yet-another-reason-sat-scores-are-non.html"&gt;this blog post&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To find P(blink|C), it's pretty much the same:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; doorC = MakeUniformSuite(0.0, 1.0, 101, name='Door C')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; evidence = 3, 10&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; Update(doorC, evidence)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;And to finish it off, we apply the law of total probability:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; print TotalProbability(doorA, doorC, ProbWinning)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;TotalProbability() enumerates the values from doorA and doorC, and calls ProbWinning() for each pair:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def TotalProbability(pmf1, pmf2, func):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """Enumerates pairs from the Pmfs, calls the func, and returns&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; the total probability.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; func: takes a value from each Pmf and returns a probability.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; total = 0.0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for x, px in pmf1.Items():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for y, py in pmf2.Items():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if px and py:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; total += px * py * func(x, y)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return total&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Finally, ProbWinning() takes P(blink|A) and P(blink|C) and returns P(A|E):&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def ProbWinning(pbA, pbC):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """Computes the probability that the car is behind door A:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pbA: probability that Monty blinks if the car is behind A&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pbC: probability that Monty blinks if the car is behind C&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pea = 0.5 * pbA&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pec = 1.0 * pbC&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pae = pea / (pea + pec)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return pae&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
You can download all this code &lt;a href="http://greenteapress.com/thinkstats/blinky.py"&gt;here&lt;/a&gt;. &amp;nbsp;If you run it, you'll see the posterior distributions for&amp;nbsp;P(blink|A) and P(blink|C):&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-_qYUnc7wu4c/TyIRZLvvopI/AAAAAAAAAqM/aRXB0AxQAIQ/s1600/blinky.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-_qYUnc7wu4c/TyIRZLvvopI/AAAAAAAAAqM/aRXB0AxQAIQ/s400/blinky.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;The most likely values are 0.6 and 0.23, but since we don't have much data, the uncertainty is still large.&lt;/div&gt;Taking it all together, the probability that the car is behind Door A, P(A|E), is 0.52. &amp;nbsp;So you are slightly better off sticking with Door A.&lt;br /&gt;
&lt;br /&gt;
To summarize:&lt;br /&gt;
&lt;br /&gt;
1) In the canonical version of the game,&amp;nbsp;P(A|E) = 1/3, so you are better off switching.&lt;br /&gt;
&lt;br /&gt;
2) In the Blinky Monty version, if we take P(blink|A) and P(blink|C) as givens, we estimate P(A|E) = 0.51, so you are slightly better off sticking with Door A.&lt;br /&gt;
&lt;br /&gt;
3) If you are a frequentist, you conclude that Monty's tell is not statistically significant, so you ignore it, switch, and lose most of the time.&lt;br /&gt;
&lt;br /&gt;
4) If you are a Bayesian, you can take advantage of the tell and maximize your chance of winning. &amp;nbsp;If Monty blinks and you stick, you win 52% of the time. &amp;nbsp;If he doesn't blink and you switch, you win 87% of the time. &amp;nbsp;Since he blinks 40% of the time, overall you can expect to win 73% of the time. &amp;nbsp;So the tell provides a substantial advantage.&lt;br /&gt;
&lt;br /&gt;
Exercise for the reader: download my code and modify it to analyze the case where Monty doesn't blink. &amp;nbsp;Hint: you only have to change two lines.&lt;br /&gt;
&lt;br /&gt;
EDIT October 19, 2011: I got a comment on reddit that raises a legitimate concern about data collection. In the scenario I presented, if you review tapes of the show and look for several potential tells (blinking, facial tics, verbal habits, etc.) and you choose one that seems to be correlated with the outcome, you could easily get fooled (see &lt;a href="http://allendowney.blogspot.com/2011/10/repeated-tests-how-bad-can-it-be.html"&gt;this post on repeated tests&lt;/a&gt;). &amp;nbsp;This is a fair warning for both the frequentist and Bayesian analyses.&lt;br /&gt;
&lt;br /&gt;
So to be more careful, maybe I should say that you were tipped off to the possibility that Monty's tell is a blink before you reviewed the tape, and that's the only data you collected.&lt;br /&gt;
&lt;br /&gt;
EDIT January 26, 2012: In the comments below, Jacob pointed out an error in my calculation. &amp;nbsp;As a result, I went back and changed the scenario to match my calculations, which forced me to make a few other revisions. &amp;nbsp;I think it is all settled now, but let me know if you disagree.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-8059000893542088957?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ky6fADRzog2AQzI9PuYZnzXza2c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ky6fADRzog2AQzI9PuYZnzXza2c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ky6fADRzog2AQzI9PuYZnzXza2c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ky6fADRzog2AQzI9PuYZnzXza2c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/IAQSjqinN98" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/8059000893542088957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/10/blinky-monty-problem.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8059000893542088957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8059000893542088957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/IAQSjqinN98/blinky-monty-problem.html" title="The Blinky Monty Problem" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-_qYUnc7wu4c/TyIRZLvvopI/AAAAAAAAAqM/aRXB0AxQAIQ/s72-c/blinky.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/10/blinky-monty-problem.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcASH89eip7ImA9WhdUGUw.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-3721859151941828832</id><published>2011-10-06T05:03:00.000-07:00</published><updated>2011-10-06T07:07:29.162-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-06T07:07:29.162-07:00</app:edited><title>Repeated tests: how bad can it be?</title><content type="html">A couple of weeks ago Red Dave wrote &lt;a href="http://liveatthewitchtrials.blogspot.com/2011/09/ab-testing-is-khan-doing-it-wrong.html"&gt;this blog post&lt;/a&gt; about the dangers of A/B testing with repeated tests. &amp;nbsp;I think he's right, and does a good job of explaining why. &amp;nbsp;But to get a better understanding of the issue, I wrote some simulations, and things can be even worse than Dave suggests.&lt;br /&gt;
&lt;br /&gt;
As an example of A/B testing, suppose you are advertising a business and you develop two versions of an ad, A and B, with different text, graphics, etc. &amp;nbsp;You want to know which ad is more effective.&lt;br /&gt;
&lt;br /&gt;
If you post your ads online, you can find out how many times each version was shown (number of impressions), and how many people clicked on each ad (number of clicks). &amp;nbsp;The number of clicks per impression is the "click-through rate," or CTR. &amp;nbsp;At least, that's what Google calls it.&lt;br /&gt;
&lt;br /&gt;
If you show each ad 1000 times, you might see a CTR of 1% for Version A and 2% for Version B. &amp;nbsp;To see whether this difference is significant, you can use a chi-square test, which compares the actual number of clicks for each ad with the expected number. &amp;nbsp;The result is a p-value, which tells you the chance of seeing a difference as big as that if the ads are actually the same. &amp;nbsp;If the p-value is small, the effect is unlikely to be due to chance, so it is more likely to be real.&lt;br /&gt;
&lt;br /&gt;
So far, this is just classical hypothesis testing. &amp;nbsp;No problem. &amp;nbsp;Here's where things get ugly.&lt;br /&gt;
&lt;br /&gt;
If, instead of showing each ad 1000 times, you run the ad for a while, and then check for a statistically-significant difference, run a while longer, check again, and repeat until you get a&amp;nbsp;significant difference, then what you are doing is Bogus.&lt;br /&gt;
&lt;br /&gt;
And when I say "Bogus", I mean capital-B Bogus, because the p-values you compute are not going to be off by a factor of 2, which would actually be acceptable for most purposes. &amp;nbsp;They are not going to be off by a factor of 10, which would make them meaningless. &amp;nbsp;They are going to be completely and totally wrong, to the point where, if you run long enough, you are nearly certain to see a "statistically significant" difference, even if both versions are the same.&lt;br /&gt;
&lt;br /&gt;
To see why, let's look at the case where you check for significance after every ad impression. &amp;nbsp;Suppose you show version A or version B with equal probability, and in either case the click-through rate is 50%. &amp;nbsp;After 100 impressions, you expect to show A and B 50 times each, and you expect 25 clicks on each.&lt;br /&gt;
&lt;br /&gt;
After each impression, we can compute the CTR for A and B, and plot the difference as a random walk. &amp;nbsp;Here's what it looks like for 10 simulations of 200 impressions:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-YeuZHqMFkDk/ToS4UHRCi5I/AAAAAAAAAmQ/QFPjAXry8JI/s1600/khan0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://2.bp.blogspot.com/-YeuZHqMFkDk/ToS4UHRCi5I/AAAAAAAAAmQ/QFPjAXry8JI/s400/khan0.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
When the number of trials is small, the difference in CTR can be big, but for n&amp;gt;50 the law of large numbers kicks in and the difference gets small.&lt;br /&gt;
&lt;br /&gt;
Instead of computing the difference, we can compute the chi-square statistic, which yields another random walk. &amp;nbsp;Here's what it looks like after 1000 steps:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-7oRBSxs1x8k/ToS5V2d52VI/AAAAAAAAAmU/Ar1yncZictg/s1600/khan1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-7oRBSxs1x8k/ToS5V2d52VI/AAAAAAAAAmU/Ar1yncZictg/s400/khan1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
After an initial transient, the distribution of the lines stabilizes, which shows that for large N, the distribution of the chi-square stat does not depend on N, which is exactly why we can use the chi-square distribution to compute p-values analytically.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://docs.scipy.org/doc/scipy/reference/stats.html"&gt;SciPy&lt;/a&gt; provides a function that evaluates the chi-squared CDF. &amp;nbsp;The following function uses it to look up chi-squared values and return the corresponding p-value:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;import scipy.stats&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;def Pvalue(chi2, df):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """Probability of getting chi2 or greater from a chi-squared distribution.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; chi2: observed chi-squared statistic&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; df: degrees of freedom&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; font-size: x-small;"&gt;&amp;nbsp; &amp;nbsp; return 1 - scipy.stats.chi2.cdf(chi2, df)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this example, the number of degrees of freedom is 3, because there are four values in the table (hits and misses for A and B), but they are constrained to add up to N.&lt;br /&gt;
&lt;br /&gt;
Now here's the key question: if we take values that are actually from a chi-squared distribution and look up the corresponding p-values, what is the distribution of the resulting p-values?&lt;br /&gt;
&lt;br /&gt;
Answer: they are uniformly distributed. &amp;nbsp;Why? &amp;nbsp;Because we are using the chi-squared CDF to get their percentile ranks. &amp;nbsp;By the definition of the CDF, 1% of them fall below the 1st percentile, 2% of them fall below the 2nd percentile, and so on.&lt;br /&gt;
&lt;br /&gt;
If we plot the p-values as a random walk, here's what it looks like (20 simulations, 2000 trials):&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ryUTE5Ez-0w/ToS9MXeLZZI/AAAAAAAAAmY/E0DMer4333E/s1600/khan2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-ryUTE5Ez-0w/ToS9MXeLZZI/AAAAAAAAAmY/E0DMer4333E/s400/khan2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;For large N, the lines are spread out uniformly from 0 to 1, as expected.&lt;br /&gt;
&lt;br /&gt;
The red line shows the significance criterion, alpha, which determines the false positive rate. &amp;nbsp;If alpha=5%, then at any point in time, we expect 5% of the lines to be below this threshold. &amp;nbsp;And in the figure, that looks about right.&lt;br /&gt;
&lt;br /&gt;
If we stop the test at a pre-determined time, or at a randomly-chosen time, we expect to find one line out of twenty below the threshold. &amp;nbsp;But if you do repeated tests, checking for significance after every trial, then the relevant question is how many of these lines cross below the threshold, ever?&lt;br /&gt;
&lt;br /&gt;
In this example, it is almost 50%. &amp;nbsp;After 10000 trials, it is 85%. &amp;nbsp;As the number of trials increases, the false positive rate approaches 100%.&lt;br /&gt;
&lt;br /&gt;
A standard quip among statisticians goes like this: "A frequentist is a person whose long-run ambition is to be wrong 5% of the time." &amp;nbsp;Here's an update: "A/B testing with repeated tests is totally legitimate, if your long-run ambition is to be wrong 100% of the time."&lt;br /&gt;
&lt;br /&gt;
You can download the code I used to generate these figures from &lt;a href="http://thinkstats.com/khan.py"&gt;thinkstats.com/khan.py&lt;/a&gt;. &amp;nbsp;The file is named after the Khan Academy because that's the context of the &lt;a href="http://liveatthewitchtrials.blogspot.com/2011/09/ab-testing-is-khan-doing-it-wrong.html"&gt;blog post&lt;/a&gt; that brought the problem to my attention.&lt;br /&gt;
&lt;br /&gt;
Note: in these examples, I used a CTR of 50%, which is much higher than you are likely to get with an online ad campaign: 1% is considered good. &amp;nbsp;If you run these simulations with more realistic CTRs, the random walks get jaggier, due to the statistics of small numbers, but the overall effect is the same.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-3721859151941828832?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vfvw0Pb6wNwjuUVm2K5nFeqcpO8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vfvw0Pb6wNwjuUVm2K5nFeqcpO8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vfvw0Pb6wNwjuUVm2K5nFeqcpO8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vfvw0Pb6wNwjuUVm2K5nFeqcpO8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/9KUeAhgls5M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/3721859151941828832/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/10/repeated-tests-how-bad-can-it-be.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3721859151941828832?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3721859151941828832?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/9KUeAhgls5M/repeated-tests-how-bad-can-it-be.html" title="Repeated tests: how bad can it be?" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-YeuZHqMFkDk/ToS4UHRCi5I/AAAAAAAAAmQ/QFPjAXry8JI/s72-c/khan0.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/10/repeated-tests-how-bad-can-it-be.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkcFRH88fyp7ImA9WhdXGUU.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-6546218205218940490</id><published>2011-08-29T18:33:00.000-07:00</published><updated>2011-09-02T09:13:35.177-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-02T09:13:35.177-07:00</app:edited><title>The Jimmy Nut Company problem</title><content type="html">&lt;div style="background-color: transparent;"&gt;&lt;span id="internal-source-marker_0.3471354506909847" style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;I read with interest an article by Robert Hayden called “&lt;a href="http://statland.org/MAAFIXED.PDF"&gt;Advice to mathematics teachers on evaluating introductory statistics textbooks&lt;/a&gt;.”  It makes two claims:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;ul&gt;&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;Statistics textbooks should emphasize real problems with real data.  I couldn't agree more.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;You should choose a statistics textbook written by a statistician at a large university who has good research publications.  I couldn't agree less.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt;On the second point, Prof. Hayden argues that statistics books contain more errors than other math books, and that the errors are more often conceptual, not just typos. &amp;nbsp;The reason, he explains, is that “introductory statistics textbooks are often written by people with little or no training in statistics.”&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;As an example (in fact, the only example) he cites this problem from an unnamed popular textbook:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;“Jimmy Nut Company advertises that their nut mix contains 40% cashews, 15% brazil nuts, 20% almonds, and only 25% peanuts. The truth in advertising investigators took a random sample (of size 20 lb) of the nut mix and found the distribution to be as follows:&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Cashews  Brazil Nuts  Almonds  Peanuts&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;6 lb &amp;nbsp;   3 lb &amp;nbsp;       5 lb &amp;nbsp;   6 lb&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div dir="ltr" style="margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;At the 0.01 level of significance, is the claim made by Jimmy Nuts true?”&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Prof. Hayden hates this problem. &amp;nbsp;He thinks it is ill-posed, and evidence of everything wrong with statistics books. &amp;nbsp;He explains: “The problem here is that the chi-squared goodness of fit test applies only to categorical (discrete) data.  It compares the actually observed counts in each category to the counts we would expect if the hypothesis being tested were true.”&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;This is true, and if you blindly plug the numbers from the problem into the formula for a chi-squared statistic, the result is meaningless. &amp;nbsp;In fact, if you express the given data in other units, you can make the resulting p-value as big or small as you like.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;But that doesn’t mean the textbook author has made a “gross error,” because the question doesn’t say “plug these numbers in blindly and write down the result without thinking.” &amp;nbsp;The question doesn’t even specify the chi-squared statistic.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The question, as written, is perfectly sensible, moderately challenging, and interesting. &amp;nbsp;It requires thought and care to formulate the question in a way that leads to a meaningful answer, and it is exactly the kind of question someone doing statistics is likely to be asked.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;I don’t know what the textbook author had in mind, but there is nothing wrong with the question as written. &amp;nbsp;And to prove it, I’m going to answer it.  I follow the procedure I recommend in my article "&lt;a href="http://allendowney.blogspot.com/2011/05/there-is-only-one-test.html"&gt;There is only one test&lt;/a&gt;."&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The first step is to make a model of the null hypothesis, which is that the proportion of nuts is as advertised. &amp;nbsp;But if the proportions are &lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;always&lt;/i&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; as advertised, the data observed would be impossible. &amp;nbsp;So we need a random model that characterizes the variation we expect to see in a sample.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;What are the sources of variation in a 20 lb sample of nuts? &amp;nbsp;One source is mechanical error; that is, the people and machines that weigh and mix nuts might be miscalibrated. &amp;nbsp;If the accuracy of this process varies from day to day, we could treat it as a random variation. &amp;nbsp;To quantify this effect, we would need some information about how the nuts are processed.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Another source of error, and probably the one the textbook author had in mind, is discrete sampling. &amp;nbsp;If we take a small sample, we would not expect the proportions to be exactly as advertised.  To model this kind of variation, we have to count individual nuts.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;To convert the data from weights to counts, we have to know how much each kind of nut weighs. &amp;nbsp;This step requires some research, which I think is an interesting element of the problem. &amp;nbsp;Since we live in a post-Google information utopia, it is reasonable to expect students to answer this question, and useful for them to practice.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;I found several sources with information about the weight of typical nuts, some more authoritative than others. &amp;nbsp;The one I use is “&lt;/span&gt;&lt;a href="http://lancaster.unl.edu/food/ftmar04.htm"&gt;&lt;span style="background-color: transparent; color: #000099; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;Nuts for Nutrition&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;,” by Alice Henneman, MS, RD, Extension Educator at the University of Nebraska Cooperative Extension - Lancaster County. &amp;nbsp;In addition to the credentials and affiliation of the author, and the witty article title, I chose this source because it provides numbers for all four nuts in one table, so even if the methodology that produced them is not ideal, it is probably consistent, which means that the relative values are likely to be good even if the absolute values are not.  F&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt;rom the table:&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Nuts per ounce: Cashew 16-18, Brazil nut 6-8, Almonds 20-24, Peanuts 28.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;To start I use the middle of each range.  With this data we can convert observed values from pounds to counts and convert the expected proportions from “by weight” to “by count”. &amp;nbsp;Here’s a function that does it:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;def ConvertToCount(sample, count_per):&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;"""Convert from weight to count.&lt;br class="kix-line-break" /&gt;&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;sample: Hist that maps from category to weight in pounds&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;count_per: dict that maps from category to count per ounce&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;"""&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for value, count in sample.Items():&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sample.Mult(value, 16 * count_per[value])&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;The code examples here use the &lt;a href="http://greenteapress.com/thinkstats/Pmf.html"&gt;Pmf&lt;/a&gt; and &lt;a href="http://greenteapress.com/thinkstats/Cdf.html"&gt;Cdf&lt;/a&gt; libraries from &lt;i&gt;Think Stats&lt;/i&gt;.  H&lt;/span&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;ere’s the code that processes the information we’re given:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;br class="kix-line-break" /&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; &amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;sample = dict(cashew=6, brazil=3, almond=5, peanut=6)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;count_per = dict(cashew=17, brazil=7,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;                     almond=22, peanut=28)&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;observed = Pmf.MakeHistFromDict(sample)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;ConvertToCount(observed, count_per)&lt;br class="kix-line-break" /&gt;&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;advertised = dict(cashew=40, brazil=15,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;                      almond=20, peanut=25)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;expected = Pmf.MakePmfFromDict(advertised)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;ConvertToCount(expected, count_per)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;expected.Normalize(observed.Total())&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Here are the results in tabular form:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Nut &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Expected &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Observed &amp;nbsp;&amp;nbsp;&amp;nbsp;% error &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;a href="http://www.ohnuts.com/"&gt;&lt;span style="background-color: transparent; color: #000099; font-family: 'Courier New'; font-style: normal; font-variant: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;"&gt;price per pound&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;cashew &amp;nbsp;&amp;nbsp;&amp;nbsp;2266 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1632 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-28 % &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$10 &lt;br class="kix-line-break" /&gt;brazil &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;350 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;336 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;- 4 % &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$8&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New';"&gt;almond &amp;nbsp;&amp;nbsp;&amp;nbsp;1467 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1760 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+20 % &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$8&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;peanut &amp;nbsp;&amp;nbsp;&amp;nbsp;2333 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2688 &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;+15 % &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$3&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;So there are 28% fewer cashews than expected, and 20% more almonds. &amp;nbsp;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Is this suspicious? &amp;nbsp;Intuitively, this looks like more deviation than I expect in a sample this large. &amp;nbsp;And the relationship between “error” and price makes it look even worse.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Let’s make that more rigorous. &amp;nbsp;The next step to choose a test statistic. &amp;nbsp;Mean relative error would be a reasonable choice. &amp;nbsp;Or I could devise a statistic that measures the excess of cheap nuts and lack of expensive nuts. &amp;nbsp;But to keep it simple I'll use the chi-square statistic. &amp;nbsp;The primary advantage of chi-square is that we can compute p-values analytically, which is efficient. &amp;nbsp;But since I am planning to use simulation, the only advantage is that it is conventional.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;For the given data the chi-square statistic is 291, which doesn’t mean anything. &amp;nbsp;To make it mean something, we have to compute the p-value, which is the probability of seeing a chi-square statistic so large under the null hypothesis.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Which means we need to get back to our model of the null hypothesis. &amp;nbsp;One option is to imagine choosing nuts one at a time from a vat that contains a large number of nuts mixed in the advertised proportions. &amp;nbsp;Here’s what that looks like:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;num_nuts = observed.Total()&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;cdf = Cdf.MakeCdfFromHist(expected)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;t = cdf.Sample(num_nuts)&lt;br class="kix-line-break" /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;hist = Pmf.MakeHistFromList(t)&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;chi2 = ChiSquared(expected, simulated)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="background-color: transparent; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;If we run that 1000 times, we can count how many samples yield &lt;/span&gt;&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;chi2&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &amp;gt; 290. &amp;nbsp;And the answer is...0. &amp;nbsp;In fact, after 1000 simulations, the largest test statistic is 20. &amp;nbsp;So the p-value is much smaller than 1/1000 and it is unlikely that the observed sample came from the advertised mixture, at least under this model.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Since there was some uncertainty in the data we collected, we should do a perturbation analysis. &amp;nbsp;For example, Jimmy might claim that he used big nuts, which would make the counts smaller and the results less significant. &amp;nbsp;So let’s give Jimmy the benefit of the doubt and run the numbers with these counts per ounce:&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Nuts per ounce: Cashew 12, Brazil nut 5, Almonds 18, Peanuts 24.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;With these data, the observed test statistic is only 215 (down from 290). &amp;nbsp;But the chance of seeing a value that large under the null hypothesis is still negligible.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;More credibly, Jimmy might claim that the model of the null hypothesis is unrealistic because the nuts are not perfectly mixed, so the sampling process is not independent. &amp;nbsp;In fact, correlation between successive draws would increase variation in the sample. &amp;nbsp;To see why, imagine the extreme scenario where the nuts are not mixed at all; in that case, most samples contain only one kind of nut.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;To model this scenario, we can make a list that represents the vat of nuts the sample is drawn from.  Initially the vat is completely unmixed.  Then we "stir" by choosing random pairs and swapping them.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; font-family: Arial; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def MakeVat(expected, num_nuts, factor=10, stir=0.0):&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """Makes a list of nuts with partial stirring."""&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; t = []&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for value, freq in expected.Items():&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t.extend([value] * int(freq * factor))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace; white-space: pre-wrap;"&gt;[RandomSwap(t) for i in xrange(int(num_nuts*factor*stir))]&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return t&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="font-family: Arial;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;expected&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; is a Pmf that represents the expected distribution.  &lt;/span&gt;&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;num_nuts&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; is the total number of nuts in the sample.  &lt;/span&gt;&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;factor&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; is the size of the vat, in multiples of &lt;/span&gt;&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;num_nuts&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;.  And &lt;/span&gt;&lt;span style="background-color: transparent; color: #38761d; font-family: 'Courier New', Courier, monospace; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;stir&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; is the number of swaps to perform per nut in the vat.&lt;/span&gt;&lt;br /&gt;
&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;I set &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;factor&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt; to 10, which means nuts are mixed in 200 lb batches.  With &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;stir &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;= 0, the nuts are unmixed and the p-value is 1; that is, it is certain that we will see a large deviation from the advertised proportions.  If &lt;/span&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;stir&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial;"&gt; &amp;gt; 2, the nuts are well mixed and the p-value is 0, as we saw before.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;Between 1.1 and 1.3 swaps per nut, the p-value drops quickly from 1 to 0.  So Jimmy's argument is plausible: if the nuts are not well mixed, that could explain the deviation we saw in the sample.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;In summary, what can we conclude about the Jimmy Nut Company?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;1) If the sample is drawn from a well mixed batch of nuts, it provides strong evidence that the mix is not as advertised.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;2) But if the nuts are not well mixed, that might explain the deviation we saw.  We could test that hypothesis by&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt;mixing the vat more thoroughly or &lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: Arial; white-space: pre-wrap;"&gt;taking small samples from several parts of the vat.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;And what can we conclude about the Jimmy Nut Company problem?&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;1) I think it's an excellent problem, as written.  It requires careful thinking and a little research, and the results could lead to interesting class discussion.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;2) I see no evidence that this problem indicates a conceptual error on the part of the textbook writer.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt;In summary, I agree with Prof. Hayden that statistics students should work with real data, but respectfully disagree with his assertion that statistics books should be written by statisticians.  I think they should be written by computer scientists.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial;"&gt;&lt;span class="Apple-style-span" style="white-space: pre-wrap;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The code I used for this article is &lt;a href="http://code.google.com/p/thinkstats/source/browse/trunk/workspace.thinkstats/ThinkStats/jimmy.py"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style="background-color: transparent;"&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;br /&gt;
UPDATE August 30, 2011: With the help of Google Books, I found the source of this problem: &lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;&lt;i&gt;&lt;a href="http://books.google.com/books?id=BOjZAAAAMAAJ&amp;amp;q=%22truth+in+advertising+investigators%22&amp;amp;dq=%22truth+in+advertising+investigators%22&amp;amp;hl=en&amp;amp;ei=4gVdToj_GcfV0QH04_2WAw&amp;amp;sa=X&amp;amp;oi=book_result&amp;amp;ct=result&amp;amp;resnum=1&amp;amp;ved=0CDMQ6AEwAA"&gt;Understandable statistics: concepts and methods&lt;/a&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="background-color: transparent; color: black; font-family: Arial; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt; by Charles Henry Brase and Corrinne Pellillo Brase.  The problem appears in the 5th edition, but not the current 9th edition.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-6546218205218940490?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ITE6N3WFFl3oC9gBC9DcqzeZ9CA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ITE6N3WFFl3oC9gBC9DcqzeZ9CA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ITE6N3WFFl3oC9gBC9DcqzeZ9CA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ITE6N3WFFl3oC9gBC9DcqzeZ9CA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/YYGwkKe5Geg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/6546218205218940490/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/08/jimmy-nut-company-problem.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/6546218205218940490?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/6546218205218940490?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/YYGwkKe5Geg/jimmy-nut-company-problem.html" title="The Jimmy Nut Company problem" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/08/jimmy-nut-company-problem.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UCQH8zfip7ImA9WhdbFE8.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-2882967383493833680</id><published>2011-08-16T07:27:00.000-07:00</published><updated>2011-10-12T05:07:41.186-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-12T05:07:41.186-07:00</app:edited><title>Upcoming webcast: Only One Test</title><content type="html">The nice people at O'Reilly Media have asked me to do a webcast or two on topics related to Think Stats. &amp;nbsp;The first one is scheduled for October 4 at 1pm EDT. &amp;nbsp;Here is &lt;a href="http://oreillynet.com/pub/e/2016"&gt;the announcement&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; color: #222222; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; line-height: 15px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style="color: black; font-size: 22px; line-height: 24px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;There's Only One Test&lt;/h3&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;img alt="Date" src="http://cdn.oreilly.com/oreilly/date-calendar.gif" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; float: left; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 5px; padding-top: 0px; width: 30px;" /&gt;&lt;span style="font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Tuesday&lt;/span&gt;,&amp;nbsp;&lt;span style="color: #990000; font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;October 4, 2011&lt;/span&gt;&lt;/div&gt;&lt;div style="clear: left; color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 10px;"&gt;&lt;img alt="Time" src="http://cdn.oreilly.com/oreilly/time-clock.gif" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; float: left; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 5px; padding-top: 0px; width: 30px;" /&gt;&lt;span style="font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span style="color: #990000; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;10am PT&lt;/span&gt;, San Francisco&amp;nbsp;&lt;br style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;&lt;span style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;6pm - London | 1pm - New York | Wed, Oct 5th at 3am - Sydney | Wed, Oct 5th at 2am - Tokyo | Wed, Oct 5th at 1am - Beijing | 10:30pm - Mumbai&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="social-counters" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span class="retweet" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;iframe allowtransparency="true" class="twitter-share-button twitter-count-horizontal" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html#_=1313504527864&amp;amp;count=horizontal&amp;amp;id=twitter_tweet_button_0&amp;amp;lang=en&amp;amp;original_referer=http%3A%2F%2Foreillynet.com%2Fpub%2Fe%2F2016&amp;amp;related=oreillymedia%3Aoreilly.com&amp;amp;text=An%20O'Reilly%20webcast%3A%20There's%20Only%20One%20Test&amp;amp;url=http%3A%2F%2Fwww.oreillynet.com%2Fpub%2Fe%2F2016&amp;amp;via=oreillymedia" style="height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; width: 110px;" title="Twitter For Websites: Tweet Button"&gt;&lt;/iframe&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="like" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://www.facebook.com/plugins/like.php?href=http://www.oreillynet.com/pub/e/2016&amp;amp;layout=button_count&amp;amp;show_faces=false&amp;amp;width=200&amp;amp;action=like&amp;amp;colorscheme=light&amp;amp;height=20" style="border-bottom-style: none; border-color: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; width: 110px;"&gt;&lt;/iframe&gt;&lt;/span&gt;&amp;nbsp;&lt;span class="plus" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div id="___plusone_0" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: #222222; display: inline-block; float: none; font-size: 11px; height: 20px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-indent: 0px; width: 90px;"&gt;&lt;iframe allowtransparency="true" frameborder="0" hspace="0" id="I1_1313504528658" marginheight="0" marginwidth="0" name="I1_1313504528658" scrolling="no" src="https://plusone.google.com/u/0/_/+1/fastbutton?url=http%3A%2F%2Fwww.oreillynet.com%2Fpub%2Fe%2F2016&amp;amp;size=medium&amp;amp;count=true&amp;amp;annotations=&amp;amp;hl=en-US&amp;amp;jsh=r%3Bgc%2F23123384-f8bf5791#id=I1_1313504528658&amp;amp;parent=http%3A%2F%2Foreillynet.com&amp;amp;rpctoken=664704651&amp;amp;_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe" style="height: 20px; left: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: static; top: 0px; visibility: visible; width: 90px;" tabindex="-1" vspace="0" width="100%"&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span style="font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;b style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Presented by:&lt;/b&gt;&amp;nbsp;&lt;a href="http://www.oreillynet.com/pub/au/4828" style="color: #1010dd; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Allen B. Downey&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span style="font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;b style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Duration:&lt;/b&gt;&amp;nbsp;Approximately 60 minutes.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;span style="font-size: 14px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;b style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Cost:&lt;/b&gt;&amp;nbsp;Free&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Can I use a t-test if my data are non-normal? What if the sample size is small? What's an exact test? And how many tests are there, anyway?&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;People working with real data are often confused about hypothesis testing and paralyzed by the number of tests and their requirements. But for many common problems, you don't need specialized tests at all.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;In this talk, I present a framework for using simple simulations to estimate p-values. This framework works well for a wide range of problems, which is why I say that there's only one test.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;You don't need prior knowledge of statistics (and you might be better off without it). I show programming examples in Python, but the talk is accessible to anyone with basic programming skills.&lt;/div&gt;&lt;h3 style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;About Allen B. Downey&lt;/h3&gt;&lt;div style="color: #222222; font-size: 11px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Allen B. Downey, author of&amp;nbsp;&lt;a href="http://oreilly.com/catalog/0636920020745" style="color: #1010dd; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;Think Stats&lt;/a&gt;. Allen is a Professor of Computer Science at Olin College of Engineering. He has taught at Wellesley College, Colby College and U.C. Berkeley. He has a Ph.D. in Computer Science from U.C. Berkeley and Master's and Bachelor's degrees from MIT.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px; line-height: 14px; margin-bottom: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;strong style="font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Questions?&lt;/strong&gt;&amp;nbsp;Please send email to&amp;nbsp;&lt;a class="" href="mailto:webcast@oreilly.com?subject=" style="color: #1010dd; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;"&gt;webcast@oreilly.com&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Here are the slides I used for this webcast:&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder="0" height="342" src="https://docs.google.com/present/embed?id=dcq7d5hs_234dwck2rf2" width="410"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
EDIT Oct 12, 2011: Posted final version of slides.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-2882967383493833680?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/41koDt01VlivzPXTKrQVcELjX3A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41koDt01VlivzPXTKrQVcELjX3A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/41koDt01VlivzPXTKrQVcELjX3A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/41koDt01VlivzPXTKrQVcELjX3A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/MzCW7fnsfe0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/2882967383493833680/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/08/upcoming-webcast-only-one-test.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2882967383493833680?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/2882967383493833680?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/MzCW7fnsfe0/upcoming-webcast-only-one-test.html" title="Upcoming webcast: Only One Test" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/08/upcoming-webcast-only-one-test.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4NQXY-eyp7ImA9WhZUFUk.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-3868144203315631402</id><published>2011-06-08T07:23:00.000-07:00</published><updated>2011-06-08T07:23:10.853-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-08T07:23:10.853-07:00</app:edited><title>A hierarchical Bayesian model of pond scum</title><content type="html">This week I am working with one of my colleagues, the extraordinary biologist Jean Huang, on an interesting problem related to bioinformatics. &amp;nbsp;This project is my first attempt at implementing a &lt;a href="http://en.wikipedia.org/wiki/Hierarchical_Bayes_model"&gt;hierarchical Bayesian model&lt;/a&gt; in Python, and it has been a pleasant surprise. &amp;nbsp;If you are familiar with tree-processing algorithms, it's pretty straightforward. &amp;nbsp;First the likelihoods propagate up the tree, then the updates propagate down.&lt;br /&gt;
&lt;br /&gt;
Here is the background: Prof Huang and&amp;nbsp;her students collect samples of pond water and culture the bacteria they find under narrow-spectrum artificial light, trying to find species that photosynthesize at different wavelengths.&lt;br /&gt;
&lt;br /&gt;
To identity the species in each culture, they amplify the &lt;a href="http://en.wikipedia.org/wiki/16S_ribosomal_RNA"&gt;16S ribosomal RNA gene&lt;/a&gt;, send it out to be sequenced, and then look up the sequence in a database like &lt;a href="http://greengenes.lbl.gov/cgi-bin/nph-blast_interface.cgi"&gt;greengenes&lt;/a&gt;. &amp;nbsp;The result is either the name of a species that has been cultured, the genus of an uncultured species, or an unknown genus.&lt;br /&gt;
&lt;br /&gt;
They usually start by identifying 15 samples from each culture. &amp;nbsp;For example, one of their cultures yielded 9 samples of one species, three of another, and one each of three more.&lt;br /&gt;
&lt;br /&gt;
Looking at the results for a given culture, biologists would like to be able to answer these questions:&lt;br /&gt;
&lt;br /&gt;
1) How many more species are there likely to be?&lt;br /&gt;
2) What is the likely prevalence of each species?&lt;br /&gt;
3) If we test &lt;i&gt;m&lt;/i&gt; additional samples, how many new species are we likely to find?&lt;br /&gt;
4) Given a limited budget, which cultures warrant additional sampling?&lt;br /&gt;
&lt;br /&gt;
To answer these questions, I implemented a hierarchical Bayesian model where the top level is "How many species are there?" and the second level is "Given that there are &lt;i&gt;n&lt;/i&gt; species, what is the prevalence of each species?" &amp;nbsp;The prevalence of a species is its proportion of the population.&lt;br /&gt;
&lt;br /&gt;
Knowing how many species there are helps model their prevalences. &amp;nbsp;In the simplest case, if we know that there is only 1 species, the prevalence of that species must be 100%. &amp;nbsp;If we know there are 2 species, I assume that the distribution of prevalences for both species is uniform from 0 to 100, so the expected prevalence for both is 50%, which makes sense.&lt;br /&gt;
&lt;br /&gt;
If we know there are 3 species, it is less obvious what the prior distribution should be; the Beta distribution is a natural choice because&lt;br /&gt;
&lt;br /&gt;
1) If we know there are &lt;i&gt;k&lt;/i&gt; species, we can use Beta(1, &lt;i&gt;k&lt;/i&gt;-1) as a prior, and the expected value is 1/&lt;i&gt;k&lt;/i&gt;, which makes sense. &amp;nbsp;For &lt;i&gt;k&lt;/i&gt;=2, the result is a uniform distribution, so that makes sense, too.&lt;br /&gt;
&lt;br /&gt;
2) For this scenario, the Beta distribution is a &lt;a href="http://en.wikipedia.org/wiki/Conjugate_prior"&gt;conjugate prior&lt;/a&gt;, which means that after an update the posterior is also a Beta distribution.&lt;br /&gt;
&lt;br /&gt;
We can represent a Beta distribution with an object that keeps track of the parameters:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;class Beta:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def __init__(self, yes, no):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Initializes a Beta distribution.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes and no are the number of&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; successful/unsuccessful trials.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.alpha = yes+1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.beta = no+1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Update couldn't be easier.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def Update(self, yes, no):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Updates a Beta distribution."""&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.alpha += yes&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.beta += no&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
At the top level ("How many species are there?") the prior is a uniform distribution from 1 to 20, at least for now. &amp;nbsp; I could replace that with a distribution that reflects more of the domain knowledge biologists have about the experiment; for example, based on how the cultures are processed, it would be rare to find more than 10 species with any substantial prevalence.&lt;br /&gt;
&lt;br /&gt;
Now that the priors are in place, how do we update? &amp;nbsp;Here's the top level:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def Update(self, evidence):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Updates based on observing a given taxon."""&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for hypo, prob in self.hypos.Items():&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; likelihood = hypo.Likelihood(evidence)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if likelihood:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.hypos.Mult(hypo, likelihood)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # if a hypothesis has been ruled out, remove it&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.hypos.Remove(hypo)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; self.hypos.Normalize()&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The evidence is a string that indicates which taxon (species or genus) was observed. &amp;nbsp;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;self.hypos&lt;/span&gt; is a Pmf that maps from a hypo to its probability (&lt;a href="http://code.google.com/p/thinkstats/source/browse/trunk/code/Pmf.py?r=18"&gt;Pmf&lt;/a&gt; is provided by the thinkstats package, a collection of modules used in my book, &lt;i&gt;&lt;a href="http://greenteapress.com/thinkstats/"&gt;Think Stats&lt;/a&gt;&lt;/i&gt;). &amp;nbsp;Each &lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;hypo&lt;/span&gt; is a hypothesis about how many taxons there are. &amp;nbsp;We ask each hypo to compute the likelihood of the evidence, then update hypos accordingly. &amp;nbsp;If we see&amp;nbsp;&lt;i&gt;N&lt;/i&gt; different taxons, all hypotheses with &lt;i&gt;k&lt;/i&gt;&amp;lt;&lt;i&gt;N&lt;/i&gt; are eliminated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Having updated the top level, we pass the evidence down to the lower level and update each hypothesis.&lt;/div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br class="Apple-interchange-newline" /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # update the hypotheses&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for hypo, prob in self.hypos.Items():&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hypo.Update(evidence)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To compute the likelihood of the evidence under a hypothesis, we ask "What is the probability of observing this taxon, given our current belief about the prevalence of each taxon?" &amp;nbsp;There are two cases:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;1) If the observed taxon is one we have seen before, we just look up the current Beta distribution and compute its mean:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def Mean(self):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Computes the mean of a Beta distribution."""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return self.alpha / (self.alpha + self.beta)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;2) If we are seeing a taxon for the first time, we get the likelihoods for all unseen taxons and add them up.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To update the lower level distributions, we loop through the Beta distributions that represent the prevalences, and update them with either a hit or a miss.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def Update(self, evidence):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Updates each Beta dist with new evidence.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; evidence is a taxon&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for taxon, dist in self.taxa.iteritems():&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if taxon == evidence:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dist.Update(1, 0)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dist.Update(0, 1)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div&gt;And that's it. &amp;nbsp;After doing a series of updates, the top level is the posterior distribution of the number of taxons, and each hypothesis at the lower level is a set of Beta distributions that represent the prevalences.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Let's look at an example. &amp;nbsp;Suppose we see 11 of one taxon, 4 of another, and 2 of a third. &amp;nbsp;The &lt;b&gt;posterior distribution of the number of taxons&lt;/b&gt;&amp;nbsp;is:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-vB-1OQm5B08/Tez1drfrRTI/AAAAAAAAANs/gLtaegHykWM/s1600/rare3.1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/-vB-1OQm5B08/Tez1drfrRTI/AAAAAAAAANs/gLtaegHykWM/s400/rare3.1.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The probability is 47% that there are only 3 taxons, 28% that there are 4, and 13% that there are 5.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;By summing over the hypotheses, we can generate &lt;b&gt;distributions for the prevalence of each taxon&lt;/b&gt;:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--psWj12bzE0/Tez2N0i3NZI/AAAAAAAAANw/r_5KpJyJGhQ/s1600/rare3.2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://1.bp.blogspot.com/--psWj12bzE0/Tez2N0i3NZI/AAAAAAAAANw/r_5KpJyJGhQ/s400/rare3.2.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The median prevalence of taxon A is 58%; the credible interval is (39%, 75%). &amp;nbsp;For taxons B and C the medians are 23% and 13%. &amp;nbsp;For taxons D, E, and F, there is a high probability that the prevalence is 0, because these taxons have not been observed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To predict the number of new taxons we might find by sequencing additional samples, I use Monte Carlo simulation. &amp;nbsp;Here is the kernel of the algorithm:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for i in range(m):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; taxon = self.GenerateTaxon()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; taxons.append(taxon)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; meta.Update(taxon)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; curve = MakeCurve(taxons)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;i&gt;m&lt;/i&gt; is the number of samples to simulate. &amp;nbsp;Each time through the loop, we generate a random taxon and then update the hierarchy. &amp;nbsp;The result is a rarefaction curve, which is the number of taxons we observe as a function of the number of samples.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To generate a random taxon, we take advantage of the recursive structure of the hierarchy; that is, we ask each hypothesis to choose a random taxon, and then choose among them in accordance with the probability for each hypothesis:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; def GenerateTaxon(self):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; """Chooses a random taxon."""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pmf = Pmf.Pmf()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for hypo, prob in sorted(self.hypos.Items()):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; taxon = hypo.GenerateTaxon()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pmf.Incr(taxon, prob)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return pmf.Random()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The algorithm the hypotheses use to generate taxons is ugly, so I will spare you the details, but ultimately it depends on the ability to generate Beta variates, which is provided in Python's random module.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Given a sequence of taxons (real or simulated), it is easy to generate a rarefaction curve:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def MakeCurve(sample):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """Makes a rarefaction curve for the given sample."""&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; s = set()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; curve = []&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for i, taxon in enumerate(sample):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s.add(taxon)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; curve.append((i+1, len(s)))&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return curve&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To show what additional samples might yield, I generate &lt;b&gt;100 rarefaction curves&lt;/b&gt; and plot them:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-vUg8za20tGo/Tez7GbkRpgI/AAAAAAAAAN0/UAzb7Rr84Fo/s1600/rare3.3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://3.bp.blogspot.com/-vUg8za20tGo/Tez7GbkRpgI/AAAAAAAAAN0/UAzb7Rr84Fo/s400/rare3.3.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The first 17 points are random permutations of the observed data, so after 17 samples, we have seen 3 taxa on every curve. &amp;nbsp;The last 15 points are based on simulated data. &amp;nbsp;The lines are shifted slightly so they don't overlap; that way you can eyeball high-probability paths.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Even after &lt;i&gt;m&lt;/i&gt;=15 additional samples, there is a good chance that we don't see any more taxons -- but there is a reasonable chance of seeing 1-2, and a small chance of seeing 3.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Finally, we estimate the probability of seeing additional taxons as a function of the number of addition samples:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-tJBJAuD75rE/Tez8RRU7IgI/AAAAAAAAAN4/egFvnG58mbM/s1600/rare3.4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="300" src="http://4.bp.blogspot.com/-tJBJAuD75rE/Tez8RRU7IgI/AAAAAAAAAN4/egFvnG58mbM/s400/rare3.4.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;With 5 additional samples, the chance of seeing at least one additional taxon is 24%; with 10 samples it's 40%, and with 15 it's 53%.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;These estimates should help biologists allocate their budget for additional samples is order to minimize the chance of missing an important low-prevalence taxon.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Next steps: I am working with Prof. Huang and her students to report the results most usefully; then we are thinking about distributing the code or deploying it as a web app.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-3868144203315631402?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZsvA4D-Im3MlsbPyVx59awEIj90/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZsvA4D-Im3MlsbPyVx59awEIj90/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZsvA4D-Im3MlsbPyVx59awEIj90/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZsvA4D-Im3MlsbPyVx59awEIj90/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/BTJMBnRy40w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/3868144203315631402/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/06/hierarchical-bayesian-model-of-pond.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3868144203315631402?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/3868144203315631402?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/BTJMBnRy40w/hierarchical-bayesian-model-of-pond.html" title="A hierarchical Bayesian model of pond scum" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-vB-1OQm5B08/Tez1drfrRTI/AAAAAAAAANs/gLtaegHykWM/s72-c/rare3.1.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/06/hierarchical-bayesian-model-of-pond.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYHR3s9cCp7ImA9WhZUEEg.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-8355048361254791115</id><published>2011-06-02T15:18:00.000-07:00</published><updated>2011-06-02T15:18:56.568-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-02T15:18:56.568-07:00</app:edited><title>More hypotheses, less trivia</title><content type="html">In my &lt;a href="http://allendowney.blogspot.com/2011/05/there-is-only-one-test.html"&gt;last post&lt;/a&gt; I wrote about hypothesis testing with simulation, and one of the readers at &lt;a href="http://www.reddit.com/r/statistics/"&gt;reddit/r/statistics&lt;/a&gt; wrote this comment:&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Is there a book or similar reference [with] examples of building such simulations? I never have enough confidence to run such simulations and I guess that is mainly because I have only seen them for trivial problems. A book or a tutorial with a number of problems with various complexity would help a lot.&lt;/span&gt;&lt;/blockquote&gt;My answer to the first part (is there a good book?) is "I don't know." &amp;nbsp;My answer to the second part (non-trivial examples) is this post with some less trivial examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Difference in means&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
If you think there is a difference between two groups, the most common test is for a difference in the means. &amp;nbsp;In Think Stats, I apply this test to &lt;a href="http://greenteapress.com/thinkstats/html/book008.html#toc57"&gt;pregnancy length and birth weight&lt;/a&gt; for first babies and others.&lt;br /&gt;
&lt;br /&gt;
In this case the &lt;i&gt;test statistic&lt;/i&gt; is obvious: compute the mean for each group and subtract. &amp;nbsp;The only hard part is deciding whether to do a one-sided test or a two-sided test. &amp;nbsp;It depends on what hypothesis you are testing. &amp;nbsp;If you think men are taller than women, or that the new drug is better than the old drug, then a one-sided test is appropriate. &amp;nbsp;If you think there is a difference between the groups but you don't know what it is, you can use a two-sided test; that is, use the absolute value of the difference as the test statistic.&lt;br /&gt;
&lt;br /&gt;
This decision can seem arbitrary, but don't worry. &amp;nbsp;The effect on the p-value is just a factor of two, and (as I argued last time) we only care about the order of magnitude. &amp;nbsp;Whether the p-value is 2% or 4% or 8% doesn't really matter.&lt;br /&gt;
&lt;br /&gt;
The &lt;i&gt;null hypothesis&lt;/i&gt; is that the two groups are actually the same. &amp;nbsp;There are several ways to implement this model:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Parametric&lt;/i&gt;&lt;/b&gt;: Merge the groups. &amp;nbsp;If the pooled distribution is well modeled by an analytic distribution, estimate the parameters (for example, the mean and variance of a normal distribution) and then generate random samples from the fitted distribution.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Resampling&lt;/i&gt;&lt;/b&gt;: Again, merge the groups, and then draw samples (with replacement) from the pooled empirical distribution.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Permutation&lt;/i&gt;&lt;/b&gt;: Or shuffle the sample and assign the elements to the groups at random. &amp;nbsp;This is equivalent to resampling without replacement.&lt;br /&gt;
&lt;br /&gt;
In this example, the difference in birthweight is significant (first babies are lighter) and the difference in pregnancy length is not. &amp;nbsp;But it turns out that first babies are more likely to be early and late (and less likely to be on time). &amp;nbsp;To test that hypothesis, I used the procedure I described last time for the casino problem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Slope of a fitted line&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In &lt;a href="http://allendowney.blogspot.com/2011/03/freshman-hordes-more-godless-than-ever.html"&gt;this post&lt;/a&gt; I fit a line to a time series and compute the slope. &amp;nbsp;The &lt;i&gt;test statistic&lt;/i&gt; is the estimated slope, so that part is easy.&lt;br /&gt;
&lt;br /&gt;
The &lt;i&gt;null hypothesis&lt;/i&gt; is that the apparent slope is due to chance, so I used a permutation model; that is, I shuffled the time series 1000 times and computed the slope each time.&lt;br /&gt;
&lt;br /&gt;
Since my hypothesis is specifically that the slope is positive, I could have used a one-sided test, but to be conservative I reported a two sided p-value:&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;The red line shows the linear least squares fit, with slope 0.033; the p-value (chance of seeing an absolute slope as big as that) is 0.006, so you can either reject the null hypothesis or update your subjective degree of belief accordingly.&lt;/span&gt;&lt;/blockquote&gt;Notice that I didn't say anything about how I computed the p-value. &amp;nbsp;Depending on where you publish, you might or might not have to be more specific.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tail curvature&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In &lt;a href="http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.132.1418"&gt;this paper&lt;/a&gt;, I was characterizing the tail behavior of long-tailed distributions and trying to quantify how well Pareto and lognormal models captured that behavior.&lt;br /&gt;
&lt;br /&gt;
If you plot the complementary CDF of a Pareto distribution on a log-log scale, you get a straight line (example &lt;a href="http://greenteapress.com/thinkstats/html/book005.html#toc34"&gt;here&lt;/a&gt;); for a lognormal distribution, the line drops off with increasing slope. &amp;nbsp;To distinguish these behaviors, I wanted a robust measure of tail curvature, so I computed the first derivative numerically and the estimated the slope. &amp;nbsp;Since slope of a derivative is the second derivative, I called the result "tail curvature" and used it as the &lt;i&gt;test statistic&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
In this example I had two hypotheses (HP for Pareto and HL for lognormal) and no &lt;i&gt;null hypothesis&lt;/i&gt;. &amp;nbsp;To compute P(E | HP) I chose a Pareto distribution that was a good fit for the tail of the observed distribution, then generated random samples, and computed tail curvature. &amp;nbsp;Likewise for P(E | HL).&lt;br /&gt;
&lt;br /&gt;
Here's how I reported the results:&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;For these cases, the curvature test provides some insight. The tail curvature of&amp;nbsp;the Calgary dataset is 0.141, which has a negligible p-value under the Pareto&amp;nbsp;model. This means that we can reject the hypothesis that the data are a&amp;nbsp;sample from a Pareto distribution. The tail curvature of the ClarkNet dataset&amp;nbsp;is 0.023, which has p &amp;gt; 0.5, which means we cannot reject the hypothesis that&amp;nbsp;the sample comes from a long-tailed distribution.&lt;/span&gt;&lt;/blockquote&gt;&lt;div&gt;I am not crazy about the "reject the null hypothesis" way of talking, but it was appropriate for the venue.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;ANOVA&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;If you collect a sample of adult human heights in centimeters, the variance might be 94 cm^2. &amp;nbsp;If you divide the sample into men and women, the variance in each group is smaller (49 and 44 cm^2), which suggests that there is a relationship between height and gender. &amp;nbsp;To test whether that is significant, you can divide the sample at random and see how often the variance drops as much. &amp;nbsp;That's an analysis of variance (ANOVA) test.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The nice thing about ANOVA is that is generalizes easily to more than two groups.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;To summarize, the &lt;i&gt;test statistic&lt;/i&gt; is the decrease in variance when you divide the sample into groups, also known as "assigning labels." &amp;nbsp;The &lt;i&gt;null hypothesis&lt;/i&gt; is that the mean is the same for all groups, so the simulation is to assign the labels at random.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;Time of day effect?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Here's a recent post from reddit/r/statistics:&lt;/div&gt;&lt;div&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394; font-family: inherit;"&gt;&lt;span id="internal-source-marker_0.3988254298456013" style="background-color: transparent; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;A reviewer wants me to test if various behavioural assays I performed were influenced by the time of day I performed them (i.e. biased).&lt;/span&gt;&lt;span id="internal-source-marker_0.3988254298456013" style="background-color: transparent; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;The assays have either binary or continuous responses. What is the best approach to this? It is as simple as fitting a GLM, response~time, and testing for a non-zero slope? That seems overly simplistic to me. I've also tried GAMs with gaussian or binomial error functions, but it doesn't seem to be doing what I expect it to do...&lt;/span&gt;&lt;span id="internal-source-marker_0.3988254298456013" style="background-color: transparent; font-style: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"&gt;Any thoughts would be greatly appreciated. I'm sure its stupidly simple, but I'm having trouble wrapping my head around the problem!&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;At first I suggested a permutation test to check whether time of day had a substantial effect. &amp;nbsp;But&amp;nbsp;the submitter added these details:&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394; font-family: inherit;"&gt;We assayed the behaviour of six species of spiders. The purpose of the study was to compare the behaviour of some species to others. For various reasons, we could not balance the time of day at which we assayed the behaviours for each species (the wonders of field biology...). It may be the case that these spiders have some sort of daily behavioural cycle, e.g. more active at night (however it could be the opposite, or really any function of time; we have no idea). I think the reviewer's concern is that this could influence the comparisons, e.g. if we assayed species 1 more often at night than species 2?&lt;br /&gt;
I suppose the explicit hypothesis I am interested in testing is that time of day has a significant effect on behavioural response, but I am unsure how to construct a model to test this, given that I have no idea if the relationship will be linear or some complex function.&lt;/span&gt;&lt;/blockquote&gt;&amp;nbsp;So there are several questions on the table here:&lt;br /&gt;
&lt;br /&gt;
1) Are the observed differences between the species significant?&lt;br /&gt;
&lt;br /&gt;
I assume the answer is yes, or the submitter would not be trying to publish (see &lt;a href="http://en.wikipedia.org/wiki/Publication_bias"&gt;publication bias&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
2) Is there a time of day effect?&lt;br /&gt;
&lt;br /&gt;
One option is to divide the day into intervals,&amp;nbsp;maybe 6 periods of 4 hours. &amp;nbsp;Then for the&amp;nbsp;continuous response variable, you could use an ANOVA test. &amp;nbsp;For the binary variable you could use a logistic regression with one dummy variable for each interval.&lt;br /&gt;
&lt;br /&gt;
Or if the question is whether there are any times of day that differ from the others, then an appropriate test statistic would be the maximum difference between any interval and the overall average (the next case study talks about this option in more detail).&lt;br /&gt;
&lt;br /&gt;
3) If there is a time of day effect, can we control for it?&lt;br /&gt;
&lt;br /&gt;
If it turns out that there is a time of day effect, it may or may not be possible to control for it. &amp;nbsp;For example, if you only observed Species 1 in the morning and Species 2 in the afternoon, then there is no way to separate the effect of the two variables. &amp;nbsp;In that case, the problem is experimental design, not statistics.&lt;br /&gt;
&lt;br /&gt;
As a quick check, you could make a table with one row per species and one column per time interval, and count how many observations fall in each cell. &amp;nbsp;If there are a lot of empty (or nearly empty) cells, you are in trouble.&lt;br /&gt;
&lt;br /&gt;
If you make the intervals bigger, you will have more observations per cell, but you might obscure an actual time of day effect.&lt;br /&gt;
&lt;br /&gt;
4) If we control for time of day, are the differences between the species still significant?&lt;br /&gt;
&lt;br /&gt;
If you get this far, you could do ANOVA or regression with dummy variables for each species and for each interval. &amp;nbsp;This is what some people suggested on reddit (if I understood correctly), but I would suggest spending some time on steps (2) and (3) before diving into (4).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Testing pair-wise differences&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Here's another recent post from reddit/r/statistics:&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote style="color: #0b5394;"&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;My data can be divided into 4 samples. I wanted to test whether the distribution of a binary variable differs significantly between the samples, so I did 6 t-tests - one for each pair of samples.&lt;br /&gt;
However, I also need to analyze how another categorical variable differs between the samples, this time with 3 possible values.&lt;br /&gt;
Is it okay to compute new t-tests, each time for a pair of values and a pair of samples, for a total of 6*3 tests? The problem is that this is too detailed: I don't want to test each pair of values, only each pair of samples.&lt;br /&gt;
SAS also gives me the option (in&amp;nbsp;&lt;em style="font-style: italic; font-weight: normal;"&gt;proc freq&lt;/em&gt;) of calculating a chi-square test for all 4 samples, but this is not enough information: it only tells me that not all of the means are equal.&lt;br /&gt;
And then there's a one-way ANOVA test, which can be used to compare the means of &amp;gt;2 samples, but apparently can't be used for categorical variables with &amp;gt;2 values. Or can it?&lt;br /&gt;
How would you analyze this data?&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If you run lots of tests, some of them are likely to be "significant" even if there is no real effect going on. &amp;nbsp;The problem is demonstrated in this &lt;a href="http://xkcd.com/882/"&gt;xkcd cartoon&lt;/a&gt;. &amp;nbsp;So in general I think it is a good idea to apply one big test to the entire dataset, not lots of little tests.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;In this case, the question seems to be whether there are&amp;nbsp;significant differences between any&amp;nbsp;pair of groups. &amp;nbsp;So an appropriate &lt;i&gt;test statistic&lt;/i&gt; would be the maximum difference between any pair.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;The &lt;i&gt;null hypothesis&lt;/i&gt; is that the groups are the same, so an easy implementation is to divide the sample into groups at random.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;For categorical variables, you can think of the distribution within each group as a vector and use a distance function to compute the difference between groups. &amp;nbsp;If the groups are roughly the same size, you could use a 1-norm or a 2-norm. &amp;nbsp;If not, you should probably normalize the vectors to length 1 before computing norms.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If you are not really interested in pair-wise differences, but you want to know whether any group deviates significantly from the expected, you could pool all the groups to get the expected distribution of the categorical variable, then compute a chi-squared statistic for each group (how much it deviates from the expected). &amp;nbsp;Again the &lt;i&gt;test statistic&lt;/i&gt; would be the maximum of the chi-square statistic.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;The important thing here is that the choice of test statistic depends on the question you are asking. &amp;nbsp;By using the maximum difference, you are effectively asking, "What is the probability of finding any group with this much deviance, just by chance?"&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;b&gt;Running a series of tests&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Here's one more question from reddit/r/statistics&lt;/span&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394; font-family: inherit;"&gt;I'm running a series of chi-square analyses and for several of them, I'm getting a message which states that "# cells have an expected count less than 5". If the results are significant, are they still worth reporting in spite of this message? I'm comparing participant selections of one of three alternatives when assigned to one of four conditions, examining pairs of comparisons.&lt;/span&gt;&lt;/blockquote&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;The problem here is that the analytic version of the chi-squared test uses an approximation that is only accurate if the sample size is large enough; otherwise you have to use a different test.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;But this is a perfect example of what I talked about in my &lt;a href="http://allendowney.blogspot.com/2011/05/there-is-only-one-test.html"&gt;last post&lt;/a&gt;: if you spend all your time in statistics class learning one damn test after another, and your entire cognitive capacity is consumed trying to remember when each of them is applicable, you have no time and no available brain cells to do the real work, which is thinking carefully about the what you are doing. &amp;nbsp;[Note: I mean this as a general warning, not a criticism of the submitter.]&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;In this case the biggest hazard is not the sample size; it's "running a series of chi-square analyses." &amp;nbsp;When I hear "series of tests," alarm bells go off in my head. &amp;nbsp;If you don't know why, please review&amp;nbsp;&lt;/span&gt;this&amp;nbsp;&lt;a href="http://xkcd.com/882/"&gt;xkcd cartoon&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
So for this question, I have two suggestions:&lt;br /&gt;
&lt;br /&gt;
1) If you use simulation, you don't have to worry about the expected count in each cell. &amp;nbsp;If the sample size is small, that tends to make the p-value bigger, but that happens without any additional effort.&lt;br /&gt;
&lt;br /&gt;
2) If you are running a series of tests, you should either (a) adjust the significance criterion using something like the&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Holm%E2%80%93Bonferroni_method"&gt;Holm–Bonferroni method&lt;/a&gt;, or (b) treat the whole series as a single test, using the maximum of the chi-square values as a test statistic. &amp;nbsp;I think (b) is simpler, and does a better job of capturing what you are trying to test.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;That's all for now!&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-8355048361254791115?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/xxm-FlruviyZ-QYnk2quy48_X9E/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xxm-FlruviyZ-QYnk2quy48_X9E/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/xxm-FlruviyZ-QYnk2quy48_X9E/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/xxm-FlruviyZ-QYnk2quy48_X9E/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/yiqzLHs0bFI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/8355048361254791115/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/06/more-hypotheses-less-trivia.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8355048361254791115?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/8355048361254791115?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/yiqzLHs0bFI/more-hypotheses-less-trivia.html" title="More hypotheses, less trivia" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>1</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/06/more-hypotheses-less-trivia.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0AHRnw9fyp7ImA9WhdXGUs.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-169013518347255903</id><published>2011-05-31T18:28:00.000-07:00</published><updated>2011-09-02T04:08:57.267-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-09-02T04:08:57.267-07:00</app:edited><title>There is only one test!</title><content type="html">A few weeks ago I started reading &lt;a href="http://www.reddit.com/r/statistics"&gt;reddit/r/statistics&lt;/a&gt; regularly. &amp;nbsp;I post links to this blog there and the readers have given me some good feedback. &amp;nbsp;And I have answered a few questions.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;One of the most commons question I see is something like, "I have some data. &amp;nbsp;Which test should I use?" &amp;nbsp;When I see this question, I always have two thoughts:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;1) I hate the way statistics is taught, because it gives students the impression that hypothesis testing is all about choosing the right test, and if you get it wrong the statistics wonks will yell at you, and&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;2) There is only one test! &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Let me explain. &amp;nbsp;All tests try to answer the same question: "Is the apparent effect real, or is it due to chance?" &amp;nbsp;To answer that question, we formulate two hypotheses: the null hypothesis, H0, is a model of the system if the effect is due to chance; the alternate hypothesis, HA, is a model where the effect is real.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Ideally we should compute the probability of seeing the effect (E) under both hypotheses; that is P(E | H0) and P(E | HA). &amp;nbsp;But formulating HA is not always easy, so in conventional hypothesis testing, we just compute&amp;nbsp;P(E | H0), which is the p-value. &amp;nbsp;If the p-value is small, we conclude that the effect is unlikely to have occurred by chance, which suggests that it is real.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;That's hypothesis testing. &amp;nbsp;All of the so-called tests you learn in statistics class are just ways to compute p-values efficiently. &amp;nbsp;When computation was expensive, these shortcuts were important, but now that computation is virtually free, they are not.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;And the shortcuts are often based on simplifying assumptions and approximations. &amp;nbsp;If you violate the assumptions, the results can be misleading, which is why statistics classes are filled with dire warnings and students end up paralyzed with fear.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Fortunately, there is a simple alternative: simulation. &amp;nbsp;If you can construct a model of the null hypothesis, you can estimate p-values just by counting. &amp;nbsp;This figure shows the structure of the simulation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-XvlZhew0MqY/TeL3zIYTvcI/AAAAAAAAANk/i4vN6nVPMnE/s1600/Hypothesistestingfigure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="480" src="http://4.bp.blogspot.com/-XvlZhew0MqY/TeL3zIYTvcI/AAAAAAAAANk/i4vN6nVPMnE/s640/Hypothesistestingfigure.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The first step is to get data from the system and compute a test statistic. &amp;nbsp;The result is some measure of the size of the effect, which I call "delta". &amp;nbsp;For example, if you are comparing the mean of two groups, delta is the difference in the means. &amp;nbsp;If you are comparing actual values with expected values, delta is a chi-squared statistic (described below) or some other measure of the distance between the observed and expected values.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The null hypothesis is a model of the system under the assumption that the apparent effect is due to chance. &amp;nbsp;For example, if you observed a difference in means between two groups, the null hypothesis is that the two groups are the same.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The next step is to use the model to generate simulated data that has the sample size as the actual data. &amp;nbsp;Then apply the test statistic to the simulated data.&lt;br /&gt;
&lt;br /&gt;
The last step is the easiest; all you have to do is count how many times the test statistic for the simulated data exceeds delta. &amp;nbsp;That's the p-value.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;As an example, let's do the Casino problem from &lt;a href="http://greenteapress.com/thinkstats/html/book008.html#toc63"&gt;Think Stats&lt;/a&gt;:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Suppose you run a casino and you suspect that a customer has&amp;nbsp;replaced a die provided by the casino with a ``crooked die''; that&amp;nbsp;is, one that has been tampered with to make one of the faces more likely to come up than the others. &amp;nbsp;You apprehend the alleged&amp;nbsp;cheater and confiscate the die, but now you have to prove that it&amp;nbsp;is crooked. &amp;nbsp;You roll the die 60 times and get the following results:&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;span class="Apple-style-span" style="background-color: #eeeeee; font-family: 'Courier New', Courier, monospace;"&gt;Value &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp;6&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;&lt;span class="Apple-style-span" style="background-color: #eeeeee; font-family: 'Courier New', Courier, monospace;"&gt;Frequency &amp;nbsp; 8 &amp;nbsp; &amp;nbsp;9 &amp;nbsp; 19 &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp;8 &amp;nbsp; 10&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;What is the probability of seeing results like this by chance?&lt;/span&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;The null hypothesis is that the die is fair. &amp;nbsp;Under that assumption, the expected frequency for each value is 10, so the frequencies 8, 9 and 10 are not surprising, but 6 is a little funny and 19 is suspicious.&lt;br /&gt;
&lt;br /&gt;
To compute a p-value, we have to choose a test statistic that measures how unexpected these results are. &amp;nbsp;The chi-squared statistic is a reasonable choice: for each value we compare the expected frequency,&amp;nbsp;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;exp&lt;/span&gt;, and the observed frequency,&amp;nbsp;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;obs&lt;/span&gt;, and compute the sum of the squared relative differences:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def ChiSquared(expected, observed):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; total = 0.0&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for x, exp in expected.Items():&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; obs = observed.Freq(x)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; total += (obs - exp)**2 / exp&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return total&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Why relative? &amp;nbsp;Because the variation in the observed values depends on the expected value. &amp;nbsp;Why squared? &amp;nbsp;Well, squaring makes the differences positive, so they don't cancel each other when we add them up. &amp;nbsp;But other than that, there is no special reason to choose the exponent 2. &amp;nbsp;The absolute value would also be a reasonable choice.&lt;br /&gt;
&lt;br /&gt;
For the observed frequencies, the chi-squared statistic is 20.6. &amp;nbsp;By itself, this number doesn't mean anything. &amp;nbsp;We have to compare it to results from the null hypothesis.&lt;br /&gt;
&lt;br /&gt;
Here is the code that generates simulated data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;def SimulateRolls(sides, num_rolls):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """Generates a Hist of simulated die rolls.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; Args:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; sides: number of sides on the die&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; num_rolls: number of times to rolls&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; Returns:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Hist object&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; """&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; hist = Pmf.Hist()&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for i in range(num_rolls):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; roll = random.randint(1, sides)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hist.Incr(roll)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; return hist&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
And here is the code that runs the simulations:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; count = 0.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; num_trials = 1000&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; num_rolls = 60&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; threshold = ChiSquared(expected, observed)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; for _ in range(num_trials):&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; simulated = SimulateRolls(sides, num_rolls)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; chi2 = ChiSquared(expected, simulated)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if chi2 &amp;gt;= threshold:&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count += 1&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; pvalue = count / num_trials&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp; &amp;nbsp; print 'p-value', pvalue&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Out of 1000 simulations, only 34 generated a chi-squared value greater than 20.6, so the estimated p-value is 3.4%. &amp;nbsp;I would characterize that as borderline significant. &amp;nbsp;Based on this result, I think the die is probably crooked, but would I have the guy whacked? &amp;nbsp;No, I would not. &amp;nbsp;Maybe just roughed up a little.&lt;br /&gt;
&lt;br /&gt;
For this problem, I could have computed the sample distribution of the test statistic analytically and computed the p-value &lt;i&gt;quickly&lt;/i&gt; and &lt;i&gt;exactly&lt;/i&gt;. &amp;nbsp;If I had to run this test many times for large datasets, computational efficiency might be important. &amp;nbsp;But usually it's not.&lt;br /&gt;
&lt;br /&gt;
And accuracy isn't very important either. &amp;nbsp;Remember that the test statistic is arbitrary, and the null hypothesis often involves arbitrary choices, too. &amp;nbsp;There is no point in computing an exact answer to an arbitrary question.&lt;br /&gt;
&lt;br /&gt;
For most problems, we only care about the order of magnitude: if the p-value is smaller that 1/100, the effect is likely to be real; if it is greater than 1/10, probably not. &amp;nbsp;If you think there is a difference between a 4.8% (significant!) and 5.2% (not significant!), you are taking it too seriously.&lt;br /&gt;
&lt;br /&gt;
So the advantages of analysis are mostly irrelevant, but the disadvantages are not:&lt;br /&gt;
&lt;br /&gt;
1) Analysis often dictates the test statistic; simulation lets you choose whatever test statistic is most appropriate. &amp;nbsp;For example, if someone is cheating at craps, they will load the die to increase the frequency of 3 and/or 4, not 1 and/or 6. &amp;nbsp;So in the casino problem the results are suspicious not just because one of the frequencies is high, but also because the frequent value is 3. &amp;nbsp;We could construct a test statistic that captures this domain knowledge (and the resulting p-value would be lower).&lt;br /&gt;
&lt;br /&gt;
2) Analytic methods are inflexible. &amp;nbsp;If you have issues like censored data, non-independence, and long-tailed distributions, you won't find an off-the-shelf test; and unless you are a mathematical statistician, you won't be able to make one. &amp;nbsp;With simulation, these kinds of issues are easy.&lt;br /&gt;
&lt;br /&gt;
3) When people think of analytic methods as&amp;nbsp;black boxes, they often fixate on finding the right test and&amp;nbsp;figuring out how to apply it, instead of thinking carefully about the problem.&lt;br /&gt;
&lt;br /&gt;
In summary, don't worry about finding the "right"&amp;nbsp;test. &amp;nbsp;There's no such thing. &amp;nbsp;Put your effort into choosing a&amp;nbsp;test statistic (one that reflects the effect you are testing) and modeling the null hypothesis. &amp;nbsp;Then simulate it, and count!&lt;br /&gt;
&lt;br /&gt;
Added June 24, 2001: For some additional examples, see &lt;a href="http://allendowney.blogspot.com/2011/06/more-hypotheses-less-trivia.html"&gt;this followup post&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-169013518347255903?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-oj70-nFLJU2fUnrLHctP8h_j3w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-oj70-nFLJU2fUnrLHctP8h_j3w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-oj70-nFLJU2fUnrLHctP8h_j3w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-oj70-nFLJU2fUnrLHctP8h_j3w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/wYOjmlHL60o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/169013518347255903/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/05/there-is-only-one-test.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/169013518347255903?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/169013518347255903?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/wYOjmlHL60o/there-is-only-one-test.html" title="There is only one test!" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-XvlZhew0MqY/TeL3zIYTvcI/AAAAAAAAANk/i4vN6nVPMnE/s72-c/Hypothesistestingfigure.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/05/there-is-only-one-test.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEEERX8ycSp7ImA9WhZWFks.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-6605274426234329526</id><published>2011-05-17T13:03:00.000-07:00</published><updated>2011-05-17T13:03:24.199-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-17T13:03:24.199-07:00</app:edited><title>Statistics Workshop</title><content type="html">I am leading a statistics workshop based on &lt;i&gt;&lt;a href="http://thinkstats.com/"&gt;Think Stats&lt;/a&gt;&lt;/i&gt; tomorrow. &amp;nbsp;If you want to follow along at home, my notes and the exercises are &lt;a href="https://sites.google.com/site/thinkstats2011a/home/bow-workshop"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-6605274426234329526?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SpZ4_6QF2YLbVsJFbotyZhMGMnE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SpZ4_6QF2YLbVsJFbotyZhMGMnE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SpZ4_6QF2YLbVsJFbotyZhMGMnE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SpZ4_6QF2YLbVsJFbotyZhMGMnE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/bGB4hz8UPew" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/6605274426234329526/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/05/statistics-workshop.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/6605274426234329526?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/6605274426234329526?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/bGB4hz8UPew/statistics-workshop.html" title="Statistics Workshop" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><thr:total>0</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/05/statistics-workshop.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkIEQ3Y7fSp7ImA9WhZXF08.&quot;"><id>tag:blogger.com,1999:blog-6894866515532737257.post-5393966241751481233</id><published>2011-05-04T17:11:00.000-07:00</published><updated>2011-05-06T15:21:42.805-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-06T15:21:42.805-07:00</app:edited><title>Think Stats will be published by O'Reilly in June</title><content type="html">No statistics today, just news. &amp;nbsp;I signed a contract with O'Reilly to publish Think Stats. &amp;nbsp;I turn in the manuscript next week, and it should be out in June. &amp;nbsp;So if you find any errors, now is the time to tell me!&lt;br /&gt;
&lt;br /&gt;
Here's my &lt;a href="http://www.oreillynet.com/pub/au/4828"&gt;new author page at O'Reilly&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Some people have asked if I get to choose the animal on the cover (which is a signature of O'Reilly cover design). &amp;nbsp;The short answer is no.&lt;br /&gt;
&lt;br /&gt;
First, I'm actually not sure whether Think Stats will be an "animal book" or part of another O'Reilly series. We haven't talked about it.&lt;br /&gt;
&lt;br /&gt;
Also, here's what the &lt;a href="http://oreilly.com/oreilly/author/ch05.html#looklike"&gt;O'Reilly author materials&lt;/a&gt; have to say on the topic:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #222222; font-family: Verdana, sans-serif; font-size: 11px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h4 style="font-size: 12px; margin-bottom: 0.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Cover Design&lt;/h4&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;The purpose of a book cover is to get a potential reader to pick up the book, and to persuade a bookstore to display it.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;We're confident that we have the most striking and effective covers in technical publishing. Despite our relatively small size, it's not unusual to see window displays of our books at technical bookstores.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;Our covers are all designed by Edie Freedman. She is open to suggestions, but has the final say on all cover designs. Here's what Edie has to say about how she designs the animal covers for Nutshell Handbooks:&lt;/div&gt;&lt;blockquote&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;I ask the authors to supply me with a description of the topic of the book. What I am looking for is adjectives that really give me an idea of the "personality" of the topic. Authors are free to make suggestions about animals, but I prefer to deal with adjectives. Once I have the information from the author, I spend some time thinking about it, and then I choose an animal. Sometimes it is based on no more than what the title sounds like. (COFF, for example, sounded like a walrus noise to me.) Sometimes it is very much linked to the name of the book or software. (For example, vi, the "Visual Editor," suggested some beast with huge eyes). And it is always subject to what sort of artwork I can find.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;It seems to work best this way. We've tried doing animals that the authors want, and have found that it works better if I do the selection, and then submit it for approval. I don't think anyone has been too disappointed with the final choices we've made.&lt;/div&gt;&lt;/blockquote&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;I'll add that if you do want a particular animal, Edie is more inclined to respond to "right brain" reasons than to obvious mental associations. For example, several people on the net suggested the obvious clam for the Perl handbook, but Edie responded instead to Larry Wall's obscure argument for the camel: ugly but serviceable, able to go long distances without a lot of nourishment.&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;In any event, you'll have a chance to see and comment on Edie's cover design before we commit it to print. If you really hate it, and can't be persuaded to feel otherwise, she'll probably try again (but no promises!).&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: #222222; font-size: 11px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
So here's what I have for "right brain" ideas: &amp;nbsp;the themes of the books are curiosity and analysis. &amp;nbsp;One of the problems I see with conventional approaches to statistics is that it makes people timid -- afraid to do the wrong thing. &amp;nbsp;One of my goals with this approach is to help students be fearless. &amp;nbsp;So I want something curious and fearless. &amp;nbsp;Ideas?&lt;br /&gt;
&lt;br /&gt;
Here's another &lt;a href="http://oreilly.com/news/ediemals_0400.html"&gt;article about the animal selection process&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
And here's the&amp;nbsp;&lt;a href="http://oreilly.com/animals.html"&gt;list of animals they've already used&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
And here&amp;nbsp;it is:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Dq-EWRMEsj4/TcR0MJcWuRI/AAAAAAAAANg/wvGUlsPDGYk/s1600/think_stats_cover.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-Dq-EWRMEsj4/TcR0MJcWuRI/AAAAAAAAANg/wvGUlsPDGYk/s1600/think_stats_cover.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span"&gt;The line drawing looks better at higher resolution, but you get the idea. &amp;nbsp;Can anyone name that fish? &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6894866515532737257-5393966241751481233?l=allendowney.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-cULI-XcRGBIbrP4GByORvTU3uc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-cULI-XcRGBIbrP4GByORvTU3uc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-cULI-XcRGBIbrP4GByORvTU3uc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-cULI-XcRGBIbrP4GByORvTU3uc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ProbablyOverthinkingIt/~4/OXs9G30GRAA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://allendowney.blogspot.com/feeds/5393966241751481233/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://allendowney.blogspot.com/2011/05/think-stats-will-be-published-by.html#comment-form" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5393966241751481233?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6894866515532737257/posts/default/5393966241751481233?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/ProbablyOverthinkingIt/~3/OXs9G30GRAA/think-stats-will-be-published-by.html" title="Think Stats will be published by O'Reilly in June" /><author><name>Allen Downey</name><uri>http://www.blogger.com/profile/01633071333405221858</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="31" height="21" src="http://1.bp.blogspot.com/_F_I4HX7LA2c/TSDsHR69C8I/AAAAAAAAAJk/maW1OBmyeek/S220/allen_gorilla.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Dq-EWRMEsj4/TcR0MJcWuRI/AAAAAAAAANg/wvGUlsPDGYk/s72-c/think_stats_cover.png" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://allendowney.blogspot.com/2011/05/think-stats-will-be-published-by.html</feedburner:origLink></entry></feed>

