<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>vgherard</title>
<link>https://vgherard.github.io/</link>
<atom:link href="https://vgherard.github.io/index.xml" rel="self" type="application/rss+xml"/>
<description>Valerio Gherardi&#39;s Personal Website</description>
<generator>quarto-1.8.25</generator>
<lastBuildDate>Sun, 03 Nov 2024 23:00:00 GMT</lastBuildDate>
<item>
  <title>Exponential of a 2x2 real matrix</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-11-04-exponential-of-a-2x2-matrix/</link>
  <description><![CDATA[ 





<p>Let <img src="https://latex.codecogs.com/png.latex?A"> be a 2x2 real matrix, with eigenvalues:</p>
<p><span id="eq-eigenvalues"><img src="https://latex.codecogs.com/png.latex?%0A%5Clambda%20_%7B%5Cpm%7D%20=%20%5Cfrac%7B%5Ctext%20%7BTr%7DA%7D%7B2%7D%5Cpm%20%5Csqrt%7B%5CDelta%7D,%20%5Cqquad%20%5CDelta%20%5Cequiv%20%5Cleft(%20%5Cfrac%7B%5Ctext%20%7BTr%7DA%7D%7B2%7D%20%5Cright%20)%5E2-%5Cdet%20A%0A%5Ctag%7B1%7D"></span></p>
<p>If <img src="https://latex.codecogs.com/png.latex?%5CDelta%20%5Cneq%200">, <img src="https://latex.codecogs.com/png.latex?A"> has two distinct eigenvalues, and we can decompose <img src="https://latex.codecogs.com/png.latex?A"> as follows:</p>
<p><span id="eq-decomposition"><img src="https://latex.codecogs.com/png.latex?%0AA%20=%20%5Clambda%20_+%20P_++%5Clambda%20_-P_-,%0A%5Ctag%7B2%7D"></span></p>
<p>with:</p>
<p><span id="eq-projectors"><img src="https://latex.codecogs.com/png.latex?%0AP_%5Cpm%20=%5Cpm%5Cdfrac%7B1%7D%7B%5Clambda%20_+%20-%20%5Clambda%20_-%7D(A-%5Clambda%20_%5Cmp),%0A%5Ctag%7B3%7D"></span></p>
<p>that satisfy:</p>
<p><span id="eq-projectors-properties"><img src="https://latex.codecogs.com/png.latex?%0A(P_%5Cpm)%5E2%20=%201,%20%5Cquad%20P_+%20P_-%20=%20P_-%20P_+%20=%200.%0A%5Ctag%7B4%7D"></span></p>
<p>Using Equations 3 and 4, one can immediately compute the exponential:</p>
<p><span id="eq-exponential-distinct-eig"><img src="https://latex.codecogs.com/png.latex?%0Ae%5EA%20=%20e%5E%7B%5Clambda%20_+%7D%20P_+%20+%20e%5E%7B%5Clambda%20_-%7D%20P_-%20%5Cqquad%20(%5CDelta%20%5Cneq%200)%0A%5Ctag%7B5%7D"></span></p>
<p>We can obtain the case <img src="https://latex.codecogs.com/png.latex?%5CDelta%20=%200"> from the <img src="https://latex.codecogs.com/png.latex?%5CDelta%20%5Cto%200"> limit of Equation&nbsp;5. Observing that:</p>
<p><span id="eq-projectors-further-properties"><img src="https://latex.codecogs.com/png.latex?%0AP_+%20+%20P_-%20=%201,%20%5Cqquad%20P_+-P_-%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B%5CDelta%7D%7D(A-%5Cfrac%7B%5Ctext%20%7BTr%7DA%7D%7B2%7D),%0A%5Ctag%7B6%7D"></span></p>
<p>from Equation&nbsp;5 we find:</p>
<p><span id="eq-exponential-limit"><img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7B-%5Cfrac%7B%5Ctext%7BTr%7DA%7D%7B2%7D%7De%5EA%20=%20%20A%20+%201-%5Cfrac%7B%5Ctext%20%7BTr%7DA%7D%7B2%7D+O(%5Csqrt%20%5CDelta)%20%5Cquad(%5CDelta%20%5Cto%200),%0A%5Ctag%7B7%7D"></span></p>
<p>that yields:</p>
<p><span id="eq-exponential-single-eig"><img src="https://latex.codecogs.com/png.latex?%0Ae%5EA%20=%20%20e%5E%7B%5Cfrac%7B%5Ctext%7BTr%7DA%7D%7B2%7D%7D%5Cleft(A%20+%201-%5Cfrac%7B%5Ctext%20%7BTr%7DA%7D%7B2%7D%5Cright)%20%5Cquad(%5CDelta%20=%200).%0A%5Ctag%7B8%7D"></span></p>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Exponential of a 2x2 Real Matrix},
  date = {2024-11-04},
  url = {https://vgherard.github.io/posts/2024-11-04-exponential-of-a-2x2-matrix/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Exponential of a 2x2 Real
Matrix.”</span> November 4, 2024. <a href="https://vgherard.github.io/posts/2024-11-04-exponential-of-a-2x2-matrix/">https://vgherard.github.io/posts/2024-11-04-exponential-of-a-2x2-matrix/</a>.
</div></div></section></div> ]]></description>
  <category>Mathematics</category>
  <guid>https://vgherard.github.io/posts/2024-11-04-exponential-of-a-2x2-matrix/</guid>
  <pubDate>Sun, 03 Nov 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Dutch book arguments</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-08-12-dutch-book-arguments/</link>
  <description><![CDATA[ 





<p>The subjective interpretation of probability is based on the premise that degrees of belief must satisfy the axioms of probability calculus. The so-called “Dutch book” arguments provide a philosophical basis for this assumption.</p>
<p>The arguments start by operationalizing<sup>1</sup> the (otherwise quantitatively vague) concept of “degree of belief”. The degree of belief of a subject into a given uncertain event<sup>2</sup> <img src="https://latex.codecogs.com/png.latex?E"> is supposed to be a number <img src="https://latex.codecogs.com/png.latex?p(E)"> that can be quantified as follows:</p>
<ul>
<li>The subject must be willing to pay an amount <img src="https://latex.codecogs.com/png.latex?p(E)">, with the condition that he will be rewarded an amount <img src="https://latex.codecogs.com/png.latex?1"> if event <img src="https://latex.codecogs.com/png.latex?E"> obtains.</li>
<li>The subject must also be willing to accept an amount <img src="https://latex.codecogs.com/png.latex?p(E)">, with the condition that he will give up an amount <img src="https://latex.codecogs.com/png.latex?1"> if event <img src="https://latex.codecogs.com/png.latex?E"> obtains.</li>
</ul>
<p>(the concrete unit of payment in these imaginary bets is irrelevant to the arguments, but is assumed to be a continuous quantity). The idea is that, for the subject not to incur into a sure loss, the rule <img src="https://latex.codecogs.com/png.latex?E%5Cmapsto%20p(E)"> must define a single valued function that follows the laws of probability.</p>
<p>Let us start by showing that the function <img src="https://latex.codecogs.com/png.latex?E%5Cmapsto%20p(E)"> must be single valued (<em>i.e.</em> the degree of belief is operatively well-defined). Suppose that someone assigns two different degrees of belief <img src="https://latex.codecogs.com/png.latex?p"> and <img src="https://latex.codecogs.com/png.latex?q"> to the same event <img src="https://latex.codecogs.com/png.latex?E">, and suppose that <img src="https://latex.codecogs.com/png.latex?p%3Eq">, for instance. This means that this person must be willing to place a bet of <img src="https://latex.codecogs.com/png.latex?p"> on <img src="https://latex.codecogs.com/png.latex?E"> and, at the same time, accept a bet of <img src="https://latex.codecogs.com/png.latex?q"> on <img src="https://latex.codecogs.com/png.latex?E">. But this doesn’t make sense, because the net result of these combined bets is a sure loss (of an amount <img src="https://latex.codecogs.com/png.latex?p-q">). We can conclude that the degree of belief assigned by any individual into a given event must be a single number.</p>
<p>With a similar approach we can prove the three basic axioms of probability:</p>
<p><strong>Positivity.</strong> Degrees of belief must be positive numbers, because no rational agent would be willing to pay a positive amount <img src="https://latex.codecogs.com/png.latex?q%20=%20-p"> (which is the only reasonable way to interpret accepting a negative amount <img src="https://latex.codecogs.com/png.latex?p%20=%20-q">), for later having to pay an additional amount <img src="https://latex.codecogs.com/png.latex?1"> if event <img src="https://latex.codecogs.com/png.latex?E"> obtains.</p>
<p><strong>Normalization.</strong> Suppose that the event <img src="https://latex.codecogs.com/png.latex?E"> is certain, and let <img src="https://latex.codecogs.com/png.latex?p"> be your degree of belief into it. If <img src="https://latex.codecogs.com/png.latex?p%20%3C%201">, one can force you to accept an amount <img src="https://latex.codecogs.com/png.latex?p">, and to give <img src="https://latex.codecogs.com/png.latex?1"> in return, with certainty since <img src="https://latex.codecogs.com/png.latex?E"> is always true. If <img src="https://latex.codecogs.com/png.latex?p%20%3E%201">, one can force you to pay an amount <img src="https://latex.codecogs.com/png.latex?p"> to get <img src="https://latex.codecogs.com/png.latex?1"> in return. In both cases, you face a sure loss of an amount <img src="https://latex.codecogs.com/png.latex?%5Cvert%201%20-%20p%5Cvert">, unless <img src="https://latex.codecogs.com/png.latex?p%20=%201">.</p>
<p><strong>Additivity.</strong> Suppose that events <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?B"> are mutually exclusive, and let <img src="https://latex.codecogs.com/png.latex?p">, <img src="https://latex.codecogs.com/png.latex?q"> and <img src="https://latex.codecogs.com/png.latex?r"> be your degrees of belief into <img src="https://latex.codecogs.com/png.latex?A">, <img src="https://latex.codecogs.com/png.latex?B"> and <img src="https://latex.codecogs.com/png.latex?A%5Ccup%20B"> ( denoting <img src="https://latex.codecogs.com/png.latex?A"> <em>or</em> <img src="https://latex.codecogs.com/png.latex?B">). If <img src="https://latex.codecogs.com/png.latex?r%20%3C%20p%20+%20q">, one can force you to accept the following bets:</p>
<ul>
<li>You pay <img src="https://latex.codecogs.com/png.latex?p"> and receive <img src="https://latex.codecogs.com/png.latex?1"> if <img src="https://latex.codecogs.com/png.latex?A"> obtains.</li>
<li>You pay <img src="https://latex.codecogs.com/png.latex?q"> and receive <img src="https://latex.codecogs.com/png.latex?1"> if <img src="https://latex.codecogs.com/png.latex?B"> obtains.</li>
<li>You receive <img src="https://latex.codecogs.com/png.latex?r"> and pay <img src="https://latex.codecogs.com/png.latex?1"> if <img src="https://latex.codecogs.com/png.latex?A%5Ccup%20B"> obtains.</li>
</ul>
<p>The fact that <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?B"> are mutually exclusive, implies that the cash flow from the returns of these three bets is always zero, and the net flow is entirely set by the initial payments. For you, this is <img src="https://latex.codecogs.com/png.latex?r%20-%20p%20-%20q%20%3C%200">, which is a sure loss. If <img src="https://latex.codecogs.com/png.latex?r%20%3E%20p%20+%20q">, your opponent could also force you into a sure loss by reversing the bet directions in the previous argument.</p>
<p>There are also Dutch book arguments showing that when some rational agent has to update its degrees of belief based on new information, it must do so according to the standard conditioning rule:</p>
<p><span id="eq-cond-prob"><img src="https://latex.codecogs.com/png.latex?%0Ap(A%5Cvert%20B)p(B)=p(A%5Ccap%20B),%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?p(A%5Cvert%20B)"> denotes the degree of belief on <img src="https://latex.codecogs.com/png.latex?A"> after finding out that <img src="https://latex.codecogs.com/png.latex?B"> is true, while <img src="https://latex.codecogs.com/png.latex?A%5Ccap%20B"> denotes the event that both <img src="https://latex.codecogs.com/png.latex?A"> <em>and</em> <img src="https://latex.codecogs.com/png.latex?B"> are true. It is worth to notice that the argument given below relies on the fact that the agent’s assessment of <img src="https://latex.codecogs.com/png.latex?p(A%5Cvert%20B)"> is fixed and declared a priori, and does not change according to whether <img src="https://latex.codecogs.com/png.latex?B"> actually obtains or not.</p>
<p>The argument goes as follows: suppose that Equation&nbsp;1 does not hold and, for instance <img src="https://latex.codecogs.com/png.latex?p(B)%5Ccdot%20p(A%5Cvert%20B)%20%3C%20p(A%5Ccap%20B)">. We can then force the agent to participate in the following bets:</p>
<ul>
<li>The agent accepts <img src="https://latex.codecogs.com/png.latex?p(B)%5Ccdot%20P(A%5Cvert%20B)">, to give <img src="https://latex.codecogs.com/png.latex?P(A%5Cvert%20B)"> in return if <img src="https://latex.codecogs.com/png.latex?B"> obtains<sup>3</sup>.</li>
<li>The agent pays <img src="https://latex.codecogs.com/png.latex?p(A%5Ccap%20B)"> to get <img src="https://latex.codecogs.com/png.latex?1"> in return if both <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?B"> obtain.</li>
<li>If <img src="https://latex.codecogs.com/png.latex?B"> obtains, the agent accepts <img src="https://latex.codecogs.com/png.latex?p(A%5Cvert%20B)"> to give in return <img src="https://latex.codecogs.com/png.latex?1"> if <img src="https://latex.codecogs.com/png.latex?A"> obtains.</li>
</ul>
<p>It is easy to see that, irrespective of the outcomes of the <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?B"> events, the agent always ends up loosing an amount <img src="https://latex.codecogs.com/png.latex?p(A%5Ccap%20B)%20-%20p(B)%20%5Ccdot%20P(A%5Cvert%20B)">. If <img src="https://latex.codecogs.com/png.latex?p(B)%5Ccdot%20p(A%5Cvert%20B)%20%3E%20p(A%5Ccap%20B)">, reversing the direction of these bets also leads to a sure loss for the agent. Clearly, the only way out is to set conditional probabilities according to Eq. Equation&nbsp;1.</p>




<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Which means “giving a practical way to measure”.↩︎</p></li>
<li id="fn2"><p>I use the word “events” in a conventional way. Strictly speaking, to reflect the wider generality of the subjectivist point of view, I should rather talk about “uncertain propositions” or “hypothetical facts”.↩︎</p></li>
<li id="fn3"><p>This is a slight generalization of the type of bet used in the operative definition of “degree of belief”, that assumes a unitary return amount. The reason why this is equivalent to the original definition is that, given bets <img src="https://latex.codecogs.com/png.latex?B_1,%5C,B_2,%5C,%5Ccdots,%5C,B_N"> with unitary return amounts, and positive numbers <img src="https://latex.codecogs.com/png.latex?x_1,%20%5C,x_2,%5C,%5Cdots,%5C,x_N">, we can always find positive integers <img src="https://latex.codecogs.com/png.latex?n_1,%5C,n_2,%5Cdots,%5C,n_N">, such that the total gain from repeating <img src="https://latex.codecogs.com/png.latex?n_i"> times bet <img src="https://latex.codecogs.com/png.latex?B_i"> for all <img src="https://latex.codecogs.com/png.latex?i=1,2,%5Cdots,N"> always has the same sign of the total gain from “generalized bets” that result by changing the return amount of bet <img src="https://latex.codecogs.com/png.latex?B_i"> to <img src="https://latex.codecogs.com/png.latex?x_i">.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Dutch Book Arguments},
  date = {2024-08-12},
  url = {https://vgherard.github.io/posts/2024-08-12-dutch-book-arguments/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Dutch Book Arguments.”</span> August 12,
2024. <a href="https://vgherard.github.io/posts/2024-08-12-dutch-book-arguments/">https://vgherard.github.io/posts/2024-08-12-dutch-book-arguments/</a>.
</div></div></section></div> ]]></description>
  <category>Bayesian Methods</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-08-12-dutch-book-arguments/</guid>
  <pubDate>Sun, 11 Aug 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>The UV diagram for a pure substance</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-07-01-the-uv-diagram-for-a-pure-substance/</link>
  <description><![CDATA[ 





<p>The thermodynamic states of pure substances and their phase transitions are often represented in <img src="https://latex.codecogs.com/png.latex?PT"> (pressure-temperature) and <img src="https://latex.codecogs.com/png.latex?PV"> (pressure-volume) diagrams. While reading the classic paper from Lieb and Yngvason <span class="citation" data-cites="LY">(Lieb and Yngvason 1999a)</span> ( see my commentary <a href="https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/">here</a>) I learned about a third possible description, in terms of the extensive volume <img src="https://latex.codecogs.com/png.latex?V"> and internal energy <img src="https://latex.codecogs.com/png.latex?U">.</p>
<p>Beside the important role that the <img src="https://latex.codecogs.com/png.latex?(U,V)"> parametrization plays in the axiomatic formulation of thermodynamics given in <span class="citation" data-cites="LY">(Lieb and Yngvason 1999a)</span>, which makes <img src="https://latex.codecogs.com/png.latex?UV"> diagrams interesting <em>per se</em>, there’s a practical advantage in these two variables, in the fact that they uniquely characterize pure substances everywhere in the phase diagram. In particular, a triple “point” becomes a triangle in the UV diagram, as can be seen by the parametrization:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AU%20=%20m_gu_g+%20m_%5Cell%20u_%5Cell+m_su_s,%5Cquad%20V%20=%20m_gv_g+m_%5Cell%20v_%5Cell+m_sv_s,%0A"> where <img src="https://latex.codecogs.com/png.latex?m_i">, <img src="https://latex.codecogs.com/png.latex?u_i"> and <img src="https://latex.codecogs.com/png.latex?v_i"> are the masses, specific internal energy and volumes of the gaseous, liquid and solid phases, respectively (the total mass <img src="https://latex.codecogs.com/png.latex?m%20=%20m_g%20+%20m_%5Cell%20+%20m_s"> is assumed to be fixed). This triangle is projected into a line in the <img src="https://latex.codecogs.com/png.latex?PV"> diagram, and into a single point in the <img src="https://latex.codecogs.com/png.latex?PT"> diagram.</p>
<p>The subsets of the <img src="https://latex.codecogs.com/png.latex?UV"> plane representing the fusion, sublimation and vaporization curves (or any other curve on the <img src="https://latex.codecogs.com/png.latex?PT"> diagram representing the coexistence of two distinct phases) are still two dimensional submanifolds, but the parametrization is more involved:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AU%20=%20m_A%20u_A(T)%20+%20m_B%20u_B(T),%5Cquad%20V=m_A%20v_A(T)%20+%20m_B%20v_B(T),%0A"> where <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?B"> are the two coexisting phases, and the specific energies and volumes vary with temperature. These sets are obtained by joining for each value of <img src="https://latex.codecogs.com/png.latex?T"> the two corresponding points on the curves <img src="https://latex.codecogs.com/png.latex?%5Cgamma%20_A(T)%20=%20m%5Ccdot(u_A(T),v_A(T))"> and <img src="https://latex.codecogs.com/png.latex?%5Cgamma%20_B(T)%20=%20m%5Ccdot(u_B(T),%20v_B(T))"> in the <img src="https://latex.codecogs.com/png.latex?UV"> plane.</p>
<p>By pure coincidence, an example of the diagrams I am referring to is shown in <span class="citation" data-cites="LYErratum">(Lieb and Yngvason 1999b)</span>, the erratum to the original reference <span class="citation" data-cites="LY">(Lieb and Yngvason 1999a)</span>.</p>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-LY" class="csl-entry">
Lieb, Elliott H., and Jakob Yngvason. 1999a. <span>“The Physics and Mathematics of the Second Law of Thermodynamics.”</span> <em>Physics Reports</em> 310 (1): 1–96. https://doi.org/<a href="https://doi.org/10.1016/S0370-1573(98)00082-9">https://doi.org/10.1016/S0370-1573(98)00082-9</a>.
</div>
<div id="ref-LYErratum" class="csl-entry">
———. 1999b. <span>“The Physics and Mathematics of the Second Law of Thermodynamics (Physics Reports 310 (1999) 1–96).”</span> <em>Physics Reports</em> 314 (6): 669. https://doi.org/<a href="https://doi.org/10.1016/S0370-1573(99)00029-0">https://doi.org/10.1016/S0370-1573(99)00029-0</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {The {UV} Diagram for a Pure Substance},
  date = {2024-07-01},
  url = {https://vgherard.github.io/posts/2024-07-01-the-uv-diagram-for-a-pure-substance/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“The UV Diagram for a Pure
Substance.”</span> July 1, 2024. <a href="https://vgherard.github.io/posts/2024-07-01-the-uv-diagram-for-a-pure-substance/">https://vgherard.github.io/posts/2024-07-01-the-uv-diagram-for-a-pure-substance/</a>.
</div></div></section></div> ]]></description>
  <category>Thermodynamics</category>
  <category>Physics</category>
  <guid>https://vgherard.github.io/posts/2024-07-01-the-uv-diagram-for-a-pure-substance/</guid>
  <pubDate>Sun, 30 Jun 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>“The Physics and Mathematics of the Second Law of Thermodynamics” by E.H. Lieb and J. Yngvason</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span>.</p>
<blockquote class="blockquote">
<p>The essential postulates of classical thermodynamics are formulated, from which the second law is deduced as the principle of increase of entropy in irreversible adiabatic processes that take one equilibrium state to another. The entropy constructed here is defined only for equilibrium states and no attempt is made to define it otherwise. Statistical mechanics does not enter these considerations. One of the main concepts that makes everything work is the comparison principle (which, in essence, states that given any two states of the same chemical composition at least one is adiabatically accessible from the other) and we show that it can be derived from some assumptions about the pressure and thermal equilibrium. Temperature is derived from entropy, but at the start not even the concept of ‘hotness’ is assumed. Our formulation offers a certain clarity and rigor that goes beyond most textbook discussions of the second law.</p>
</blockquote>
<p>The paper can be subdivided into two parts. In the first part, the authors deduce the existence of a universal entropy state function from a primitive notion of adiabatic accessibility. A key assumption in this derivation is the so-called Comparison Hypothesis, that postulates that for any two equilibrium states <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y"> of a given thermodynamic system, either <img src="https://latex.codecogs.com/png.latex?X"> is adiabatically accessible from <img src="https://latex.codecogs.com/png.latex?Y"> or <img src="https://latex.codecogs.com/png.latex?Y"> is adiabatically accessible from <img src="https://latex.codecogs.com/png.latex?X">.</p>
<p>The second part is devoted to the derivation of the Comparison Hypothesis (which becomes thus a Comparison <em>Principle</em>) for an important class of thermodynamic systems. The main ingredients for this derivation are: - The First Law of Thermodynamics and, in particular the concept of internal energy. - The notion of thermal equilibrium and its transitivity (sometimes called the “Zero-th Law”). - An assumed convex structure in the state space of thermodynamic systems.</p>
<p>So, how does such a formal endeavor improve our understanding of Nature? On one side, entropy is clarified to represent nothing more than a numerical encoding of adiabatic accessibility. Its existence is independent of the concepts of energy, heat or temperature that appear in the usual formulations of Thermodynamics. On the other side, the classical statements of the Second Law of Kelvin-Planck and Clausius, which are explicitly formulated in terms of heat and temperature, are seen to be <em>theorems</em> on the adiabatic (in)accessibility of certain states, that follow from how the concepts of internal energy and thermal equilibrium interact with the primitive notion of adiabatic accessibility. Both of these are major advancements, because they clarify the physical content and universality of the Second Law of Thermodynamics.</p>
<p>The last Section of <span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span> provides a useful summary of the formalism and of the logical paths followed by the mathematical derivations. The rest of this post are some personal notes on the original reference.</p>
<section id="formal-framework" class="level3">
<h3 class="anchored" data-anchor-id="formal-framework">Formal framework</h3>
<p>Systems are described as collections of thermodynamic states, with two binary operations that have the operative interpretations of “composition” (of non-interacting systems) and “scaling”, respectively. In detail:</p>
<ul>
<li><p><strong>Systems.</strong> A <em>system</em> is just a set <img src="https://latex.codecogs.com/png.latex?%5CGamma">, whose elements correspond to physical (thermodynamic) states.</p></li>
<li><p><strong>Composition.</strong> A binary operation that takes as input two thermodynamic states <img src="https://latex.codecogs.com/png.latex?X_1"> and <img src="https://latex.codecogs.com/png.latex?X_2"> of two systems <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1"> and <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_2">, and returns a new state <img src="https://latex.codecogs.com/png.latex?X_1%20%5Coplus%20X_2%20%5Cin%20%5CGamma%20_1%20%5Coplus%20%5CGamma%20_2">, where the latter set can be informally thought as the Cartesian product <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1%20%5Ctimes%20%5CGamma%20_2">. Since the ordering in the enumeration of systems is inconsequential from the physical point of view, we assume that compositions are equipped with an equivalence relation <img src="https://latex.codecogs.com/png.latex?%5Cstackrel%7B%5Coplus%7D%7B%5Csim%7D">, such that <img src="https://latex.codecogs.com/png.latex?X_1%20%5Coplus%20X_2%20%5Cstackrel%7B%5Coplus%7D%7B%5Csim%7D%20X_2%20%5Coplus%20X_1"> and that <img src="https://latex.codecogs.com/png.latex?(X_1%20%5Coplus%20X_2)%5Coplus%20X_3%20%5Cstackrel%7B%5Coplus%7D%7B%5Csim%7D%20X_1%20%5Coplus%20(X_2%5Coplus%20X_3)">.</p></li>
<li><p><strong>Scaling.</strong> A binary operation that takes as input a positive number <img src="https://latex.codecogs.com/png.latex?%5Clambda"> and a thermodynamic state <img src="https://latex.codecogs.com/png.latex?X%5Cin%20%5CGamma">, and returns a new state $X $ as output. The operation is assumed to satisfy <img src="https://latex.codecogs.com/png.latex?t(sX)%20=%20(ts)X">, as well as <img src="https://latex.codecogs.com/png.latex?t(X_1%5Coplus%20X_2)=(tX_1)%20%5Coplus%20(tX_2)">.</p></li>
</ul>
<p>Some care is needed in the operative interpretation of the scaling operation for systems that are not scale invariant, such as a droplet of liquid with a non-negligible surface energy. This particular example is discussed in detail by the authors in Sec. 3.1, in connection with simple systems. In short, for such systems we should interpret the state space as a submanifold of an extended state space corresponding to a scale invariant system. It is for this latter system that the axioms of <span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span> are assumed to hold.</p>
</section>
<section id="axioms-of-adiabatic-accessibility" class="level3">
<h3 class="anchored" data-anchor-id="axioms-of-adiabatic-accessibility">Axioms of adiabatic accessibility</h3>
<p>A central notion in <span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span> is that of <em>adiabatic accessibility</em>. From the operative point of view this corresponds to the possibility of transforming a thermodynamic state into another without supplying heat to the system. Mathematically, adiabatic accessibility is a relation <img src="https://latex.codecogs.com/png.latex?%5Cprec"> on the set of all thermodynamic states that satisfies (among other things) the axioms of a pre-order: reflexivity and transitivity.</p>
<p>More in detail, <img src="https://latex.codecogs.com/png.latex?%5Cprec"> is assumed to satisfy the following axioms:</p>
<ul>
<li><strong>(A1) Reflexivity</strong>. <img src="https://latex.codecogs.com/png.latex?X%20%5Cprec%20X"> for any <img src="https://latex.codecogs.com/png.latex?X">.</li>
<li><strong>(A2) Transitivity</strong>. <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> and <img src="https://latex.codecogs.com/png.latex?Y%20%5Cprec%20Z"> implies <img src="https://latex.codecogs.com/png.latex?X%20%5Cprec%20Z"> for all <img src="https://latex.codecogs.com/png.latex?X">, <img src="https://latex.codecogs.com/png.latex?Y"> and <img src="https://latex.codecogs.com/png.latex?Z">.</li>
<li><strong>(A3) Consistency</strong>. <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> and <img src="https://latex.codecogs.com/png.latex?X%5E%5Cprime%20%5Cprec%20Y%20%5E%5Cprime"> implies <img src="https://latex.codecogs.com/png.latex?X%5Coplus%20X%5E%5Cprime%20%5Cprec%20Y%20%5Coplus%20Y%5E%5Cprime"> for all <img src="https://latex.codecogs.com/png.latex?X">, <img src="https://latex.codecogs.com/png.latex?X%5E%5Cprime">, <img src="https://latex.codecogs.com/png.latex?Y"> and <img src="https://latex.codecogs.com/png.latex?Y%5E%5Cprime"></li>
<li><strong>(A4) Scaling invariance</strong>. <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> implies <img src="https://latex.codecogs.com/png.latex?%5Clambda%20X%20%5Cprec%20%5Clambda%20Y"> for all <img src="https://latex.codecogs.com/png.latex?X">, <img src="https://latex.codecogs.com/png.latex?Y"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%3E0">.</li>
<li><strong>(A5) Splitting and recombination</strong>. <img src="https://latex.codecogs.com/png.latex?X%20%5Cprec%20(%5Clambda%20X,(1-%5Clambda)X)%20%5Cprec%20X"> for all <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?0%3C%5Clambda%20%3C1">.</li>
<li><strong>(A6) Stability</strong>: if <img src="https://latex.codecogs.com/png.latex?%0A(X,%5Cvarepsilon%20_n%20Z)%20%5Cprec%20(Y,%5Cvarepsilon_n%20W)%0A"> holds for some sequence <img src="https://latex.codecogs.com/png.latex?%5Cvarepsilon%20_n%20%5Cto%200">, then <img src="https://latex.codecogs.com/png.latex?X%20%5Cprec%20Z">.</li>
</ul>
</section>
<section id="existence-and-uniqueness-of-entropy" class="level3">
<h3 class="anchored" data-anchor-id="existence-and-uniqueness-of-entropy">Existence and uniqueness of entropy</h3>
<p>The first part of <span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span> is concerned with the existence and uniqueness of the entropy function. The authors prove that, under axioms A1-A6 characterizing adiabatic accessibility, the two following conditions are equivalent:</p>
<ul>
<li><em>(i)</em> Given states <img src="https://latex.codecogs.com/png.latex?X_i"> and <img src="https://latex.codecogs.com/png.latex?Y_i"> of a system <img src="https://latex.codecogs.com/png.latex?%5CGamma"> and positive numbers <img src="https://latex.codecogs.com/png.latex?%5Clambda%20_i"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,%5C,2,%5C,%5Cdots,%5C,n">, the two states <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Clambda_1%20X_1%20%5Coplus%20%5Clambda_2%20X_2%20%5Coplus%20%5Ccdots%20%5Coplus%20%5Clambda%20_n%20X_n"> and <img src="https://latex.codecogs.com/png.latex?Y%20=%20%5Clambda_1%20Y_1%20%5Coplus%20%5Clambda_2%20Y_2%20%5Coplus%20%5Ccdots%20%5Coplus%20%5Clambda%20_n%20Y_n"> are always comparable, in the sense that either <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> or <img src="https://latex.codecogs.com/png.latex?Y%20%5Cprec%20X">. This is expressed by saying that “the comparison hypothesis holds on multiple scaled copies of <img src="https://latex.codecogs.com/png.latex?%5CGamma">”.</li>
<li><em>(ii)</em> There exists a function <img src="https://latex.codecogs.com/png.latex?S_%5CGamma%20%5Ccolon%20%5CGamma%20%5Cto%20%5Cmathbb%20R"> with the following property: if <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Clambda_1%20X_1%20%5Coplus%20%5Clambda_2%20X_2%20%5Coplus%20%5Ccdots%20%5Coplus%20%5Clambda%20_n%20X_n"> and <img src="https://latex.codecogs.com/png.latex?Y%20=%20%5Cgamma_1%20Y_1%20%5Coplus%20%5Cgamma_2%20Y_2%20%5Coplus%20%5Ccdots%20%5Coplus%20%5Cgamma%20_m%20Y_m">, where <img src="https://latex.codecogs.com/png.latex?%5Csum%20_%7Bi=1%7D%5En%20%5Clambda%20_i%20=%20%5Csum%20_%7Bj=1%7D%5Em%20%5Cgamma%20_j">, we have <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> if and only if<sup>1</sup>:</li>
</ul>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20_%7Bi=1%7D%5En%20%5Clambda%20_iS(X_i)%5Cleq%20%5Csum%20_%7Bi=1%7D%5Em%20%5Cgamma%20_iS(Y_i).%0A"> Furthermore, the function <img src="https://latex.codecogs.com/png.latex?S"> is given by <img src="https://latex.codecogs.com/png.latex?S%20=%20a%20S%5E*%20+%20b"> for some constants <img src="https://latex.codecogs.com/png.latex?a,b"> with <img src="https://latex.codecogs.com/png.latex?a%3E0">, where<sup>2</sup>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AS%5E*(X)%20=%20%5Csup%20%5C%7B%5Clambda%20%5Ccolon%20(1-%5Clambda)X_0%5Coplus%20%5Clambda%20X_1%20%5Cprec%20X%5C%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?X_%7B0,1%7D%5Cin%20%5CGamma"> are two reference states such that <img src="https://latex.codecogs.com/png.latex?X_0%20%5Cprec%20X_1"> but the reverse does not hold (the definition enforces <img src="https://latex.codecogs.com/png.latex?S%5E*(X_0)=0"> and <img src="https://latex.codecogs.com/png.latex?S%5E*(X_1)%20=%201">).</p>
</section>
<section id="convexity" class="level3">
<h3 class="anchored" data-anchor-id="convexity">Convexity</h3>
<ul>
<li><strong>(A7) Convex combination</strong>. The space <img src="https://latex.codecogs.com/png.latex?%5CGamma"> is a locally convex subset of a vector space, meaning that <img src="https://latex.codecogs.com/png.latex?tX%20+%20(1-t)Y%20%5Cin%20%5CGamma"> for all <img src="https://latex.codecogs.com/png.latex?X,Y%5Cin%20%5CGamma"> and <img src="https://latex.codecogs.com/png.latex?0%3Ct%3C1">. Furthermore, we have that <img src="https://latex.codecogs.com/png.latex?t%20X%20%5Coplus%20(1-t)Y%5Cprec%20t%20X%20+%20(1-t)Y">.</li>
</ul>
<p>It is easily seen that if an entropy function (in the sense of the previous section) exists, then the second part of the previous axiom (involving <img src="https://latex.codecogs.com/png.latex?%5Cprec">) is equivalent to the requirement that entropy is a concave function, <em>i.e.</em> <img src="https://latex.codecogs.com/png.latex?S(t%20X%20+%20(1-t)Y)%5Cgeq%20tS(X)+(1-t)S(Y)=S(tX%5Coplus(1-t)Y)">.</p>
<p>The convex combination of states is most easily interpreted for simple systems (see below), and corresponds to a state in which energy and work coordinates take the intermediate values <img src="https://latex.codecogs.com/png.latex?t%5Cxi(X)+(1-t)%5Cxi(Y)">. The possibility of forming convex combinations of states and their adiabatic accessibility is quite obvious for systems such as gas or liquids. For example, suppose we are given <img src="https://latex.codecogs.com/png.latex?n_i"> moles of gas with energies <img src="https://latex.codecogs.com/png.latex?n_iU_i"> and volumes <img src="https://latex.codecogs.com/png.latex?n_iV_i">, where <img src="https://latex.codecogs.com/png.latex?n_1%20+%20n_2%20=%201">, and the two gases are separated by a rigid, adiabatic wall. The convex combination is the state of 1 mole of gas that is produced by simply removing the barrier. For solids or more complicated systems, the axiom looks much more questionable, but can be at least experimentally tested for any given system, by exploiting its equivalence with the concavity of entropy.</p>
</section>
<section id="simple-systems" class="level3">
<h3 class="anchored" data-anchor-id="simple-systems">Simple systems</h3>
<p>The discussion moves on to concrete systems whose state space is assumed to be an open convex subset of <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20R%5E%7Bn+1%7D"> for some <img src="https://latex.codecogs.com/png.latex?n%3E0">, in agreement with A7. The points of these systems are denoted by pairs <img src="https://latex.codecogs.com/png.latex?(U,V)">, where <img src="https://latex.codecogs.com/png.latex?U%5Cin%20%5Cmathbb%20R"> and <img src="https://latex.codecogs.com/png.latex?V%20%5Cin%20%5Cmathbb%20R%20%5En"> have the physical interpretation of energy and extensive work coordinates, respectively. The possibility of a parametrization with internal energy as one coordinate is the content of the First Law of Thermodynamics.</p>
<p>Simple systems are characterized by the following axioms (the separation of S2 into S2a and S2b is mine):</p>
<ul>
<li><strong>(S1) Irreversibility</strong>. For each <img src="https://latex.codecogs.com/png.latex?X"> there is a point <img src="https://latex.codecogs.com/png.latex?Y"> such that <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y">. (This axiom is actually implied by the stronger axiom T4, see below.)</li>
<li><strong>(S2a) Tangent Plane</strong>. For each <img src="https://latex.codecogs.com/png.latex?X">, the forward sector <img src="https://latex.codecogs.com/png.latex?A_X=%5C%7BY%5Cin%20%5CGamma%5Ccolon%20X%5Cprec%20Y%5C%7D"> has a unique tangent plane parametrized by an equation of the form:</li>
</ul>
<p><img src="https://latex.codecogs.com/png.latex?%0AU-U(X)+%5Csum%20_%7Bi=1%7D%5En%20p_i(X)%5Ccdot(V_i-V_i(X))=0%0A"> - <strong>(S2b) Lipschitz Continuity.</strong> The functions <img src="https://latex.codecogs.com/png.latex?p_i"> in the previous axiom are locally Lipschitz continuous functions. - <strong>(S3) Connectedness of the boundary.</strong> The boundary of any forward sector is connected.</p>
<p>Using only axioms <strong>(S1)</strong> and <strong>(S2a)</strong>, the Kelvin-Planck statement of the Second Law of Thermodynamics can be proved, namely:</p>
<blockquote class="blockquote">
<p>No process is possible, the sole result of which is a change in the energy of a simple system (without changing the work coordinates) and the raising of a weight.</p>
</blockquote>
<p>Including also <strong>(S2b)</strong> and <strong>(S3)</strong>, the main theorem of this section can be proved, stating that <em>any two states of a simple system are comparable</em>.</p>
</section>
<section id="thermal-equilibrium" class="level3">
<h3 class="anchored" data-anchor-id="thermal-equilibrium">Thermal Equilibrium</h3>
<ul>
<li><p><strong>(T1) Thermal Contact</strong>. For any two simple systems. For any two simple systems with state spaces <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1"> and <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_2">, there is another simple system, the <em>thermal join</em> of <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1"> and <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_2">, with state space: <img src="https://latex.codecogs.com/png.latex?%0A%5CGamma_1%20%5Cstackrel%7BT%7D%7B%5Coplus%7D%5CGamma_2%20%5Cequiv%20%5C%7B(U_1+U_2,V_1,V_2)%5C,%5Ccolon%20(U_i,V_i)%5Cin%5CGamma_i%5C%7D,%0A"> whose states satisfy: <img src="https://latex.codecogs.com/png.latex?%0A%5CGamma_1%5Coplus%5CGamma_2%5Cni(U_1,V_1)%5Coplus(U_2,V_2)%20%5Cprec%20(U_1+U_2,V_1,V_2)%5Cin%20%5CGamma_1%20%5Cstackrel%7BT%7D%7B%5Coplus%7D%5CGamma_2.%0A"></p></li>
<li><p><strong>(T2) Thermal Splitting</strong>. For any state of the thermal join <img src="https://latex.codecogs.com/png.latex?(U,V_1,V_2)%5Cin%20%5CGamma_1%5Cstackrel%7BT%7D%7B%5Coplus%7D%5CGamma_2"> there exist states <img src="https://latex.codecogs.com/png.latex?(U_i,V_i)%5Cin%20%5CGamma%20_i"> such that <img src="https://latex.codecogs.com/png.latex?U_1%20+%20U_2%20=U"> and: <img src="https://latex.codecogs.com/png.latex?%0A(U,V_1,V_2)%20%5Cprec%20(U_1,V_1)%20%5Coplus%20(U_2,V_2).%0A"> In particular, if <img src="https://latex.codecogs.com/png.latex?(U,V)%5Cin%20%5CGamma"> is a state of a simple system and <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%5Cin%20(0,1)">, we have: <img src="https://latex.codecogs.com/png.latex?%0A(U,%5Clambda%20V,(1-%5Clambda)V)%5Cprec%5Clambda(U,V)%20%5Coplus%20(1-%5Clambda)(U,V)%0A"> The right-hand side here is an element of <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%5CGamma%20%5Coplus%20(1-%5Clambda)%20%5CGamma">, while the left hand side is an element of the thermal join of scaled copies <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%5CGamma%20%5Cstackrel%7BT%7D%7B%5Coplus%7D%20(1-%5Clambda)%20%5CGamma">.</p></li>
<li><p><strong>(T3) Zero-th law</strong>. The relation <img src="https://latex.codecogs.com/png.latex?%5Cstackrel%7BT%7D%7B%5Csim%7D"> defined in the following is an equivalence relation: <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1%20%5Cni(U_1,V_1)%5Cstackrel%7BT%7D%7B%5Csim%7D(U_2,V_2)%5Cin%20%5CGamma%20_2"> if <img src="https://latex.codecogs.com/png.latex?(U_1%20+%20U_2,%20V_1,%20V_2)%20%5Cprec%20(U_1,V_1)%20%5Coplus%20(U_2,V_2)">.</p></li>
<li><p><strong>(T4) Transversality</strong>. If <img src="https://latex.codecogs.com/png.latex?%5CGamma"> is a simple system and <img src="https://latex.codecogs.com/png.latex?X%5Cin%20%5CGamma">, there exist <img src="https://latex.codecogs.com/png.latex?X_0,X_1%5Cin%20%5CGamma"> such that <img src="https://latex.codecogs.com/png.latex?X_0%20%5Cprec%20%5Cprec%20X%20%5Cprec%20%5Cprec%20X_1"> and <img src="https://latex.codecogs.com/png.latex?X_0%20%5Cstackrel%7BT%7D%7B%5Csim%7D%20X_1">.</p></li>
<li><p><strong>(T5) Universal temperature range</strong>. If <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1"> and <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_2"> are simple systems, and <img src="https://latex.codecogs.com/png.latex?V_1"> is in the projection of <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_1"> onto its work coordinates, for every <img src="https://latex.codecogs.com/png.latex?X_2%20%5Cin%20%5CGamma%20_2"> there is a <img src="https://latex.codecogs.com/png.latex?U_1"> such that <img src="https://latex.codecogs.com/png.latex?(U_1,V_1)%20%5Cstackrel%7BT%7D%7B%5Csim%7D%20X_2"></p></li>
</ul>
<p>The main result from these additional axioms is <em>comparability in the product spaces of simple systems</em>. Also, thermal equilibrium is found to be characterized by maximum entropy, in the sense that if <img src="https://latex.codecogs.com/png.latex?(U_i,V_i)%5Cin%20%5CGamma%20_i"> are states of simple systems with (consistent) entropies <img src="https://latex.codecogs.com/png.latex?S_i"> respectively, then:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A(U_1,V_1)%5Cstackrel%7BT%7D%7B%5Csim%7D%20(U_2,V_2)%20%5Ciff%20S_1+S_2=%5Cmax_%7BU_1%5E%5Cprime%20+U_2%5E%5Cprime=U_1+U_2%7D%5C%7BS(U_1%5E%5Cprime,V_1)+S(U_2%20%5E%5Cprime%20,V_2)%5C%7D.%0A"></p>
<p>If (T3) is assumed, and if we postulate that for each state <img src="https://latex.codecogs.com/png.latex?X"> there is at least one state in thermal equilibrium with it - which is guaranteed by (T5) - then the second part of (T2) is equivalent to scaling invariance <img src="https://latex.codecogs.com/png.latex?%5Cstackrel%7BT%7D%7B%5Csim%7D">. In fact, transitivity and symmetry of <img src="https://latex.codecogs.com/png.latex?%5Cstackrel%7BT%7D%7B%5Csim%7D"> implies <img src="https://latex.codecogs.com/png.latex?X%5Cstackrel%7BT%7D%7B%5Csim%7DX"> for any <img src="https://latex.codecogs.com/png.latex?X">. Then the second part of (T2) is equivalent to <img src="https://latex.codecogs.com/png.latex?t%20X%20%5Cstackrel%7BT%7D%7B%5Csim%7D(1-t)X"> for any <img src="https://latex.codecogs.com/png.latex?t%20%5Cin%20(0,1)"> and any <img src="https://latex.codecogs.com/png.latex?X">, which is in turn equivalent to <img src="https://latex.codecogs.com/png.latex?%5Clambda%20Y%20%5Csim%20Y"> for any <img src="https://latex.codecogs.com/png.latex?Y"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%3E0">.</p>
</section>
<section id="temperature" class="level3">
<h3 class="anchored" data-anchor-id="temperature">Temperature</h3>
<p>Temperature is a derived concept in the formalism of <span class="citation" data-cites="LY1">(Lieb and Yngvason 1999)</span>, by means of the usual bridge law <img src="https://latex.codecogs.com/png.latex?T%20=%20%5Cleft(%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20S%7D%5Cright)_V">. The differentiability of entropy is shown to be a consequence of the axioms stated so far.</p>
<p>Using the derived concept of temperature, the authors prove the Clausius inequality for a Carnot cycle:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cdelta%20Q_1%7D%7BT_1%7D+%5Cfrac%7B%5Cdelta%20Q_2%7D%7BT_2%7D%20%5Cleq0,%0A"> where <img src="https://latex.codecogs.com/png.latex?T_1"> and <img src="https://latex.codecogs.com/png.latex?T_2"> are the <em>final</em> temperatures of the reservoirs, that do not need to be assumed of infinite mass.</p>
</section>
<section id="chemical-mixtures-and-reactions" class="level3">
<h3 class="anchored" data-anchor-id="chemical-mixtures-and-reactions">Chemical mixtures and reactions</h3>
<p>The last result of the paper concerns thermodynamic processes that connect states of different systems. The notion of connection of state spaces is introduced: two state spaces <img src="https://latex.codecogs.com/png.latex?%5CGamma"> and <img src="https://latex.codecogs.com/png.latex?%5CGamma%20%5E%5Cprime"> are said to be connected if there are state spaces <img src="https://latex.codecogs.com/png.latex?%5CGamma%20_0,%5C,%5CGamma_1,%5C,%5Cdots,%5CGamma_N"> and states <img src="https://latex.codecogs.com/png.latex?X_i,Y_i%20%5Cin%20%5CGamma%20_i">, and <img src="https://latex.codecogs.com/png.latex?X%5Cin%20%5CGamma"> and <img src="https://latex.codecogs.com/png.latex?Y%5Cin%20%5CGamma%20%5E%5Cprime">, such that:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A(X,%5C,X_0)%20%5Cprec%20Y_1,%20%5Cquad%20X_i%20%E2%89%BA%20Y_%7Bi+1%7D%20%5C%20(i%20=%201,...,N%20%E2%88%92%201),%20%5Cquad%20X_N%20%5Cprec%20(Y%20,%5C,Y_0).%0A"> If <img src="https://latex.codecogs.com/png.latex?%5CGamma"> is connected to <img src="https://latex.codecogs.com/png.latex?%5CGamma%20%5E%5Cprime"> we write <img src="https://latex.codecogs.com/png.latex?%5CGamma%20%5Cprec%20%5CGamma%20%5E%5Cprime">. The last axiom is:</p>
<ul>
<li><strong>(M) Absence of sinks</strong>. <img src="https://latex.codecogs.com/png.latex?%5CGamma%20%5Cprec%20%5CGamma%20%5E%5Cprime%20%5Cimplies%20%5CGamma%20%5E%5Cprime%20%5Cprec%20%5CGamma">.</li>
</ul>
<p>With this additional axiom, one can prove a “weak” form of the entropy principle: that the multiplicative and additive constants in the definition of <img src="https://latex.codecogs.com/png.latex?S"> for each simple system can be chosen in such a way that <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Y"> implies <img src="https://latex.codecogs.com/png.latex?S(X)%20%5Cleq%20S(Y)"> for any two comparable states (not necessarily of the same system).</p>
<p>The strong form of the entropy principle consists in the statement that all states in connected spaces are comparable, and that adiabatic accessibility is completely characterized by <img src="https://latex.codecogs.com/png.latex?S">, in the sense that <img src="https://latex.codecogs.com/png.latex?X%20%5Cprec%20Y"> if and only if <img src="https://latex.codecogs.com/png.latex?S(X)%5Cleq%20S(Y)">. This result depends on a particular assumption (Eq. (6.34) of the reference) that the authors do not axiomatize, but that is subject to experimental verification.</p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-LY1" class="csl-entry">
Lieb, Elliott H., and Jakob Yngvason. 1999. <span>“The Physics and Mathematics of the Second Law of Thermodynamics.”</span> <em>Physics Reports</em> 310 (1): 1–96. https://doi.org/<a href="https://doi.org/10.1016/S0370-1573(98)00082-9">https://doi.org/10.1016/S0370-1573(98)00082-9</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>In particular, the states <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y"> are always comparable if <img src="https://latex.codecogs.com/png.latex?%5Csum%20_%7Bi=1%7D%5E%7Bn%7D%20%5Clambda%20_i%20=%20%5Csum%20_%7Bj=1%7D%5Em%20%5Cgamma%20_j">. This does not need to be the case if the two sums differ.↩︎</p></li>
<li id="fn2"><p>If <img src="https://latex.codecogs.com/png.latex?t%3C0">, we can interpret <img src="https://latex.codecogs.com/png.latex?X%20+%20tY%20%5Cprec%20Z"> as <img src="https://latex.codecogs.com/png.latex?X%5Cprec%20Z%20-tY">.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {“{The} {Physics} and {Mathematics} of the {Second} {Law} of
    {Thermodynamics}” by {E.H.} {Lieb} and {J.} {Yngvason}},
  date = {2024-06-25},
  url = {https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“<span>‘The Physics and Mathematics of
the Second Law of Thermodynamics’</span> by E.H. Lieb and J.
Yngvason.”</span> June 25, 2024. <a href="https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/">https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Thermodynamics</category>
  <category>Physics</category>
  <guid>https://vgherard.github.io/posts/2024-06-25-the-physics-and-mathematics-of-the-second-law-of-thermodynamics-by-eh-lieb-and-j-yngvason/</guid>
  <pubDate>Mon, 24 Jun 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>“Data Fission: Splitting a Single Data Point” by Leiner et al.</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-06-03-data-fission-splitting-a-single-data-point-by-leiner-et-al/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="datafission">(James Leiner and Ramdas 2023)</span>. The <a href="https://arxiv.org/pdf/2112.11079">arXiv version</a> is actually a bit more comfortable to read. Abstract:</p>
<blockquote class="blockquote">
<p>Suppose we observe a random vector <img src="https://latex.codecogs.com/png.latex?X"> from some distribution in a known family with unknown parameters. We ask the following question: when is it possible to split <img src="https://latex.codecogs.com/png.latex?X"> into two pieces <img src="https://latex.codecogs.com/png.latex?f(X)"> and <img src="https://latex.codecogs.com/png.latex?g(X)"> such that neither part is sufficient to reconstruct <img src="https://latex.codecogs.com/png.latex?X"> by itself, but both together can recover <img src="https://latex.codecogs.com/png.latex?X"> fully, and their joint distribution is tractable? One common solution to this problem when multiple samples of <img src="https://latex.codecogs.com/png.latex?X"> are observed is data splitting, but Rasines and Young offers an alternative approach that uses additive Gaussian noise — this enables post-selection inference in finite samples for Gaussian distributed data and asymptotically when errors are non-Gaussian. In this article, we offer a more general methodology for achieving such a split in finite samples by borrowing ideas from Bayesian inference to yield a (frequentist) solution that can be viewed as a continuous analog of data splitting. We call our method data fission, as an alternative to data splitting, data carving and <img src="https://latex.codecogs.com/png.latex?p">-value masking. We exemplify the method on several prototypical applications, such as post-selection inference for trend filtering and other regression problems, and effect size estimation after interactive multiple testing. Supplementary materials for this article are available online.</p>
</blockquote>
<p>The paper offers a clear review and systematization of older work, most prominently <span class="citation" data-cites="splittingstrategies">(Rasines and Young 2022)</span> (cited in the abstract), with some useful generalizations.</p>
<p>The idea is cool, but I find the applications to practical regression cases given in the paper somewhat… impractical. For usual linear regression with a continuous response, the applicability of the method relies on (1) noise being homoskedastic and gaussian, (2) the existence of a consistent estimator <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Csigma"> of noise variance, and (3) samples being large enough (guarantees are only asymptotic). On the other hand, in the theoretically simpler case of logistic regression, there’s a technical complication in that, under the usual GLM assumption <img src="https://latex.codecogs.com/png.latex?%5Ctheta(X)%20=%20X%5Cbeta">, the relevant log-likelihood for maximization in the inferential stage is not a concave function of <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, possibly hindering optimization. If I got it right, the authors suggest to ignore the conditional dependence of <img src="https://latex.codecogs.com/png.latex?g(Y_i)"> on <img src="https://latex.codecogs.com/png.latex?f(Y_i)"> to circumvent these complications (see Appendix E.4), which I honestly don’t understand.</p>
<p>A case in which planets align and results have a nice analytic form is that of Poisson regression, for which I will sketch the idea in some detail. Suppose that we are given data <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20D%20_0%20=%20%5C%7B(X_i,Y_i)%5C%7D_%7Bi=1%7D%5EN"> independently drawn from a joint <img src="https://latex.codecogs.com/png.latex?(X,Y)"> distribution, and we assume <img src="https://latex.codecogs.com/png.latex?Y%20%5Cvert%20X%20%5Csim%20%5Ctext%7BPois%7D(%5Clambda%20(X))"> for some unknown function <img src="https://latex.codecogs.com/png.latex?%5Clambda%20(X)"> we would like to model. The key observation is (<em>cf.</em> Appendix A of the reference) that if <img src="https://latex.codecogs.com/png.latex?Z%20%5Cvert%20Y%20%5Csim%20%5Ctext%7BBinom%7D(Y,%5C,p)">, then <img src="https://latex.codecogs.com/png.latex?Z%20%5Csim%20%5Ctext%20%7BPois%7D(p%5Clambda)"> and <img src="https://latex.codecogs.com/png.latex?%5Coverline%20Z%20=%20Y%20-%20Z%20%5Csim%20%5Ctext%7BPois%7D((1-p)%5Clambda)">, with <img src="https://latex.codecogs.com/png.latex?Z"> and <img src="https://latex.codecogs.com/png.latex?%5Coverline%20Z"> unconditionally independent. Hence, if we randomly draw <img src="https://latex.codecogs.com/png.latex?Z%20_i"> according to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BBinom%7D(Y_i,%5C,p)">, and set <img src="https://latex.codecogs.com/png.latex?%5Coverline%20Z%20_i%20=%20Y_i%20-Z_i">, the two datasets <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20D%20=%20%5C%7B(X_i,%5C,Z_i)%5C%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Coverline%7B%5Cmathcal%20D%7D%20=%20%5C%7B(X_i,%5C,%5Coverline%20Z_i)%5C%7D">, are conditionally independent given the observed covariates <img src="https://latex.codecogs.com/png.latex?X_i">. This allows to decouple different aspects of modeling, such as model selection and inference, avoiding the usual biases associated with the intrinsic randomness of the selection step.</p>
<p>The authors focus on regression with fixed covariates, because in that setting the simpler option of data-splitting is less motivated, calling for alternatives. However, the method can be applied equally well to deal with selective inference in random covariates settings, since it leads - at least in principle - to inferences which are valid conditionally on the observed covariates and (in the general case) the randomized responses <img src="https://latex.codecogs.com/png.latex?f(Y_i)"> of the selection stage.</p>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-datafission" class="csl-entry">
James Leiner, Larry Wasserman, Boyan Duan, and Aaditya Ramdas. 2023. <span>“Data Fission: Splitting a Single Data Point.”</span> <em>Journal of the American Statistical Association</em> 0 (0): 1–12. <a href="https://doi.org/10.1080/01621459.2023.2270748">https://doi.org/10.1080/01621459.2023.2270748</a>.
</div>
<div id="ref-splittingstrategies" class="csl-entry">
Rasines, D García, and G A Young. 2022. <span>“<span class="nocase">Splitting strategies for post-selection inference</span>.”</span> <em>Biometrika</em> 110 (3): 597–614. <a href="https://doi.org/10.1093/biomet/asac070">https://doi.org/10.1093/biomet/asac070</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {“{Data} {Fission:} {Splitting} a {Single} {Data} {Point}” by
    {Leiner} Et Al.},
  date = {2024-06-03},
  url = {https://vgherard.github.io/posts/2024-06-03-data-fission-splitting-a-single-data-point-by-leiner-et-al/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“<span>‘Data Fission: Splitting a Single
Data Point’</span> by Leiner Et Al.”</span> June 3, 2024. <a href="https://vgherard.github.io/posts/2024-06-03-data-fission-splitting-a-single-data-point-by-leiner-et-al/">https://vgherard.github.io/posts/2024-06-03-data-fission-splitting-a-single-data-point-by-leiner-et-al/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Selective Inference</category>
  <category>Model Selection</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-06-03-data-fission-splitting-a-single-data-point-by-leiner-et-al/</guid>
  <pubDate>Sun, 02 Jun 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Statements of the Second Law of Thermodynamics</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-06-01-statements-of-the-second-law-of-thermodynamics/</link>
  <description><![CDATA[ 





<p>The Second Law of Thermodynamics is commonly stated in the forms of Kelvin’s and Clausius’ postulates. These can be enunciated in the following way <span class="citation" data-cites="dittman2021heat">(Dittman and Zemansky 2021)</span> <sup>1</sup>:</p>
<blockquote class="blockquote">
<p><strong>Kelvin’s Postulate.</strong> It is impossible to construct an engine that, operating in a cycle, will produce no effect other than the extraction of heat from a reservoir and the performance of an equivalent amount of work.</p>
</blockquote>
<blockquote class="blockquote">
<p><strong>Clausius’ Postulate.</strong> It is impossible to construct a refrigerator that, operating in a cycle, will produce no effect other than the transfer of heat from a lower-temperature reservoir to a higher temperature reservoir.</p>
</blockquote>
<p>Either formulation is equivalent to the other and leads to the fundamental <em>Clausius’ theorem</em>. This asserts the existence of a universal state function <img src="https://latex.codecogs.com/png.latex?T">, the <em>absolute temperature</em>, defined for any thermodynamic system, that satisfies the <em>Clausius inequality</em>. Concretely, if a system undergoes a cyclic process, during which it absorbs quantities <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q%20_i"> of energy in the form of heat from reservoirs at absolute temperatures <img src="https://latex.codecogs.com/png.latex?T_i">, the inequality:</p>
<p><span id="eq-clausius-theorem"><img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20_i%5Cfrac%7B%5CDelta%20Q_i%7D%7BT_i%7D%20%5Cleq%200%0A%5Ctag%7B1%7D"></span> always holds.</p>
<p>The derivation of Equation&nbsp;1 from Kelvin’s and Clausius’ postulates, a clever argument that employs ideal Carnot engines, is standard textbook material; see for example <span class="citation" data-cites="fermi1956thermodynamics">(Fermi 1956)</span>. On the other hand, I’ve never seen the converse being stressed, that is, that Clausius theorem allows one to recover versions of Kelvin’s and Clausius’ postulates. Here are two (fairly obvious) arguments in this direction.</p>
<p>Consider a cyclic process of a thermodynamic system during which a quantity <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q"> of heat is absorbed from a reservoir at constant temperature <img src="https://latex.codecogs.com/png.latex?T_0">. Equation&nbsp;1 applied to this special process implies:</p>
<p><span id="eq-kelvin-proof-1"><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta%20Q%5Cleq%200.%0A%5Ctag%7B2%7D"></span></p>
<p>The fact that <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q%5Cleq%200"> means that the heat reservoir can only absorb energy during a cycle, which must be supplied by performing a positive work on the system. This is the content of Kelvin’s postulate.</p>
<p>Similarly, if the system performs a cycle exchanging amounts of heat <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q_1"> and <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q_2"> with two heat sources at temperatures <img src="https://latex.codecogs.com/png.latex?T_1"> and <img src="https://latex.codecogs.com/png.latex?T_2"> respectively, Equation&nbsp;1 implies:</p>
<p><span id="eq-clausius-proof-1"><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5CDelta%20Q_1%7D%7BT_1%7D+%5Cfrac%7B%5CDelta%20Q_2%7D%7BT_2%7D%5Cleq%200%0A%5Ctag%7B3%7D"></span></p>
<p>But <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q_1%20+%20%5CDelta%20Q_2%20=%20%5CDelta%20Q%20=-%5CDelta%20W">, the external work performed on the system during a cycle. Hence:</p>
<p><span id="eq-clausius-proof-2"><img src="https://latex.codecogs.com/png.latex?%0A(%5Cfrac%7B1%7D%7BT_1%7D-%5Cfrac%7B1%7D%7BT_2%7D)%5CDelta%20Q_1%5Cleq%20%5Cfrac%7B%5CDelta%20W%7D%7BT_2%7D.%0A%5Ctag%7B4%7D"></span></p>
<p>Therefore, <img src="https://latex.codecogs.com/png.latex?%5CDelta%20Q_1%20%5Cgeq%200"> with <img src="https://latex.codecogs.com/png.latex?T_1%20%3C%20T_2"> requires <img src="https://latex.codecogs.com/png.latex?%5CDelta%20W%20%5Cgeq%200">. In other words, in order to perform a cycle in which a positive amount of heat is transferred from a low-temperature reservoir to a high-temperature one, we must necessarily perform some positive work<sup>2</sup>. This is the content of Clausius’ postulate.</p>
<p>A subtle point that may require some elucidation is that, in the usual logical exposition of Thermodynamics, the temperature to which Kelvin’s and Clausius’ postulates make reference is the <em>empirical</em> temperature, call it <img src="https://latex.codecogs.com/png.latex?%5Ctheta">. This is the “quantity measured by a thermometer” <span class="citation" data-cites="fermi1956thermodynamics">(Fermi 1956)</span>, and is logically distinct from the absolute temperature <img src="https://latex.codecogs.com/png.latex?T">, whose existence is a consequence of the second law. What we actually proved here are versions of Kelvin’s and Clausius’ postulates <em>formulated in terms of the absolute temperature</em>, <img src="https://latex.codecogs.com/png.latex?T">.</p>
<p>Now, if we take Kelvin’s or Clausius’ postulate (formulated in terms of <img src="https://latex.codecogs.com/png.latex?%5Ctheta">) as our logical starting point, we can actually prove that <img src="https://latex.codecogs.com/png.latex?T"> is an increasing function of <img src="https://latex.codecogs.com/png.latex?%5Ctheta">, in which case there is no point in specifying which temperature the postulates refer to. However, if our starting point is<br>
Clausius’ Theorem, there is no <em>a priori</em> logical reason for a relation between <img src="https://latex.codecogs.com/png.latex?T"> and <img src="https://latex.codecogs.com/png.latex?%5Ctheta">, which should be considered as an additional assumption.</p>
<hr>
<p>Even though this goes a bit beyond the original scope of the post, I’d like to show here how Equation&nbsp;1 leads the existence of another state function, the <em>entropy</em> <img src="https://latex.codecogs.com/png.latex?S">, which satisfies a generalized version of Equation&nbsp;1, namely:</p>
<p><span id="eq-clausius-theorem-entropy"><img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20_i%5Cfrac%7B%5CDelta%20Q_i%7D%7BT_i%7D%20%5Cleq%20%5CDelta%20S%0A%5Ctag%7B5%7D"></span></p>
<p>where quantities have the same meaning as in Equation&nbsp;1, but the process is not necessarily cyclic. One can additionally show that the differential of <img src="https://latex.codecogs.com/png.latex?S"> is given by:</p>
<p><span id="eq-entropy-differential"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20dS%20=%20%5Cfrac%7B%5Cdelta%20Q%20_R%7D%7BT%7D,%0A%5Ctag%7B6%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q_R%20=%20%5Ctext%20d%20U%20+%20%5Cdelta%20W_R"> is the differential heat absorbed by the system in a reversible process, and <img src="https://latex.codecogs.com/png.latex?T"> is the system’s temperature.</p>
<p>We start by observing that, for a reversible process, equality must hold in Equation&nbsp;1. This is so because, for a reversible cycle, the inverse cycle, in which the system absorbs amounts <img src="https://latex.codecogs.com/png.latex?-%5CDelta%20Q_i"> of heat at temperatures <img src="https://latex.codecogs.com/png.latex?T_i">, must also be possible. Altogether, the Clausius inequalities for the direct and inverse cycles thus imply:</p>
<p><span id="eq-clausius-theorem-rev"><img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20_i%5Cfrac%7B%5CDelta%20Q_i%7D%7BT_i%7D%20=%200%5Cquad%20%5Ctext%7B(reversible%20process)%7D.%0A%5Ctag%7B7%7D"></span></p>
<p>Imagining an ideal cyclic process, in which the system exchanges infinitesimal amounts of heat <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q(T')"> with a continuous distribution of sources at temperatures <img src="https://latex.codecogs.com/png.latex?T'">, we should replace the sum in Equation&nbsp;7 with an integral:</p>
<p><span id="eq-clausius-theorem-rev-int"><img src="https://latex.codecogs.com/png.latex?%0A%5Cintop%20%5Cfrac%7B%5Cdelta%20Q(T')%7D%7BT'%7D%20=%200%20%5Cquad%5Ctext%7B(reversible%20process)%7D%0A%5Ctag%7B8%7D"></span> We now fix a reference state <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_0"> of our system, and define for any other state <img src="https://latex.codecogs.com/png.latex?%5Csigma">:</p>
<p><span id="eq-entropy-def"><img src="https://latex.codecogs.com/png.latex?%0AS(%5Csigma;%5Csigma%20_0)%20=%20%5Cintop%20_%7B%5Csigma_0%7D%5E%5Csigma%20%5Cfrac%7B%5Cdelta%20Q(T')%7D%7BT'%7D%0A%5Ctag%7B9%7D"></span></p>
<p>where the integral is taken along <em>any</em> reversible path that connects <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_0"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma">, and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q(T')"> is the amount of heat exchanged at temperature <img src="https://latex.codecogs.com/png.latex?T'"> along this representative process. The fact that the integral in Equation&nbsp;9 depends only upon the final states <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_0"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma"> is guaranteed by Equation&nbsp;8.</p>
<p>By construction, we see that Equation&nbsp;6 must hold with <img src="https://latex.codecogs.com/png.latex?T"> being the temperature of a source that, if placed in thermal contact with the system, can produce a reversible exchange of heat. It remains to be shown that this temperature is nothing but the temperature of the system itself. Consider a reversible process in which two systems at temperatures <img src="https://latex.codecogs.com/png.latex?T_1"> and <img src="https://latex.codecogs.com/png.latex?T_2"> exchange an (infinitesimal) amount of heat. From what we have just said:</p>
<p><span id="eq-entropy-differential-switched"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20S_1%20=%20%5Cfrac%7B%5Cdelta%20Q_1%7D%7BT_2%7D,%5Cquad%20%5Ctext%20d%20S_2%20=%20%5Cfrac%7B%5Cdelta%20Q%20_2%7D%7BT_1%7D,%0A%5Ctag%7B10%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q_i"> is the heat absorbed by system <img src="https://latex.codecogs.com/png.latex?i">, and <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20S_i"> is its corresponding entropy change. However, since the composite system is thermally insulated, we must have <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q_1%20+%20%5Cdelta%20Q_2=0"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20S_1%20+%20%5Ctext%20d%20S_2%20=%200"><sup>3</sup>. Equation&nbsp;10 then implies that, if the process is reversible, we must necessarily have <img src="https://latex.codecogs.com/png.latex?T_1%20=%20T_2">. This completes the proof of Equation&nbsp;6.</p>





<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-dittman2021heat" class="csl-entry">
Dittman, Richard H, and Mark W Zemansky. 2021. <span>“Heat and Thermodynamics SEVENTH EDITION.”</span>
</div>
<div id="ref-fermi1956thermodynamics" class="csl-entry">
Fermi, E. 1956. <em>Thermodynamics</em>. Dover Books in Physics and Mathematical Physics. Dover Publications. <a href="https://books.google.es/books?id=VEZ1ljsT3IwC">https://books.google.es/books?id=VEZ1ljsT3IwC</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>We may compare these with the corresponding formulations given in Enrico Fermi’s famous book <span class="citation" data-cites="fermi1956thermodynamics">(Fermi 1956)</span>. For instance, Kelvin’s postulate reads: <em>“A transformation whose only final result is to transform into work heat extracted from a source which is at the same temperature throughout is impossible.”</em>. Even though I’m a big fan of Fermi’s book, I find the more modern formulations given in <span class="citation" data-cites="dittman2021heat">(Dittman and Zemansky 2021)</span> clearer.↩︎</p></li>
<li id="fn2"><p>In fact, Equation&nbsp;4 tells us a bit more than Clausius postulate, since it gives the maximum theoretical efficiency of a refrigerator operating between temperatures <img src="https://latex.codecogs.com/png.latex?T_1%20%3C%20T_2">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5CDelta%20Q_1%7D%7B%5CDelta%20W%7D%20%5Cleq%20%5Cfrac%7BT_1%7D%7BT_2-T_1%7D%0A">↩︎</p></li>
<li id="fn3"><p>The additivity of entropy is a consequence of the additivity of heat, which in turn would require a dedicate discussion. Such a requirement boils down to the additivity of external work, which holds generally if the interaction energies of the systems being composed are negligible. This is always assumed (more or less explicitly) whenever discussing the interaction of a system with a heat reservoir.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Statements of the {Second} {Law} of {Thermodynamics}},
  date = {2024-06-01},
  url = {https://vgherard.github.io/posts/2024-06-01-statements-of-the-second-law-of-thermodynamics/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Statements of the Second Law of
Thermodynamics.”</span> June 1, 2024. <a href="https://vgherard.github.io/posts/2024-06-01-statements-of-the-second-law-of-thermodynamics/">https://vgherard.github.io/posts/2024-06-01-statements-of-the-second-law-of-thermodynamics/</a>.
</div></div></section></div> ]]></description>
  <category>Thermodynamics</category>
  <category>Physics</category>
  <guid>https://vgherard.github.io/posts/2024-06-01-statements-of-the-second-law-of-thermodynamics/</guid>
  <pubDate>Fri, 31 May 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Authorship Attribution in Lennon-McCartney Songs</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-05-23-authorship-attribution-in-lennon-mccartney-songs/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="Glickman2019Data">(Glickman, Brown, and Song 2019)</span>. An enjoyable read. The authors present a statistical analysis of the Beatles’ repertoire from the point of view of authorship (Lennon <em>vs.</em> McCartney), a <a href="https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/">topic with which I’ve been lately involved</a>. As a side-note, this also made me discover the <a href="https://hdsr.mitpress.mit.edu/">Harvard Data Science Review</a>.</p>
<p>From the paper’s abstract:</p>
<blockquote class="blockquote">
<p>The songwriting duo of John Lennon and Paul McCartney, the two founding members of the Beatles, composed some of the most popular and memorable songs of the last century. Despite having authored songs under the joint credit agreement of Lennon-McCartney, it is well-documented that most of their songs or portions of songs were primarily written by exactly one of the two. Furthermore, the authorship of some Lennon-McCartney songs is in dispute, with the recollections of authorship based on previous interviews with Lennon and McCartney in conflict. For Lennon-McCartney songs of known and unknown authorship written and recorded over the period 1962-66, we extracted musical features from each song or song portion. These features consist of the occurrence of melodic notes, chords, melodic note pairs, chord change pairs, and four-note melody contours. We developed a prediction model based on variable screening followed by logistic regression with elastic net regularization. Out-of-sample classification accuracy for songs with known authorship was 76%, with a c-statistic from an ROC analysis of 83.7%. We applied our model to the prediction of songs and song portions with unknown or disputed authorship.</p>
</blockquote>
<p>The modeling approach looks to me very sound and appropriate to the small sample size available (<img src="https://latex.codecogs.com/png.latex?N%20=%2070">, the statistical unit corresponding to a song of known authorship). Effective model selection and testing is achieved through three nested layers of cross-validation (😱): one for elastic net hyperparameter tuning, one for feature screening, and finally one for estimating the prediction error.</p>
<p>The discussion of feature importance is insightful, in that it identifies concrete aspects of McCartney’s compositions that make them distinguishable from Lennon’s ones. This type of interpretability is a big plus for authorship analysis. The general qualitative conclusion, that McCartney’s music tended to exhibit more complex and unusual patterns kinda resonates with my perception of Beatles’ songs.</p>
<p>Armed with the trained logistic regression model, together with a valid accuracy estimate (76%), the authors set out to apply their model to authorship prediction for controversial cases within the Beatles’ corpus (outside of the training sample). I don’t fully understand the authors approach in this part of the paper, and some points appear to be questionable, for the reasons I explain below.</p>
<p>One of the advantages of fitting a full probability model, such as logistic regression, rather than a conceptually simpler pure classification model (like a tree, for example), is that the output of the former is not a mere class (McCartney or Lennon), but rather a <em>probability</em> of belonging to that class. This allows one to make much more informative statements in the analysis of new cases, since the strength of evidence provided by the data towards the predicted class can be quantified on a case by case basis. All of this is true, of course, <em>provided that the fitted model gives a decent approximation to the true data generating process</em>.</p>
<p>With similar considerations in mind, I suppose, the authors produce probability estimates for each of the disputed cases considered, in the form of a point estimate and a confidence interval to represent uncertainty. I think there is room for improvement here, in two aspects.</p>
<p>My first objection is what I already pointed out above: nothing in the modeling process explained in the paper suggests that the final model provides a good approximation to the true class probability conditional on features. The model has, with reasonable confidence, a predictive performance close to the best achievable within the possibilities considered - quantified by 76% accuracy and 84% AUC - but this says nothing about its correct specification as a probability model. Without a careful specification study, it is impossible to conclude anything on the nature of the true estimation targets of the fitted “probabilities”: they may perfectly have nothing to do with the actual <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(%5Ctext%7Bauthor%7D%5C,%5Cvert%5C,%20%5Ctext%7Bsong%20features%7D)"> the authors are after. There is still value, I believe, in reporting fitted probabilities as qualitative measures of evidence, but these should not be conflated with the true (unknown) class probabilities… at least without some serious attempt to detect differences between the two.</p>
<p>My second point is a technical one and concerns how they construct confidence intervals for fitted probabilities. The construction resembles that of bootstrap percentile confidence intervals but, rather than the usual bootstrap synthetic datasets, the delete-one datasets used in leave-one-out cross-validation are used to obtain replicas of the fitted probabilities. This is nothing but Jackknife resampling in disguise, and it is well known that the resampling standard deviation of such Jackknife replicae is roughly <img src="https://latex.codecogs.com/png.latex?N%20%5E%7B-1/2%7D"> times the true standard deviation, see <em>e.g.</em> <span class="citation" data-cites="tibshirani1993introduction">(Tibshirani and Efron 1993)</span>. Therefore, I have strong reasons to believe that the reported intervals strongly underestimate the uncertainty associated with these probability estimates.</p>
<p>All in all, the attempt to go beyond reporting simple classes - backed up by an overall 76% accuracy estimate - is well-motivated in principle, but the final outcome is not very dependable.</p>
<p>As usual, I’m more eloquent when criticizing than when praising, but let me end on a very positive note. The authors do a <em>great</em> favor to the reader, by including a discussion of the informal steps performed prior and in parallel to the formal analysis presented in the paper. This kind of transparency - which is also present in the rest of the discussion - is, I believe, not so common as it should, and is what makes it eventually possible to think critically about someone else’s work.</p>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-Glickman2019Data" class="csl-entry">
Glickman, Mark, Jason Brown, and Ryan Song. 2019. <span>“(<span>A</span>) <span>Data</span> in the <span>Life</span>: Authorship <span>Attribution</span> in <span>Lennon</span>-<span>McCartney</span> <span>Songs</span>.”</span> <em>Harvard Data Science Review</em> 1 (1).
</div>
<div id="ref-tibshirani1993introduction" class="csl-entry">
Tibshirani, Robert J, and Bradley Efron. 1993. <span>“An Introduction to the Bootstrap.”</span> <em>Monographs on Statistics and Applied Probability</em> 57 (1): 1–436.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Authorship {Attribution} in {Lennon-McCartney} {Songs}},
  date = {2024-05-23},
  url = {https://vgherard.github.io/posts/2024-05-23-authorship-attribution-in-lennon-mccartney-songs/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Authorship Attribution in
Lennon-McCartney Songs.”</span> May 23, 2024. <a href="https://vgherard.github.io/posts/2024-05-23-authorship-attribution-in-lennon-mccartney-songs/">https://vgherard.github.io/posts/2024-05-23-authorship-attribution-in-lennon-mccartney-songs/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Authorship Verification</category>
  <category>Natural Language Processing</category>
  <category>Machine Learning</category>
  <category>Music</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-05-23-authorship-attribution-in-lennon-mccartney-songs/</guid>
  <pubDate>Wed, 22 May 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Frequentist bounds for Bayesian sequential hypothesis testing</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-05-22-frequentist-bounds-for-bayesian-sequential-hypothesis-testing/</link>
  <description><![CDATA[ 





<p>I just came across <span class="citation" data-cites="kerridge1963bounds">(Kerridge 1963)</span>, an old result which falls under the umbrella of “frequentist properties of Bayesian inference”. Specifically, the theorem proved in this reference applies to sequential testing, a context in which the mechanics of Bayesian inference, with its typical sequential updates, may be regarded as natural.</p>
<p>Suppose we wish to compare two hypotheses <img src="https://latex.codecogs.com/png.latex?H_0"> and <img src="https://latex.codecogs.com/png.latex?H_1">, where <img src="https://latex.codecogs.com/png.latex?H_0"> is simple<sup>1</sup>. We start collecting data until our sample meets some specific requirement, according to some given <em>stopping rule</em> <img src="https://latex.codecogs.com/png.latex?S">. If this ever occurs, we compute the <em>Bayes factor</em>:</p>
<p><span id="eq-bayes-ratio"><img src="https://latex.codecogs.com/png.latex?%0AB%20=%20%5Cfrac%7B%5Ctext%7BPr%7D(%5Ctext%20%7Bdata%7D%20%5Cvert%20H_0)%7D%7B%5Ctext%7BPr%7D(%5Ctext%20%7Bdata%7D%20%5Cvert%20H_1)%7D.%0A%5Ctag%7B1%7D"></span></p>
<p>and reject <img src="https://latex.codecogs.com/png.latex?H_0"> if <img src="https://latex.codecogs.com/png.latex?B%20%5Cleq%20b">, for some <img src="https://latex.codecogs.com/png.latex?b%20%3E%200">. The theorem is that if <img src="https://latex.codecogs.com/png.latex?H_0"> is the true data generating process, the above procedure has a false rejection rate lower than <img src="https://latex.codecogs.com/png.latex?b">, <em>independently of the stopping rule employed to end sampling</em>.</p>
<p>Notice that the rejection event is composed by two parts:</p>
<ol type="1">
<li>Sampling has stopped at some point during data taking.</li>
<li>When sampling stopped, <img src="https://latex.codecogs.com/png.latex?B%20%5Cleq%20b"> held.</li>
</ol>
<p>We also note that the stopping rule needs not be deterministic, although this appears to be implicitly assumed in the original reference. In general, the data collected up to a certain point will only determine the <em>probability</em> that sampling stops at that time (and, to reinforce the previous point, the sum of these probabilities will not, in general, add up to <img src="https://latex.codecogs.com/png.latex?1">).</p>
<p>In order to prove this theorem, let us set up some notation. Let <img src="https://latex.codecogs.com/png.latex?(X_n)_%7Bn%5Cin%20%5Cmathbb%20N%7D"> be some stochastic process representing “data”, where each <img src="https://latex.codecogs.com/png.latex?X_n%20%5Cin%20%5Cmathcal%20%20X"> is a data point. We denote by <img src="https://latex.codecogs.com/png.latex?P%5E%7B(0)%7D"> the probability distribution of <img src="https://latex.codecogs.com/png.latex?X"> under <img src="https://latex.codecogs.com/png.latex?H_0">, which is completely defined since <img src="https://latex.codecogs.com/png.latex?H_0"> is simple. We further denote by <img src="https://latex.codecogs.com/png.latex?P_n%20%5E%7B(0)%7D"> the corresponding probability measure on <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20X%20%5En"> for the set of the first <img src="https://latex.codecogs.com/png.latex?n"> observations <img src="https://latex.codecogs.com/png.latex?X_1,%5C,X_2,%5C,%5Cdots,%20%5C,X_n">.</p>
<p>We first consider the case in which <img src="https://latex.codecogs.com/png.latex?H_1"> is also simple, and denote by <img src="https://latex.codecogs.com/png.latex?P%5E%7B(1)%7D"> and <img src="https://latex.codecogs.com/png.latex?P%5E%7B(1)%7D_n"> the corresponding measures. The Bayes factor is defined as the Radon-Nikodym derivative:</p>
<p><span id="eq-bayes-ratio-radon-nikodym"><img src="https://latex.codecogs.com/png.latex?%0AB_n%20%5Cequiv%20%5Cfrac%7B%5Ctext%20d%20P%5E%7B(0)%7D_n%7D%7B%5Ctext%20d%20P_n%5E%7B(1)%7D%7D%0A%5Ctag%7B2%7D"></span></p>
<p>(we assume regularity conditions so that such a derivative exists).</p>
<p>Also, we assume for the moment that the stopping rule is deterministic, embodied by binary functions <img src="https://latex.codecogs.com/png.latex?S_n=S(X_1,%5C,X_2,%5C,%5Cdots,X_n)"> of the first <img src="https://latex.codecogs.com/png.latex?n"> observations, with <img src="https://latex.codecogs.com/png.latex?S_n%20=%201"> if sampling can stop at step <img src="https://latex.codecogs.com/png.latex?n">.</p>
<p>Now fix <img src="https://latex.codecogs.com/png.latex?b%3E0">. A rejection of <img src="https://latex.codecogs.com/png.latex?H_0"> at sampling step <img src="https://latex.codecogs.com/png.latex?n"> is represented by the event:</p>
<p><span id="eq-rejection-events"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%20R%20_%7Bn%7D(b)%5Cequiv%20%5C%7BB_n%5Cleq%20b,%5C,S_n=1,%5C,S_i=0%5C,%5Ctext%7B%20for%20%7Di%3Cn%5C%7D,%0A%5Ctag%7B3%7D"></span></p>
<p>which, with abuse of notation, we may identify with a subset of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20X%20%5En">. The overall rejection event (at any sampling step) is given by:</p>
<p><span id="eq-big-rejection-event"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%20R%20(b)%5Cequiv%20%5Cbigcup%20_%7Bn=1%7D%20%5E%5Cinfty%20%5Cmathcal%20R_n(b),%0A%5Ctag%7B4%7D"></span></p>
<p>so that our theorem amounts to the bound:</p>
<p><span id="eq-theorem-statement"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R(b))%5Cleq%20b.%0A%5Ctag%7B5%7D"></span></p>
<p>In order to prove this, we first note that:</p>
<p><span id="eq-theorem-step-1"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R%20_n(b))=%0A%20%20%20%20%20%20%20%20%5Cintop%20_%7B%5Cmathcal%20R%20_n(b)%7D%20%5Ctext%20d%20P_n=%0A%20%20%20%20%20%20%20%20%5Cintop%20_%7B%5Cmathcal%20R%20_n(b)%7DB_n%20%5Ctext%20d%20Q_n%20%5Cleq%0A%20%20%20%20%20%20%20%20b%5Cintop%20_%7B%5Cmathcal%20R%20_n(b)%7D%20%5Ctext%20d%20Q_n=b%5Ccdot%5Ctext%7BPr%7D_%7BH_1%7D(%5Cmathcal%20R%20_n(b)).%0A%5Ctag%7B6%7D"></span></p>
<p>Hence, since the events <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20R%20_n(b)"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20R%20_m(b)"> are clearly disjoint for <img src="https://latex.codecogs.com/png.latex?n%5Cneq%20m">, we have:</p>
<p><span id="eq-theorem-step-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R(b))%5Cleq%20b%5Ccdot%5Ctext%7BPr%7D_%7BH_1%7D(%5Cmathcal%20R%20(b)),%0A%5Ctag%7B7%7D"></span></p>
<p>which, since <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D_Q(%5Ccdot)%5Cleq1">, implies Equation&nbsp;5.</p>
<p>We may relax the assumption that the alternative hypothesis is simple, by considering a parametric family of measures <img src="https://latex.codecogs.com/png.latex?(P%5E%7B(1)%7D_%5Ctheta)_%7B%5Ctheta%20%5Cin%20%5CTheta%7D">, where the parameter <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> has some prior probability <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%5CPhi(%5Ctheta)">. The argument given above still applies to this case, if <img src="https://latex.codecogs.com/png.latex?P%5E%7B(1)%7D"> is replaced by the mixture <img src="https://latex.codecogs.com/png.latex?P%5E%7B(1)%7D%20=%20%5Cintop%20%5Ctext%20d%20%5CPhi(%5Ctheta)%20P%5E%7B(1)%7D_%5Ctheta"> (under appropriate regularity assumptions). In the notation of Equation&nbsp;1, the denominator <img src="https://latex.codecogs.com/png.latex?%5Ctext%20%7BPr%7D(%5Ctext%20%7Bdata%7D%20%5Cvert%20H_1)%5Cequiv%20%5Cintop%20%5Ctext%20d%20%5CPhi(%5Ctheta)%5C,%5Ctext%7BPr%7D(%5Ctext%7Bdata%7D%20%5Cvert%20H_%7B1,%5Ctheta%7D)">.</p>
<p>Finally, in order to lift the assumption that our stopping rule is deterministic, let us first consider the following special (deterministic) stopping rule:</p>
<p><span id="eq-data-dredging"><img src="https://latex.codecogs.com/png.latex?%0AS%5E*_n%20=1%5Ciff%20B_n%20%5Cleq%20b.%0A%5Ctag%7B8%7D"></span></p>
<p>In other words, we stop sampling whenever the sample would reject <img src="https://latex.codecogs.com/png.latex?H_0"> according to <img src="https://latex.codecogs.com/png.latex?B_n%20%5Cleq%20b">. The rejection event <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20R(b)"> for this special stopping rule is simply:</p>
<p><span id="eq-rejection-data-dredging"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%20R%5E*(b)%20%5Cequiv%20%5C%7BB_n%20%5Cleq%20b%5Ctext%7B%20for%20some%20%7Dn%5Cin%20%5Cmathbb%20N%5C%7D.%0A%5Ctag%7B9%7D"></span></p>
<p>Since we already proved the theorem for any deterministic stopping rule, Equation&nbsp;5 implies:</p>
<p><span id="eq-bound-data-dredging"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R%5E*(b))%20%5Cleq%20b.%0A%5Ctag%7B10%7D"></span></p>
<p>But Equation&nbsp;10 clearly implies the theorem for any stopping rule, deterministic or not, since in general:</p>
<p><span id="eq-proper-subset-data-dredging"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%20R(b)%20%5Csubseteq%20%5Cmathcal%20R%5E*(b)%0A%5Ctag%7B11%7D"></span></p>
<p>(we need <img src="https://latex.codecogs.com/png.latex?B_n%5Cleq%20b"> to hold for some <img src="https://latex.codecogs.com/png.latex?n%5Cin%20%5Cmathbb%20N"> in order to reject <img src="https://latex.codecogs.com/png.latex?H_0">).</p>
<p>Interestingly, the argument just given leads to a more accurate statement of our main result Equation&nbsp;5:</p>
<p><span id="eq-theorem-statement-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R(b))%5Cleq%20%5Ctext%20%7BPr%7D_%7BH_0%7D(B_n%20%5Cleq%20b%5Ctext%7B%20for%20some%20%7Dn%5Cin%20%5Cmathbb%20N)%20%5Cleq%20b,%0A%5Ctag%7B12%7D"></span></p>
<p>where the leftmost quantity is the false rejection rate of a selective testing procedure, such as the one we have been considering so far, wheareas the central quantity is the false rejection rate of a <em>simultaneous</em> testing procedure (that checks whether <img src="https://latex.codecogs.com/png.latex?B_n%20%5Cleq%20b"> at each step of sampling). What’s happening here is analogous to a phenomenon observed in the context of parameter estimation following model selection <span class="citation" data-cites="berk2013valid">(Berk et al. 2013)</span>, where one can show that, in order to guarantee marginal coverage for the selected parameters, if the selection rule is allowed to be completely arbitrary one must actually require <em>simultaneous</em> coverage for all possible parameters.</p>
<p>To conclude the post, let us remark that Equation&nbsp;5 was originally formulated in terms of the posterior probability <img src="https://latex.codecogs.com/png.latex?Q_n(%5Cpi)"> of <img src="https://latex.codecogs.com/png.latex?H_0">:</p>
<p><span id="eq-posterior-prob"><img src="https://latex.codecogs.com/png.latex?%0AQ_n(%5Cpi)%20=%20%5Cfrac%7B%5Cpi%20%7D%7B%5Cpi%20+(1-%5Cpi)B%5E%7B-1%7D_n%7D,%0A%5Ctag%7B13%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cpi"> and <img src="https://latex.codecogs.com/png.latex?1-%5Cpi"> are the prior probabilities of the two competing models <img src="https://latex.codecogs.com/png.latex?H_0"> and <img src="https://latex.codecogs.com/png.latex?H_1">, respectively. We may use <img src="https://latex.codecogs.com/png.latex?Q_n(%5Cpi)%20%5Cleq%20q">, rather than <img src="https://latex.codecogs.com/png.latex?B_n%20%5Cleq%20b">, as the relevant criterion for rejecting <img src="https://latex.codecogs.com/png.latex?H_0">. From the pure frequentist point of view, this doesn’t add anything to our formulation in terms of the Bayes ratio, as <img src="https://latex.codecogs.com/png.latex?Q_n(%5Cpi)%5Cleq%20q"> is equivalent to <img src="https://latex.codecogs.com/png.latex?B_n%20%5Cleq%20b"> as long as <img src="https://latex.codecogs.com/png.latex?b%20=%20%5Cfrac%7Bq%7D%7B1-q%7D%5Cfrac%7B1-%5Cpi%7D%7B%5Cpi%7D">. In particular, the bound analogous to Equation&nbsp;5 reads:</p>
<p><span id="eq-theorem-statement-3"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D_%7BH_0%7D(%5Cmathcal%20R(q))%5Cleq%20%5Ctext%20%7BPr%7D_%7BH_0%7D(Q_n(%5Cpi)%20%5Cleq%20q%5Ctext%7B%20for%20some%20%7Dn%5Cin%20%5Cmathbb%20N)%20%5Cleq%20%5Cfrac%7Bq%7D%7B1-q%7D%5Cfrac%7B1-%5Cpi%7D%7B%5Cpi%7D.%0A%5Ctag%7B14%7D"></span></p>





<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-berk2013valid" class="csl-entry">
Berk, Richard, Lawrence Brown, Andreas Buja, Kai Zhang, and Linda Zhao. 2013. <span>“Valid Post-Selection Inference.”</span> <em>The Annals of Statistics</em>, 802–37.
</div>
<div id="ref-kerridge1963bounds" class="csl-entry">
Kerridge, D. 1963. <span>“Bounds for the Frequency of Misleading Bayes Inferences.”</span> <em>The Annals of Mathematical Statistics</em> 34 (3): 1109–10.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>This is a technical term, meaning that <img src="https://latex.codecogs.com/png.latex?H_0"> completely characterizes the probability distribution of data. An example of a non-simple hypothesis would be a parametric model depending on some unknown parameter <img src="https://latex.codecogs.com/png.latex?%5Ctheta">.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Frequentist Bounds for {Bayesian} Sequential Hypothesis
    Testing},
  date = {2024-05-22},
  url = {https://vgherard.github.io/posts/2024-05-22-frequentist-bounds-for-bayesian-sequential-hypothesis-testing/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Frequentist Bounds for Bayesian
Sequential Hypothesis Testing.”</span> May 22, 2024. <a href="https://vgherard.github.io/posts/2024-05-22-frequentist-bounds-for-bayesian-sequential-hypothesis-testing/">https://vgherard.github.io/posts/2024-05-22-frequentist-bounds-for-bayesian-sequential-hypothesis-testing/</a>.
</div></div></section></div> ]]></description>
  <category>Sequential Hypothesis Testing</category>
  <category>Bayesian Methods</category>
  <category>Frequentist Methods</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-05-22-frequentist-bounds-for-bayesian-sequential-hypothesis-testing/</guid>
  <pubDate>Tue, 21 May 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>AIC in the well-specified linear model: theory and simulation</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/</link>
  <description><![CDATA[ 





<section id="theory" class="level2">
<h2 class="anchored" data-anchor-id="theory">Theory</h2>
<section id="aic" class="level3">
<h3 class="anchored" data-anchor-id="aic">AIC</h3>
<p>Consider the AIC for the usual linear model <img src="https://latex.codecogs.com/png.latex?Y%20=%20X%5Cbeta%20+%20%5Cvarepsilon">:</p>
<p><span id="eq-aic"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BAIC%7D%20=%20%5Cfrac%7B1%7D%7B2%7D%5Cln(2%5Cpi%20e%5Chat%20%5Csigma%5E2)+%5Cfrac%7Bp+1%7D%7BN%7D%0A%5Ctag%7B1%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?p"> is the dimension of the covariate vector <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Csigma%20%5E2"> is the ML estimate of the <img src="https://latex.codecogs.com/png.latex?Y%5Cvert%20X"> conditional variance. The expectation of Equation&nbsp;1 under model assumptions can be found by using the fact that, for a <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2"> random variable with <img src="https://latex.codecogs.com/png.latex?%5Cnu"> degrees of freedom<sup>1</sup>:</p>
<p><span id="eq-expec-log-X2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Cln%5Cchi%20%5E2%20)=%5Cln2+%20%5Cpsi(%5Cfrac%7B%5Cnu%7D%7B2%7D)%0A%5Ctag%7B2%7D"></span></p>
<p>where: <span id="eq-psi-fun"><img src="https://latex.codecogs.com/png.latex?%0A%5Cpsi(x)%5Cequiv%5Cfrac%7B%5Ctext%20d%7D%7B%5Ctext%20d%20x%7D%5Cln%20%5CGamma(x)%20%5Capprox%20%5Cln%20x-%5Cfrac%7B1%7D%7B2x%7D%0A%5Ctag%7B3%7D"></span></p>
<p>and the second equality results from the Stirling approximation <img src="https://latex.codecogs.com/png.latex?%5CGamma(x)%20=%20%5Csqrt%7B2%5Cpi%7Dx%5E%7Bx-%5Cfrac%7B1%7D%7B2%7D%7De%5E%7B-x%7D">. We obtain:</p>
<p><span id="eq-expec-aic"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Ctext%7BAIC%7D)%20=%20%5Cfrac%7B%5Cln%20%5Cleft%5B2%5Cpi%20e%5Cmathbb%20V(Y%5Cvert%20X)%5Cright%5D%20%7D%7B2%7D+%5Cfrac%7B1%7D%7B2%7D%5Cln%5Cleft(%5Cfrac%7BN-p%7D%7B2%7D%5Cright)-%5Cfrac%7B1%7D%7B2%7D%5Cfrac%7B1%7D%7BN-p%7D+%5Cfrac%7Bp+1%7D%7BN%7D,%0A%5Ctag%7B4%7D"></span></p>
<p>where, according to standard assumptions, <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20V(Y%20%5Cvert%20X)"> is assumed to be constant in <img src="https://latex.codecogs.com/png.latex?X">.</p>
<p>Now consider two such models, with different covariate vectors <img src="https://latex.codecogs.com/png.latex?X_1"> and <img src="https://latex.codecogs.com/png.latex?X_2">, of dimension <img src="https://latex.codecogs.com/png.latex?p_1"> and <img src="https://latex.codecogs.com/png.latex?p_2"> respectively, both assumed to be well specified. Denote, as before:</p>
<p><span id="eq-aic-i"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BAIC%7D_i%20=%5Cfrac%7B1%7D%7B2%7D%5Cln(2%5Cpi%20e%5Chat%20%5Csigma%5E2_i)+%5Cfrac%7Bp_i+1%7D%7BN%7D%0A%5Ctag%7B5%7D"></span></p>
<p>for <img src="https://latex.codecogs.com/png.latex?i%20=%201,%5C,2">. Equation&nbsp;4 gives the unconditional expectation of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D"> for both models<sup>2</sup>, so that:</p>
<p><span id="eq-delta-expec-aic"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Ctext%7BAIC%7D_1%20-%20%5Ctext%7BAIC%7D_2)%20=%20%5Cfrac%7B1%7D%7B2%7D%5Cln%5Cleft(%5Cfrac%7B%5Cmathbb%20V(Y%5Cvert%20X_1)%7D%7B%5Cmathbb%20V(Y%5Cvert%20X_2)%7D%5Cright)+%5Cfrac%7Bp_1-p_2%7D%7B2N%7D+%5Cmathcal%20O(N%5E%7B-2%7D).%0A%5Ctag%7B6%7D"></span></p>
<p>Assuming, without loss of generality, that <img src="https://latex.codecogs.com/png.latex?p_1%20%5Cleq%20p_2">, we have:</p>
<p><span id="eq-aic-condition"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Ctext%7BAIC%7D_1%20-%20%5Ctext%7BAIC%7D_2)%20%3C%200%20%5Ciff%20N%20%3C%20%5Cfrac%7Bp_2-p_1%7D%7B%5Cln%5Cleft(%5Cfrac%7B%5Cmathbb%20V(Y%5Cvert%20X_1)%7D%7B%5Cmathbb%20V(Y%5Cvert%20X_2)%7D%5Cright)%7D.%0A%5Ctag%7B7%7D"></span></p>
<p>To gain some intuition, suppose that the set of variables contained in <img src="https://latex.codecogs.com/png.latex?X_1"> is a subset of those contained in <img src="https://latex.codecogs.com/png.latex?X_2">, so that the two corresponding models are nested. Equation&nbsp;7 tells us that, for <img src="https://latex.codecogs.com/png.latex?N"> below a certain threshold, AIC will prefer the more “parsimonious” model involving <img src="https://latex.codecogs.com/png.latex?X_1"> only. In particular, if <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20V(Y%5Cvert%20X_1)%5Capprox%20%5Cmathbb%20V(Y%5Cvert%20X_2)">, we can make a first-order approximation in the RHS of Equation&nbsp;7, that yields:</p>
<p><span id="eq-aic-condition-approx"><img src="https://latex.codecogs.com/png.latex?%0AN%20%5Clesssim%20%5Cfrac%7B%5Cmathbb%20V(Y%5Cvert%20X_2)%7D%7B%5Cmathbb%20V(Y%5Cvert%20X_1)-%5Cmathbb%20V(Y%5Cvert%20X_2)%7D(p_2-p_1).%0A%5Ctag%7B8%7D"></span></p>
</section>
<section id="cross-entropy" class="level3">
<h3 class="anchored" data-anchor-id="cross-entropy">Cross-entropy</h3>
<p>In parallel to AIC, we can consider the exact “information criterion” provided by the model in-sample cross-entropy under the true data generating process. For a single linear model, the in-sample cross-entropy is:</p>
<p><span id="eq-in-sample-cross-entropy"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BCE%7D_%7B%5Ctext%20%7Bin%7D%7D%20=%20%5Cfrac%7B1%7D%7B2%7D%5Cln(2%5Cpi%20e%20%5Chat%20%5Csigma%20%5E2)%20+%5Cfrac%7B1%7D%7B2%7D%5Cfrac%7B%5Csigma%20%5E2-%5Chat%20%5Csigma%20%5E2+%5Cfrac%7B1%7D%7BN%7D(%5Cbeta-%5Chat%7B%5Cbeta%7D)%5E%7BT%7D%5Cmathbf%7BX%7D%5E%7BT%7D%5Cmathbf%7BX%7D(%5Cbeta-%5Chat%7B%5Cbeta%7D)%7D%7B%5Chat%20%5Csigma%20%5E2%7D.%0A%5Ctag%7B9%7D"></span></p>
<p>(“in-sample” refers to the fact that we fix, <em>i.e.</em> condition, on the covariate vector of the training sample, <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20X">.) The <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20X"> conditional expectation of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BCE%7D_%7B%5Ctext%20%7Bin%7D%7D">, again under model assumptions, can be computed by noticing two facts:</p>
<ul>
<li>The numerator and denominator are conditionally independent <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2"> variables with <img src="https://latex.codecogs.com/png.latex?p"> and <img src="https://latex.codecogs.com/png.latex?N-p"> degrees of freedom respectively. This can be seen by rewriting these as <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20%5Cepsilon%20%5ET%20%5Cmathbf%20H%20%5Cboldsymbol%20%5Cepsilon">, and <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20%5Cepsilon%20%5ET%20(1-%5Cmathbf%20H)%20%5Cboldsymbol%20%5Cepsilon">, respectively, where <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20H%20=%20%5Cmathbf%20X%20(%5Cmathbf%20X%20%5ET%20%5Cmathbf%20X)%5E%7B-1%7D%20%5Cmathbf%20X%20%5ET"> as usual.</li>
<li>For a <img src="https://latex.codecogs.com/png.latex?%5Cchi%20%5E2"> random variable with <img src="https://latex.codecogs.com/png.latex?%5Cnu"> degrees of freedom we have <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5Cfrac%7B1%7D%7B%5Cchi%20%5E2%7D)=%5Cfrac%7B1%7D%7B%5Cnu%20-%202%7D">.</li>
</ul>
<p>Using these results, we can show that:</p>
<p><span id="eq-aic-vs-ce"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Ctext%7BCE%7D_%7B%5Ctext%20%7Bin%7D%7D%5Cvert%20%5Cmathbf%20X)=%5Cmathbb%20E(%5Ctext%7BAIC%7D%5Cvert%20%5Cmathbf%20X)+%5Cmathcal%20O(N%5E%7B-2%7D)%0A%5Ctag%7B10%7D"></span></p>
<p>(an equation which is true by design of AIC).</p>
<p>Before rushing to the (wrong) conclusion that <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D_1%20-%20%5Ctext%7BAIC%7D_2"> will correspondingly estimate a difference of expected cross-entropies, let us notice that the relevant in-sample cross-entropy to be considered for model evaluation is Equation&nbsp;9 with <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20X"> <em>corresponding to the full covariate vector</em>: this is the target we should try to estimate (at least to the extent that our goal is predicting <img src="https://latex.codecogs.com/png.latex?Y"> given <img src="https://latex.codecogs.com/png.latex?X">). For this reason, strictly speaking, Equation&nbsp;10 is exact only if our model is well specified as a model of <img src="https://latex.codecogs.com/png.latex?Y%20%5Cvert%20X">. Otherwise, in order to estimate consistently <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5Ctext%7BCE%7D_%7B%5Ctext%20%7Bin%7D%7D%5Cvert%20%5Cmathbf%20X)">, we should use Takeuchi’s Information Criterion (TIC) rather than AIC.</p>
<p>A bit more pragmatically, in the real world we could assume the remainder of Equation&nbsp;10 to be <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20O%20(N%5E%7B-1%7D)"> (rather than <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20O%20(N%5E%7B-2%7D)">), but generally small with respect the leading order AIC correction (<img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bp+1%7D%7BN%7D">). This will be the case if the models being compared are approximately well specified.</p>
</section>
</section>
<section id="simulation" class="level2">
<h2 class="anchored" data-anchor-id="simulation">Simulation</h2>
<section id="setup" class="level3">
<h3 class="anchored" data-anchor-id="setup">Setup</h3>
<p>We take the data generating process to be:</p>
<p><span id="eq-dgp-sim"><img src="https://latex.codecogs.com/png.latex?%0AY%20=%20m%20X%20+%20q%20+%20%5Cvarepsilon,%0A%5Ctag%7B11%7D"></span></p>
<p>with:</p>
<p><span id="eq-dgp-sim-2"><img src="https://latex.codecogs.com/png.latex?%0AX%20%5Csim%20%5Cmathcal%20N%20(0,%5C,1),%5Cquad%20%5Cvarepsilon%20%5Csim%20%5Cmathcal%20N(0,%5C,1),%5Cquad%20%5Cvarepsilon%20%5Cperp%20X.%0A%5Ctag%7B12%7D"></span></p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span></span>
<span id="cb1-2">q <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb1-3"></span>
<span id="cb1-4">rxy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n) {</span>
<span id="cb1-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb1-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb1-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> m <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> q <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-8">        )</span>
<span id="cb1-9">}</span></code></pre></div></div>
</div>
<p>We compare the model with <em>vs.</em> without slope term (<img src="https://latex.codecogs.com/png.latex?m%20=%200"> <em>vs.</em> <img src="https://latex.codecogs.com/png.latex?m%20%5Cneq%200">), which we will denote by suffixes <img src="https://latex.codecogs.com/png.latex?1"> and <img src="https://latex.codecogs.com/png.latex?1%5Coplus%20X">, respectively. The functions below compute AIC and in-sample cross-entropy from the corresponding <code>lm</code> objects. We also define a “Naive Information Criterion” <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BNIC%7D%20%5Cequiv%20%5Clog(%5Chat%20%5Csigma)">.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">nic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(fit) {</span>
<span id="cb2-2">    p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit))</span>
<span id="cb2-3">    n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nobs</span>(fit)</span>
<span id="cb2-4">    sigma_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigma</span>(fit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n)</span>
<span id="cb2-5">    </span>
<span id="cb2-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(sigma_hat)</span>
<span id="cb2-7">}</span>
<span id="cb2-8"></span>
<span id="cb2-9">aic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(fit) {</span>
<span id="cb2-10">    p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit))</span>
<span id="cb2-11">    n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nobs</span>(fit)</span>
<span id="cb2-12">    sigma_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigma</span>(fit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n)</span>
<span id="cb2-13">    </span>
<span id="cb2-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(sigma_hat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pi))</span>
<span id="cb2-15">}</span>
<span id="cb2-16"></span>
<span id="cb2-17">ce <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(fit, data) {</span>
<span id="cb2-18">    p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit))</span>
<span id="cb2-19">    n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nobs</span>(fit)</span>
<span id="cb2-20">    sigma_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigma</span>(fit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n)</span>
<span id="cb2-21">    y_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fitted</span>(fit)</span>
<span id="cb2-22">    mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> m <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> q</span>
<span id="cb2-23">    </span>
<span id="cb2-24">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb2-25">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sigma_hat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-26">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(sigma_hat)</span>
<span id="cb2-27">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (y_hat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sigma_hat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb2-28">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> pi)</span>
<span id="cb2-29"></span>
<span id="cb2-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(res)</span>
<span id="cb2-31">}</span></code></pre></div></div>
</div>
<p>From our results above, we expect:</p>
<p><span id="eq-delta-expec-aic-sim"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Ctext%7BAIC%7D_%7B1%5Coplus%20X%7D-%5Ctext%7BAIC%7D_%7B1%7D%20)%3C0%20%5Ciff%20N%20%5Cgeq%20%5Cfrac%7B1%7D%7B%5Cln(1+m%5E2)%7D%5Cleft(1+%5Cmathcal%20O(m%5E2%20)%5Cright)%0A%5Ctag%7B13%7D"></span></p>
<p>The expected in-sample cross-entropies cannot be computed explicitly, but for relatively small <img src="https://latex.codecogs.com/png.latex?m%5E2"> we expect (<em>cf.</em> Equation&nbsp;10):</p>
<p><span id="eq-aic-vs-ce-sim"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E((%5Ctext%7BCE%7D_%7B%5Ctext%20%7Bin%7D%7D)_i)=%5Cmathbb%20E(%5Ctext%7BAIC%7D_i)+%5Cmathcal%20O(N%5E%7B-2%7D,%5C,m%5E2N%5E%7B-1%7D),%0A%5Ctag%7B14%7D"></span></p>
<p>I will use tidyverse for plotting results.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span></code></pre></div></div>
</div>
<p>In order to make results reproducible let’s:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">840</span>)</span></code></pre></div></div>
</div>
</section>
<section id="results" class="level3">
<h3 class="anchored" data-anchor-id="results">Results</h3>
<p>We simulate fitting models <img src="https://latex.codecogs.com/png.latex?1"> and <img src="https://latex.codecogs.com/png.latex?1%5Coplus%20X"> at different sample sizes from the data generating process described above.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">fits <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb5-2">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e3</span></span>
<span id="cb5-3">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(n, rxy)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(n, b, data) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">    tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb5-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</span>(), \(i) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(model[[i]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data[[i]])),</span>
<span id="cb5-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ce =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</span>(), \(i) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ce</span>(fit[[i]], data[[i]])),</span>
<span id="cb5-11">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">aic =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(fit, aic),</span>
<span id="cb5-12">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nic =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(fit, nic),</span>
<span id="cb5-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(model)</span>
<span id="cb5-14">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(fit, data))</span></code></pre></div></div>
</div>
<p>The plots below show the dependence from sample size of <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5CDelta%5Ctext%7BAIC%7D)"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5CDelta%5Ctext%7BCE%7D_%5Ctext%7Bin%7D)">, as well as AIC selection frequencies. Notice that for <img src="https://latex.codecogs.com/png.latex?N%20=%20%5Cfrac%7B1%7D%7Bm%5E2%7D">, even though <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5CDelta%5Ctext%7BAIC%7D)%20=%200">, the selection frequency of the “complex” model <img src="https://latex.codecogs.com/png.latex?1%5Coplus%20X"> is still below <img src="https://latex.codecogs.com/png.latex?%5Ctext%7B50%20%25%7D">. This is because the distribution of <img src="https://latex.codecogs.com/png.latex?%5CDelta%5Ctext%7BAIC%7D"> is asymmetric, as seen in the second plot, and <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5CDelta%5Ctext%7BAIC%7D)%20%3C%20%5Ctext%20%7Bmedian%7D(%5CDelta%5Ctext%7BAIC%7D)">.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">fits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-3">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">is_baseline =</span> model <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y ~ 1"</span>,</span>
<span id="cb6-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_ce =</span> ce <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ce[is_baseline], </span>
<span id="cb6-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_aic =</span> aic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> aic[is_baseline],</span>
<span id="cb6-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_nic =</span> nic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> nic[is_baseline],</span>
<span id="cb6-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n, b),</span>
<span id="cb6-8">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_baseline) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb6-11">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">E( ΔCE )</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(delta_ce), </span>
<span id="cb6-12">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">E( ΔAIC )</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(delta_aic),</span>
<span id="cb6-13">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">E( ΔNIC )</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(delta_nic),</span>
<span id="cb6-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> n</span>
<span id="cb6-15">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">    tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb6-17">        <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"metric"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span></span>
<span id="cb6-18">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> value, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> metric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-20">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-21">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-22">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-23">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-24">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample Size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-25">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(IC)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-26">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-27">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AIC vs. in-sample cross-entropy"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Expected values"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-28">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/index_files/figure-html/aic_exp-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">fits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(aic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(aic), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n, b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n, model)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> model, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-5">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-6">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample Size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-7">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AIC model selection frequencies"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/index_files/figure-html/aic_freq-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">fits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_aic =</span> aic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> aic[model <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y ~ 1"</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n, b)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(model <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y ~ 1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expec =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> m<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> delta_aic, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(n))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-7">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-9">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ΔAIC"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample Size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-10">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ΔAIC probability density"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/index_files/figure-html/aic_density-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Finally, here is something I have no idea where it comes from. The plot below shows the scatterplot of in-sample cross-entropy differences <em>vs.</em> the AIC differences. It is well known that AIC only estimates the expectation of these differences, averaged over potential training samples. One may ask whether AIC has anything to say about the actual cross-entropy difference for the estimated models, conditional on the realized training sample.</p>
<p>Assuming I have made no errors here, the tilted-U shape of this scatterplot is a clear negative answer. What’s especially interesting is that, apparently, these differences have a negative correlation. I fail to see where do the negative correlation and the U-shape come from.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">fits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb9-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">is_baseline =</span> model <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y ~ 1"</span>,</span>
<span id="cb9-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_ce =</span> ce <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ce[is_baseline], </span>
<span id="cb9-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta_aic =</span> aic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> aic[is_baseline],</span>
<span id="cb9-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n, b),</span>
<span id="cb9-8">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>is_baseline) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> delta_aic, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> delta_ce)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-11">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-12">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lims</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-13">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ΔAIC"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ΔCE"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-14">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AIC vs. in-sample cross-entropy"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Point values for N = 100"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-15">        <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/index_files/figure-html/aic_vs_ce_2-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>


</section>
</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>See <em>e.g.</em> <a href="https://arxiv.org/pdf/1503.06266">1503.06266</a>↩︎</p></li>
<li id="fn2"><p>The same equation actually gives the expectation of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D"> conditional to the in-sample covariate vector <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20X">. Since this conditioning differs for the two different models involving <img src="https://latex.codecogs.com/png.latex?X_1"> and <img src="https://latex.codecogs.com/png.latex?X_2">, in our comparison of expected values we must interpret this as unconditional expectations, in general.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {AIC in the Well-Specified Linear Model: Theory and
    Simulation},
  date = {2024-05-17},
  url = {https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“AIC in the Well-Specified Linear Model:
Theory and Simulation.”</span> May 17, 2024. <a href="https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/">https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/</a>.
</div></div></section></div> ]]></description>
  <category>Model Selection</category>
  <category>Linear Models</category>
  <category>Regression</category>
  <category>Statistics</category>
  <category>R</category>
  <guid>https://vgherard.github.io/posts/2024-05-09-aic-in-the-well-specified-linear-model-theory-and-simulation/</guid>
  <pubDate>Thu, 16 May 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Grammar as a biometric for Authorship Verification</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/</link>
  <description><![CDATA[ 





<p>About a month ago we finally managed to drop <span class="citation" data-cites="nini2024authorship">(Nini et al. 2024)</span>, <em>“Authorship Verification based on the Likelihood Ratio of Grammar Models”</em>, on the arXiv. Delving into topics such as authorship verification, grammar and forensics, was quite a detour for me, and I’d like to summarize here some of the ideas and learnings I got from working with all this new and interesting material.</p>
<p>The main qualitative idea put forward by Ref. <span class="citation" data-cites="nini2024authorship">(Nini et al. 2024)</span> is that <em>grammar is a fundamentally personal and unique trait of an individual</em>, therefore providing a sort of “behavioural biometric”. One first goal of this work was to put this general principle under test, by applying it to the problem of Authorship Verification (AV): the process of validating whether a certain document was written by a claimed author. Concretely, we built an algorithm for AV that relies entirely on the grammatical features of the examined textual data, and compared it with the state-of-the-art methods for AV.</p>
<p>The results were very encouraging. In fact, our method actually turned out to be generally superior to the previous state-of-the-art on the benchmarks we examined. This is a notable result, keeping also into account that our method uses <em>less</em> textual information (only the grammar part) than other methods to perform its inferences.</p>
<section id="the-algorithm" class="level2">
<h2 class="anchored" data-anchor-id="the-algorithm">The algorithm</h2>
<p>I sketch here a pseudo-implementation of our method in R. For the fit of <img src="https://latex.codecogs.com/png.latex?k">-gram models and perplexity computations, I use my package <a href="https://vgherard.github.io/kgrams/"><code>{kgrams}</code></a>, which can be installed from CRAN. Model (hyper)parameters such as number of impostors, order of the <img src="https://latex.codecogs.com/png.latex?k">-gram models, etc. are hardcoded, see <span class="citation" data-cites="nini2024authorship">(Nini et al. 2024)</span> for details.</p>
<p>This is just for illustrating the essence of the method. For practical reasons, in the code chunk below I’m not reproducing the definition of the function <code>extract_grammar()</code>, which in our work is embodied by the POS-noise algorithm. This function should transform a regular sentence, such as “He wrote a sentence”, to its underlying grammatical structure, say “[Pronoun] [verb] a [noun]”.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param q_doc character. Text document whose authorship is questioned.</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param auth_corpus character. Text corpus of claimed author.</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param imp_corpus character. Text corpus of impostors.</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param n_imp a positive number. Number of "impostor" simulations.</span></span>
<span id="cb1-5"></span>
<span id="cb1-6">score <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(q_doc, auth_corpus, imp_corpus, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_imp =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) </span>
<span id="cb1-7">{</span>
<span id="cb1-8">    q_doc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_grammar</span>(q_doc)</span>
<span id="cb1-9">    auth_corpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_grammar</span>(auth_corpus)</span>
<span id="cb1-10">    imp_corpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_grammar</span>(imp_corpus)</span>
<span id="cb1-11"></span>
<span id="cb1-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute perplexity based on claimed author's language model.</span></span>
<span id="cb1-13">    auth_mod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">train_language_model</span>(auth_corpus)</span>
<span id="cb1-14">  auth_perp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">perplexity</span>(q_doc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> auth_mod)</span>
<span id="cb1-15">  </span>
<span id="cb1-16">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute perplexity based on impostor language models.</span></span>
<span id="cb1-17">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb1-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Each impostor is trained on a synthetic corpus obtained by sampling from</span></span>
<span id="cb1-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the impostor corpus the same number of sentences as the corpus of the </span></span>
<span id="cb1-20">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># claimed author.</span></span>
<span id="cb1-21">  n_sents_auth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tknz_sent</span>(auth_corpus))</span>
<span id="cb1-22">  imp_corpus_sentences <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tknz_sent</span>(imp_corpus)</span>
<span id="cb1-23">  imp_mod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(n_imp, {</span>
<span id="cb1-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(imp_corpus_sentences, n_sents_auth) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">train_language_model</span>()</span>
<span id="cb1-25">  })</span>
<span id="cb1-26">  imp_perp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(imp_mod, \(m) kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">perplexity</span>(q_doc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> m))</span>
<span id="cb1-27">  </span>
<span id="cb1-28">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Score is the fraction of impostor models that perform worse (higher </span></span>
<span id="cb1-29">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># perplexity) than the proposed authors language model</span></span>
<span id="cb1-30">  score <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(auth_perp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> imp_perp)</span>
<span id="cb1-31">  </span>
<span id="cb1-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(score)</span>
<span id="cb1-33">}</span>
<span id="cb1-34"></span>
<span id="cb1-35">train_language_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(text)</span>
<span id="cb1-36">{</span>
<span id="cb1-37">  text <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-38">    kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kgram_freqs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.tknz_sent =</span> kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>tknz_sent) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-39">    kgrams<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">language_model</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">smoother =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kn"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">D =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb1-40">}</span>
<span id="cb1-41"></span>
<span id="cb1-42">extract_grammar <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> identity  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Just a placeholder - see above.</span></span></code></pre></div></div>
</div>
<p>To be used as follows:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">q_doc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a a b a. b a. c b a. b a b. a."</span> </span>
<span id="cb2-2">auth_corpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a a b a b. b c b. a b c a. b a. b c a."</span> </span>
<span id="cb2-3">imp_corpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a a. b. a. b a. b a. c. a b a. d. a b. a d. a b a b c b a."</span></span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">840</span>)</span>
<span id="cb2-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">score</span>(q_doc, auth_corpus, imp_corpus)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.89</code></pre>
</div>
</div>
<p>The “score” computed by this algorithm turns out to be a good truthfulness predictor for the claimed authorship, higher scores being correlated with true attributions. <em>If</em> the impostor corpus is fixed once and for all, and <em>if</em> the pairs <code>q_doc</code> and <code>auth_corpus</code> are randomly sampled from a fixed joint distribution, we can set a threshold for score in such a way that the attribution criterion <code>score &gt; threshold</code> maximizes some objective such as accuracy. This is, more or less, what we studied quantitatively in our paper.</p>
</section>
<section id="reflections-on-in-silico-authorship-verification" class="level2">
<h2 class="anchored" data-anchor-id="reflections-on-in-silico-authorship-verification">Reflections on <em>in silico</em> Authorship Verification</h2>
<p>The various <em>ifs</em> at the end of the previous sections led me to reflexionate on the applicability of machine-learning approaches, such as the one we discussed in our work, to real-life contexts.</p>
<p>As implied above, in order for a metric such as accuracy to represent a sensible measure of predictive performance, we should be able to regard the AV problems encountered in our favorite practical use case as random samples from some <em>fixed</em> population. In other words, we consider a stationary source of random authorship claims, and assume that our trained model is routinely used to verify claims from this source.</p>
<p>Now, while there are many circumstances in which the above assumptions make total sense, I think there are also interesting AV applications in which one is not interested in the long-run properties of the method but, rather, in a single inference. The real case of the poem “Shall I die?”, controversially attributed to Shakespeare in 1985, is an example of this kind. An approach to this case based on empirical Bayes is discussed in <span class="citation" data-cites="efron2021computer">(Efron and Hastie 2021, vol. 6, sec. 6.2)</span>. Although we may be able to build a reasonable impostor corpus to be used with this problem, it is not clear how one should come up with a relevant testing dataset of AV problems to empirically quantify uncertainty.</p>
<p>For cases such as the “Shall I die?” controversy, the machine-learning setting considered in our study is just an <em>in silico</em> model of real AV. As such, I believe it still provides useful indications on what could be good authorship indicators and work in general, but we must acknowledge the practical limitations in our way to quantify uncertainty. Other approaches, such as classical null hypothesis testing, may be more suited to this specific kind of AV problems.</p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-efron2021computer" class="csl-entry">
Efron, Bradley, and Trevor Hastie. 2021. <em>Computer Age Statistical Inference, Student Edition: Algorithms, Evidence, and Data Science</em>. Vol. 6. Cambridge University Press.
</div>
<div id="ref-nini2024authorship" class="csl-entry">
Nini, Andrea, Oren Halvani, Lukas Graner, Valerio Gherardi, and Shunichi Ishihara. 2024. <span>“Authorship Verification Based on the Likelihood Ratio of Grammar Models.”</span> <a href="https://arxiv.org/abs/2403.08462">https://arxiv.org/abs/2403.08462</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Grammar as a Biometric for {Authorship} {Verification}},
  date = {2024-04-25},
  url = {https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Grammar as a Biometric for Authorship
Verification.”</span> April 25, 2024. <a href="https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/">https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/</a>.
</div></div></section></div> ]]></description>
  <category>Authorship Verification</category>
  <category>Natural Language Processing</category>
  <category>Forensic Science</category>
  <category>Machine Learning</category>
  <category>Statistics</category>
  <category>R</category>
  <guid>https://vgherard.github.io/posts/2024-04-25-grammar-as-a-biometric-for-authorship-verification/</guid>
  <pubDate>Wed, 24 Apr 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>“Induction and Deduction in Bayesian Data Analysis” by A. Gelman</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-04-25-induction-and-deduction-in-bayesian-data-analysis-by-a-gelman/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="gelman2011induction">(Gelman 2011)</span>. From the paper’s abstract:</p>
<blockquote class="blockquote">
<p>The classical or frequentist approach to statistics (in which inference is centered on significance testing), is associated with a philosophy in which science is deductive and follows Popper’s doctrine of falsification. In contrast, Bayesian inference is commonly associated with inductive reasoning and the idea that a model can be dethroned by a competing model but can never be directly falsified by a significance test. The purpose of this article is to break these associations, which I think are incorrect and have been detrimental to statistical practice, in that they have steered falsificationists away from the very useful tools of Bayesian inference and have discouraged Bayesians from checking the fit of their models. From my experience using and developing Bayesian methods in social and environmental science, I have found model checking and falsification to be central in the modeling process.</p>
</blockquote>
<p>Comments:</p>
<ul>
<li><p>I don’t know nothing about applied Bayesian analysis, but I’m a bit surprised by the fact that the recommendation to check model’s fit requires a whole paper in the 21st century. What is the supposed argument why Bayesians should not worry about model fit?</p></li>
<li><p>I’m a bit confused about how one would actually interpret the model posterior checks discussed in the paper. If I understand correctly, the <img src="https://latex.codecogs.com/png.latex?p">-value is the posterior probability of observing a statistic as extreme as in the original data. Should I interpret this as a strength of evidence against the model - similar to Fisherian significance testing? What is the philosophical basis for rejecting models with small <img src="https://latex.codecogs.com/png.latex?p">-values? I guess these questions are answered in the technical references by the same author.</p></li>
</ul>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-gelman2011induction" class="csl-entry">
Gelman, Andrew. 2011. <span>“Induction and Deduction in Bayesian Data Analysis.”</span>
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {“{Induction} and {Deduction} in {Bayesian} {Data} {Analysis}”
    by {A.} {Gelman}},
  date = {2024-04-25},
  url = {https://vgherard.github.io/posts/2024-04-25-induction-and-deduction-in-bayesian-data-analysis-by-a-gelman/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“<span>‘Induction and Deduction in
Bayesian Data Analysis’</span> by A. Gelman.”</span> April 25, 2024. <a href="https://vgherard.github.io/posts/2024-04-25-induction-and-deduction-in-bayesian-data-analysis-by-a-gelman/">https://vgherard.github.io/posts/2024-04-25-induction-and-deduction-in-bayesian-data-analysis-by-a-gelman/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Bayesian Methods</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-04-25-induction-and-deduction-in-bayesian-data-analysis-by-a-gelman/</guid>
  <pubDate>Wed, 24 Apr 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>“The Abuse of Power” by J. M. Hoenig and D. M. Heisey</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-04-18-the-abuse-of-power-by-j-m-hoenig-and-d-m-heisey/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="hoenig2001abuse">(Hoenig and Heisey 2001)</span>. From the paper’s abstract:</p>
<blockquote class="blockquote">
<p>It is well known that statistical power calculations can be valuable in planning an experiment. There is also a large literature advocating that power calculations be made whenever one performs a statistical test of a hypothesis and one obtains a statistically nonsignificant result. Advocates of such post-experiment power calculations claim the calculations should be used to aid in the interpretation of the experimental results. This approach, which appears in various forms, is fundamentally flawed. We document that the problem is extensive and present arguments to demonstrate the flaw in the logic.</p>
</blockquote>
<p>The point on observed power is very elementary: for a given hypothesis test at a fixed size <img src="https://latex.codecogs.com/png.latex?%5Calpha">, observed power is a function of the observed <img src="https://latex.codecogs.com/png.latex?p">-value, and thus cannot add any information to the one already contained in the latter.</p>
<p>Observed power will be typically small for non-significant (<img src="https://latex.codecogs.com/png.latex?p%3E%5Calpha">) results, and high otherwise. The authors discuss the example of a one-tailed, one-sample <img src="https://latex.codecogs.com/png.latex?Z">-test for the null hypothesis that <img src="https://latex.codecogs.com/png.latex?Z%20%5Csim%20%5Cmathcal%20N%20(%5Cmu,%201)"> has mean <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cleq%200">. The <img src="https://latex.codecogs.com/png.latex?p">-value and observed power <img src="https://latex.codecogs.com/png.latex?%5Ctilde%20%5Cbeta"> are, respectively:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap%20=%201%20-%20%5CPhi(Z),%5Cquad%20%5Ctilde%5Cbeta=1-%5CPhi(Z_%5Calpha-Z),%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?Z_%5Calpha%20=%20%5CPhi%20%5E%7B-1%7D(1-%5Calpha)"> is the significance threshold at level <img src="https://latex.codecogs.com/png.latex?%5Calpha">. Below significance, one always has <img src="https://latex.codecogs.com/png.latex?Z%3CZ_%5Calpha">, implying low observed power <img src="https://latex.codecogs.com/png.latex?%5Ctilde%20%5Cbeta%20%3C%5Cfrac%7B1%7D%7B2%7D">. This implies that observed power cannot be used to tell whether a null result comes from a small effect or from a low detection capability.</p>
<p>The authors also criticize the notion of “detectable effect size”, but their arguments look less convincing to me in this case. In their example we have an i.i.d. sample <img src="https://latex.codecogs.com/png.latex?%5C%7BX_i%5C%7D_%7Bi=1%7D%5EN">, where <img src="https://latex.codecogs.com/png.latex?X_i%20%5Csim%20%5Cmathcal%20N(%5Cmu,%20%5Csigma%20%5E2)">, and we again test the null <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cleq%200">. For a fixed power <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, the detectable effect size is that value of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> that would yield a type II error rate of exactly <img src="https://latex.codecogs.com/png.latex?1-%5Cbeta">, if <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5E2"> is taken to be equal to the observer sample standard deviation. Their argument against this construct (Sec. 2.2) seems to rest on the premise that a smaller <img src="https://latex.codecogs.com/png.latex?p">-value should always be interpreted as stronger evidence against the null hypothesis, even when the <img src="https://latex.codecogs.com/png.latex?p">-value is not significant and the null hypothesis is accepted. But this is inconsistent, because <img src="https://latex.codecogs.com/png.latex?p">-values are uniformly distributed under the null hypothesis, so that their actual values should be given no meaning once this is accepted.</p>
<p>In fact, I would argue that the detectable effect size provides a decent heuristics to quantify the uncertainty of a non-significant result on the scale of the parameter of interest. The true point against its usage is that (as also recognized in this work) there is a tool available which is much more suited for the same purpose <sup>1</sup>, the <em>confidence interval</em>, which has a clear probabilistic characterization in terms of its coverage probability.</p>





<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-hoenig2001abuse" class="csl-entry">
Hoenig, John M, and Dennis M Heisey. 2001. <span>“The Abuse of Power: The Pervasive Fallacy of Power Calculations for Data Analysis.”</span> <em>The American Statistician</em> 55 (1): 19–24.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>In the previous example, assuming a large sample size <img src="https://latex.codecogs.com/png.latex?N"> so that we can approximate the <img src="https://latex.codecogs.com/png.latex?t"> distribution with a normal one, the <img src="https://latex.codecogs.com/png.latex?1-%5Calpha">-level lower limit on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> (appropriate for a one-sided test of the null hypothesis <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cleq%200">) is given by: <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu%20_%5Ctext%7Blo%7D%20=%20%5Coverline%20X-%5Cfrac%7Bs%7D%7B%5Csqrt%20N%7D%5CPhi%5E%7B-1%7D(1-%5Calpha),%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Coverline%20X"> and <img src="https://latex.codecogs.com/png.latex?s"> are the observed sample mean and standard deviation, respectively. The detectable effect size <img src="https://latex.codecogs.com/png.latex?d"> is the minimum value of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> such that <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(%5Cmu%20_%5Ctext%7Blo%7D%20%3E%200)%20%5Cgeq%201-%5Cbeta">, that is: <img src="https://latex.codecogs.com/png.latex?%0Ad%20=%20%5Cfrac%7Bs%7D%7B%5Csqrt%20N%7D%5Cleft%5B%5CPhi%5E%7B-1%7D(1-%5Calpha)+%5CPhi%5E%7B-1%7D(1-%5Cbeta)%5Cright%5D.%0A">↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {“{The} {Abuse} of {Power}” by {J.} {M.} {Hoenig} and {D.}
    {M.} {Heisey}},
  date = {2024-04-18},
  url = {https://vgherard.github.io/posts/2024-04-18-the-abuse-of-power-by-j-m-hoenig-and-d-m-heisey/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“<span>‘The Abuse of Power’</span> by J.
M. Hoenig and D. M. Heisey.”</span> April 18, 2024. <a href="https://vgherard.github.io/posts/2024-04-18-the-abuse-of-power-by-j-m-hoenig-and-d-m-heisey/">https://vgherard.github.io/posts/2024-04-18-the-abuse-of-power-by-j-m-hoenig-and-d-m-heisey/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Hypothesis Testing</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-04-18-the-abuse-of-power-by-j-m-hoenig-and-d-m-heisey/</guid>
  <pubDate>Wed, 17 Apr 2024 22:00:00 GMT</pubDate>
</item>
<item>
  <title>AIC for the linear model: known vs. unknown variance</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-03-13-aic-for-the-linear-model-known-vs-unknown-variance/</link>
  <description><![CDATA[ 





<p>The Akaike Information Criterion (AIC) for the linear model <img src="https://latex.codecogs.com/png.latex?Y%20=%20X%20%5Cbeta%20+%20%5Cvarepsilon">, with takes the form:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(k)%7D%7D%20=%20%5Cfrac%7B(%5Cmathbf%20Y-%5Cmathbf%20X%5Chat%20%5Cbeta%20)%5E2%7D%7B%5Csigma%20%5E2%7D%20+%202p%0A"></p>
<p>if the noise variance <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5E2%20=%20%5Cmathbb%20V(%5Cvarepsilon%5Cvert%20X)"> is known, and:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D%20=%20N%5Cln(%5Chat%20%5Csigma%20%5E2)%20+%202(p%20+%201)%0A"></p>
<p>if <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> is unknown. Here <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Cbeta"> denotes the maximum-likelihood estimate of <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, and <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Csigma%20%5E2%20=%20%5Cfrac%7B1%7D%7BN%7D(%5Cmathbf%20Y%20-%5Cmathbf%20X%20%5Chat%20%5Cbeta)%5E2"> the corresponding estimate of <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5E2"> if the latter is unknown; <img src="https://latex.codecogs.com/png.latex?p"> is the dimension of the covariate vector <img src="https://latex.codecogs.com/png.latex?X">.</p>
<p>One would expect knowledge on variance to have little effect on model selection for the mean, at least in a limit in which variance can be considered to be reasonably well estimated. In order to check that this is actually the case, we expand <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D"> differences to first order <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Csigma%20_1%20%5E2%20-%20%5Chat%20%5Csigma%20_2%20%5E2">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D_1-%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D_2%20&amp;=%20N%5Cln(%5Cfrac%7B%5Chat%20%5Csigma%20%5E2_1%7D%7B%5Chat%20%5Csigma%20%5E2_2%7D)%20+%202(p_1-p_2)%5C%5C%0A&amp;%5Capprox%20N%5Cfrac%7B%5Chat%20%5Csigma%20_%7B1%7D%5E2-%5Chat%20%5Csigma%20_2%20%5E2%7D%7B%5Chat%20%5Csigma%20_2%20%5E2%7D%20+%202(p_1-p_2)%5C%5C%0A&amp;%20=%20%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(k)%7D%7D_1-%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(k)%7D%7D_2+N%5Cfrac%7B(%5Chat%20%5Csigma%20_%7B1%7D%5E2-%5Chat%20%5Csigma%20_2%20%5E2)(%5Csigma%20%5E2-%5Chat%20%5Csigma%20_2%20%5E2)%7D%7B%5Chat%20%5Csigma%20_2%20%5E2%5Csigma%5E2%7D%0A%5Cend%7Bsplit%7D%0A"></p>
<p>The approximation in the second line requires <img src="https://latex.codecogs.com/png.latex?%5Cvert%20%5Chat%20%5Csigma%20_1%20%5E2%20-%20%5Chat%20%5Csigma%20_2%20%5E2%5Cvert%20%5Cll%5Chat%20%5Csigma%20_2%20%5E2">. Furthermore, the last term in the final expression is a small fraction of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D_1-%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D_2"> if <img src="https://latex.codecogs.com/png.latex?%7C%5Csigma%20%5E2%20-%5Chat%20%5Csigma%20_2%20%5E2%7C%20%5Cll%20%5Csigma%20%5E2">.</p>
<p>Putting these two conditions together, we obtain:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%7C%5Chat%20%5Csigma%20_1%20%5E2%20-%5Chat%20%5Csigma%20_2%20%5E2%7C,%7C%5Csigma%20%5E2%20-%5Chat%20%5Csigma%20_2%20%5E2%7C%20%5Cll%20%5Csigma%20%5E2,%5Cqquad%0A"></p>
<p>which means that <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(u)%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BAIC%7D%5E%7B%5Ctext%7B(k)%7D%7D"> lead to the same model selection provided that the models involved in the AIC comparison estimate reasonably well the true variance.</p>
<p>Concluding remarks:</p>
<ul>
<li><p>Although the maximum-likelihood estimates plugged in the AIC are derived from normal theory, the theorem about the equivalence of AIC selection in the known and unknown variance cases continues to hold irrespective of this assumption.</p></li>
<li><p>What happens in misspecified cases, in which <img src="https://latex.codecogs.com/png.latex?%5Chat%20%5Csigma%20%5E2"> does not consistently estimate <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20V(%5Cvarepsilon%20%5Cvert%20X)">, either because of non-linearity or heteroskedasticity?</p></li>
</ul>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {AIC for the Linear Model: Known Vs. Unknown Variance},
  date = {2024-03-13},
  url = {https://vgherard.github.io/posts/2024-03-13-aic-for-the-linear-model-known-vs-unknown-variance/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“AIC for the Linear Model: Known Vs.
Unknown Variance.”</span> March 13, 2024. <a href="https://vgherard.github.io/posts/2024-03-13-aic-for-the-linear-model-known-vs-unknown-variance/">https://vgherard.github.io/posts/2024-03-13-aic-for-the-linear-model-known-vs-unknown-variance/</a>.
</div></div></section></div> ]]></description>
  <category>Model Selection</category>
  <category>Linear Models</category>
  <category>Regression</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-03-13-aic-for-the-linear-model-known-vs-unknown-variance/</guid>
  <pubDate>Tue, 12 Mar 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>“A Closer Look at the Deviance” by T. Hastie</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-03-07-a-closer-look-at-the-deviance-by-t-hastie/</link>
  <description><![CDATA[ 





<p><span class="citation" data-cites="CloserLookDeviance">(Hastie 1987)</span>. This short review provides a compendium of useful results on the <em>deviance</em> defined by <img src="https://latex.codecogs.com/png.latex?%5Ctext%20-2%20%5Clog%20%5Cmathcal%20L%20+2%5Clog%5Cmathcal%20L%5E*">, where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20L%5E*"> denotes the likelihood of a “saturated” model, as explained in the paper. From the paper’s abstract:</p>
<blockquote class="blockquote">
<p>Prediction error and Kullback-Leibler distance provide a useful link between least squares and maximum likelihood estimation. This article is a summary of some existing results, with special reference to the deviance function popular in the GLIM literature.</p>
</blockquote>
<p>Of particular interest:</p>
<ul>
<li>Clarifies the definition of a “saturated” model for i.i.d. samples.</li>
<li>Highlights the parallels between <img src="https://latex.codecogs.com/png.latex?L_2"> and Kullback-Leibler loss. In particular, the expectation is shown to be the optimal regression function for the general KL loss.</li>
<li>Discusses optimism in the training error estimate of the in-sample (fixed predictors) error rate in terms of KL loss, within the context of Generalized Linear models.</li>
</ul>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-CloserLookDeviance" class="csl-entry">
Hastie, Trevor. 1987. <span>“A Closer Look at the Deviance.”</span> <em>The American Statistician</em> 41 (1): 16–20. <a href="https://doi.org/10.1080/00031305.1987.10475434">https://doi.org/10.1080/00031305.1987.10475434</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {“{A} {Closer} {Look} at the {Deviance}” by {T.} {Hastie}},
  date = {2024-03-07},
  url = {https://vgherard.github.io/posts/2024-03-07-a-closer-look-at-the-deviance-by-t-hastie/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“<span>‘A Closer Look at the
Deviance’</span> by T. Hastie.”</span> March 7, 2024. <a href="https://vgherard.github.io/posts/2024-03-07-a-closer-look-at-the-deviance-by-t-hastie/">https://vgherard.github.io/posts/2024-03-07-a-closer-look-at-the-deviance-by-t-hastie/</a>.
</div></div></section></div> ]]></description>
  <category>Comment on...</category>
  <category>Maximum Likelihood Estimation</category>
  <category>Linear Models</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-03-07-a-closer-look-at-the-deviance-by-t-hastie/</guid>
  <pubDate>Wed, 06 Mar 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>No binomial overdispersion from variations at the individual level</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-03-06-no-binomial-overdispersion-from-variations-at-the-individual-level/</link>
  <description><![CDATA[ 





<p>I came across some confusing statements regarding how <em>overdispersion</em> can arise in binary or count data, such as the typical <a href="https://en.wikipedia.org/wiki/Mark_and_recapture">capture-recapture</a> data encountered in Biology and Ecology. The term generally refers to a variance inflation with respect to the prediction of a specific statistical model (or family of models) for the data generating process under study. Such extra variability is sometimes ascribed to “inhomogeneities in the population”, a phrase that is not very precise from a mathematical point of view, and can be misleading without further qualification.</p>
<p>Let’s get to the point. Consider a binomial model:</p>
<p><span id="eq-binomial"><img src="https://latex.codecogs.com/png.latex?%0AB_%7BN,%5C,p%7D(k)%20=%20%5Cbinom%7BN%7D%7Bk%7Dp%5Ek(1-p)%5E%7BN-k%7D.%0A%5Ctag%7B1%7D"></span></p>
<p>For concreteness, imagine that we are studying survival in a population of animals, and Equation&nbsp;1 is proposed to model the survival probability of an initial cohort of <img src="https://latex.codecogs.com/png.latex?N"> individuals (from one year to the next, say).</p>
<p>Clearly, we should not expect <img src="https://latex.codecogs.com/png.latex?p"> to represent the survival probability for each single animal. In fact are a lot of factors that are only determined at the level of the individual and that could realistically affect survival: age, sex, weight, <em>etc.</em>. If we are not including any individual variable in our analysis (because they were not measured, for example) we may model the survival probability <img src="https://latex.codecogs.com/png.latex?q"> of any individual by a probability distribution <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi(q)"> with mean <img src="https://latex.codecogs.com/png.latex?%5Cbar%20q%20=%20%5Cint%20q%5C,%5Ctext%20d%20%5Cpi%20(q)">. If we further assume that survival probabilities of several individuals are independent and identically distributed (i.i.d.), we can derive explicitly the probability of <img src="https://latex.codecogs.com/png.latex?k"> survivals out of <img src="https://latex.codecogs.com/png.latex?N"> initial individuals:</p>
<p><span id="eq-binomial-derivation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Ctext%7BPr%7D(k)%20&amp;=%20%5Cintop%20%5Ctext%20d%5Cpi(q_1)%5Ctext%20d%5Cpi%20(q_2)%5Ccdots%20%5Ctext%20d%5Cpi(q_N)%5Csum%20_%7By%5Cin%20E_%7BN,k%7D%7D%5Cprod_%7Bi=1%7D%5ENq_i%5E%7By_i%7D(1-q_i)%5E%7B(1-y_i)%7D%5C%5C%0A&amp;%20=%20%5Csum%20_%7By%5Cin%20E_%7BN,k%7D%7D%5Cprod_%7Bi=1%7D%5EN%20%5Cleft(%5Cintop%20%5Ctext%20d%20%5Cpi(q_i)q_i%5E%7By_i%7D(1-q_i)%5E%7B(1-y_i)%7D%5Cright)%20%5C%5C%0A&amp;%20=%20%5Csum%20_%7By%5Cin%20E_%7BN,k%7D%7D%5Cprod_%7Bi=1%7D%5EN%20%5Cbar%20q%5E%7By_i%7D(1-%5Cbar%20q)%5E%7B1-y_i%7D%20%5C%5C%0A&amp;%20=%20B_%7BN,%5Cbar%20q%7D(k)%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B2%7D"></span></p>
<p>where we have denoted by <img src="https://latex.codecogs.com/png.latex?E_%7BN,k%7D"> the set of <img src="https://latex.codecogs.com/png.latex?Y%5Cin%20%5C%7B0,%5C,1%5C%7D%5EN"> such that <img src="https://latex.codecogs.com/png.latex?%5Csum%20_%7Bi=1%7D%5E%7BN%7DY_i=k">. Notice that the integrand in the first line of Equation&nbsp;2 is the conditional probability of <img src="https://latex.codecogs.com/png.latex?k"> successes out of <img src="https://latex.codecogs.com/png.latex?N"> trials with probabilities for the individual trials given by <img src="https://latex.codecogs.com/png.latex?q_1,%5C,q_2,%5C,%5Cdots,%5C,q_N">.</p>
<p>In other words, assuming that the survival probabilities of individuals are i.i.d. according to <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi%20(q)">, we see that the binomial distribution Equation&nbsp;1 holds exactly with <img src="https://latex.codecogs.com/png.latex?p%20=%20%5Cintop%20%5Ctext%20d%20%5Cpi%20(q)%20q"> for the unconditional (on individual level covariates) distribution of survivals. <em>A fortiori</em>, no overdispersion with respect to the binomial variance, <em>i.e.</em> <img src="https://latex.codecogs.com/png.latex?Np(1-p)">, is possible under these assumptions.</p>
<p>Let us examine a bit more in detail the i.i.d. assumption. First of all, we observe that “identically distributed” is not the same as “identical”, which would be the case if <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi%20(q)%20=%20%5Cdelta%20(q%20-%20%5Cbar%20q)%5Ctext%20dq">. Quite the contrary, the purpose of <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi%20(q)"> is exactly to reflect the variability of <img src="https://latex.codecogs.com/png.latex?q"> in the overall population. On the other hand, assuming all individuals are sampled from the <em>same</em> population, the distribution <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi"> is simply the result of such a sampling scheme, and it doesn’t really make sense to consider different distributions for different individuals. The only case in which we should use different <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20%5Cpi%20_i(q_i)"> distributions is if our experimental design involved systematically sampling individuals from distinct populations and putting them together into a single cohort (<em>e.g.</em> we always start with <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BN%7D%7B2%7D"> individuals from population <img src="https://latex.codecogs.com/png.latex?A"> and <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BN%7D%7B2%7D"> from population <img src="https://latex.codecogs.com/png.latex?B">). Finally, if the analysis included some individual covariate, such as <em>sex</em> or <em>age</em>, all the discussion would remain valid, with unconditional survival probabilities replaced by conditional (on <em>sex</em> and <em>age</em>) probabilities.</p>
<p>The rather strong assumption is, instead, independence. How could independence be violated? Suppose there is some set of variables <img src="https://latex.codecogs.com/png.latex?X"> not included in the analysis, which globally affect survival for all individuals - in our example <img src="https://latex.codecogs.com/png.latex?X"> may include for instance things like <em>food availability</em> and <em>metereological conditions</em>. Suppose, further, that survival probabilities are actually i.i.d. <em>conditional on</em> <img src="https://latex.codecogs.com/png.latex?X">, with joint distribution:</p>
<p><span id="eq-survival-cond-iid"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20%5CPi(q_1,q_2,%5Cdots,%20q_N%5Cvert%20X)=%5Ctext%20d%5Cpi(q_1%5Cvert%20X)%5Ctext%20d%5Cpi(q_2%5Cvert%20X)%5Ccdots%5Ctext%20d%5Cpi%20(q_N%5Cvert%20X)%0A%5Ctag%7B3%7D"></span></p>
<p>Then, unconditionally:</p>
<p><span id="eq-survival-cond-integrated"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20%5CPi(q_1,q_2,%5Cdots,%20q_N)=%5Cintop%20%5Ctext%20dF(X)%5C,%5Ctext%20d%5Cpi(q_1%5Cvert%20X)%5Ctext%20d%5Cpi(q_2%5Cvert%20X)%5Ccdots%5Ctext%20d%5Cpi%20(q_N%5Cvert%20X),%0A%5Ctag%7B4%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20F(X)"> is the marginal distribution of <img src="https://latex.codecogs.com/png.latex?X">. Crucially, this is in general not a product measure, and (looking back at our derivation, Equation&nbsp;2) we see that this dependence can indeed change the form of the resulting distribution - and lead to overdispersion with respect to the binomial expectation, in particular.</p>
<p>I think the discussion above clearly shows that binomial overdispersion is not caused by inhomogeneities in the population, if these are understood as random (patternless) variations at the individual level. Quite the contrary, what can easily make data look non-binomial is the presence of unobserved global factors that can change randomly between experimental repetitions, and influence (or simply correlate with) survival probability at the population level.</p>
<p>A few concluding remarks:</p>
<ul>
<li><p>From a pure mathematical point of view, in the limit in which initial cohorts are sampled from a single, infinite population, the validity of the i.i.d. assumption is guaranteed by <a href="https://en.wikipedia.org/wiki/De_Finetti%27s_theorem">De Finetti’s theorem on infinite exchangeable sequences</a> (in the finite case there are also guarantees of approximate validity). Clearly, if the experimental design involves sampling individuals from several populations in a systematic way, the resulting sequence of Bernoulli variables (alive/dead) is not exchangeable.</p></li>
<li><p>If the De Finetti measure in the previous point can change between different cohort releases, depending on some random and unmeasured parameter <img src="https://latex.codecogs.com/png.latex?X">, this will effectively lead to the same kind of dependence between individual probability parameters illustrated above.</p></li>
<li><p>Another form in which dependence may arise is when survival of one individual may influence, or simply correlate with, survival of other individuals. Imagine, for instance, that we may only observe individuals in pairs. Mathematically, this will again manifest in the form of non-exchangeability.</p></li>
</ul>
<p><strong>Further references:</strong></p>
<ul>
<li><span class="citation" data-cites="cox1989analysis">(Cox and Snell 1989)</span></li>
</ul>




<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-cox1989analysis" class="csl-entry">
Cox, D. R., and E. J. Snell. 1989. <em>Analysis of Binary Data, Second Edition</em>. Chapman &amp; Hall/CRC Monographs on Statistics &amp; Applied Probability. Taylor &amp; Francis.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {No Binomial Overdispersion from Variations at the Individual
    Level},
  date = {2024-03-06},
  url = {https://vgherard.github.io/posts/2024-03-06-no-binomial-overdispersion-from-variations-at-the-individual-level/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“No Binomial Overdispersion from
Variations at the Individual Level.”</span> March 6, 2024. <a href="https://vgherard.github.io/posts/2024-03-06-no-binomial-overdispersion-from-variations-at-the-individual-level/">https://vgherard.github.io/posts/2024-03-06-no-binomial-overdispersion-from-variations-at-the-individual-level/</a>.
</div></div></section></div> ]]></description>
  <category>Population Dynamics</category>
  <category>Biology</category>
  <category>Ecology</category>
  <category>Statistics</category>
  <guid>https://vgherard.github.io/posts/2024-03-06-no-binomial-overdispersion-from-variations-at-the-individual-level/</guid>
  <pubDate>Tue, 05 Mar 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>On the first and second laws of thermodynamics for open systems</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-02-29-on-the-first-and-second-laws-of-thermodynamics-for-open-systems/</link>
  <description><![CDATA[ 





<p>The first and second laws of thermodynamics for closed systems are commonly expressed as:</p>
<p><span id="eq-12-law-closed-gen"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7Bd%7DU%20-%5Cdelta%20W=%20%5Cdelta%20Q%20%5Cleq%20T'%5C,%5Ctext%20dS%20%5Cqquad%5Ctext%7B%5Bclosed%20system%5D%7D,%0A%5Ctag%7B1%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?U">, and <img src="https://latex.codecogs.com/png.latex?S"> denote the internal energy and entropy of the system, <img src="https://latex.codecogs.com/png.latex?T'"> is the temperature of the heat source, and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q"> are the amounts of energy transferred to the system in the form of heat and work, respectively. For concreteness, I will focus on volume work <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W%20=%20-p%5C,%5Ctext%20d%20V"> and reversible processes, so that the equal sign in Equation&nbsp;1 holds with the temperature of the source <img src="https://latex.codecogs.com/png.latex?T'"> being equal to <img src="https://latex.codecogs.com/png.latex?T">, the temperature of the system. Equation&nbsp;1 then implies:</p>
<p><span id="eq-12-law-closed-pv"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20U%20=%20T%5C,%5Ctext%20d%20S%20-%20p%20%5C,%5Ctext%20d%20V%5Cqquad%5Ctext%7B%5Bclosed%20system%5D%7D,%0A%5Ctag%7B2%7D"></span></p>
<p>from which we can identify:</p>
<p><span id="eq-partial-derivatives"><img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20S%7D%5Cright)_%7BV,N%7D%20=%20T,%20%5Cquad%20%5Cleft(%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20V%7D%5Cright)_%7BS,N%7D%20=%20-p%0A%5Ctag%7B3%7D"></span></p>
<p>In the previous equation, <img src="https://latex.codecogs.com/png.latex?N"> represents the quantity of matter (say number of moles) in the system. The suffixes indicate that the partial derivatives are taken at constant <img src="https://latex.codecogs.com/png.latex?N">, which may look trivial for closed systems. In open systems, however, <img src="https://latex.codecogs.com/png.latex?N"> can vary due to matter exchanges with the surrounding, so that the internal energy <img src="https://latex.codecogs.com/png.latex?U%20=%20U(S,V,N)"> is also a function of <img src="https://latex.codecogs.com/png.latex?N">, and this dependence defines the <em>chemical potential</em>:</p>
<p><span id="eq-chemical-potential"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu%20%5Cequiv%20%5Cleft(%5Cfrac%7B%5Cpartial%20U%7D%7B%5Cpartial%20N%7D%5Cright)_%7BS,V%7D.%0A%5Ctag%7B4%7D"></span></p>
<p>Putting this together with Equation&nbsp;3, we obtain a generalization of Equation&nbsp;2 for an open system:</p>
<p><span id="eq-12-law-open-pv"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20U%20=%20T%5Ctext%20d%20S%20-%20p%20%5Ctext%20d%20V%20+%20%5Cmu%20%5Ctext%20dN.%0A%5Ctag%7B5%7D"></span></p>
<p>One should realize that this equation represents, at the present stage, no more than a <em>mathematical definition</em> of the partial derivatives of <img src="https://latex.codecogs.com/png.latex?U">. In order to attach some physical content to it, we should connect the various terms appearing in Equation&nbsp;5 with <em>operatively defined</em> quantities.</p>
<p>To appreciate this point, let us make a step back to the closed system case, and examine the physical content of the first two laws of thermodynamics. For a closed system we have the relations <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W%20=%20-%20p%5C,%5Ctext%20dV"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q%20=%20T%5C,%5Ctext%20d%20S">. It is important to realize that <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q"> have independent operative definitions: <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W"> is defined as the work performed by external forces during the process considered, whereas <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q"> is defined as the difference <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q=%5Ctext%20d%20U%20-%20%5Cdelta%20W">. It is in light of these operative definitions that the laws of thermodynamics acquire physical content<sup>1</sup>.</p>
<p>In order to establish a similar physical interpretation for the open system case, let us decompose the change in internal energy as follows:</p>
<p><span id="eq-du-open-system"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20U%20=%20%5Cdelta%20Q%20+%20%5Cdelta%20W%20+%20%5Cdelta%20X.%0A%5Ctag%7B6%7D"></span></p>
<p>Here the first two terms correspond to heat and work, as before, while the new term <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20X"> accounts for energy exchange due to matter transfer. Comparing Equation&nbsp;6 and Equation&nbsp;5, and given the expressions of <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W"> in the closed system case, it is tempting to conclude that:</p>
<p><span id="eq-wrong-dq-dw-dx"><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20Q%20%5Coverset%7B?%7D%7B=%7D%20T%20%5Ctext%20d%20S,%5Cquad%20%5Cdelta%20W%20%5Coverset%7B?%7D%7B=%7D-p%5Ctext%20d%20V,%5Cquad%0A%5Cdelta%20X%20%5Coverset%7B?%7D%7B=%7D%20%5Cmu%20%5Ctext%20d%20N,%0A%5Ctag%7B7%7D"></span></p>
<p>but these identifications are easily seen to be <em>wrong</em>.</p>
<p>Before discussing the correct version of Equation&nbsp;7, let us comment why these identifications can be dangerously misleading. Consider a gas enclosed by rigid and thermally insulating walls, so that no energy exchange with the exterior in the form of heat is possible and, since volume is constant, also no work is possible (according to Equation&nbsp;7). Suppose now that we have some mechanism to inject a number <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20N"> of additional particles into the system. Due to what was said above, we would be lead to conclude that the corresponding variation of internal energy should be <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bd%7DU%20%20%5Coverset%7B?%7D%7B=%7D%20%5Cmu%20%5Ctext%20d%20N">, which is incorrect (the correct answer is discussed below).</p>
<p>The physical reason why Equation&nbsp;7 are wrong is that exchanged matter also carries an amount <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bd%7DS%5E%7B%5Ctext%7B(e)%7D%7D%20=%20s%5C,%5Ctext%20dN"> of entropy and has a volume <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bd%7DV%5E%7B%5Ctext%7B(e)%7D%7D%20=%20v%5C,%5Ctext%20dN">, where <img src="https://latex.codecogs.com/png.latex?s"> and <img src="https://latex.codecogs.com/png.latex?v"> are the entropy and volume per particle of the external source of matter (<img src="https://latex.codecogs.com/png.latex?s%20=%20%5Cfrac%7BS%7D%7BN%7D"> and <img src="https://latex.codecogs.com/png.latex?v%20=%20%5Cfrac%7BV%7D%7BN%7D"> if the exchanged particles are in thermal equilibrium with the open system). This additional entropy and volume flows must be kept into account in the corresponding variations for opens system, that become:</p>
<p><span id="eq-correct-ds-dv"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7Bd%7D%20S%20=%20%5Cfrac%7B%5Cdelta%20Q%7D%7BT%7D+s%5C,%5Ctext%20dN,%5Cquad%20-p%5Ctext%20dV=%20%5Cdelta%20W-p%5Ctext%20dV%5E%7B%5Ctext%7B(e)%7D%7D,%0A%5Ctag%7B8%7D"></span></p>
<p>Plugging this into Equation&nbsp;5 and comparing with Equation&nbsp;6, we obtain:</p>
<p><span id="eq-correct-dq-dw-dx"><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20Q%20=T%20%5Ctext%20d%20S-Ts%5C,%5Ctext%20dN,%5Cquad%20%5Cdelta%20W%20=-p%5Ctext%20d%20V+p%20v%5Ctext%20dN,%5Cquad%0A%5Cdelta%20X%20=%20u%5Ctext%20d%20N,%0A%5Ctag%7B9%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?u%20%5Cequiv%20%5Cmu%20+%20Ts-pv"> is the internal energy per particle (the chemical potential can be shown to be equal to the Gibbs energy per particle).</p>
<p>The meaning of Equation&nbsp;9 is best clarified with a few examples. Consider first a process which simply consists in bringing together two quantities <img src="https://latex.codecogs.com/png.latex?N"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20N"> of gas molecules kept at the same temperature <img src="https://latex.codecogs.com/png.latex?T"> and pressure <img src="https://latex.codecogs.com/png.latex?p">. This amounts to a mere rescaling of the original system by a factor <img src="https://latex.codecogs.com/png.latex?%5Clambda%20=%20(1+%5Cfrac%7B%5Ctext%20d%20N%7D%7BN%7D)">, so that all extensive quantities are simply scaled by this same factor:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%20d%20S%20=%20s%5Ctext%20dN=(%5Clambda%20-1)S,%5Cquad%20%5Ctext%20d%20V%20=%20v%5Ctext%20dN=%20(%5Clambda%20-1)V.%0A"> Clearly, this process involves no energy exchange in the form of heat or work, and we see indeed from Equation&nbsp;9 that:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20Q%20=%20%5Cdelta%20W%20=%200,%5Cquad%20%5Ctext%20d%20U%20=%20%5Cdelta%20X%20=%20u%20%5Ctext%20d%20N=(%5Clambda%20-%201)U%0A"> Had we neglected the extra terms <img src="https://latex.codecogs.com/png.latex?-T%5Ctext%20d%20S%20%5E%7B%5Ctext%7B(e)%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?+p%5Ctext%20d%20V%20%5E%7B%5Ctext%7B(e)%7D%7D"> in the equations for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W">, we would have concluded that the system has exchanged heat or performed work during such a null process.</p>
<p>As our second example, we consider a vapor-liquid phase transition. The vapor-liquid system, assumed to be in equilibrium, is enclosed in a cylinder with thermal conducting walls and surrounded by a medium at constant temperature <img src="https://latex.codecogs.com/png.latex?T">. A piston on one extremity of the cylinder allows to condense vapor by compression.</p>
<p>If we consider either the vapor or liquid phases as open systems, in an isobaric and isothermal transformation in which a quantity <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20N"> of vapor molecules is condensed, we have as in Equation&nbsp;9:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Ctext%20d%20U%20_i%20&amp;=%20%5Cdelta%20Q_i%20+%20%5Cdelta%20W_i%20+%20%5Cdelta%20X_i,%5C%5C%0A%5Cdelta%20Q_i%20&amp;=%20T%5C,%5Ctext%20dS_i-T%5C,s_i%20%5C,%5Ctext%20dN_i,%5C%5C%0A%5Cdelta%20W_i%20&amp;=-p%5C,%5Ctext%20d%20V_i+p%5C,v_i%5C,%5Ctext%20dN_i,%5C%5C%0A%5Cdelta%20X_i%20&amp;=%20u_i%5C,%5Ctext%20dN_i,%0A%5Cend%7Bsplit%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?i%20=%20%5Ctext%20%7Bl%20or%20v%7D"> (denoting liquid or vapor), and <img src="https://latex.codecogs.com/png.latex?%5Ctext%20dN_%7B%5Ctext%7Bl%7D%7D%20=%20-%5Ctext%20dN_%7B%5Ctext%7Bv%7D%7D%20%5Cequiv%20%5Ctext%20d%20N">. But, since specific quantities at the phase transition only depend on temperature, which is held constant, the overall changes in entropy and volume are simply equal to the amounts due to matter transfer <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20S_i%20=%20s_i%5C,%5Ctext%20d%20N_i"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20V_i%20=%20v_i%5C,%5Ctext%20d%20N_i">, which implies:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20Q_i%20=%20%5Cdelta%20W_i%20=%200,%5Cquad%20%5Cdelta%20X_i%20=u_i%5C,%5Ctext%20dN_i.%0A"> This is not unreasonable since, from the point of view of the open system, what is happening is simply that a quantity <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20N"> of vapor or liquid (that was produced before, somehow), is getting transferred to the system. This is entirely analogous to the previous example, in which two chunks of identical substance were simply joined together.</p>
<p>On the other hand, the conventional approach to the same problem treats the vapor-liquid system as a closed system. For this system, we can directly relate the changes in entropy and volume to heat and work:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20Q%20=%20T(s_%5Ctext%20l-s_%5Ctext%20v%20)%5Ctext%20dN,%5Cquad%5Cdelta%20W%20=%20-p(v_%5Ctext%20l-v_%5Ctext%20v%20)%5Ctext%20dN,%20%5Cquad%20%5Cdelta%20X=0,%0A"> which looks superficially different from the open system point of view.</p>
<p>There is no contradiction in the fact that <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q%20%5Cneq%20%5Cdelta%20Q_1+%5Cdelta%20Q%20_2"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W%20%5Cneq%20%5Cdelta%20W_1%20+%20%5Cdelta%20W_2">, since the open and closed system points of view are describing the condensation process from a very different angle. In order to see this, let’s imagine breaking down the process as follows. Starting with our system with internal energy <img src="https://latex.codecogs.com/png.latex?U_0">:</p>
<ol type="1">
<li>We separate an amount <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20N"> of vapor from the rest of the system, leaving the system with energy <img src="https://latex.codecogs.com/png.latex?U_1%20=%20U_0%20-%20u_%5Ctext%7Bv%7D%5Ctext%20dN">.</li>
<li>We heat and compress the small portion <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BdN%7D"> while keeping it at constant temperature and pressure, until it condenses completely. The energy transferred to the small mass is <img src="https://latex.codecogs.com/png.latex?(u_%5Ctext%7Bl%7D-u_%5Ctext%7Bv%7D)%5Ctext%20d%20N">, while the vapor-liquid system’s energy of course does not change, <img src="https://latex.codecogs.com/png.latex?U_2%20=%20U_1">.</li>
<li>We add the condensed liquid <img src="https://latex.codecogs.com/png.latex?%5Ctext%20d%20N"> back to the vapor-liquid system, whose energy becomes <img src="https://latex.codecogs.com/png.latex?U_3%20=%20U_2%20+%20u_%5Ctext%7Bl%7D%5Ctext%20d%20N=U_0%20+%20(u_%5Ctext%7Bl%7D-u_%5Ctext%7Bv%7D)%5Ctext%20dN"></li>
</ol>
<p>The crucial observation is that the open system point of view is only describing steps 1 and 3, while the closed system only describes step 2. The fact that <img src="https://latex.codecogs.com/png.latex?U_3%20-%20U_0%20=%20(u_%5Ctext%7Bl%7D-u_%5Ctext%7Bv%7D)%5Ctext%20d%20N">, implies that the two points of view lead to the same energy balance, as it should be. This can be easily verified:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Ctext%20d%20U%20&amp;=%20%5Cdelta%20Q%20+%20%5Cdelta%20W%5C%5C%0A&amp;=%5BT%5Ctext(s_%5Ctext%20l-s_%5Ctext%20v)-p(v_%5Ctext%20l-v_%5Ctext%20v)%5D%5Ctext%20dN%5C%5C%0A&amp;=%5Cdelta%20X_%5Ctext%20l+%20%5Cdelta%20X_%5Ctext%20v%5C%5C%0A&amp;=%20%5Ctext%20dU_%5Ctext%20l+%20%5Ctext%20d%20U_%5Ctext%20v%0A%5Cend%7Bsplit%7D%0A"></p>
<p>where in the third equality we used the fact that <img src="https://latex.codecogs.com/png.latex?%5Cmu_%5Ctext%20l%20=%20%5Cmu_%5Ctext%20v"> at the phase transition, so that <img src="https://latex.codecogs.com/png.latex?u_%5Ctext%20l%20-%20u_%5Ctext%20v%20=%20T%5Ctext(s_%5Ctext%20l-s_%5Ctext%20v)-p(v_%5Ctext%20l-v_%5Ctext%20v)">.</p>
<p>As a final note, let me mention that some references (especially from the engineering field) include the work required to transfer matter across the open system boundary in the definition of <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20X">, which thus becomes proportional to the molar <em>enthalpy</em> <img src="https://latex.codecogs.com/png.latex?h%20=%20u%20+%20pv"> (see <em>e.g.</em> <span class="citation" data-cites="knuiman2012relation">(Knuiman, Barneveld, and Besseling 2012)</span>). As a consequence, the external work performed on an open system simply reads <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20W%20=%20-%20p%20%5Ctext%20d%20V">, as in the closed system case. The reason why this could make sense is that if the “open system” is defined in terms of a (physical or imaginary) spatial boundary surface, which allows the flow of matter through some injection mechanism, one could be interested in the work resulting from the expansion of the boundary only - sometimes called <em>shaft work</em>, in contrast with the <em>flow work</em> <img src="https://latex.codecogs.com/png.latex?-p%20%5C,%5Ctext%20d%20V%5E%7B%5Ctext%7B(e)%7D%7D"> included in the enthalpy. In the way I see it, this leads to a cumbersome physical description in the context of the examples mentioned above.</p>





<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-knuiman2012relation" class="csl-entry">
Knuiman, Jan T, Peter A Barneveld, and Nicolaas AM Besseling. 2012. <span>“On the Relation Between the Fundamental Equation of Thermodynamics and the Energy Balance Equation in the Context of Closed and Open Systems.”</span> <em>Journal of Chemical Education</em> 89 (8): 968–72.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>The first law, in its essence, postulates the existence of certain experimental conditions (thermal insulation) under which the work required by any transformation of a thermodynamic system depends only on the initial and final states - allowing the definition of a state function <img src="https://latex.codecogs.com/png.latex?U">, the internal energy. Similarly, the second law postulates the existence of a state function <img src="https://latex.codecogs.com/png.latex?S"> that bounds the heat exchange with a source at temperature <img src="https://latex.codecogs.com/png.latex?T'"> by <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20Q%20%5Cleq%20T'%20%5C,%5Ctext%20d%20S">.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {On the First and Second Laws of Thermodynamics for Open
    Systems},
  date = {2024-03-04},
  url = {https://vgherard.github.io/posts/2024-02-29-on-the-first-and-second-laws-of-thermodynamics-for-open-systems/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“On the First and Second Laws of
Thermodynamics for Open Systems.”</span> March 4, 2024. <a href="https://vgherard.github.io/posts/2024-02-29-on-the-first-and-second-laws-of-thermodynamics-for-open-systems/">https://vgherard.github.io/posts/2024-02-29-on-the-first-and-second-laws-of-thermodynamics-for-open-systems/</a>.
</div></div></section></div> ]]></description>
  <category>Open Systems</category>
  <category>Thermodynamics</category>
  <category>Physics</category>
  <guid>https://vgherard.github.io/posts/2024-02-29-on-the-first-and-second-laws-of-thermodynamics-for-open-systems/</guid>
  <pubDate>Sun, 03 Mar 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Gravity waves in an ideal fluid</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-02-22-gravity-waves-in-an-ideal-fluid/</link>
  <description><![CDATA[ 





<section id="intro" class="level2">
<h2 class="anchored" data-anchor-id="intro">Intro</h2>
<p>We compare two derivations of the stability conditions for hydrostatic equilibrium of an ideal fluid:</p>
<ul>
<li>A “parcel” argument, that follows the motion of a small particle of fluid, ignoring the dynamics of the surroundings.</li>
<li>Standard linearization of the ideal fluid equations.</li>
</ul>
<p>The two derivations turn out to give the same answer, but the intermediate steps in the parcel argument contain some hidden assumptions, which are clarified in the second approach.</p>
</section>
<section id="the-parcel-method" class="level2">
<h2 class="anchored" data-anchor-id="the-parcel-method">The parcel method</h2>
<p>We start with a fluid at rest in a constant gravitational field <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20g%20=%20-g%5Chat%20%7B%5Cmathbf%20z%7D">, and consider a small portion of fluid initially located at height <img src="https://latex.codecogs.com/png.latex?z_0">. We imagine that this parcel is now vertically displaced to height <img src="https://latex.codecogs.com/png.latex?z_1%20=%20z_0%20+%20%5Cdelta%20z">, and that no heat is transferred between the parcel and the surroundings during this process. We further assume that the pressure inside the parcel rapidly equalizes with the pressure outside of it (on a time scale much shorter than the one involved in the displacement). Finally, <em>we assume that the whole process does not appreciably alter the pressure field</em> <img src="https://latex.codecogs.com/png.latex?p"> with respect to its equilibrium configuration, satisfying <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20d%20p%7D%7B%5Ctext%20d%20z%7D=%20-%5Crho%20g">, where <img src="https://latex.codecogs.com/png.latex?%5Crho"> is the fluid’s density at rest. To anticipate, in the second derivation below, we will see that the last assumption may actually fail, giving rise to different dynamics than the one discussed in these Section.</p>
<p>The derivation below follows <span class="citation" data-cites="landau2013fluid">(Landau and Lifshitz 2013)</span>. The parcel’s acceleration in the vertical direction is given by Newton’s second law:</p>
<p><span id="eq-newton-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Crho%20_%5Ctext%7Bp%7D%5Cddot%20%7B%5Cdelta%20z%7D=-%5Crho%20_%5Ctext%7Bp%7Dg-%5Cfrac%7B%5Ctext%7Bd%7Dp%7D%7B%5Ctext%7Bd%7Dz%7D=-(%5Crho%20_%5Ctext%7Bp%7D-%5Crho)g,%0A%5Ctag%7B1%7D"></span></p>
<p>where the equilibrium assumption was used in the second equality, where <img src="https://latex.codecogs.com/png.latex?%5Crho%20_%5Ctext%7Bp%7D"> is the parcel’s density, while <img src="https://latex.codecogs.com/png.latex?%5Crho"> is the density of the surroundings evaluated at the parcel’s height <img src="https://latex.codecogs.com/png.latex?z_1=z_0%20+%20%5Cdelta%20z">.</p>
<p>Using the thermodynamic state equation of the fluid, we can express densities in terms of pressure <img src="https://latex.codecogs.com/png.latex?p"> and specific entropy <img src="https://latex.codecogs.com/png.latex?s">. For the fluid density, this means:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Crho%20=%20%5Crho(p(z_1),%5C,s(z_1)),%0A"> while for the parcel we have:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Crho%20_%5Ctext%7Bp%7D%20=%20%5Crho%20(p(z_1),%20s(z_0)),%0A"> due to the fact that the process is adiabatic. Hence, expanding the right hand side of Equation&nbsp;1 to first order in <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20z">, we obtain:</p>
<p><span id="eq-osc-arm"><img src="https://latex.codecogs.com/png.latex?%0A%5Cddot%20%7B%5Cdelta%20z%7D%20=%20-%5COmega%20%20%5E2%20%5Cdelta%20z,%0A%5Ctag%7B2%7D"></span></p>
<p>where:</p>
<p><span id="eq-bv-freq"><img src="https://latex.codecogs.com/png.latex?%0A%5COmega%20%20%5E2%20%5Cequiv%20-%5Cdfrac%7Bg%7D%7B%5Crho%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20s%7D%5Cright)_p%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D=-%5Cdfrac%7Bg%7D%7B%5Crho%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20s%7D%5Cright)_p%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D,%0A%5Ctag%7B3%7D"></span></p>
<p>is called the <em>Brunt–Väisälä frequency</em>, or <em>buoyancy frequency</em> (all quantities in this equation can be evaluated at <img src="https://latex.codecogs.com/png.latex?z%20=%20z_0"> in the linear approximation we are considering). Equations Equation&nbsp;2 imply that, in order for hydrostatic equilibrium to be stable, we must have <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2%20%3E%200">, that is:</p>
<p><span id="eq-equilibrium-cond"><img src="https://latex.codecogs.com/png.latex?%0A-%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20s%7D%5Cright)_p%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D%20%3E%200%0A%5Ctag%7B4%7D"></span></p>
<p>There are a few alternative ways to express Equation&nbsp;4. First of all, using the Maxwell relation <img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20s%7D%5Cright)_p=%5Cfrac%7BT%7D%7Bc_p%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20T%7D%5Cright)_p">, we see that equilibrium requires:</p>
<p><span id="eq-equilibrium-cond-1"><img src="https://latex.codecogs.com/png.latex?%0A-%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20T%7D%5Cright)_p%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D%3E0.%0A%5Ctag%7B5%7D"></span></p>
<p>Moreover, assuming <img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%20%7D%7B%5Cpartial%20T%7D%5Cright)_p%3C0">, this simplifies to:</p>
<p><span id="eq-equilibrium-cond-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D%20%3E0%0A%5Ctag%7B6%7D"></span></p>
<p>Considering <img src="https://latex.codecogs.com/png.latex?s"> as a function of <img src="https://latex.codecogs.com/png.latex?p"> and <img src="https://latex.codecogs.com/png.latex?T">, we have:</p>
<p><span id="eq-equilibrium-cond-3"><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ctext%20d%20s%7D%7B%5Ctext%20d%20z%7D%20=%20%5Cleft(%5Cfrac%7B%5Cpartial%20s%7D%7B%5Cpartial%20T%7D%5Cright)_p%20%5Cfrac%7B%5Ctext%20d%20T%7D%7B%5Ctext%20d%20z%7D+%5Cleft(%5Cfrac%7B%5Cpartial%20s%7D%7B%5Cpartial%20p%7D%5Cright)_T%20%5Cfrac%7B%5Ctext%20d%20p%7D%7B%5Ctext%20d%20z%7D=c_p%20%5Cfrac%7B%5Ctext%20d%20T%7D%7B%5Ctext%20d%20z%7D+%5Cleft(%5Cfrac%7B%5Cpartial%20V%7D%7B%5Cpartial%20T%7D%5Cright)_p%5Cfrac%7B%5Ctext%20d%20p%7D%7B%5Ctext%20d%20z%7D%3E0,%0A%5Ctag%7B7%7D"></span></p>
<p>where the Maxwell relation <img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cfrac%7B%5Cpartial%20s%7D%7B%5Cpartial%20p%7D%5Cright)_T=%5Cleft(%5Cfrac%7B%5Cpartial%20V%7D%7B%5Cpartial%20T%7D%5Cright)_p"> and the definition of the specific heat at constant pressure <img src="https://latex.codecogs.com/png.latex?c_p%20%5Cequiv%20%5Cleft(%5Cfrac%7B%5Cpartial%20s%7D%7B%5Cpartial%20p%7D%5Cright)_T"> were used. Finally, using again the equilibrium condition <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20d%20p%7D%7B%5Ctext%20d%20z%7D%20=%20-g%20/V">, we obtain</p>
<p><span id="eq-equilibrium-cond-4"><img src="https://latex.codecogs.com/png.latex?%0A-%5Cfrac%7B%5Ctext%20d%20T%7D%7B%5Ctext%20d%20z%7D%20%3C%20-%5Cfrac%7B%5Cbeta%20Tg%7D%7B%5Crho%20c_p%7D,%0A%5Ctag%7B8%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20%5Cequiv%20-%5Cfrac%7B1%7D%7B%5Crho%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Crho%7D%7B%5Cpartial%20T%7D%5Cright)_p"> is the thermal expansion coefficient. For an ideal gas, the right hand side is just <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bg%7D%7Bc_p%7D">.</p>
<p>The Brunt–Väisälä oscillation frequency (Equation&nbsp;3) is actually correct only in a certain limit, which is best clarified in the more careful approach, that proceeds from the ideal fluid equations. Nonetheless, the equilibrium condition <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2%20%3E0"> turns out to be correct.</p>
</section>
<section id="linearization-of-the-ideal-fluid-equations" class="level2">
<h2 class="anchored" data-anchor-id="linearization-of-the-ideal-fluid-equations">Linearization of the ideal fluid equations</h2>
<p>In fluid dynamics, our system would be described by the ideal fluid equations:</p>
<p><span id="eq-ideal-fluid-equations"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Cfrac%20%7B%5Ctext%20D%20%5Cmathbf%20v%7D%7B%5Ctext%20D%20t%7D&amp;=-%5Cfrac%7B%5Cnabla%20p%7D%7B%5Crho%20%7D+%5Cmathbf%20g,%0A%5C%5C%0A%5Cfrac%7B%5Ctext%20D%20%5Crho%20%7D%7B%5Ctext%20D%20t%7D%20&amp;=-%5Crho%20(%5Cnabla%20%5Ccdot%20%5Cmathbf%20v),%0A%5C%5C%0A%5Cfrac%7B%5Ctext%20D%20s%7D%7B%5Ctext%20D%20t%7D&amp;=0,%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B9%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20D%7D%7B%5Ctext%20D%20t%7D%20=%20%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20t%7D+%5Cmathbf%20v%20%5Ccdot%20%5Cnabla"> denotes the material derivative. The last equation can be exchanged for<sup>1</sup>:</p>
<p><span id="eq-pressure-mat-der"><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ctext%7BD%7Dp%7D%7B%5Ctext%20Dt%7D=c_s%5E2%5Cfrac%7B%5Ctext%20D%20%5Crho%7D%7B%5Ctext%20D%20t%7D%0A%5Ctag%7B10%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?c_s%5E2%20%5Cequiv%20(%5Cfrac%7B%5Cpartial%20p%7D%7B%5Cpartial%20%5Crho%7D)_s"> is the speed of sound. Denoting by <img src="https://latex.codecogs.com/png.latex?p_0"> and <img src="https://latex.codecogs.com/png.latex?%5Crho_0"> the pressure and density field of the hydrostatic solution, satisfying <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20p%20_0%20=%20%5Cmathbf%20g%20%5Crho%20_0">, we consider a perturbation of the form:</p>
<p><span id="eq-def-perturbation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%20v%20=%20%5Cdelta%20%5Cmathbf%20v,%5Cquad%20p=p_0+%5Cdelta%20p,%5Cquad%20%5Crho=%5Crho_0+%5Cdelta%20%5Crho.%0A%5Ctag%7B11%7D"></span></p>
<p>To linear order in the small quantities <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Cmathbf%20v">, <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20p"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Crho">, the equations of motion read:</p>
<p><span id="eq-lin-system-1"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A0%20&amp;=-%5Cfrac%20%7B%5Cpartial%20%20%5Cdelta%20%5Cmathbf%20v%7D%7B%5Cpartial%20t%7D-%5Cfrac%7B%5Cnabla%20(%5Cdelta%20p)%7D%7B%5Crho%20_0%7D+%5Cmathbf%20g%5Cfrac%7B%5Cdelta%20%5Crho%20%7D%7B%5Crho%20_0%7D,%0A%5C%5C%0A0%20&amp;=%5Cfrac%7B%5Cpartial%20(%5Cdelta%20%5Crho)%20%7D%7B%5Cpartial%20t%7D+%5Cdelta%5Cmathbf%20v%20%5Ccdot%20%5Cnabla%20%5Crho%20_0+%5Crho_0%20(%5Cnabla%20%5Ccdot%20%5Cdelta%20%5Cmathbf%20v)%20,%0A%5C%5C%0A0&amp;=%5Cfrac%7B%5Cpartial%20(%5Cdelta%20p%20)%7D%7B%5Cpartial%20t%7D+%5Cdelta%20%5Cmathbf%20v%20%5Ccdot%20%5Cnabla%20p_0-c_s%5E2%5Cfrac%7B%5Cpartial%20(%5Cdelta%20%5Crho%20)%7D%7B%5Cpartial%20t%7D-c_s%5E2%5Cmathbf%20%5Cdelta%20%5Cmathbf%20v%20%5Ccdot%20%5Cnabla%20%5Crho_0.%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B12%7D"></span></p>
<p>These equations take a rather simple form if we re-express them in terms of the mass flux density <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20j%20=%20%5Crho%20%5Cmathbf%20v">, that is <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Cmathbf%20j%20=%20%5Crho%20_0%20%5Cdelta%20%5Cmathbf%20v"> to linear order. Before doing so, we notice that:</p>
<p><span id="eq-grad-rho"><img src="https://latex.codecogs.com/png.latex?%0A%5Cnabla%20%5Crho_0=(%5Cfrac%20%7B%5Cpartial%20%5Crho%7D%7B%5Cpartial%20p%7D)_s%5Cnabla%20p_0+(%5Cfrac%20%7B%5Cpartial%20%5Crho%7D%7B%5Cpartial%20s%7D)_p%5Cnabla%20s=-(%5Cfrac%7Bg%7D%7Bc_s%5E2%7D%20+%5Cfrac%7B%5COmega%20%5E2%7D%7Bg%7D)%20%5Crho_0%20%5Chat%20%7B%5Cmathbf%20z%7D,%0A%5Ctag%7B13%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2"> is the buoyancy frequency defined above (<em>cf.</em> Equation&nbsp;3) and we assume, consistent with cylindrical symmetry, <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20s"> to lie in the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%7D"><sup>2</sup>. Putting everything together, we obtain:</p>
<p><span id="eq-lin-system-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A0%20&amp;=-%5Cfrac%20%7B%5Cpartial%20(%5Cdelta%20%5Cmathbf%20j)%7D%7B%5Cpartial%20t%7D-%5Cnabla%20(%5Cdelta%20p)+%5Cmathbf%20g%5Cdelta%20%5Crho,%0A%5C%5C%0A0%20&amp;=%5Cfrac%7B%5Cpartial%20(%5Cdelta%20%5Crho)%20%7D%7B%5Cpartial%20t%7D+%5Cnabla%20%5Ccdot%20(%5Cdelta%5Cmathbf%20j)%20,%0A%5C%5C%0A0&amp;=%5Cfrac%7B%5Cpartial%20(%5Cdelta%20p%20)%7D%7B%5Cpartial%20t%7D+c_s%5E2%5Cnabla%20%5Ccdot%20%20(%5Cdelta%20%5Cmathbf%20j)+%5Cfrac%7Bc_s%5E2%5COmega%20%5E2%7D%7Bg%7D(%5Cdelta%20%5Cmathbf%20j)%20%5Ccdot%20%20%5Chat%20%7B%5Cmathbf%20z%7D.%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B14%7D"></span></p>
<p>Strictly speaking, the quantities <img src="https://latex.codecogs.com/png.latex?c_s%5E2"> and <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2"> appearing in this equation are scalar fields with a non-trivial spatial variation. However, assuming that the spatial scale of the perturbation is much smaller than the typical scale of variation of <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2"> and <img src="https://latex.codecogs.com/png.latex?c_s%5E2">, we can treat these two numbers as constants. For simplicity, we will work with units such that <img src="https://latex.codecogs.com/png.latex?c_s%20=%20g%20=%201"> (this is the same as using <img src="https://latex.codecogs.com/png.latex?L=c_s%5E2g%5E%7B-1%7D"> and <img src="https://latex.codecogs.com/png.latex?T%20=%20c_sg%5E%7B-1%7D"> as units of time and length, respectively; the dependence from <img src="https://latex.codecogs.com/png.latex?c_s"> and <img src="https://latex.codecogs.com/png.latex?g"> can be reintroduced in the final formulas through dimensional analysis).</p>
<p>The system becomes then a linear system with constant coefficients, which suggests to search for simple solutions of the form:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%20j%20=%20%5Cmathbf%20u%20e%5E%7Bi(%5Comega%20t-%5Cmathbf%20q%20%20%5Ccdot%20%5Cmathbf%20r)%7D,%5Cquad%20%5Cmathbf%20%5Cdelta%20%5Crho%20=%20%5Calpha%20e%5E%7Bi(%5Comega%20t-%5Cmathbf%20q%20%20%5Ccdot%20%5Cmathbf%20r)%7D,%5Cquad%5Cdelta%20p%20=%20%5Cbeta%20e%5E%7Bi(%5Comega%20t-%5Cmathbf%20q%20%20%5Ccdot%20%5Cmathbf%20r)%7D.%0A"></p>
<p>Plugging these into the linearized system, we obtain:</p>
<p><span id="eq-lin-system-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A0%20&amp;=-i%5Comega%20%5Cmathbf%20u+i%5Cmathbf%20q%20%5Cbeta%20-%5Chat%20%7B%5Cmathbf%20z%7D%5Calpha,%0A%5C%5C%0A0%20&amp;=i%5Comega%20%5Calpha-i%5Cmathbf%20q%20%5Ccdot%20%5Cmathbf%20u%20,%0A%5C%5C%0A0&amp;=i%5Comega%20%5Cbeta%20+%5COmega%20%5E2%5Cmathbf%20u%20%5Ccdot%20%5Chat%7B%5Cmathbf%20z%7D-i%5Cmathbf%20q%20%5Ccdot%20%5Cmathbf%20u,%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B15%7D"></span></p>
<p>In order to solve these equations, we write:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%20q%20=%20q_z%20%5Chat%20%7B%5Cmathbf%20z%7D+q_%5Cperp%20%5Chat%20%7B%5Cmathbf%20x%7D.%0A"> From the first equation we obtain:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%20u%20%5Ccdot%20%5Chat%20%7B%5Cmathbf%20x%7D%20=%20%5Cfrac%7B%5Cbeta%20q_%5Cperp%7D%7B%5Comega%7D,%5Cquad%20%5Cmathbf%20u%20%5Ccdot%20%5Chat%7B%5Cmathbf%20y%7D%20=%200,%20%5Cquad%0A%5Cmathbf%20u%20%5Ccdot%20%5Chat%20%7B%5Cmathbf%20z%7D%20=%20%5Cfrac%7B%5Cbeta%20q_z+i%5Calpha%20%7D%7B%5Comega%7D.%0A"></p>
<p>The second equation then yields:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdfrac%7B%5Calpha%7D%7B%5Cbeta%7D=%5Cdfrac%20%7B%5Cmathbf%20q%5E2%7D%7B%5Comega%20%5E2%20-i%20q_z%7D%0A"></p>
<p>Finally, from the third equation we obtain:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A0%20=%5Comega%20%5E4%20-%5Comega%20%5E2%20%5Bi(1+%5COmega%20%5E2)%20q_z+%5Cmathbf%20q%5E2%5D+q_%5Cperp%20%5E2%5COmega%20%5E2%0A"></p>
<p>We now require <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20q"> to have an imaginary part <img src="https://latex.codecogs.com/png.latex?%5Ctext%20%7BIm%7D(%5Cmathbf%20q)%20=%20-%5Cfrac%7B1+%5COmega%20%5E2%7D%7B2%7D%5Chat%20%7B%5Cmathbf%20z%7D">, as we rigorously justify below. Under this assumption, the equation for <img src="https://latex.codecogs.com/png.latex?%5Comega%20%5E2"> has two real roots:</p>
<p><span id="eq-iff-freq"><img src="https://latex.codecogs.com/png.latex?%0A%5Comega%20%5E2_%5Cpm%20=%20%5Cfrac%20%7Bc_s%5E2%20(%5Cmathbf%20k%20%5E2+%5Clambda%5E%7B-2%7D)%7D%7B2%7D%5Cleft(1%5Cpm%20%5Csqrt%20%7B1-%5Cdfrac%7B4%5COmega%20%5E2k_%5Cperp%5E2%7D%7Bc_s%5E2%20(%5Cmathbf%20k%20%5E2+%5Clambda%5E%7B-2%7D)%5E2%7D%7D%5Cright),%0A%5Ctag%7B16%7D"></span></p>
<p>with:</p>
<p><span id="eq-lambda"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%20k%20=%20%5Ctext%7BRe%7D(%5Cmathbf%20q),%5Cqquad%20%20%5Clambda%5E%7B-1%7D%5Cequiv%20%5Cfrac%7B1%7D%7B2%7D(%20%5Cfrac%7Bg%7D%7Bc_s%5E2%7D%20+%5Cfrac%7B%5COmega%20%5E2%7D%7Bg%7D)%0A%5Ctag%7B17%7D"></span></p>
<p>(<img src="https://latex.codecogs.com/png.latex?g"> and <img src="https://latex.codecogs.com/png.latex?c_s"> have been reintroduced in these formulas as explained above).</p>
<p>Before proceeding further, we notice that the frequencies <img src="https://latex.codecogs.com/png.latex?%5Comega%20_-"> (those from the minus sign branch in Equation&nbsp;16) are real if and only if <img src="https://latex.codecogs.com/png.latex?%5COmega%20%5E2%20%3E%200">, which is the same as the equilibrium condition derived from the parcel argument. The actual frequencies of oscillation are not given by <img src="https://latex.codecogs.com/png.latex?%5COmega">, in general.</p>
</section>
<section id="physical-interpretation" class="level2">
<h2 class="anchored" data-anchor-id="physical-interpretation">Physical interpretation</h2>
<p>In order to understand the two branches of Equation&nbsp;16, we start by noticing that, for the whole linearization approach to be valid, we must have (in natural units <img src="https://latex.codecogs.com/png.latex?g=c_s=1">):</p>
<p><span id="eq-small-scale-approx"><img src="https://latex.codecogs.com/png.latex?%0A%5Cdfrac%7B4%5COmega%20%5E2k_%5Cperp%5E2%7D%7B(%5Cmathbf%20k%20%5E2+%5Clambda%5E%7B-2%7D)%5E2%7D%20%5Cll%201,%0A%5Ctag%7B18%7D"></span></p>
<p>This must be the case for the perturbation to be localized in the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%7D"> direction, which requires <img src="https://latex.codecogs.com/png.latex?k_z%20%5Cgg%201"> (notice that <img src="https://latex.codecogs.com/png.latex?%5COmega,%20%5Clambda%20%5Csim%20%5Cmathcal%20O(1)"> in natural units).</p>
<p>Assuming Equation&nbsp;18, we can approximate the two roots in Eq. Equation&nbsp;16 as follows:</p>
<p><span id="eq-iff-freq-approx"><img src="https://latex.codecogs.com/png.latex?%0A%5Comega%20%5E2_+%20%5Capprox%5Cmathbf%20k%20%5E2,%5Cqquad%5Comega%20%5E2_-%20%5Capprox%20%5Cfrac%7B%20k_%5Cperp%20%5E2%7D%7Bk_z%5E2+k_%5Cperp%20%5E2%7D%5COmega%20%5E2.%0A%5Ctag%7B19%7D"></span></p>
<p>We also notice that the fluid velocity field satisfies (without any approximation):</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bv_z%7D%7Bv_%5Cperp%7D%20=%20%5Cfrac%7Bk_z%7D%7Bk_%5Cperp%7D%5Cleft(%5Cdfrac%7B1+i%5Cfrac%7Bk_%5Cperp%5E2%7D%7Bk_z%5Comega%5E2%7D-i%5Cfrac%7B1+%5COmega%20%5E2%7D%7B2k_z%7D%7D%7B1-i%5Cfrac%7Bk_z%7D%7B%5Comega%5E2%7D-%5Cfrac%7B1+%5COmega%20%5E2%7D%7B2%5Comega%5E2%7D%7D%5Cright)%0A"> Let us first consider waves associated with <img src="https://latex.codecogs.com/png.latex?%5Comega%20_+">, which are essentially sound waves and for which gravity plays very little role. These have both phase and group velocity aligned with <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20k"> and close to <img src="https://latex.codecogs.com/png.latex?1"> (the speed of sound), and the fluid velocity is also in the direction of <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20k"> (the waves are longitudinal):</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bv_z%7D%7Bv_%5Cperp%7D%5Capprox%20%5Cfrac%7Bk_z%7D%7Bk_%5Cperp%20%7D,%0A"></p>
<p>In contrast, waves associated with <img src="https://latex.codecogs.com/png.latex?%5Comega%20_%7B-%7D">, called <em>gravity waves</em>, have vanishing phase and group velocity in the limit <img src="https://latex.codecogs.com/png.latex?k_z%20%5Cto%20%5Cinfty">, in general. The material velocity is perpendicular to <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20k">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bv_z%7D%7Bv_%5Cperp%7D%5Capprox%20-%5Cfrac%7Bk_%5Cperp%7D%7Bk_z%20%7D,%0A"> The wave frequency depends on the angle <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> between <img src="https://latex.codecogs.com/png.latex?k"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20g">, since <img src="https://latex.codecogs.com/png.latex?%5Comega%20_%7B-%7D%5E2%20=%20%5Csin%5E2%20%5Ctheta%20%5Ccdot%20%5COmega%20%5E2">. In particular, in the limit of plane waves in the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%7D"> direction, <em>i.e.</em> <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20%5Cto%200">, we have <img src="https://latex.codecogs.com/png.latex?%5Comega%20_%7B-%7D%5E2%20%5Cto%200">, while plane waves orthogonal to gravity <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20%5Cto%20%5Cfrac%7B%5Cpi%7D%7B2%7D"> have frequency <img src="https://latex.codecogs.com/png.latex?%5Comega%20_%7B-%7D%5E2%20%5Capprox%20%5COmega%20%5E2">. From the physical point of view, these two limits correspond to the cases in which the horizontal spatial scale of the perturbation is much larger/smaller than the vertical scale, respectively.</p>
<p>We realize that the kind of perturbation analysed in the parcel argument implicitly refers to gravity waves of the second type (with small horizontal scales). From Equation&nbsp;19, we see that the oscillation frequency coincides with the buoyancy frequency Equation&nbsp;3 only if <img src="https://latex.codecogs.com/png.latex?k%20_%5Cperp%20%5Cgg%20k_z">, that is, if the vertical spatial scale of the perturbation is much larger than its horizontal scale.</p>
<section id="mathematical-details-on-the-wave-solution" class="level4">
<h4 class="anchored" data-anchor-id="mathematical-details-on-the-wave-solution">Mathematical details on the wave solution</h4>
<p>In order to justify the procedure used in the derivation of the plane waves solutions, consider a <em>localized</em> perturbation (say with compact support) at <img src="https://latex.codecogs.com/png.latex?t%20=%200"> and let <img src="https://latex.codecogs.com/png.latex?%5CPsi(t=0)"> denote the vector of quantities <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Crho(t=0)">, <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20p%20(t=0)"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Cmathbf%20j%20(t=0)">. Since <img src="https://latex.codecogs.com/png.latex?%5CPsi(t=0)"> is localized, we can define:</p>
<p><span id="eq-modified-fourier"><img src="https://latex.codecogs.com/png.latex?%0A%5Cwidetilde%20%5CPsi(%5Cmathbf%20k,t=0)=%5Cintop%20%5Ctext%20d%20%5E3%20%5Cmathbf%20r%20%5C,e%5E%7Bi%5Cmathbf%20k%20%5Ccdot%20%5Cmathbf%20r%7D%20e%5E%7Bz/%5Clambda%7D%20%5CPsi(%5Cmathbf%20r,%20t=0)%0A%5Ctag%7B20%7D"></span> and the inverse of the Fourier transform gives:</p>
<p><span id="eq-modified-fourier-inverse"><img src="https://latex.codecogs.com/png.latex?%0A%5CPsi(%5Cmathbf%20r,%20t=0)%20=%20e%5E%7B-z/%5Clambda%7D%5Cintop%20%20%5Cfrac%7B%5Ctext%20d%20%5E3%5Cmathbf%20k%7D%7B(2%5Cpi)%5E3%7D%20e%5E%7B-i%5Cmathbf%20k%20%5Ccdot%20%5Cmathbf%20r%7D%5Cwidetilde%20%5CPsi(%5Cmathbf%20k,t=0).%0A%5Ctag%7B21%7D"></span></p>
<p>The Fourier components <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%20%5CPsi%20(%5Cmathbf%20k,%20t)"> for a fixed <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20k"> satisfy a linear system of ordinary differential equations, for which we already found four independent solutions (two for each frequency) in the previous Section. The fifth solution can be easily verified to correspond to a static, divergence-less velocity perturbation, with the velocity field orthogonal to the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%7D"> axis:</p>
<p><span id="eq-last-solution"><img src="https://latex.codecogs.com/png.latex?%0A%5Cwidetilde%20%7B%5Cdelta%20%5Cmathbf%20j%7D(%5Cmathbf%20k%20,t)%20=%20f(%5Cmathbf%20k)%20%5C,%7B%5Cmathbf%20k%7D%20%5Ctimes%20%5Cmathbf%20g,%5Cqquad%20%5Cwidetilde%20%7B%5Cdelta%20p%7D=0%5Cqquad%5Cwidetilde%20%7B%5Cdelta%20%5Crho%7D%20=%200%0A%5Ctag%7B22%7D"></span></p>
<p>In momentum space, in the basis provided by the four eigenvectors with eigenvalues given by Equation&nbsp;16, plus this last (static) solution, time evolution is trivial.</p>
<p>As a parenthetical remark, we notice that if we drop the requirement of a <em>localized</em> perturbation, we can have additional solutions that are not covered by the previous remarks. A trivial example is that of an hydrostatic equations - <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20p%20=%20%5Cmathbf%20g%20%5Crho">, with <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%5Cmathbf%20j%20=%20%5Cmathbf%200">, all fields being independent of time. These solutions are clearly not localized, since the pressure field changes only in the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%20%7D"> direction. Another example is provided by Lamb waves, that satisfy the constraint:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20%5Cmathbf%20j%20%5Ccdot%20%5Chat%20%7B%5Cmathbf%20z%7D%20=%200%0A"></p>
<p>and take the general form:</p>
<p><span id="eq-lamb-waves"><img src="https://latex.codecogs.com/png.latex?%0A%5CPsi(%5Cmathbf%20r,t)%20=%20e%5E%7B-(%5Cfrac%7B%5COmega%20%5E2%7D%7Bg%7D-%5Cfrac%7Bg%7D%7Bc_s%5E2%7D)z%7D%5Cintop%20%5Cfrac%7B%5Ctext%20d%20%5E2%20%5Cmathbf%20k%20_%5Cperp%7D%7B(2%5Cpi)%5E2%7D%20e%5E%7B-i%5Cmathbf%20k%20_%5Cperp%20%5Ccdot%20%5Cmathbf%20r%7D%20%20%5Cleft%5Ba(%5Cmathbf%20k%20_%5Cperp)e%5E%7Bi%20kc_st%7D+b(%5Cmathbf%20k%20_%5Cperp)e%5E%7B-i%20kc_st%7D%5Cright%5D.%0A%5Ctag%7B23%7D"></span></p>
<p>These waves are clearly not localized in the <img src="https://latex.codecogs.com/png.latex?%5Chat%20%7B%5Cmathbf%20z%7D"> direction.</p>
</section>
</section>
<section id="further-problems" class="level2">
<h2 class="anchored" data-anchor-id="further-problems">Further problems</h2>
<p>This is the point where I felt the algebra was getting a bit too involved and I left the problem. There are still a few things that it may be interesting to investigate. In particular, it would be nice to derive the explicit evolution of a wave packet, say:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta%20%5Cmathbf%20v%20(%5Cmathbf%20r,%200)%20=%20%5Cmathbf%20V%20%5Cexp%5Cleft%5B%7B-%5Cfrac%7Bx%5E2+y%5E2%7D%7B2%5Csigma%20_%5Cperp%5E2%7D-%5Cfrac%7Bz%5E2%7D%7B2%5Csigma%20_z%5E2%7D%7D%5Cright%5D.%0A"> with vanishing density and pressure perturbation (to simplify the algebra a little bit). One should compute the “modified” Fourier transform Equation&nbsp;20 and express the coefficients in terms of the five eigenvectors derived above. Perturbations like this will in general give rise to a combination of acoustic and longitudinal waves, depending on the direction of <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%20V"> and on the ratio of vertical and horizontal scales, <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_z"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_%5Cperp">.</p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-landau2013fluid" class="csl-entry">
Landau, Lev Davidovich, and Evgenii Mikhailovich Lifshitz. 2013. <em>Fluid Mechanics: Landau and Lifshitz: Course of Theoretical Physics, Volume 6</em>. Vol. 6. Elsevier.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>In order to see this, we simply write <img src="https://latex.codecogs.com/png.latex?p%20=%20p(%5Crho,%20s)"> as a function of <img src="https://latex.codecogs.com/png.latex?%5Crho"> and <img src="https://latex.codecogs.com/png.latex?s"> and take the material derivative.↩︎</p></li>
<li id="fn2"><p>From the pure mathematical point of view, this is not a strict consequence of Equation&nbsp;9, which are in fact consistent with any static density configuration, as long as <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20p%20=%20%5Cmathbf%20g%20%5Crho"> is satisfied. The physical reason is, of course, that we’re neglecting thermal conductivity, which allows for an arbitrary temperature gradient to persist forever in the absence of motion.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Gravity Waves in an Ideal Fluid},
  date = {2024-02-22},
  url = {https://vgherard.github.io/posts/2024-02-22-gravity-waves-in-an-ideal-fluid/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Gravity Waves in an Ideal Fluid.”</span>
February 22, 2024. <a href="https://vgherard.github.io/posts/2024-02-22-gravity-waves-in-an-ideal-fluid/">https://vgherard.github.io/posts/2024-02-22-gravity-waves-in-an-ideal-fluid/</a>.
</div></div></section></div> ]]></description>
  <category>Atmospheric Physics</category>
  <category>Fluid Dynamics</category>
  <category>Waves</category>
  <category>Physics</category>
  <guid>https://vgherard.github.io/posts/2024-02-22-gravity-waves-in-an-ideal-fluid/</guid>
  <pubDate>Wed, 21 Feb 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Binary digits of uniform random variables</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2024-01-29-binary-digits-of-uniform-random-variables/</link>
  <description><![CDATA[ 





<p>Let <img src="https://latex.codecogs.com/png.latex?X"> be a random number in the unit interval <img src="https://latex.codecogs.com/png.latex?%5B0,%5C,1%5D">, and let <img src="https://latex.codecogs.com/png.latex?Z%20%5Cequiv%20(Z_k)_%7Bk%5Cin%20%5Cmathbb%20N%7D"> represent the sequence of its binary digits, so that <img src="https://latex.codecogs.com/png.latex?Z_k%20%5Cin%20%5C%7B0,%5C,1%5C%7D"> for all <img src="https://latex.codecogs.com/png.latex?k"> and:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AX%20=%20%5Csum%20_%7Bk%20=%201%7D%20%5E%5Cinfty%20Z_k%20%5Ccdot%202%5E%7B-k%7D%0A"> Notice that the representation <img src="https://latex.codecogs.com/png.latex?Z"> is unique for all <img src="https://latex.codecogs.com/png.latex?X"> outside of a countable subset of the unit interval.<sup>1</sup></p>
<p>The cool theorem proved below is that <img src="https://latex.codecogs.com/png.latex?X"> is uniformly distributed in <img src="https://latex.codecogs.com/png.latex?%5B0,%5C,1%5D"> if and only if all <img src="https://latex.codecogs.com/png.latex?Z_k">’s are independent and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Z_k%20=%201)%20=%20%5Ctext%7BPr%7D(Z_k%20=%200)%20=%20%5Cfrac%7B1%7D%7B2%7D">. That is to say, the binary representation <img src="https://latex.codecogs.com/png.latex?Z"> of a random variable <img src="https://latex.codecogs.com/png.latex?X%5Csim%20%5Ctext%7BUnif%7D(0,%5C,1)"> amounts to a sequence of independent fair coin tosses.</p>
<p>We fix <img src="https://latex.codecogs.com/png.latex?n%20%5Cin%20%5Cmathbb%20N"> and decompose the unit interval as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5B0,1)%20=%20%5Ccup%20_%7Bj%20=%201%7D%20%5E%7B2%5En%7D%20I%5En_j,%5Cquad%20I%5En_j%20=%20%5B(j-1)%20%5Ccdot2%5E%7B-n%7D,j%5Ccdot2%5E%7B-n%7D)%0A"> Each interval <img src="https://latex.codecogs.com/png.latex?I%5En_j"> corresponds to a specific set of values for the first <img src="https://latex.codecogs.com/png.latex?n"> digits <img src="https://latex.codecogs.com/png.latex?Z_1,%5C,Z_2,%5C,%5Cdots,%5C,Z_n">, that is <img src="https://latex.codecogs.com/png.latex?X%5Cin%20I%5En%20_j"> if and only if <img src="https://latex.codecogs.com/png.latex?Z_1%20=%20z_1,%5C,Z_2%20=z_2,%5C,%5Cdots,%5C,Z_n=z_n"> for some <img src="https://latex.codecogs.com/png.latex?z_1,%5C,z_2,%5C,%5Cdots,%5C,z_n"> that depend on the interval <img src="https://latex.codecogs.com/png.latex?I%5En%20_j">. Therefore:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(X%5Cin%20I%5En%20_j)%20=%20%5Ctext%7BPr%7D(Z_1%20=%20z_1,%5C,Z_2%20=%20z_2,%5C,%5Cdots,%5C,Z_n%20=%20z_n)%0A"> Now, <img src="https://latex.codecogs.com/png.latex?X"> is uniformly distributed if and only if the left hand side of this equation equals <img src="https://latex.codecogs.com/png.latex?2%5E%7B-n%7D"> for all <img src="https://latex.codecogs.com/png.latex?n%5Cin%20%5Cmathbb%20N"> and <img src="https://latex.codecogs.com/png.latex?1%5Cleq%20j%20%5Cleq%202%5E%7Bn%7D"> <sup>2</sup>. Furthermore, the <img src="https://latex.codecogs.com/png.latex?2%5E%7Bn%7D"> possible values of <img src="https://latex.codecogs.com/png.latex?j"> correspond to the <img src="https://latex.codecogs.com/png.latex?2%5E%7Bn%7D"> possible values of <img src="https://latex.codecogs.com/png.latex?z_1,%5C,z_2,%5C,%5Cdots,%5C,z_n"> in the right hand side. Therefore, <img src="https://latex.codecogs.com/png.latex?X"> is uniform if and only if:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(Z_1%20=%20z_1,%5C,Z_2%20=%20z_2,%5C,%5Cdots,%5C,Z_n%20=%20z_n)%20=%202%5E%7B-n%7D%0A"> for all <img src="https://latex.codecogs.com/png.latex?z_1,%5C,z_2,%5C,%5Cdots,%5C,z_n%20%5Cin%20%5C%7B0,%5C,1%5C%7D">. More generally, this implies that, for any <img src="https://latex.codecogs.com/png.latex?k%20%5Cin%20%5Cmathbb%20N%20%5Ccup%20%5C%7B0%5C%7D"> we have:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(Z_%7Bk+1%7D%20=%20z_1,%5C,Z_%7Bk+2%7D%20=%20z_2,%5C,%5Cdots,%5C,Z_%7Bk+n%7D%20=%20z_n)%20=%202%5E%7B-n%7D%20=%20%5Cprod%20_%7Bi=1%7D%5E%7Bn%7D%5Ctext%7BPr%7D(Z_%7Bk+i%7D%20=%20z_i),%0A"></p>
<p>where the second equality follows from the special case <img src="https://latex.codecogs.com/png.latex?n=1">. This is equivalent to saying that all <img src="https://latex.codecogs.com/png.latex?Z_k">’s are independent, each having <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Z_k%20=%201)%20=%20%5Ctext%7BPr%7D(Z_k%20=%200)%20=%20%5Cfrac%7B1%7D%7B2%7D">.</p>




<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>That is, the set of numbers that have a <em>finite</em> expansion <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Csum%20_%7Bk%20=%201%7D%20%5EN%20Z_k%20%5Ccdot%202%5E%7B-k%7D"> for some finite <img src="https://latex.codecogs.com/png.latex?N">, with <img src="https://latex.codecogs.com/png.latex?Z_N%20=%201">. These numbers also have the equivalent infinite expansion <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Csum%20_%7Bk%20=%201%7D%20%5E%7BN-1%7D%20Z_k%20%5Ccdot%202%5E%7B-k%7D%20+%20%5Csum%20_%7Bk%20=%20N+1%7D%20%5E%7B%5Cinfty%7D2%5E%7B-k%7D">. For these numbers we can make the convention of using the first (finite) representation.↩︎</p></li>
<li id="fn2"><p>That this is sufficient follows from the fact that any interval of the real line can be obtained by taking countable unions and intersections of intervals of the form <img src="https://latex.codecogs.com/png.latex?I%5En%20_j">.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2024,
  author = {Gherardi, Valerio},
  title = {Binary Digits of Uniform Random Variables},
  date = {2024-01-29},
  url = {https://vgherard.github.io/posts/2024-01-29-binary-digits-of-uniform-random-variables/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2024" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2024. <span>“Binary Digits of Uniform Random
Variables.”</span> January 29, 2024. <a href="https://vgherard.github.io/posts/2024-01-29-binary-digits-of-uniform-random-variables/">https://vgherard.github.io/posts/2024-01-29-binary-digits-of-uniform-random-variables/</a>.
</div></div></section></div> ]]></description>
  <category>Probability Theory</category>
  <guid>https://vgherard.github.io/posts/2024-01-29-binary-digits-of-uniform-random-variables/</guid>
  <pubDate>Sun, 28 Jan 2024 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Interpreting the Likelihood Ratio cost</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/</link>
  <description><![CDATA[ 





<section id="intro" class="level2">
<h2 class="anchored" data-anchor-id="intro">Intro</h2>
<p>During the last few months, I’ve been working on a machine learning algorithm with applications in <a href="https://en.wikipedia.org/wiki/Forensic_science">Forensic Science</a>, a.k.a. Criminalistics. In this field, one common task for the data analyst is to present the <em>trier-of-fact</em> (the person or people who determine the facts in a legal proceeding) with a numerical assessment of the strength of the evidence provided by available data towards different hypotheses. In more familiar terms, the forensic expert is responsible of computing the likelihoods (or likelihood ratios) of data under competing hypotheses, which are then used by the trier-of-fact to produce Bayesian posterior probabilities for the hypotheses in question<sup>1</sup>.</p>
<p>In relation to this, forensic scientists have developed a bunch of techniques to evaluate the performance of a likelihood ratio model in discriminating between two alternative hypothesis. In particular, I have come across the so called <em>Likelihood Ratio Cost</em>, usually defined as:</p>
<p><span id="eq-cllr"><img src="https://latex.codecogs.com/png.latex?%0AC_%7B%5Ctext%7BLLR%7D%7D%20=%20%5Cfrac%7B1%7D%7B2N_1%7D%20%5Csum%20_%7BY_i=1%7D%20%5Clog(1+r(X_i)%20%5E%7B-1%7D)+%5Cfrac%7B1%7D%7B2N_0%7D%20%5Csum%20_%7BY_i=0%7D%20%5Clog(1+r(X_i)),%0A%5Ctag%7B1%7D"></span> where we assume we have data consisting of <img src="https://latex.codecogs.com/png.latex?N_1+N_0"> independent identically distributed observations <img src="https://latex.codecogs.com/png.latex?(X_i,%5C,Y_i)">, with binary <img src="https://latex.codecogs.com/png.latex?Y">; <img src="https://latex.codecogs.com/png.latex?N_1"> and <img src="https://latex.codecogs.com/png.latex?N_0"> stand for the number of positive (<img src="https://latex.codecogs.com/png.latex?Y=1">) and negative (<img src="https://latex.codecogs.com/png.latex?Y=0">) cases; and <img src="https://latex.codecogs.com/png.latex?r(X)"> is a model for the likelihood ratio <img src="https://latex.codecogs.com/png.latex?%5CLambda(X)%20%5Cequiv%20%5Cfrac%7B%5Ctext%7BPr%7D(X%5Cvert%20Y%20=%201)%7D%7B%5Ctext%7BPr%7D(X%5Cvert%20Y%20=%200)%7D">.</p>
<p>The main reason for writing this note was to understand a bit better what it means to optimize Equation&nbsp;1, which does not look immediately obvious to me from its definition<sup>2</sup>. In particular: is the population minimizer of Equation&nbsp;1 the actual likelihood ratio? And in what sense is a model with lower <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> better than one with a correspondingly higher value?</p>
<p>The short answers to these questions are: yes; and: <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> optimization seeks for the model with the best predictive performance in a Bayesian inference setting with uninformative prior on <img src="https://latex.codecogs.com/png.latex?Y">, assuming that this prior actually reflects reality (<em>i.e.</em> <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Y=1)%20=%20%5Ctext%7BPr%7D(Y=0)%20=%20%5Cfrac%7B1%7D%7B2%7D">). The mathematical details are given in the rest of the post.</p>
<!-- Strictly speaking, there are several aspects to what I have simply referred to as the "performance of a likelihood ratio model". First of all, there is the -->
<!-- left-over uncertainty on $Y$ after measuring $X$, which is an intrinsic property of the data and is independent of modeling. Second, $X$ may not correspond to raw data, but rather be the result of some data-processing/summary, which will in general reduce the amount of available information on $Y$. Finally, in the general case, the likelihood ratio $r(X)$ will not be an exact model, but only an approximation estimated from data. All this aspects get captured and mixed by @ref(eq:CLLR), luckily in a way that can be actually decomposed (see below). -->
</section>
<section id="cross-entropy-with-random-weights" class="level2">
<h2 class="anchored" data-anchor-id="cross-entropy-with-random-weights">Cross-entropy with random weights</h2>
<p>We start with a mathematical digression, which will turn out useful for further developments. Let <img src="https://latex.codecogs.com/png.latex?%5C%7B(X_i,%5C,Y_i)%5C%7D_%7Bi=1,%5C,2,%5C,%5Cdots,N%7D"> be independent draws from a joint distribution, with binary <img src="https://latex.codecogs.com/png.latex?Y_i%20%5Cin%20%5C%7B0,%5C,1%5C%7D">. Given a function <img src="https://latex.codecogs.com/png.latex?w=w(%5Cboldsymbol%20Y)"> that is symmetric in its arguments<sup>3</sup>, we define the random functional:</p>
<p><span id="eq-weighted-loss"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%20L_N%5Ew%5Bf%5D%20=%20-%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi=1%7D%20%5EN%20%5Cleft%5Bw(%5Cboldsymbol%20Y)Y_i%20%5Clog(f(X_i))+%20w(%7B%5Cboldsymbol%20Y%7D%5Ec)(%20Y_i%5Ec)%20%5Clog(f(X_i)%5Ec)%5Cright%5D,%0A%5Ctag%7B2%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?f=f(X)"> is any function satisfying <img src="https://latex.codecogs.com/png.latex?f(X)%5Cin%20%5B0,%5C,1%5D"> for all <img src="https://latex.codecogs.com/png.latex?X">, and we let <img src="https://latex.codecogs.com/png.latex?q%5Ec%20=%201-q"> for any number <img src="https://latex.codecogs.com/png.latex?q%20%5Cin%20%5B0,%5C,1%5D">. Notice that for <img src="https://latex.codecogs.com/png.latex?w(%5Cboldsymbol%7BY%7D)%20%5Cequiv%201">, this is just the usual cross-entropy loss.</p>
<p>We now look for the population minimizer of Equation&nbsp;2, <em>i.e.</em> the function <img src="https://latex.codecogs.com/png.latex?f_*"> that minimizes the functional <img src="https://latex.codecogs.com/png.latex?f%20%5Cmapsto%20%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)"><sup>4</sup>. Writing the expectation as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)%20=%20-%5Cfrac%7B1%7D%7BN%7D%5Csum%20_%7Bi=1%7D%20%5EN%20%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%5Cvert%20X_i)%5Ccdot%20%5Clog(f(X_i))+E(Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%20%5Ec)%5Cvert%20X_i)%5Ccdot%20%5Clog(f%5Ec(X_i))%5Cright%5D,%0A"> we can easily see that <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)"> is a convex functional with a unique minimum given by:</p>
<p><span id="eq-pop-minimizer"><img src="https://latex.codecogs.com/png.latex?%0Af_*(X_i)%20=%20%5Cfrac%7B1%7D%7B1+r(X_i)%5E%7B-1%7D%7D,%5Cquad%20r_*(X_i)%20=%20%5Cdfrac%7BE(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%5Cvert%20X_i)%7D%7BE(Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20X_i)%7D.%0A%5Ctag%7B3%7D"></span></p>
<p>The corresponding expected loss is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D)%20=%20%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20X_i)%5Ccdot%20%5Cmathcal%20H(f_*(X_i))%5Cright%5D,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20H(p)%20=%20-p%20%5Clog%20(p)%20-(1-p)%20%5Clog(1-p)"> is the entropy of a binary random variable <img src="https://latex.codecogs.com/png.latex?Z"> with probability <img src="https://latex.codecogs.com/png.latex?p%20=%20%5Ctext%7BPr%7D(Z=1)"> (the index <img src="https://latex.codecogs.com/png.latex?i"> in the previous expression can be any index, since data points are assumed to be identically distributed).</p>
<p>Before looking at values of <img src="https://latex.codecogs.com/png.latex?f"> other than <img src="https://latex.codecogs.com/png.latex?f_*">, we observe that the previous expectation can be succintly expressed as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D)%20=%20k%20%5Ccdot%20H%5E%5Cprime(Y%5Cvert%20X),%0A"></p>
<p>where</p>
<p><span id="eq-def-kappa"><img src="https://latex.codecogs.com/png.latex?%0Ak%20=%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec))%0A%5Ctag%7B4%7D"></span></p>
<p>and <img src="https://latex.codecogs.com/png.latex?H'(Y%5Cvert%20X)"> is the conditional entropy of <img src="https://latex.codecogs.com/png.latex?Y%5Cvert%20X"> with respect to a <em>different</em> probability measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime">, defined by:</p>
<p><span id="eq-def-pr-prime"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D%5E%5Cprime(E)%20=%20t%20%5Ccdot%20%5Ctext%20%7BPr%7D(E%20%5Cvert%20Y%20=%201)%20+%20(1-t)%5Ccdot%20%5Ctext%20%7BPr%7D(E%20%5Cvert%20Y%20=%200),%0A%5Ctag%7B5%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?t=%5Ctext%7BPr%7D%5E%5Cprime(Y=1)%5Cin%20%5B0,%5C,1%5D"> is fixed by the requirement<sup>5</sup>:</p>
<p><span id="eq-def-pr-prime-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cdfrac%7B%5Ctext%20%7BPr%7D%5E%5Cprime%20(Y=1)%7D%7B%5Ctext%7BPr%7D%5E%5Cprime%20(Y=0)%7D=%5Cdfrac%7B%5Ctext%20%7BPr%7D%20(Y=1)%7D%7B%5Ctext%7BPr%7D%20(Y=0)%7D%5Ccdot%5Cdfrac%7B%5Cmathbb%20E(w(%5Cboldsymbol%20Y)%5Cvert%20%5Csum%20_i%20Y_i%20%3E0)%7D%7B%5Cmathbb%20E(w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20%5Csum%20_i%20Y_i%5Ec%20%3E0)%7D.%0A%5Ctag%7B6%7D"></span></p>
<p>In terms of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime">, the population minimizers <img src="https://latex.codecogs.com/png.latex?f_*"> and <img src="https://latex.codecogs.com/png.latex?r_*"> in Equation&nbsp;3 can be simply expressed as:</p>
<p><span id="eq-pop-minimizer-2"><img src="https://latex.codecogs.com/png.latex?%0Ar_*(X)=%5Cdfrac%7B%5Ctext%20%7BPr%7D%5E%5Cprime(Y=1%5Cvert%20X)%7D%7B%5Ctext%20%7BPr%7D%5E%5Cprime(Y=0%5Cvert%20X)%7D,%5Cqquad%20f_*(X)=%5Ctext%20%7BPr%7D%5E%5Cprime(Y=1%5Cvert%20X).%0A%5Ctag%7B7%7D"></span></p>
<p>If now <img src="https://latex.codecogs.com/png.latex?f"> is an arbitrary function, we have:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)%20-%20%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D)%20&amp;=%20%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20X_i)%5Ccdot%20%5Cmathcal%20D(f_*(X_i)%5Cvert%20%5Cvert%20f(X_i))%5Cright%5D%0A&amp;=%20k%5Ccdot%20D(%5Ctext%7BPr%7D%5E%5Cprime%5Cvert%20%5Cvert%20%5Ctext%7BPr%7D%5E%5Cprime%20_f)%0A%5Cend%7Bsplit%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20D(p%5Cvert%20%5Cvert%20q)%20=%20p%20%5Clog%20(%5Cfrac%7Bp%7D%7Bq%7D)%20+%20(1-p)%20%5Clog%20(%5Cfrac%7B1-p%7D%7B1-q%7D)">, and <img src="https://latex.codecogs.com/png.latex?D(%5Ctext%7BPr%7D%5E%5Cprime%5Cvert%20%5Cvert%20%5Ctext%7BPr%7D%5E%5Cprime%20_f)"> is the Kullback-Liebler divergence between the measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime"> and the measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime%20_f"> defined by:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D%5E%5Cprime%20_f(Y%20=%201%5Cvert%20X)=f(X),%5Cqquad%20%5Ctext%7BPr%7D%5E%5Cprime%20_f(X)=%5Ctext%7BPr%7D%5E%5Cprime(X)%0A"> (notice that <img src="https://latex.codecogs.com/png.latex?%5Ctext%20%7BPr%7D%20%5E%7B%5Cprime%7D%20_%7Bf_*%7D%20%5Cequiv%20%5Ctext%7BPr%7D%20%5E%7B%5Cprime%7D"> by definition). Finally, suppose that <img src="https://latex.codecogs.com/png.latex?X%20=%20g(%5Cwidetilde%20X)"> for some random variable <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%20X">, and define the corresponding functional:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew%5B%5Cwidetilde%20f%5D%20%20=%20-%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi=1%7D%20%5EN%20%5Cleft%5Bw(%5Cboldsymbol%20Y)Y_i%20%5Clog(%5Cwidetilde%20f(%5Cwidetilde%20X))+%20w(%7B%5Cboldsymbol%20Y%7D%5Ec)(%20Y_i%5Ec)%20%5Clog(%5Cwidetilde%20f(%5Cwidetilde%20X)%5Ec)%5Cright%5D.%0A"> Then <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D%20=%20%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew%5Bf%20%5Ccirc%20g%5D">. If <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%20f%20%20_*%20="> is the population minimizer of <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew">, it follows that <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E%20(%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew%5B%5Cwidetilde%20f%20_*%5D)%20%5Cleq%20%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D)">.</p>
<p>Putting everything together, we can decompose the expected loss for a function <img src="https://latex.codecogs.com/png.latex?f=f(X)">, where <img src="https://latex.codecogs.com/png.latex?X=%20g(%5Cwidetilde%20X)">, in the following suggestive way:</p>
<p><span id="eq-decomposition-weighted-loss"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)%20&amp;=%20(L_N%20%5Ew)_%5Ctext%7Bmin%7D+(L_N%20%5Ew)_%5Ctext%7Bproc%7D%20+(L_N%20%5Ew)_%5Ctext%7Bmissp%7D,%5C%5C%0A(L_N%20%5Ew)_%5Ctext%7Bmin%7D&amp;%5Cequiv%5Cmathbb%20E(%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew%5B%7B%5Cwidetilde%20f%7D%20_*%5D)%20%20%5C%5C%20&amp;=%0A%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20%5Cwidetilde%20X%20_i)%5Ccdot%20%5Cmathcal%20H(%7B%5Cwidetilde%20f%7D%20_*(%5Cwidetilde%20X%20_i))%5Cright%5D%5C%5C%0A&amp;=k%5Ccdot%20H%5E%5Cprime(Y%5Cvert%20%5Cwidetilde%20X),%5C%5C%0A(L_N%20%5Ew)_%5Ctext%7Bproc%7D&amp;%5Cequiv%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D-%5Cwidetilde%7B%5Cmathcal%20L%7D%20_N%5Ew%5B%5Cphi_*%5D)%20%20%5C%5C&amp;%20=%0A%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20X_i)%5Ccdot%20%20%5Cmathcal%20H(f_*(X_i))%0A%5Cright%5D-%20(L_N%20%5Ew)_%5Ctext%7Bmin%7D%5C%5C%0A&amp;%20=%20k%5Ccdot%20I%5E%5Cprime(Y;%20%5Cwidetilde%20X%5Cvert%20X),%5C%5C%0A(L_N%20%5Ew)_%5Ctext%7Bmissp%7D%20&amp;%20%5Cequiv%20%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf%5D)%20-%20%5Cmathbb%20E(%5Cmathcal%20L%20_N%20%5Ew%20%5Bf_*%5D)%20%5C%5C&amp;=%20%5Cmathbb%20E%5Cleft%5B%20%5Cmathbb%20E(Y_i%5Ccdot%20w(%5Cboldsymbol%20Y)%20+%20Y_i%5Ec%5Ccdot%20w(%5Cboldsymbol%20Y%5Ec)%5Cvert%20X_i)%5Ccdot%20%20%5Cmathcal%20%20D(f_*(X_i)%5Cvert%20%5Cvert%20f(X_i))%5Cright%5D%5C%5C%20&amp;=k%5Ccdot%20D(%5Ctext%20%7BPr%7D%5E%5Cprime%5Cvert%20%5Cvert%20%5Ctext%20%7BPr%7D%5E%5Cprime%20_f),%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B8%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?k"> is defined in Equation&nbsp;4. In the equation for <img src="https://latex.codecogs.com/png.latex?(L%5Ew%20_N)_%5Ctext%7Bproc%7D"> we introduced the conditional mutual information (with respect to the measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime">), that satisfies [<span class="citation" data-cites="Cover2006">Cover and Thomas (2006)</span>]:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AI(%5Cwidetilde%20X;Y%5Cvert%20X)%20=%20I(%5Cwidetilde%20X,Y)-I(X,Y)%20=%20H(Y%5Cvert%20X)-H(Y%5Cvert%20%5Cwidetilde%20X).%0A"></p>
<p>The three components in Equation&nbsp;8 can be interpreted as follows: <img src="https://latex.codecogs.com/png.latex?(L_N%20%5Ew)_%5Ctext%7Bmin%7D"> represents the minimum expected loss achievable, given the data available <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%20X">; <img src="https://latex.codecogs.com/png.latex?(L_N%20%5Ew)_%5Ctext%7Bproc%7D"> accounts for the information lost in the processing transformation <img src="https://latex.codecogs.com/png.latex?X=g(%5Cwidetilde%20X)">; finally <img src="https://latex.codecogs.com/png.latex?(L_N%20%5Ew)_%5Ctext%7Bmissp%7D"> is due to misspecification, <em>i.e.</em> the fact that the model <img src="https://latex.codecogs.com/png.latex?f(X)"> for the true posterior probability <img src="https://latex.codecogs.com/png.latex?f_*(X)"> is an approximation.</p>
<p>All the information-theoretic quantities (and their corresponding operative interpretations hinted in the previous paragraph) make reference to the measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime"> defined by Equation&nbsp;5 and Equation&nbsp;6. This is merely the result of altering the proportion of positive (<img src="https://latex.codecogs.com/png.latex?Y=1">) and negative (<img src="https://latex.codecogs.com/png.latex?Y=0">) examples in the <img src="https://latex.codecogs.com/png.latex?X">-<img src="https://latex.codecogs.com/png.latex?Y"> joint distribution by a factor dictated by the weight function <img src="https://latex.codecogs.com/png.latex?w"> - while keeping conditional distributions such as <img src="https://latex.codecogs.com/png.latex?X%5Cvert%20Y"> unchanged.</p>
</section>
<section id="a-familiar-case-cross-entropy-loss" class="level2">
<h2 class="anchored" data-anchor-id="a-familiar-case-cross-entropy-loss">A familiar case: cross-entropy loss</h2>
<p>For <img src="https://latex.codecogs.com/png.latex?w(%5Cboldsymbol%20%7BY%7D)%20=%201">, the functional <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20%7BL%7D%20_%7BN%7D%20%5E%7Bw%7D%5Bf%5D"> coincides with the usual cross-entropy loss<sup>6</sup>:</p>
<p><span id="eq-cross-entropy-loss"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BCE%7D%5Bf%5D%20=%20-%5Cfrac%7B1%7D%7BN%7D%5Csum_%7Bi=1%7D%20%5EN%20%5Cleft%5BY_i%20%5Clog(f(X_i))+%20(1-Y_i)%20%5Clog(1-f(X_i))%5Cright%5D.%0A%5Ctag%7B9%7D"></span></p>
<p>From Equation&nbsp;6 we see that the measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%7B%5Cprime%7D"> coincides with the original <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D">, so that by Equation&nbsp;3 the population minimizer of Equation&nbsp;9 is <img src="https://latex.codecogs.com/png.latex?f_%7B*%7D(X)%20=%20%5Ctext%7BPr%7D(Y=1%5Cvert%20X)"> (independently of sample size). Since <img src="https://latex.codecogs.com/png.latex?k%20=%201"> (<em>cf.</em> Equation&nbsp;4), the decomposition Equation&nbsp;8 reads:</p>
<p><span id="eq-decomposition-ce"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Cmathbb%20E(%5Ctext%7BCE%7D%20%5Bf%5D)%20&amp;=%20(%5Ctext%7BCE%7D)_%5Ctext%7Bmin%7D+(%5Ctext%7BCE%7D)_%5Ctext%7Bproc%7D%20+(%5Ctext%7BCE%7D)_%5Ctext%7Bmissp%7D,%5C%5C%0A(%5Ctext%7BCE%7D)_%5Ctext%7Bmin%7D&amp;=H(Y%5Cvert%20%5Cwidetilde%20X),%5C%5C%0A(%5Ctext%7BCE%7D)_%5Ctext%7Bproc%7D&amp;=%20I(Y;%20%5Cwidetilde%20X%5Cvert%20X),%5C%5C%0A(%5Ctext%7BCE%7D)_%5Ctext%7Bmissp%7D%20&amp;=D(%5Ctext%20%7BPr%7D%5Cvert%20%5Cvert%20%5Ctext%20%7BPr%7D%20_%7Bf%7D),%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B10%7D"></span></p>
<p>where conditional entropy <img src="https://latex.codecogs.com/png.latex?H">, mutual information <img src="https://latex.codecogs.com/png.latex?I"> and relative entropy <img src="https://latex.codecogs.com/png.latex?D"> now simply refer to the original measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D">.</p>
</section>
<section id="the-likelihood-ratio-cost" class="level2">
<h2 class="anchored" data-anchor-id="the-likelihood-ratio-cost">The Likelihood Ratio Cost</h2>
<p>The quantity <img src="https://latex.codecogs.com/png.latex?C_%7B%5Ctext%7BLLR%7D%7D"> defined in Equation&nbsp;1 can be put in the general form Equation&nbsp;2, if we let <img src="https://latex.codecogs.com/png.latex?f(X)%20=%20(1+r(X)%5E%7B-1%7D)%5E%7B-1%7D"> and<sup>7</sup>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aw(%5Cboldsymbol%20Y)%20=%20%5Cleft(%5Cdfrac%7B2%7D%7BN%7D%5Csum%20_%7Bi%20=%201%7D%5E%7BN%7DY_j%20%5Cright)%5E%7B-1%7D%0A"> In what follows, I will consider a slight modification of the usual <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D">, defined by the weight function:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aw(%5Cboldsymbol%20Y)%20=%20%5Cdfrac%7B1%7D%7B2(N-1)%7D%5Csum%20_%7Bi%20=%201%7D%5E%7BN%7D(1-Y_j).%0A"> This yields Equation&nbsp;1 multiplied by <img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7BN_1N_0%7D%7BN(N-1)%7D">, which I will keep denoting as <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D">, with a slight abuse of notation.</p>
<p>We can easily compute<sup>8</sup>:</p>
<p><span id="eq-prior-cllr"><img src="https://latex.codecogs.com/png.latex?%0A%5Cdfrac%7B%5Ctext%20%7BPr%7D%5E%5Cprime%20(Y=1)%7D%7B%5Ctext%7BPr%7D%5E%5Cprime%20(Y=0)%7D=1,%0A%5Ctag%7B11%7D"></span></p>
<p>so that, by Equation&nbsp;3, the population minimizer of <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ar_*(X)%20=%20%5CLambda%20(X),%5Cquad%20f_*(X)=%5Cdfrac%7B1%7D%7B1+%5CLambda(X)%5E%7B-1%7D%7D,%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5CLambda(X)"> denotes the <em>likelihood-ratio</em> of <img src="https://latex.codecogs.com/png.latex?X">, schematically:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5CLambda(X)%5Cequiv%20%5Cdfrac%7B%5Ctext%7BPr%7D(X%5Cvert%20Y%20=%201)%7D%7B%5Ctext%7BPr%7D(X%5Cvert%20Y%20=%200)%7D.%0A"></p>
<p>The constant <img src="https://latex.codecogs.com/png.latex?k"> in Equation&nbsp;4 is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ak%20=%20%5Ctext%7BPr%7D(Y%20=%201)%5Ctext%7BPr%7D(Y%20=%200)=%5Ctext%7BVar%7D(Y)%0A"></p>
<p>The general decomposition Equation&nbsp;8 becomes: <span id="eq-decomposition-ce"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5Cmathbb%20E(C_%5Ctext%7BLLR%7D%20%5Bf%5D)%20&amp;=%20(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bmin%7D+(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bproc%7D%20+(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bmissp%7D,%5C%5C%0A(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bmin%7D&amp;=%5Ctext%7BVar%7D(Y)%5Ccdot%20H%5E%7B%5Cprime%7D(Y%5Cvert%20%5Cwidetilde%20X),%5C%5C%0A(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bproc%7D&amp;=%20%5Ctext%7BVar%7D(Y)%5Ccdot%20I%5E%7B%5Cprime%7D(Y;%20%5Cwidetilde%20X%5Cvert%20X),%5C%5C%0A(C_%5Ctext%7BLLR%7D)_%5Ctext%7Bmissp%7D%20&amp;=%5Ctext%7BVar%7D(Y)%5Ccdot%20D%5E%7B%5Cprime%7D(%5Ctext%20%7BPr%7D%5Cvert%20%5Cvert%20%5Ctext%20%7BPr%7D%20_%7Bf%7D),%0A%5Cend%7Bsplit%7D%0A%5Ctag%7B12%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime"> is now given by Equation&nbsp;11.</p>
</section>
<section id="discussion" class="level2">
<h2 class="anchored" data-anchor-id="discussion">Discussion</h2>
<p>The table below provides a comparison between cross-entropy and likelihood-ratio cost, summarizing the results from previous sections.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Cross-entropy</th>
<th>Likelihood Ratio Cost</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="https://latex.codecogs.com/png.latex?f_*(X)"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Y%20=%201%5Cvert%20X)"></td>
<td><img src="https://latex.codecogs.com/png.latex?(1+%5CLambda(X)%5E%7B-1%7D)%5E%7B-1%7D"></td>
</tr>
<tr class="even">
<td><img src="https://latex.codecogs.com/png.latex?r_*(X)">`</td>
<td>Posterior odds ratio</td>
<td>Likelihood ratio</td>
</tr>
<tr class="odd">
<td>Minimum Loss</td>
<td><img src="https://latex.codecogs.com/png.latex?H(Y%5Cvert%20%5Cwidetilde%20X)"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(Y)%20%5Ccdot%20H%5E%5Cprime(Y%5Cvert%20%5Cwidetilde%20X)"></td>
</tr>
<tr class="even">
<td>Processing Loss</td>
<td><img src="https://latex.codecogs.com/png.latex?I(Y;%20%5Cwidetilde%20X%5Cvert%20X)"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(Y)%20%5Ccdot%20I%5E%5Cprime(Y;%20%5Cwidetilde%20X%5Cvert%20X)"></td>
</tr>
<tr class="odd">
<td>Misspecification Loss</td>
<td><img src="https://latex.codecogs.com/png.latex?D(f_*%5Cvert%5Cvert%20f)"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(Y)%20%5Ccdot%20D%5E%5Cprime(f_*%5Cvert%5Cvert%20f)"></td>
</tr>
<tr class="even">
<td>Reference measure</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%7B%5Cprime%7D%20=%20%5Cfrac%7B%5Ctext%7BPr%7D(%5Ccdot%20%5Cvert%20Y%20=%201)+%5Ctext%7BPr%7D(%5Ccdot%20%5Cvert%20Y%20=%200)%7D%7B2%7D"></td>
</tr>
</tbody>
</table>
<p>The objective of <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> is found to be the likelihood ratio, as terminology suggests. The interpretation of model selection according to <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> minimization turns out to be slightly more involved, compared to cross-entropy, which we first review.</p>
<p>Suppose we are given a set of predictive models <img src="https://latex.codecogs.com/png.latex?%5C%7B%5Cmathcal%20M_i%5C%7D_%7Bi%5Cin%20I%7D">, each of which consists of a processing transformation, <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%20X%20%5Cmapsto%20X">, and an estimate of the posterior probability <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Y%20=%201%5Cvert%20X)">. When the sample size <img src="https://latex.codecogs.com/png.latex?N%20%5Cto%20%5Cinfty">, cross-entropy minimization will almost certainly select the model that minimizes <img src="https://latex.codecogs.com/png.latex?I(Y;%20%5Cwidetilde%20X%5Cvert%20X)%20+%20D(f_*%5Cvert%20%5Cvert%20f)">. Following standard Information Theory arguments, we can interpret this model as the statistically optimal compression algorithm for <img src="https://latex.codecogs.com/png.latex?Y">, assuming <img src="https://latex.codecogs.com/png.latex?X"> to be available at both the encoding and decoding ends.</p>
<p>The previous argument carries over <em>mutatis mutandi</em> to <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> minimization, with an important qualification: optimal average compression is now achieved for data distributed according to a different probability measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D'(%5Ccdot)%20=%20%5Cfrac%7B1%7D%7B2%7D%5Ctext%20%7BPr%7D(%5Ccdot%5Cvert%20Y%20=%201)%20+%20%5Cfrac%7B1%7D%7B2%7D%5Ctext%20%7BPr%7D(%5Ccdot%5Cvert%20Y%20=%200)">. In particular, according to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D'">, the likelihood ratio coincides with the posterior odds ratio, and <img src="https://latex.codecogs.com/png.latex?(1+%5CLambda(X)%5E%7B-1%7D)%5E%7B-1%7D"> coincides with posterior probability, which clarifies why we can measure differences from the true likelihood-ratio through the Kullback-Liebler divergence.</p>
<p>The measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D'"> is not just an abstruse mathematical construct: it is the result of balanced sampling from the original distribution, <em>i.e.</em> taking an equal number of positive and negative cases<sup>9</sup>. If the <img src="https://latex.codecogs.com/png.latex?(X,%5C,Y)"> distribution is already balanced, either by design or because of some underlying symmetry in the data generating process, our analysis implies that likelihood-ratio cost and cross-entropy minimization are essentially equivalent for <img src="https://latex.codecogs.com/png.latex?N%5Cto%20%5Cinfty">. In general, with <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%20(Y=1)%20%5Cneq%20%5Ctext%7BPr%7D%20(Y=0)">, this is not the case<sup>10</sup>.</p>
<p>The fact that <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> seeks for optimal predictors according to the balanced measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D'"> is, one could argue, not completely crazy from the point of view of forensic science, where “<img src="https://latex.codecogs.com/png.latex?Y%5Cin%5C%7B0,1%5C%7D">” often stands for a sort verdict (guilty <em>vs.</em> not guilty, say). Indeed, optimizing with respect to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime"> means that our predictions are designed to be optimal in a world in which the verdict could be <em>a priori</em> <img src="https://latex.codecogs.com/png.latex?Y=0"> or <img src="https://latex.codecogs.com/png.latex?Y=1"> with equal probability - which is what an unbiased trier-of-fact should ideally assume. Minimizing <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D">, we guard ourselves against any bias that may be implicit in the training dataset, extraneous to the <img src="https://latex.codecogs.com/png.latex?X">-<img src="https://latex.codecogs.com/png.latex?Y"> relation and not explicitly modeled, a feature that may be regarded as desirable from a legal standpoint.</p>
</section>
<section id="simulated-example" class="level2">
<h2 class="anchored" data-anchor-id="simulated-example">Simulated example</h2>
<p>In general, the posterior odd ratio and likelihood ratio differ only by a constant, so it is reasonable to try to fit the same functional form to both of them. Let us illustrate with a simulated example of this type the differences between cross-entropy and <img src="https://latex.codecogs.com/png.latex?C_%7B%5Ctext%7BLLR%7D%7D"> optimization mentioned in the previous Section.</p>
<p>Suppose that <img src="https://latex.codecogs.com/png.latex?X%20%5Cin%20%5Cmathbb%20R"> has conditional density: <img src="https://latex.codecogs.com/png.latex?%0A%5Cphi(X%5Cvert%20Y)%20=%20(2%5Cpi%5Csigma%20_Y%5E2)%5E%7B-%5Cfrac%7B1%7D%7B2%7D%7D%20%5Cexp(-%5Cfrac%7B(X-%5Cmu_Y)%5E2%7D%7B2%5Csigma%20_Y%5E2%7D)%0A"> and <img src="https://latex.codecogs.com/png.latex?Y"> has marginal probability <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Y%20=%201)%20=%20%5Cpi">. The true likelihood-ratio and posterior odds ratio are respectively given by:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bsplit%7D%0A%5CLambda%20(X)%20&amp;%0A%20%20%20%20%5Cequiv%20%5Cfrac%7B%5Cphi(X%5Cvert%20Y=1)%7D%7B%5Cphi(X%5Cvert%20Y=0)%7D%0A%20%20%20%20=%20e%20%5E%20%7Ba%20X%5E2%20+%20bX%20+c%7D,%5C%5C%0A%5Crho%20(X)%20&amp;%0A%20%20%20%20%5Cequiv%20%5Cfrac%7B%5Ctext%7BPr%7D(Y%20=%201%5Cvert%20X)%7D%7B%5Ctext%7BPr%7D(Y%20=%200%5Cvert%20X)%7D%0A%20%20%20%20=%20e%20%5E%20%7Ba%20X%20%5E%202%20+%20bX%20+c+d%7D,%0A%5Cend%7Bsplit%7D%0A"> where we have defined:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Aa%20%20%5Cequiv%20%5Cdfrac%7B%5Csigma%20_1%20%5E2%20-%5Csigma_0%20%5E2%7D%7B2%5Csigma%20_0%20%5E2%5Csigma_1%20%5E2%7D,%5Cquad%0Ab%20%20%5Cequiv%20%5Cmu%20_1%20-%20%5Cmu%20_0,%20%5Cquad%0Ac%20%20%5Cequiv%20%5Cdfrac%7B%5Cmu_0%5E2%7D%7B2%5Csigma_0%5E2%7D%20-%5Cdfrac%7B%5Cmu_1%20%5E2%7D%7B2%5Csigma%20_1%5E2%7D+%5Cln(%5Cfrac%7B%5Csigma%20_0%20%7D%7B%5Csigma%20_1%20%7D),%5Cquad%0Ad%20%20%5Cequiv%20%5Cln%20(%5Cfrac%20%7B%5Cpi%7D%7B1-%5Cpi%7D)%20.%0A"></p>
<p>Suppose that we fit an exponential function <img src="https://latex.codecogs.com/png.latex?r(X)=e%5E%7BmX%20+q%7D"> to <img src="https://latex.codecogs.com/png.latex?%5CLambda(X)"> by likelihood-ratio cost minimization, and similarly <img src="https://latex.codecogs.com/png.latex?r'(X)=e%5E%7Bm'X+q'%7D"> to <img src="https://latex.codecogs.com/png.latex?%5Crho(X)"> by cross-entropy minimization<sup>11</sup>. Due to the previous discussion, one could reasonably expect the results of the two procedure to differ in some way, which is demonstrated below by simulation.</p>
<p>The chunk of R code below defines the function and data used for the simulation. In particular, I’m considering a heavily unbalanced case (<img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(Y%20=%201)%20=%200.1%5C%25">) in which negative cases give rise to a sharply localized <img src="https://latex.codecogs.com/png.latex?X"> peak around <img src="https://latex.codecogs.com/png.latex?X=0"> (<img src="https://latex.codecogs.com/png.latex?%5Cmu%20_0%20=%200">, <img src="https://latex.codecogs.com/png.latex?%5Csigma_0%20=%20.25">), while the few positive cases give rise to a broader signal centered at <img src="https://latex.codecogs.com/png.latex?X=1"> (<img src="https://latex.codecogs.com/png.latex?%5Cmu%20_1%20=%201">, <img src="https://latex.codecogs.com/png.latex?%5Csigma%20_1%20=%201">).</p>
<div class="cell" data-code_folding="true">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Tidyverse facilities for plotting</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2) </span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Loss functions</span></span>
<span id="cb1-6">weighted_loss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(par, data, w) {</span>
<span id="cb1-7">    m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> par[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb1-8">    q <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> par[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb1-9">    x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x</span>
<span id="cb1-10">    y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y</span>
<span id="cb1-11">    </span>
<span id="cb1-12">    z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> m <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> q</span>
<span id="cb1-13">    p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>z))</span>
<span id="cb1-14">    </span>
<span id="cb1-15">    <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p))</span>
<span id="cb1-16">}</span>
<span id="cb1-17"></span>
<span id="cb1-18">cross_entropy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(par, data) </span>
<span id="cb1-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted_loss</span>(par, data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> \(y) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-20"></span>
<span id="cb1-21">cllr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(par, data) </span>
<span id="cb1-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted_loss</span>(par, data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> \(y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y))</span>
<span id="cb1-23"></span>
<span id="cb1-24"></span>
<span id="cb1-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Data generating process</span></span>
<span id="cb1-26">rxy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">001</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu0 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>) { </span>
<span id="cb1-27">    y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> pi</span>
<span id="cb1-28">    x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> mu1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> mu0, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sd0)</span>
<span id="cb1-29">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)</span>
<span id="cb1-30">}</span>
<span id="cb1-31">pi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formals</span>(rxy)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pi</span>
<span id="cb1-32"></span>
<span id="cb1-33"></span>
<span id="cb1-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulation</span></span>
<span id="cb1-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">840</span>)</span>
<span id="cb1-36">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rxy</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e6</span>)</span>
<span id="cb1-37">par_cllr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), cllr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par</span>
<span id="cb1-38">par_cross_entropy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), cross_entropy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par</span>
<span id="cb1-39">par_cross_entropy[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> par_cross_entropy[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(pi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pi))</span>
<span id="cb1-40"></span>
<span id="cb1-41"></span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Helpers to extract LLRs from models</span></span>
<span id="cb1-43">llr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, par)</span>
<span id="cb1-44">    par[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> par[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] </span>
<span id="cb1-45"></span>
<span id="cb1-46">llr_true <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb1-47">    mu1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formals</span>(rxy)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mu1 </span>
<span id="cb1-48">    mu0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formals</span>(rxy)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mu0 </span>
<span id="cb1-49">    sd1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formals</span>(rxy)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sd1</span>
<span id="cb1-50">    sd0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formals</span>(rxy)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sd0</span>
<span id="cb1-51">        </span>
<span id="cb1-52">    a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (sd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sd1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-53">    b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sd1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sd0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-54">    c <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (mu0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sd0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (sd1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(sd0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sd1)</span>
<span id="cb1-55">    a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> c</span>
<span id="cb1-56">}</span></code></pre></div></div>
</div>
<p>So, what do our best estimates look like? The plot below shows the best fit lines for the log-likelihood ratio from <img src="https://latex.codecogs.com/png.latex?C_%7B%5Ctext%7BLLR%7D%7D"> minimization (in solid red) and cross-entropy minimization (in solid blue). The true log-likelihood ratio parabola is the black line. Also shown are the <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BLLR%7D=0"> line (in dashed red) and the <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BLLR%7D=%5Cln(%5Cfrac%7B1-%5Cpi%7D%7B%5Cpi%7D)"> (in dashed blue), which are the appropriate Bayes thresholds for classifying a data point as positive (<img src="https://latex.codecogs.com/png.latex?Y=1">), assuming data comes from a balanced and unbalanced distribution, respectively.</p>
<div class="cell" data-code_folding="true">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr</span>(x, par_cllr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr</span>(x, par_cross_entropy), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr_true</span>(x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-6">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(pi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pi))), </span>
<span id="cb2-7">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log-Likelihood Ratio"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The reason why the lines differ is that they are designed to solve a different predictive problem: as we’ve argued above, minimizing <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> looks for the best <img src="https://latex.codecogs.com/png.latex?Y%5Cvert%20X"> conditional probability estimate according to the balanced measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D'">, whereas cross-entropy minimization does the same for the original measure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D">. This is how data looks like under the two measures (the histograms are stacked - in the unbalanced case, positive examples are invisible on the linear scale of the plot):</p>
<div class="cell" data-code_folding="true">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">test_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb3-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rxy</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Balanced"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">llr_thresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb3-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rxy</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Unbalanced"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">llr_thresh =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(pi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pi)))</span>
<span id="cb3-4">    )</span>
<span id="cb3-5"></span>
<span id="cb3-6">test_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> ., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>These differences are reflected in the misclassification rates of the resulting classifiers defined by <img src="https://latex.codecogs.com/png.latex?%5Chat%20Y(X)=I(%5Ctext%7BLLR%7D(X)%3E%5Ctext%7Bthreshold%7D)">, where the appropriate threshold is zero in the balanced case, and <img src="https://latex.codecogs.com/png.latex?%5Cln(%5Cfrac%7B1-%5Cpi%7D%7B%5Cpi%7D)"> in the unbalanced case. According to intuition, we see that the <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> optimizer beats the cross-entropy optimizer on the balanced sample, while performing significantly worse on the unbalanced one.</p>
<div class="cell" data-code_folding="true">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">test_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb4-3">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">llr_cllr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr</span>(x, par_cllr),</span>
<span id="cb4-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">llr_cross_entropy =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr</span>(x, par_cross_entropy),</span>
<span id="cb4-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">llr_true =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">llr_true</span>(x)</span>
<span id="cb4-6">        ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb4-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cllr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((llr_cllr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> llr_thresh) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> y),</span>
<span id="cb4-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cross_entropy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((llr_cross_entropy <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> llr_thresh) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> y),</span>
<span id="cb4-11">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_llr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((llr_true <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> llr_thresh) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> y)</span>
<span id="cb4-12">        )</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 4
  type           cllr cross_entropy true_llr
  &lt;chr&gt;         &lt;dbl&gt;         &lt;dbl&gt;    &lt;dbl&gt;
1 Balanced   0.166         0.185    0.140   
2 Unbalanced 0.000994      0.000637 0.000518</code></pre>
</div>
</div>
</section>
<section id="final-remarks" class="level2">
<h2 class="anchored" data-anchor-id="final-remarks">Final remarks</h2>
<p>Our main conclusion in a nutshell is that <img src="https://latex.codecogs.com/png.latex?C_%5Ctext%7BLLR%7D"> minimization is equivalent, <em>in the infinite sample limit</em>, to cross-entropy minimization on a balanced version of the original distribution. We haven’t discussed what happens for finite samples where variance starts to play a role, affecting the <em>efficiency</em> of loss functions as model optimization and selection criteria. For instance, for a well specified model of likelihood ratio, how do the convergence properties of <img src="https://latex.codecogs.com/png.latex?C_%7B%5Ctext%7BLLR%7D%7D"> and cross-entropy estimators compare to each other? I expect that answering questions like this would require a much more in-depth study than the one performed here (likely, with simulation playing a central role).</p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-BRUMMER2006230" class="csl-entry">
Brümmer, Niko, and Johan du Preez. 2006. <span>“Application-Independent Evaluation of Speaker Detection.”</span> <em>Computer Speech &amp; Language</em> 20 (2): 230–75. https://doi.org/<a href="https://doi.org/10.1016/j.csl.2005.08.001">https://doi.org/10.1016/j.csl.2005.08.001</a>.
</div>
<div id="ref-Cover2006" class="csl-entry">
Cover, Thomas M., and Joy A. Thomas. 2006. <em>Elements of Information Theory 2nd Edition (Wiley Series in Telecommunications and Signal Processing)</em>. Hardcover; Wiley-Interscience.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>This is how I understood things should <em>theoretically</em> work, from discussions with friends who are actually working on this field. I have no idea on how much day-to-day practice comes close to this mathematical ideal, and whether there exist alternative frameworks to the one I have just described.↩︎</p></li>
<li id="fn2"><p>The Likelihood Ratio Cost was introduced in <span class="citation" data-cites="BRUMMER2006230">(Brümmer and du Preez 2006)</span>. The reference looks very complete, but I find its notation and terminology so unfamiliar that I decided to do my own investigation and leave this reading for a second moment.↩︎</p></li>
<li id="fn3"><p>That is to say, <img src="https://latex.codecogs.com/png.latex?w(Y_%7B%5Csigma(1)%7D,%5C,Y_%7B%5Csigma(2)%7D,%5Cdots,%5C,Y_%7B%5Csigma(N)%7D)=w(Y_1,%5C,Y_2,%5Cdots,%5C,Y_N)"> for any permutation <img src="https://latex.codecogs.com/png.latex?%5Csigma"> of the set <img src="https://latex.codecogs.com/png.latex?%5C%7B1,%5C,2,%5C,%5Cdots,%5C,N%5C%7D">.↩︎</p></li>
<li id="fn4"><p><em>Nota bene:</em> the function <img src="https://latex.codecogs.com/png.latex?f"> is here assumed to be fixed, whereas the randomness in the quantity <img src="https://latex.codecogs.com/png.latex?L%20_N%20%5Ew%20%5Bf%5D"> only comes from the paired observations <img src="https://latex.codecogs.com/png.latex?%5C%7B(X_i,%5C,Y_i)%5C%7D_%7Bi=1,%5C,2,%5C,%5Cdots,N%7D">.↩︎</p></li>
<li id="fn5"><p>Notice that, due to symmetry <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20E(w(%5Cboldsymbol%20Y)%5Cvert%20%5Csum%20_i%20Y_i%20%3E0)%20=%20%5Cmathbb%20E(w(%5Cboldsymbol%20Y)%5Cvert%20Y_1%20=%201)">, which might be easier to compute.↩︎</p></li>
<li id="fn6"><p>Here and below I relax a bit the notation, as most details should be clear from context.↩︎</p></li>
<li id="fn7"><p>The quantity <img src="https://latex.codecogs.com/png.latex?w(%5Cboldsymbol%20Y)"> is not defined when all <img src="https://latex.codecogs.com/png.latex?Y_i">’s are zero, as the right-hand side of Equation&nbsp;1 itself. In this case, we make the convention <img src="https://latex.codecogs.com/png.latex?w(%5Cboldsymbol%20Y)%20=%200">.↩︎</p></li>
<li id="fn8"><p>For the original loss in Equation&nbsp;1, without the modification discussed above, the result would have been <img src="https://latex.codecogs.com/png.latex?%5Cdfrac%7B%5Ctext%20%7BPr%7D%5E%5Cprime%20(Y=1)%7D%7B%5Ctext%7BPr%7D%5E%5Cprime%20(Y=0)%7D=%5Cdfrac%7B1-%5Ctext%20%7BPr%7D(Y=0)%5EN%7D%7B1-%5Ctext%20%7BPr%7D(Y=1)%5EN%7D.">↩︎</p></li>
<li id="fn9"><p>Formally, given an i.i.d. stochastic process <img src="https://latex.codecogs.com/png.latex?Z_i%20=%20(X_i,%5C,Y_i)">, we can define a new stochastic process <img src="https://latex.codecogs.com/png.latex?Z_i%20%5E%5Cprime%20=%20(X_i%5E%5Cprime,%5C,Y_i%5E%5Cprime)"> such that <img src="https://latex.codecogs.com/png.latex?Z_i%20%5E%5Cprime%20=%20Z_%7B2i%20-%201%7D"> if <img src="https://latex.codecogs.com/png.latex?Y_%7B2i-1%7D%5Cneq%20Y_%7B2i%7D">, and <img src="https://latex.codecogs.com/png.latex?Z_i%20%5E%5Cprime%20=%20%5Cperp"> (not defined) otherwise. Discarding <img src="https://latex.codecogs.com/png.latex?%5Cperp"> values, we obtain an i.i.d. stochastic process whose individual observations are distributed according to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D%5E%5Cprime">.↩︎</p></li>
<li id="fn10"><p>There is another case in which <img src="https://latex.codecogs.com/png.latex?C_%7B%5Ctext%7BLLR%7D%7D"> and cross-entropy minimization converge to the same answer as <img src="https://latex.codecogs.com/png.latex?N%5Cto%20%5Cinfty">: when used for model selection among a class of models for the likelihood or posterior odds ratio that contains their correct functional form.↩︎</p></li>
<li id="fn11"><p>This is just logistic regression. It could be a reasonable approximation if <img src="https://latex.codecogs.com/png.latex?%5Csigma_0%20%5E2%5Capprox%20%5Csigma_1%20%5E2">, which however I will assume below to be badly violated.↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2023,
  author = {Gherardi, Valerio},
  title = {Interpreting the {Likelihood} {Ratio} Cost},
  date = {2023-11-15},
  url = {https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2023" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2023. <span>“Interpreting the Likelihood Ratio
Cost.”</span> November 15, 2023. <a href="https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/">https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/</a>.
</div></div></section></div> ]]></description>
  <category>Forensic Science</category>
  <category>Bayesian Methods</category>
  <category>Information Theory</category>
  <category>Probability Theory</category>
  <category>R</category>
  <guid>https://vgherard.github.io/posts/2023-11-15-interpreting-the-likelihood-ratio-cost/</guid>
  <pubDate>Tue, 14 Nov 2023 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Conditional Probability</title>
  <dc:creator>Valerio Gherardi</dc:creator>
  <link>https://vgherard.github.io/posts/2023-11-03-conditional-probability/</link>
  <description><![CDATA[ 





<p>Let <img src="https://latex.codecogs.com/png.latex?(%5COmega,%20%5C,%5Cmathcal%20E,%5C,P)"> be a probability space, and let <img src="https://latex.codecogs.com/png.latex?X%5Ccolon%20%5COmega%20%5Cto%20%5COmega%20_X"> be a random variable with target space <img src="https://latex.codecogs.com/png.latex?(%5COmega%20_X,%20%5Cmathcal%20X)">. We denote the corresponding push-forward measure on <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20X"> by <img src="https://latex.codecogs.com/png.latex?X_*P">, so that:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A(X_*P)(B)=%20P(X%5E%7B-1%7D(B))%0A"> for all <img src="https://latex.codecogs.com/png.latex?B%5Cin%20%5Cmathcal%20X">. A measurable function <img src="https://latex.codecogs.com/png.latex?f%5Ccolon%20%5COmega%20_X%20%5Cto%20%5Cmathbb%20R"> is integrable with respect to <img src="https://latex.codecogs.com/png.latex?X_*P"> if and only if <img src="https://latex.codecogs.com/png.latex?f%5Ccirc%20X"> is integrable with respect to <img src="https://latex.codecogs.com/png.latex?P">, in which case<sup>1</sup>: <img src="https://latex.codecogs.com/png.latex?%0A%5Cintop%20_%5Cmathcal%20X%20f%5C,%5Ctext%20d(X_*P)%20=%20%5Cintop%20_%5Cmathcal%20%5COmega%20(f%20%5Ccirc%20X)%5C,%5Ctext%20dP.%0A"> Now, given an arbitrary event <img src="https://latex.codecogs.com/png.latex?E%5Cin%20%5Cmathcal%20E"> define <img src="https://latex.codecogs.com/png.latex?(X_*P)_E(A)=P(E%5Ccap%20X%5E%7B-1%7D(A))">. Then <img src="https://latex.codecogs.com/png.latex?(X_*P)_E"> is a measure on <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20X"> which is clearly dominated by <img src="https://latex.codecogs.com/png.latex?X_*P">, and there exists a Radon-Nikodym derivative <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20d%20(X_*P)_E%7D%7B%5Ctext%20d%20(X_*P)%7D%20%5Cin%20L_1(X_*P)">. We define the conditional probability of event <img src="https://latex.codecogs.com/png.latex?E"> with respect to the random variable <img src="https://latex.codecogs.com/png.latex?X"> as the random variable:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%5Cvert%20X)%5Cequiv%20%5Cfrac%7B%5Ctext%20d%20(X_*P)_E%7D%7B%5Ctext%20d%20(X_*P)%7D.%0A"></p>
<p>The intuition behind this definition comes from the tautology (given the definition in terms of Radon-Nikodym derivative):</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%20%5Ccap%20(X%5Cin%20A))%20=%20%5Cintop%20_%7BA%7D%20P(E%5Cvert%20X)%5C,%5Ctext%20d(X_*P).%0A"> On one hand, from elementary probability theory, one would expect any sensible definition of conditional probability to satisfy this theorem. On the other hand, the theorem univocally identifies <img src="https://latex.codecogs.com/png.latex?P(E%5Cvert%20X)"> as the Radon-Nikodym derivative <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20d%20(X_*P)_E%7D%7B%5Ctext%20d%20(X_*P)%7D">, modulo a set of <img src="https://latex.codecogs.com/png.latex?X_*P"> measure zero.</p>
<p>It is fairly easy to verify the following properties of conditional probability:</p>
<ul>
<li><p><em>Countable additivity</em>. For any finite or countable family <img src="https://latex.codecogs.com/png.latex?(E_i)_%7Bi%5Cin%20I%7D"> of disjoint events, <img src="https://latex.codecogs.com/png.latex?E_i%20%5Ccap%20E_j%20=%20%5Cemptyset">, we have: <img src="https://latex.codecogs.com/png.latex?%0AP(%5Ccup%20_%7Bi%5Cin%20I%7D%20E_i%20%5Cvert%20X%20=%20x)%20=%20%5Csum%20_%7Bi%20%5Cin%20I%7DP(E_i%20%5Cvert%20X%20=%20x)%0A"> for almost all <img src="https://latex.codecogs.com/png.latex?x%5Cin%20%5COmega_X">.</p></li>
<li><p><em>Positivity</em>. For any event <img src="https://latex.codecogs.com/png.latex?E"> we have <img src="https://latex.codecogs.com/png.latex?P(E%20%5Cvert%20X=x)%20%5Cgeq%200"> for almost all <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5COmega">.</p></li>
<li><p><em>Normalization</em>. <img src="https://latex.codecogs.com/png.latex?P(%5COmega%20%5Cvert%20X%20=%20x)%20=%201"> for almost all <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5COmega">.</p></li>
</ul>
<p>This, however, does not generally imply that <img src="https://latex.codecogs.com/png.latex?P(%5Ccdot%20%5Cvert%20X%20=%20x)"> is a probability measure for almost all <img src="https://latex.codecogs.com/png.latex?x%5Cin%20%5COmega_X"><sup>2</sup>. Functions <img src="https://latex.codecogs.com/png.latex?%5Cnu%20%5Ccolon%20%5Cmathcal%20E%20%5Ctimes%20%5COmega%20_X%20%5Cto%20%5Cmathbb%20R%5E+"> such that <img src="https://latex.codecogs.com/png.latex?%5Cnu(%5Ccdot,%20x)"> is a measure for all <img src="https://latex.codecogs.com/png.latex?x%5Cin%20%5COmega%20_X">, and <img src="https://latex.codecogs.com/png.latex?%5Cnu%20(E,%5Ccdot)"> is <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20X">-measurable for all <img src="https://latex.codecogs.com/png.latex?E%5Cin%20%5Cmathcal%20E"> are called <em>random measures</em>. If <img src="https://latex.codecogs.com/png.latex?%5Cnu"> satisfies <img src="https://latex.codecogs.com/png.latex?%0AP(E%20%5Ccap%20(X%5Cin%20A))%20=%20%5Cintop%20_%7BA%7D%20%5Cnu%20(E,%5Ccdot)%5C,%5Ctext%20d(X_*P)%0A"> (or, equivalently, if <img src="https://latex.codecogs.com/png.latex?%5Cnu%20(E,%5Ccdot)"> is a version of <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%20d%20(X_*P)_E%7D%7B%5Ctext%20d%20(X_*P)%7D">) for all <img src="https://latex.codecogs.com/png.latex?E%5Cin%20%5Cmathcal%20E">, <img src="https://latex.codecogs.com/png.latex?%5Cnu"> is called a <em>regular conditional probability</em> for the random variable <img src="https://latex.codecogs.com/png.latex?X">. If the space <img src="https://latex.codecogs.com/png.latex?(%5COmega,%5C,%20%5Cmathcal%20E)"> is regular enough (<em>e.g.</em> if it is a Borel space) one can prove that a regular conditional probability exists for any random variable <img src="https://latex.codecogs.com/png.latex?X">, see <em>e.g.</em> <span class="citation" data-cites="kallenberg1997foundations">(Kallenberg 1997)</span>.</p>
<p>If <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Cchi%20_A%20%5Ccolon%20%5COmega%20%5Cto%20%5C%7B0,1%5C%7D">, where <img src="https://latex.codecogs.com/png.latex?A%5Cin%20%5Cmathcal%20E"> has positive probability <img src="https://latex.codecogs.com/png.latex?0%3CP(A)%3C1">, we can easily compute:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%5Cvert%20%5Cchi%20_A)%20=%20%5Cchi%20_A%5Ccdot%20%5Cfrac%7BP(E%5Ccap%20A)%7D%7BP(A)%7D%20+%20(1-%5Cchi%20_A)%5Ccdot%20%5Cfrac%7BP(E%5Ccap%20A%5Ec)%7D%7BP(A%5Ec)%7D%0A"> In particular, <img src="https://latex.codecogs.com/png.latex?P(E%5Cvert%20A)%20%5Cequiv%20P(E%5Cvert%20%5Cchi%20_A%20=%201)"> agrees with the usual elementary definition of conditional probability.</p>
<p>More generally, if <img src="https://latex.codecogs.com/png.latex?X%20=%20%5Ctext%20%7Bid%7D%20_%5COmega">, where the target space is equipped with a sub-<img src="https://latex.codecogs.com/png.latex?%5Csigma">-algebra <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20F%20%5Csubseteq%20%5Cmathcal%20E">, we have:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%5Cvert%20%5Cmathcal%20F)%5Cequiv%20%5Cfrac%7B%5Ctext%20d%20(P%5Cvert%20_%5Cmathcal%20F)_E%7D%7B%5Ctext%20d%20(P%5Cvert%20_%5Cmathcal%20F)%7D,%0A"> which is sometimes taken as the definition of conditional probability with respect to a sub-<img src="https://latex.codecogs.com/png.latex?%5Csigma">-algebra. When <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20F"> is the <img src="https://latex.codecogs.com/png.latex?%5Csigma">-algebra generated by a finite or countable partition <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20A%20=%20(A_i)_%7Bi%5Cin%20I%7D"> of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%20%5COmega"> such that <img src="https://latex.codecogs.com/png.latex?P(A_i)%3E0"> for all <img src="https://latex.codecogs.com/png.latex?i%5Cin%20I">, we find:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%5Cvert%20%5Cmathcal%20A)=%5Csum%20_%7Bi%5Cin%20I%7D%20%5Cfrac%7BP(E%5Ccap%20A_i)%7D%7BP(A_i)%7D%5Cchi%20_%7BA_i%7D,%0A"> again in agreement with elementary definitions.</p>
<p>Finally, if <img src="https://latex.codecogs.com/png.latex?X%5Ccolon%20%5COmega%20%5Cto%20%5Cmathbb%20R"> is a real-valued random variable, where <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%20R"> is equipped with the Borel <img src="https://latex.codecogs.com/png.latex?%5Csigma">-algebra, <img src="https://latex.codecogs.com/png.latex?X_*P"> coincides with the Stieltjes measure generated by the cumulative distribution function <img src="https://latex.codecogs.com/png.latex?P_X"> of <img src="https://latex.codecogs.com/png.latex?X">. Denoting <img src="https://latex.codecogs.com/png.latex?P(E%5Cvert%20X)(x)%20%5Cequiv%20P(E%5Cvert%20X%20=%20x)">, we may write:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E%20%5Ccap%20(X%20%5Cin%20B))=%5Cintop%20_B%20P(E%5Cvert%20X=x)%20%5C,%5Ctext%20dP_X(x).%0A"> and, in particular:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(E)=%5Cintop%20_%5Cmathbb%20R%20P(E%5Cvert%20X=x)%20%5C,%5Ctext%20dP_X(x).%0A"></p>





<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-kallenberg1997foundations" class="csl-entry">
Kallenberg, Olav. 1997. <em>Foundations of Modern Probability</em>. Vol. 2. Springer.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>These claims can be proved by a standard argument using approximations by simple functions.↩︎</p></li>
<li id="fn2"><p>For instance, denoting by <img src="https://latex.codecogs.com/png.latex?N_E%20=%20%5C%7Bx%20%5Cin%20%5COmega_X%20%5Cvert%20P(E%5Cvert%20X%20=%20x)%20%5Cgeq%200%5C%7D">, positivity implies that <img src="https://latex.codecogs.com/png.latex?(X_*P)(N_E)=0">. However, there’s no guarantee that <img src="https://latex.codecogs.com/png.latex?%5Ccup%20_%7BE%5Cin%20%5Cmathcal%20E%7D%20N_E"> is also a measure zero set (and in fact it does not need to be measurable, since the union is generally uncountable).↩︎</p></li>
</ol>
</section><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a></div></div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{gherardi2023,
  author = {Gherardi, Valerio},
  title = {Conditional {Probability}},
  date = {2023-11-03},
  url = {https://vgherard.github.io/posts/2023-11-03-conditional-probability/},
  langid = {en}
}
</code></pre><div class="quarto-appendix-secondary-label">For attribution, please cite this work as:</div><div id="ref-gherardi2023" class="csl-entry quarto-appendix-citeas">
Gherardi, Valerio. 2023. <span>“Conditional Probability.”</span>
November 3, 2023. <a href="https://vgherard.github.io/posts/2023-11-03-conditional-probability/">https://vgherard.github.io/posts/2023-11-03-conditional-probability/</a>.
</div></div></section></div> ]]></description>
  <category>Probability Theory</category>
  <category>Measure Theory</category>
  <guid>https://vgherard.github.io/posts/2023-11-03-conditional-probability/</guid>
  <pubDate>Thu, 02 Nov 2023 23:00:00 GMT</pubDate>
</item>
</channel>
</rss>
