<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jordan Ryda on Medium]]></title>
        <description><![CDATA[Stories by Jordan Ryda on Medium]]></description>
        <link>https://medium.com/@jpryda?source=rss-2bffef734ec4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*D3O3wRCkDilHYyw7.</url>
            <title>Stories by Jordan Ryda on Medium</title>
            <link>https://medium.com/@jpryda?source=rss-2bffef734ec4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:11:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jpryda/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[X-Ray for Podcasts]]></title>
            <link>https://medium.com/data-science/x-ray-for-podcasts-65289a36d9e4?source=rss-2bffef734ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/65289a36d9e4</guid>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <dc:creator><![CDATA[Jordan Ryda]]></dc:creator>
            <pubDate>Sun, 20 Oct 2019 02:33:13 GMT</pubDate>
            <atom:updated>2022-03-02T13:37:55.208Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9Jjw9aZJ9cBx4VvAJrCaQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@priscilladupreez?utm_source=medium&amp;utm_medium=referral">Priscilla Du Preez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>How to identify different speakers without labels</h4><p>Amazon offers a tool for Kindle and Video it calls “X-Ray” that gives you access to extra information about the scene at hand. The information includes the characters present and helps to navigate between sections of a book or drill into the filmography of a vaguely familiar actor.</p><p>One might imagine the demands of producing such a service require some form of labelling (either exhaustively by hand or for a classifier). However wouldn’t it be cool if we could infer the splits without any labelling labour at all? With this we could calculate the extent to which characters steal the limelight, when and for how long, as well as changing conversation dynamics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nXAzDpYznJzm8Nx2lfY1g.png" /><figcaption>X-Ray for Video on Amazon Prime. Pretty pretty good</figcaption></figure><p>I chose to look at audio — simpler than video but also one component of a similar video task. To test a simple base case I selected a podcast that contained slowly alternating dialogue between two people and landed upon Sam Harris’s chat with Ezra Klein in <a href="https://samharris.org/podcasts/123-identity-honesty/">#123-Identify &amp; Honesty</a> — two different male voices that our ears have no trouble discerning. The final product should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAK52a63zd9Q8ZaCXwM7Ng.png" /><figcaption>The final audio X-Ray</figcaption></figure><h3><strong>1. Creating “chunks” to label</strong></h3><p>Reading audio in is a breeze with <a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.io.wavfile.read.html">scipy</a> — monophonic audio is just a 1D array of chronological values. We now consider the tradeoffs in varying the window size used store the “chunks” of data we will label. The sample frequency <em>Fs</em> here is the standard 44.1 kHz which means our arrays will be of size 44,100 * N for chunk time <em>N</em> seconds. The smaller the window the more precise the location in time and less likely the voices interrupt one another.</p><p>But longer time windows can also help in identifying a voice — and not just a sharp vowel sound. We could suspect this involves looking at some sort of <em>average</em> timbre over a sufficiently long period of time. Five seconds ended up giving good results based on the lengthy speaking times in this discussion (if there were more interruptions this could have been too large).</p><p>There is also a more fundamental compromise in frequency resolution (think shorter time windows give broader spectral peaks). But this phenomenon is only important if<em> </em>we extract the spectrum for the <em>entire chunk. </em>We can steer clear of this if we analyse sub-chunks that collectively inform the chunk label (and this is exactly what I do).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*HtIoxzIHWt4QoVtoQ8L4Bw.png" /><figcaption>Chunking audio has the same effect as applying a rectangular window — it changes the green peak to the blue peaks. The frequency resolution in a discrete Fourier transform is proportional to <em>Fs</em>/<em>N</em>. Source <a href="http://saadahmad.ca/fft-spectral-leakage-and-windowing/">http://saadahmad.ca/fft-spectral-leakage-and-windowing/</a></figcaption></figure><blockquote>The Fourier transform is the mathematics that connects “reciprocal coordinates”. Its scaling property captures the tradeoff we observe in many physical phenomena such as in spectral analysis (resolution of frequency vs precision in time); <a href="https://en.wikipedia.org/wiki/Fraunhofer_diffraction">Fraunhofer diffraction</a> (the smaller the slit spacing the wider the diffraction pattern); <a href="https://en.wikipedia.org/wiki/Uncertainty_principle">uncertainty</a> in quantum mechanics (the more precisely we determine the position the greater the uncertainty in momentum).</blockquote><h3><strong>2. Audio features</strong></h3><p>The time component of a signal doesn’t reveal much about the intrinsic character of a sound. Sound waves are just pressure disturbances in air and the periodicity of these disturbances does reveal a signature of sorts in the frequency domain. A Fast Fourier Transform (<a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.fftpack.fft.html">FFT</a>) of each chunk does the trick and produces the frequency spectra depicted below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xa7hNjB1VhBzPipPhya9LQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DLJwzc-xW90I4GegkDDoRQ.png" /><figcaption>Frequency spectra for Ezra Klein (left) at 30:00–30:05 and Sam Harris (right) at 16:40–16:45. We actually only need the positive terms since for purely real input the output coefficients are “Hermitian-symmetric” i.e. every complex conjugate appears and these correspond to redundant negative-frequencies</figcaption></figure><p>These spectra are clearly pretty dense and high dimensional and so we might use the <a href="https://en.wikipedia.org/wiki/Voice_frequency">bandwidth of the male vocal range</a> to apply a crude cutoff.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c554035edca32cce96d110f47fff6ff/href">https://medium.com/media/0c554035edca32cce96d110f47fff6ff/href</a></iframe><p>This reduces the dimensionality of the spectrum, but recall there are actually <em>two </em>values for each frequency component — a real and imaginary part. When we view a spectrum we’re looking at the magnitude which accounts for both parts. However, it’s the phase in a Fourier transform (the ratio of the two parts) that carries much of the signal for images as for audio.</p><p>We can test this by crossing the magnitude and phase between the Ezra and Sam clips and below are a handful of (unnormalised) mutant clips.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86869513ad8451ae9532674c28dbe83e/href">https://medium.com/media/86869513ad8451ae9532674c28dbe83e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Fplaylists%252F903494380%26show_artwork%3Dtrue%26secret_token%3Ds-AIUbry0juCt&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fjpryda%2Fsets%2Fclips-from-123-identify-honesty%2Fs-AIUbry0juCt%3Futm_source%3Dclipboard%26utm_medium%3Dtext%26utm_campaign%3Dsocial_sharing&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f1b810d8d4c52baf3f90f2f5f5fcfba/href">https://medium.com/media/5f1b810d8d4c52baf3f90f2f5f5fcfba/href</a></iframe><p>At this point we could pass the structure of magnitudes and phases to a dimensionality reduction algorithm (see section 4) to visualise the output. This is what I did initially to produce two very fuzzy groups and it wasn’t quick either.</p><p>The librosa library has a number of <a href="https://librosa.github.io/librosa/feature.html">functions</a> to extract features from the frequency spectrum (e.g. the “centre of mass”, the energy distribution etc.) or time series (e.g. zero-crossing rate). We might also consider detecting frequency peaks and peak widths using <a href="https://docs.scipy.org/doc/scipy/reference/signal.html">scipy.signal</a>. <strong>The features we choose however must be specific to the task of separating voices by their timbre in a way that is pitch-invariant</strong>. If the problem centred on pitch detection we would choose features that distinguish pitch and not timbre.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*g1Vj-uCbuz-6oLCs7jDw6g.png" /><figcaption>Examples of audio features as described in Eronen, Antti &amp; Klapuri, Anssi. (2000), Musical instrument recognition using cepstral features and temporal features</figcaption></figure><p>In other words, we must ensure the features chosen don’t precisely “fingerprint” the data — we need something fuzzier. We turn to the feature that proved to be the most successful at this — Mel-Frequency Cepstral Coefficients (MFCCs).</p><h3><strong>3. Extracting Mel-Frequency Cepstral Coefficients (MFCCs)</strong></h3><p>MFCCs were originally developed to represent sounds made by the human vocal tract. It makes use of the Mel scale, a logarithmic transformation of frequency, that aims to capture the non-linear human perception of sound which results in a lower sensitivity to differences at higher frequencies. This means that a large distance between MFCC vectors relates to a large perceptual change and so capture timbre more robustly and not simply pitch. <a href="https://medium.com/linagoralabs/computing-mfccs-voice-recognition-features-on-arm-systems-dae45f016eb6">This</a> and <a href="https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html">this</a> dive into the mechanics of their computation much better than I can and so I will refrain from doing so here.</p><p>Automatic speech recognition tasks typically look at 12–20 cepstral coefficients and the 0th coefficient can be dropped as it only conveys a constant offset of the average power, not relevant to the overall spectrum shape. My results turned out just fine by picking 15 coefficients and dropping the 0th order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*lEw3lR0wcRo6lJnOydz7Bg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*g8GNly8SARqtswxRAK1TdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*JfKaoiVi9ZtiOOH7FH0iSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*0mzgHy4WvQBiSdC9_pJmLQ.png" /><figcaption>MFCC spectrogram for Ezra Klein (left) at 30:00–30:05 and Sam Harris (right) at 16:40–16:45. Removing the 0th order coefficient in the top row gives the bottom row which exhibits a smaller range between the coefficients</figcaption></figure><p>MFCC extraction involves “framing” or “windowing” which applies a sliding window over the input, much like a <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a>, to produce a few hundred sets of 15 coefficients (within each audio chunk), one for each consecutive frame. The rationale here is we want to preserve frequency contours of the signal that occur when temporarily stationary. These can be lost if we Fourier transform the entire chunk (as I did initially).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/0*x1W4TSXHR0b8q5fR.png" /><figcaption><strong>Framing</strong> within a single “chunk” of audio being identified. Consecutive frames are often set to overlap partially</figcaption></figure><p>Some additional Fourier theory is worth considering here when analysing small windows of audio. Modelling discontinuities such as the sharp corners of square wave requires many high frequency terms. If we create sharp bins throughout the audio we could expect discontinuities at the edges that produces <a href="https://en.wikipedia.org/wiki/Gibbs_phenomenon">spurious high-frequency contributions</a> as well as <a href="https://en.wikipedia.org/wiki/Spectral_leakage">spectral leakage</a> and so it makes sense to taper the edges with a <a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.hamming.html">window function</a>.</p><p>The process of calculating MFCCs from a spectrum has the added benefit of greatly reducing the dimensionality of the input. In every frame we are taking a large number of samples (2048 here), reducing these to 15 coefficients per frame. The final feature vector is built up from the mean of the coefficients across all of these frames. Adding the variance didn’t improve results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*ZDINY8p0FAA3xdJM.jpg" /><figcaption>The process for extracting MFCCs. Mel filter banks have a triangular bandwidth response on a Mel-scale and there are typically 40 of them. Source: <a href="https://www.ijser.org/paper/Performance-analysis-of-isolated-Bangla-speech-recognition-system-using-Hidden-Markov-Model.html">https://www.ijser.org/paper/Performance-analysis-of-isolated-Bangla-speech-recognition-system-using-Hidden-Markov-Model.html</a></figcaption></figure><h3><strong>4. Dimensionality reduction</strong></h3><p><strong>PCA</strong> is the de-facto workhorse of dimensionality reduction — a quick, deterministic, linear transformation that preserves <strong>global</strong> structure of the data when separating data along the eigenvectors of maximal variance. For example, if we were to <a href="https://github.com/lmcinnes/umap">group MNIST digits</a> we would see that the centroids for the clusters of 1s is far from the 0s and 4,7,9 clusters are relatively close. However we can’t assume that neighbours close-by are also close in high dimensional space.</p><p>A more modern approach is <strong>tSNE</strong>, a stochastic technique that benefits from preserving <strong>local</strong> structure — it places neighbours in the high dimensional space close to each other, but at the cost of some global structure. For example, grouping MNIST digits we see cleanly isolated clusters while PCA produces a continuous smear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DutrezQGlN9VhJv5" /><figcaption>UMAP and tSNE on different datasets. The global structure in the MNIST dataset is apparent</figcaption></figure><p><a href="https://github.com/lmcinnes/umap"><strong>UMAP</strong></a> is a newer technique able to capture both the global structure (à la PCA) and local structure (à la tSNE). It’s also significantly faster than the best multicore tSNE implementations (13X faster on MNIST) and custom distance functions can be supplied too. In this two voice problem the decision of dimensionality reduction technique is probably less critical but it’s also nice to get some hands-on experience. Once the MFCCs do the first stage of reduction, the processing time on 3600 chunks x 15 coefficients is very fast.</p><h3>5. <strong>Results</strong></h3><p>The graph below shows not two distinct clusters but <strong>three</strong>! The colour of each point indicates the time into the podcast and edges connect consecutive chunks. The dark blue points therefore indicate that the introduction was probably recorded at a different time — with different equipment or in a different setting. What’s nice here is that the introduction cluster (dark blue) where Sam opens is closer to his dialogue cluster. These two clusters can actually be subsumed if we remove some of the higher MFCC coefficients (8+) although at a cost to the global separation between Sam and Ezra.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N8qMWanHOdHuLP1IXTPWrg.png" /><figcaption>The three distance metrics I saw perform the most reliably for this task of the many UMAP has built in were manhattan, braycurtis and cosine. Silhouette scores above each plot were used for light guidance on clustering performance. A small dark blue cluster appears sometimes given different MFCC parametric configurations</figcaption></figure><p>From here we can apply kmeans for k=3 clusters to map each point to a one of three labels by listening to points in each cluster. But wouldn’t it be nice to link each point to its audio chunk for playback on click? This would help with <em>validation</em> of the clusters and answer questions such as “do points in one cluster closest to another cluster represent a chunk with both voices”? It turned out to be surprisingly challenging, but not insurmountable, using <a href="https://plot.ly/dash/">Dash</a> and plotly as well as some javascript and a <a href="https://github.com/jimmybow/visdcc">3rd party library</a>.</p><p>Anyhow…the results!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIvsLy6l5CKA%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIvsLy6l5CKA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIvsLy6l5CKA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bc41d73e9f4a9cc432bdf4471779a6d/href">https://medium.com/media/7bc41d73e9f4a9cc432bdf4471779a6d/href</a></iframe><p>Not too shabby? Now that we have our kmeans labels we can compute the oft-quoted debate statistic, duration spoken.</p><pre><strong>Sam Harris</strong>    365 chunks<br><strong>Ezra Klein</strong>    272 chunks<br><strong>Intro</strong>          85 chunks</pre><p>Sam spoke for 57% of the time excluding the intro! Well it is his podcast after all. And adding back in the temporal component of each chunk, here is a rather satisfying final product: the X-Ray timeline for the conversation. The frequency of exchange during Sam’s phase at 2500s suggests this section is particularly interesting/heated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAK52a63zd9Q8ZaCXwM7Ng.png" /><figcaption>The final audio X-Ray, again</figcaption></figure><h3>Code</h3><p>I have spruced up my Jupyter notebook which can be found in <a href="https://gist.github.com/jpryda/7e57e6ce3cf57308aed85478c1ec3975">this gist</a></p><h3><strong>References</strong></h3><ul><li><a href="https://musicinformationretrieval.com/mfcc.html">mfcc</a></li><li><a href="https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html">Speech Processing for Machine Learning: Filter banks, Mel-Frequency Cepstral Coefficients (MFCCs) and What&#39;s In-Between</a></li><li><a href="https://medium.com/@LeonFedden/comparative-audio-analysis-with-wavenet-mfccs-umap-t-sne-and-pca-cb8237bfce2f">Comparative Audio Analysis With Wavenet, MFCCs, UMAP, t-SNE and PCA</a></li><li><a href="https://medium.com/linagoralabs/computing-mfccs-voice-recognition-features-on-arm-systems-dae45f016eb6">Computing MFCCs voice recognition features on ARM systems</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65289a36d9e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/x-ray-for-podcasts-65289a36d9e4">X-Ray for Podcasts</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bayesian Musings from a Non-Statistician]]></title>
            <link>https://medium.com/@jpryda/bayesian-musings-from-a-non-statistician-f226ea7d5739?source=rss-2bffef734ec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f226ea7d5739</guid>
            <category><![CDATA[bayesian-statistics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[bayesian]]></category>
            <dc:creator><![CDATA[Jordan Ryda]]></dc:creator>
            <pubDate>Thu, 15 Nov 2018 03:37:57 GMT</pubDate>
            <atom:updated>2020-01-05T17:30:42.581Z</atom:updated>
            <content:encoded><![CDATA[<h4>Ah-ha! moments in making sense of Bayesian statistics</h4><p><em>This post is aimed at those who have already dipped their toe into Bayesian statistics without any rigorous formal training i.e. myself.</em></p><h4>Table of Contents</h4><ul><li>101 Recap</li><li>Primary Frequentist Differences</li><li>Some Ah-ha!s</li><li>MCMC</li><li>AB Testing</li><li>Hierarchical Modelling</li></ul><h3>101 Recap</h3><ol><li><strong>“Probability and statistical inference have inverse objectives”</strong></li></ol><p>With probability modelling we set the parameters for a specified model and simulate potential outcomes. Statistical inference on the other hand ingests measurements from the world and backtracks to estimate the parameters of a chosen model.</p><p>The bidirectional relationship underpins the way we validate statistical techniques’ potential to capture the essence of reality: we synthesise data from a known distribution, blur the signal with some noise that represents random sampling error and estimate the true parameters, <em>point </em>estimates.</p><p>Similarly, Bayesians <a href="http://edwardlib.org/tutorials/criticism">criticise</a> and revise their models by analysing a posterior predictive <em>distribution </em>(c.f point estimates from before). These “posterior predictive checks”<em> </em>examine the deviation of data simulated by the fitted posterior model from the observed data.</p><p><strong>2. “Conditional probabilities can be visualised”</strong></p><p><a href="https://seeing-theory.brown.edu/compound-probability/index.html#section3">Conditional probability</a> has nothing to do with Bayesian vs frequentist inference. It represents a recalculation of probability that accounts for additional information on which the event of interest depends (i.e. if not independent). One way to visualise conditional probabilities is as areas within a complete probability space. The event being conditioned on collapses the sample space from the “universe” to that particular event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*sbbw3rtG0kdmClFSxfN7eQ.png" /><figcaption><a href="https://oscarbonilla.com/2009/05/visualizing-bayes-theorem/">P(A|B) = area given by|AB|/|B|</a></figcaption></figure><p><strong>3. </strong><a href="https://towardsdatascience.com/statistics-for-people-in-a-hurry-a9613c0ed0b"><strong>“All classical hypothesis testing is asking is whether the evidence makes the null hypothesis look ridiculous”</strong></a></p><p>Hypotheses are uncertain descriptions of what the world looks like. They can can either be discrete (innocence or guilt, <a href="http://allendowney.blogspot.com/2018/09/tom-bayes-and-case-of-double-dice.html">which die did I roll</a>) or continuous (mean level of gene expression). Bayesians in either case think of stretching a probability distribution across the hypotheses (for both prior and posterior). There is <strong>nothing fundamentally different between the prior and the posterior</strong> — they represent your state of knowledge at any point in the process with the data you’ve observed so far.</p><p>More specifically we throw data into the likelihood (by initialising the random variable to these fixed<em> </em>observed<em> </em>values)<em> </em>so that it “tugs” on the prior distribution of each of the parameters for that likelihood parameters (both functions of the unknown parameters, see Appendix A).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FrUoJvogN7qQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DrUoJvogN7qQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FrUoJvogN7qQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f55ece8463d0c72b5d0a35ab0a753e04/href">https://medium.com/media/f55ece8463d0c72b5d0a35ab0a753e04/href</a></iframe><h3>Primary Frequentist Differences</h3><ol><li><a href="https://towardsdatascience.com/statistics-for-people-in-a-hurry-a9613c0ed0b"><strong>“Statistics is the science of changing your mind”</strong></a></li></ol><p>Frequentist statistics is characterised by changing your mind about <em>default actions </em>based on the <strong>“unsurprising-ness”</strong> of the data (the [in]famous p-value). Bayesians change their minds about <em>prior beliefs </em>instead. Frequentists need not form a belief to have a default action — this is purely something one commits to without analysing any data.</p><p>2. <strong>“Source of uncertainty”</strong></p><p>Inference from a frequentist’s perspective says that sampled data is drawn from a large or infinite sample space that we may take expectations over. The randomness of data gives the standard error in regression coefficient estimates — uncertainty in what would happen to the estimates <em>if we observed more data sets that look like our own</em>. This sampling error is the <em>variance</em><strong> </strong>in a classifier’s predictions as discussed in more explicit machine learning contexts (linear regression is a part of the ML toolkit after all). A high variance means you’ve overfit on your one sample and have claimed to make sense out of the randomness present.</p><p>Bayesians reason instead that a probability distribution represents the unknown-ness of a quantity, not the randomness of the quantity from the data. The uncertainty in one’s state of knowledge of the system is described by their strength of “belief” about the true and unknown parameter values for the observed data thus far.</p><p>Being pedantic, while the source of uncertainty is different, Bayesians <a href="https://stats.stackexchange.com/questions/83731/would-a-bayesian-admit-that-there-is-one-fixed-parameter-value">may agree</a> with frequentists that the “true” parameter takes a fixed value that we would like to know, whether fixed from the start or potentially generated from a physically random mechanism. There are however instances in Physics, say the uncertainty principle, where we nature fundamentally can only ever reveal a distribution.</p><p>Since frequentists don’t regard the unknown parameter as a random variable, P(H0|D) makes no sense in classical hypothesis testing; the truth of a particular hypothesis is <a href="https://stats.stackexchange.com/questions/5591/why-do-people-use-p-values-instead-of-computing-probability-of-the-model-given-d">not a random variable</a>. It is either true or it’s not. This is one of the mistakes in suggesting that a p-value is the “probability that an observation is due to chance” when it is computed <em>assuming</em> H0 is true, that sample differences are caused random chance. The p-value is instead P(D*|H0) where D* refers to the observed, or more extreme, data.</p><p>Either way the frequency guarantees of confidence intervals and uncertainty quantification of credible intervals <a href="http://varianceexplained.org/r/credible_intervals_baseball/">converge</a> once there is enough information.</p><h3>Some Ah-ha!s</h3><p>1. <strong>“Bayes’ theorem </strong>≠ <strong>Bayesian inference. The first is a general formula, the second is statistical”</strong></p><h3>\mathfrak{Michael &quot;El Muy Muy&quot; Betancourt} on Twitter</h3><p>Remember that using Bayes&#39; Theorem doesn&#39;t make you a Bayesian. Quantifying uncertainty with probability makes you a Bayesian.</p><p><strong>Bayes’ theorem is not a Bayesian approach per se. </strong>The theorem is a formula foundational to probability theory that connects inverse conditional probabilities. It allows us to invert relative frequencies derived from contingency tables just fine (e.g. a confusion matrix).</p><blockquote>What makes one a Bayesian is quantifying uncertainty with probability over hypotheses</blockquote><p>Bayesian<strong> </strong>inference is the quantitative method to update ones’ beliefs given new information that manifests as a reallocation of probability across hypotheses.</p><p>It’s worth prefacing that only in the most trivial cases do data have deterministic relations to candidate causes; where conditional probability tables contain 0s and/or 1s (e.g. a 3, 6 and 8 sided dice are in a box and rolling an unknown dice to give a 7 rules out the first two hypotheses). In reality inferences are probabilistic and the data relate to their underlying causes with degrees of certainty (as well as being subject to measurement noise).</p><p>Nonetheless, if we have <em>complete knowledge</em> of the probability space of mutually exclusive hypotheses — we know exacts priors (base rates) and likelihoods for all hypotheses — then <a href="https://ocw.mit.edu/courses/mathematics/18-05-introduction-to-probability-and-statistics-spring-2014/readings/MIT18_05S14_Reading20.pdf">Bayes’ formula computes the posterior <strong>exactly</strong></a>. Such is the case when we <a href="https://allendowney.blogspot.com/2018/09/tom-bayes-and-case-of-double-dice.html">roll a die</a> that is randomly selected from a box whose contents we already know, or we have complete population information in a contingency table. This is <em>deductive logic</em> of probability theory, and it gives a direct way to compare hypotheses, draw conclusions, and make decisions. The Monty Hall problem presents another such case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTSmX9RJTosERykZiH2QBA.png" /><figcaption>Monty Hall Problem: complete knowledge of the prior and posterior probability spaces. You select door A, H is the hypothesis a prize is behind door {A,B,C}, and D represents the event that Monty opens door B <strong>and</strong> no prize is there. Bayes’ theorem makes the complexity of the problem more manageable and computes full probabilities, although a maximum likelihood approach will also tell you to switch</figcaption></figure><p>A frequentist would have no problem with this and gets to the same answer using relative frequencies, as can be demonstrated with hard code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30f123907f4183ae9a9423598bdd201b/href">https://medium.com/media/30f123907f4183ae9a9423598bdd201b/href</a></iframe><p>However, in most experiments the prior probabilities of hypotheses are <em>not</em> known exactly. When this is the case, our recourse is the art of statistical inference. We either introduce a prior (Bayesian treatment) or do our best using only the likelihood (frequentist treatment). Note that if we estimate our probabilities with relative sample frequencies and plug them into Bayes’ formula this is <a href="https://www.lesswrong.com/posts/THdadTRy9d8w5ZhK2/bayes-rule-bayesian-inference">still not</a> true Bayesian inference since it produces a point estimate.</p><p>2. “<strong>How Bayesian reasoning can give us both “correct” but also “subjective” probabilities”</strong></p><p>In the previous point we decoupled Bayes’ theorem from Bayesian inference. This point follows then quite naturally; we can access conditional probabilities of <em>real </em>interest using Bayes’ theorem that control for dependence between events. For example the canonical disease screening example highlight the <em>correct</em> conditional value we should be concerned with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGW1w78kp6S392kUMOHhnQ.png" /><figcaption>Screening testing example: event A is actually having the disease, and event B testing positive for it. The prior P(A) is disease prevalence and we often have a lot of data on this. We have a test for cancer, separate from the event of being diagnosed with cancer. Tests are of course also flawed and so the the probability of a result one way or another is weaker than it might initially sound.</figcaption></figure><p>On the other hand the Bayesian interpretation of probability, as credibility specific to an individual with a certain state of knowledge, doesn’t sit well with many frequentists due to its “subjectivity” — should science accept that different individuals with identical data may sensibly reach different conclusions? (It can however be argued that the likelihood is also <a href="http://dustintran.com/blog/on-bayesian-and-frequentist-latent-variables-and-parameters">subjective</a> — Bayesian modellers commit a priori to a <em>joint </em>distribution of the data and parameters, <em>p</em>(<em>θ, </em>data), and not simply the prior).</p><p>3. <strong>“Precision and Recall are directly related through Bayes theorem”</strong></p><p>This becomes clear if we define precision and recall as conditional probabilities, for disease present D and positive test +ve.</p><p>Precision: P(D|+ve)<br>Recall: P(+ve|D)</p><p>Read from right to left, precision asks “given a +ve test, what’s the probability the disease is present” while recall asks “given a disease present, what’s the probability the test is +ve”. These are two very different things and wrong to assume that a screening test with high recall implies a high precision too — this is the <strong>prosecutor’s fallacy </strong>(explained visually next). One can have 100% recall but low precision due to false positives i.e. P(D|+ve) ≪ P(D|+ve). More realistically, the product of a small disease prevalence (large P(D’)) with a non-insignificant false alarm rate P(+ve|D’) can reduce the value of precision far below that of the recall.</p><p>4. <strong>“The effect of a small prior done visually” (the prosecutor’s fallacy)</strong></p><p>A <a href="https://medium.com/s/story/im-a-heart-doctor-heres-why-im-wary-of-the-new-apple-watch-2b1999f2d942">well-reasoned concern</a> was published by a heart doctor on the new ECG feature on the Apple. The crux of his piece rested on the rarity of people with atrial fibrillation (about 1%) which would cause false alarms, and <em>many</em> false alarms given the number of sales one can expect from a company that generated <a href="https://www.cnbc.com/2018/05/11/apple-made-more-profit-in-three-months-than-amazon-has-generated-during-its-lifetime.html">more profit in 3 months</a> than Amazon has ever done. The red line below left should be committed to memory by anyone who builds or uses classifiers or diagnostic tests; small priors have a dramatic effect on false positives <strong>even with tests that have a specificity = sensitivity = 99%</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgzdNO8NK7AnWgmAm0dEgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*LFPDFPyc1p8W12m6G3cCzw.png" /><figcaption>Left, probability of a true disease given a positive test, with specificity = sensitivity = 99%, revealing dramatic variation with the magnitude of the prior. Right, grey areas are the quadrants needed to calculate P(D|+ve), which is underdetermined from the sensitivity and specificity of a screening.</figcaption></figure><p>One way to understand why this is is to consider a confusion matrix whose areas are proportional to a quadrant’s probability. If we artificially vary the prior D (normally a fixed estimate from the data) toward 0 we get a precision 1/(1+FP/TP) that tends to 0 as TP falls quickly due to its change in area whilst FP increases.</p><p>It’s worth pointing out that while precision (and NPV) are dependent on the population being tested — influenced by the prevalence of disease — sensitivity, P(+ve|D), and specificity, P(-ve|D’), are <em>conditioned on</em> the diseased/healthy state (they are determined horizontally above).</p><blockquote><strong><em>ML Tangent</em></strong><em><br>Since recall and specificity are conditioned on the class label, ROC curves are invariant to the baseline probability (class imbalance) compared to precision-recall (PR) curves. They typically give an optimistic (deceptive?) picture of model performance on datasets with class imbalance (because of the use of true negatives in the False Positive Rate in the ROC Curve which PR curves carefully avoid).</em></blockquote><blockquote><em>Where baseline probabilities of the problem are important, and the “positive” class is more interesting than the negative class, PR curves may be more useful in characterising classifier performance.</em></blockquote><p>Another way to see the effect of a small prior is by representing the probabilities as Venn diagrams which allow the fractions to be visualised more readily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*nyNTMLdbM84ZeOu7whsJjg.png" /><figcaption><a href="https://oscarbonilla.com/2009/05/visualizing-bayes-theorem/">A: atrial fibrillation; B: Positive ECG. P(A|B)&lt;&gt;P(B|A)</a></figcaption></figure><p>The graphic shows again how a rare disease (small red area) with a test that has 99% sensitivity/recall (large intersection within red) and 99% specificity (large white area) can still yield many false positives and hence low precision (large green area).</p><p>I’ve left one final intuitive tool, using natural frequencies, in Appendix B.</p><p>5. <strong>Empirical Bayes: “Look at your data <em>then</em> set your priors”</strong></p><p>Empirical Bayes is useful in ranking and analysing a large list of proportions such as CTRs and gene expression levels. Knowledge of the entire distribution is brought into each estimate and shrinks the credible intervals whilst pulling the expected values toward it, particularly those observations with smaller amounts of data. It may be viewed as an approximation to a fully Bayesian treatment of a hierarchical model (see below) where the hyperpriors are set to their most likely values, instead of being integrated out.</p><p>6. <strong>“Prior information can formally inject <em>common-sense</em> into the equation”</strong></p><p>In the contrived coin toss experiment with coin of bias <em>p</em>, the Bayesian’s input of common sense manifests as a “head start” in their maximum a posteriori estimate of the coin’s bias for a Beta distribution of potential biases,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*v5dn47dB3jXgfcGrjQNG5w.png" /></figure><p>with number of successes <em>s</em> and failures <em>f</em>. For a uniform prior, Beta(<em>α</em>=1,<em>β</em>=1), we revert to the intuitive <strong>maximum likelihood </strong>answer of <em>s/(s+f) </em>from the pure frequentist who assumes that the sample data is representative of the population of coin tosses because that’s all there is. This makes a difference with small sample sizes. “4 heads and 0 tails you say? The coin is 100% biased”.</p><p>However it should be said that since Bayesians have a full posterior distribution over parameter values there is a preference for expected values — integrating the full posterior to account for full uncertainty and potential multi-modality.</p><p>7. <strong>“Prior information can regularise a model”</strong></p><p><a href="https://en.wikipedia.org/wiki/Lasso_(statistics)">Lasso regression</a> constrains large coefficient estimates and shrinks some towards zero, effectively performing variable selection and choosing a simpler model. This avoids overfitting and is much better suited in dealing with datasets that contain collinearity.</p><p>Another way to phrase this is that we have a <em>prior belief</em> that most coefficients should be close to zero, and this can be expressed through a prior <em>distribution</em> (rather than through a cost function with a penalty term). This is <a href="https://austinrochford.com/posts/2013-09-02-prior-distributions-for-bayesian-regression-using-pymc.html">exactly what can be achieved</a> using Bayesian regression with the appropriate priors.</p><p>8. <strong>“Uncertainty in your neural network predictions”</strong></p><p>Bayesian deep learning aims to move from point estimates of weights to full distributions for all latent variables. As a by-product we get to propagate through the uncertainty of random variables to the uncertainty of the prediction. Note that we effectively double the number of parameters we must learn (mean and spread).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMWxxqV_8AGnxNF-qVqopQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUgsz0bm4AyPv0DVieX1YQ.png" /><figcaption><a href="https://ericmjl.github.io/bayesian-deep-learning-demystified">https://ericmjl.github.io/bayesian-deep-learning-demystified</a></figcaption></figure><p>Wide and deep neural networks represent more complex Bayesian models that can contain millions of parameters and in these instance Monte-Carlo methods are slow to converge — they may take weeks to discover the full posterior. To help solve this a technique called <a href="https://blog.evjang.com/2016/08/variational-bayes.html">Variational Inference</a> has been gaining momentum through probabilistic programming libraries such as Uber’s <a href="https://github.com/uber/pyro">Pyro</a> and Google’s <a href="https://github.com/tensorflow/probability/tree/master/tensorflow_probability/python/edward2">Edward2</a>.</p><h3>MCMC</h3><ol><li><strong>“Monte Carlo techniques are not just for Bayesians”</strong></li></ol><p>What’s well known is the use of bootstrap resampling to compute the standard error in an arbitrary statistic using sample data without ever having seen the parent or population distribution. But what is less well known is that random sampling can be used to produce a <a href="https://allendowney.blogspot.com/2016/06/there-is-still-only-one-test.html">much more flexible</a> null hypothesis significance test (NHST) framework than an “off-the-shelf” analytical model.</p><p>With <a href="https://github.com/jpryda/Two-Sample-Test-Simulation">such</a> a framework you have full choice over the test statistic and are forced to make your model assumptions explicit in setting up the simulations. It can be useful to prototype different test statistics and models that may turn out to yield different results — something potentially noteworthy. Packages such as <a href="https://github.com/tidymodels/infer">infer</a> do just that.</p><p>For <a href="https://stats.stackexchange.com/questions/301355/correlation-measure-between-binary-variables">example</a>, if you wanted to compute the p-value of the Hamming similarity between two vectors you could:</p><ol><li>Randomly shuffle your two vectors and compute the Hamming similarity (the null hypothesis is that the vectors are unrelated)</li><li>Repeat step 1 many (<em>N</em>) times and measure the number of times (<em>x</em>) that the simulated statistic is larger than the observed value of the two original vectors</li></ol><p>The proportion of times that the simulated vectors were more similar than the original vectors, <em>x</em>/<em>N, </em>is the (one-sided) p-value by definition.</p><p>2. <strong>“We still care about the normalising constant P(data) in sampling problems”</strong></p><p>If we only care about point estimates in our posterior (e.g. find the MAP) we can drop P(data), a normalising constant, since we just care about exploring the parameter space to maximise likelihood * prior. <strong>This is an optimisation problem: find </strong><em>θ</em><strong> that maximises the proportionality.</strong> P(data) is equally irrelevant if doing hypothesis comparison on the same dataset using the Bayes Factor.</p><p>This situation is different for MCMC sampling problems. A denominator is necessary to squeeze out fully-fledged probabilities. <strong>This is a sampling distribution problem: find P(</strong><em>θ</em><strong>|data), which requires integration over the entire sample space. </strong>This can be computationally difficult!</p><p>3. “<strong>The intractability of the normalising constant”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*3eTNVb48ZAKRrfntLzfm1w.gif" /></figure><p>Notice how marginalising out <em>θ</em> in the denominator is the same problem as attempting to normalise the numerator with an unknown constant so that it integrates to 1. This is by deliberate setup of a “probability” — from the law of total probability the numerator will be a subset of the denominator that defines the scope of the entire space.</p><p>Consider a system of binary variables (say quantum spin states in the <a href="https://tanyaschlusser.github.io/posts/mcmc-and-the-ising-model/">Ising model</a>) where we seek a probability mass function of the spin configurations. Calculating the integral in the denominator (where x is the data) can be difficult even here since to produce a normalised probability we must sum over all of the possible spin configurations which increases exponentially with the number of variables. For a small 10 x 10 grid this is 2¹⁰⁰ different configurations to calculate the average magnetisation.</p><p>MCMC is our heuristic knight in shining armour — it allows us to sample from a distribution g(x)/k without knowing or caring about k and it does this by stepping through the probability space with a <strong>weighted random walk</strong> that’s biased toward the more likely states.</p><h3>AB Testing</h3><ol><li><strong>“Hypothesis testing = Parameter estimation”</strong></li></ol><p>To answer questions that are posed as hypothesis tests, we can <a href="https://stats.stackexchange.com/questions/246481/bayesian-parameter-estimation-or-bayesian-hypothesis-testing">elegantly transpose</a> the question to be one of parameter estimation and inferring the HPD. This style feels much more natural and in this way we get the effect sizes between groups. The <a href="https://docs.pymc.io/">PyMC3</a> library uses <em>deterministic random variables</em> (values fully determined by their parent values) to handle all the transformations necessary under the hood that ultimately output the desired P(B-A &gt; 0).</p><p>2. <strong>“</strong><a href="https://www.countbayesie.com/blog/2015/4/25/bayesian-ab-testing"><strong>Magnitude is more important than statistical significance</strong></a><strong>”</strong></p><p>NHST (say a Chi-square test or logistic fit) can at most tell us “these two things are not likely to be the same” (unless we bake a difference threshold into our hypotheses).</p><p>When running a test we’re often aiming to not just understand <em>whether </em>a variant will perform better, but <em>by how much. </em>For example, if testing whether a drug will improve IQ more than a placebo, if we have achieved a boost of 3 IQ points, even within our posterior credibility interval, can we <em>really</em> say that the drug is effective and worthy of approval?</p><p>3. <a href="https://medium.com/convoy-tech/the-power-of-bayesian-a-b-testing-f859d2219d5"><strong>“The frequentist approach is more risk averse in decision making”</strong></a></p><p>The primary focus of NHST is avoiding Type I errors; there is a preference to stick to default actions (the null hypothesis is assigned with this assumption). If a new recommendation algorithm is only slightly better than the current model but has a p-value of 0.11, we might be tempted to discard it. However not all false positives are created equally. For example, choosing variant B with CTR 8% and A is 8.3% is a very different mistake to make than if A were 15%. Again it’s the magnitude that is also of interest.</p><p>4. <strong>“Remind me, what’s a p-value again?”</strong></p><p>Interpretability is crucial in communicating ideas and articulating byzantine concepts like p-values takes some care. Would you rather report to your boss that “the probability that A is greater than B is 7%”, or perhaps “assuming the null hypothesis that A is equal to B, the probability that we would see a result at least this extreme in A versus B is 3%”?</p><p>Bayesians are also better equipped to posit stronger statements to make decisions from e.g. P(B-A &gt; δ) where δ can be any difference we specify (set δ=0 for any improvement).</p><h3>Hierarchical Modelling</h3><ol><li><strong>“Assumption: observations are related to one another”</strong></li></ol><p>Hierarchical modelling can be seen as a <a href="https://twiecki.github.io/blog/2014/03/17/bayesian-glms-3/">middle-ground</a> between pooling all measurements together and creating separate regressions for treatment groups. It is distinct from empirical Bayes since we are no longer estimating hyperpriors but are modelling their uncertainty through a hyperprior distribution.</p><p>Through such a design we impose a model structure with our <em>assumptions</em> that our treatment groups of observations are related to one another. Depending on the scenario this can be sensible, say justified using the biological concept of common descent. Everything we use to justify our model structure comes from assumptions extrinsic to the data — domain knowledge<strong> — </strong>that we still have to qualitatively and quantitatively verify. <strong>There is no free lunch</strong>; we have to describe our assumptions explicitly and encode them in the model structure or in the probability distributions used e.g. you might ultimately justify a parsimonious model following Occam’s razor.</p><blockquote>“All models are wrong, but some are useful” — George E. P. Box</blockquote><p>2. <strong>“Rare species are not alone”</strong></p><p>When we have a new sample for which we have very few observations we are able to borrow evidence from the rest of the population to make more tightly-bound inferences about the new sample. In some cases the collection of new data is simply not feasible e.g the beak length of a new rare species of bird.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*2q4OPMzsVotIh2ieYgY2RA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*ndUsGZdWi2eLm0Zwz6dYBA.png" /><figcaption>Before (left) and after (right) applying a hierarchical design — we see “variance shrinkage” in our estimates of the unknown species’s beak depth.</figcaption></figure><p>A non-hierarchical design in this scenario will give a nonsensically wide credible interval (characterised by the high posterior density [HPD] interval) for a rare species. This is because we impose identical uninformative priors on each species that “let the data speak for itself” thus leaving us with large uncertainties. In the non-hierarchical case, the prior parameters are point estimates and not drawn from a parent distribution.</p><p>3. <strong>“The generative story” and “information pooling”</strong></p><p>The generative story is as follows: the population as a whole has a parental hyperprior distribution that constrains the region from which the prior parameters of individual species are drawn (independently). Ultimately all the data influences estimates from global hyperprior distributions which in turn influence the individual estimates and this manifests with the aforementioned shrinkage effect. We could justify this assumption of underlying similarity in this case by deferring to common ancestry, or when inferring the bias of different coins produced by the same mint.</p><p>If the individual prior parameters are strongly dependent on the shared hyperprior (a strong correlation), the posterior of the smaller N species are strongly influenced by the data from the larger N species (see Appendix C).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZvLizs4qZn-NswCcsBkEA.png" /><figcaption>The arrows represent dependencies and describe data generation where sampling the t-distribution P(y|σ,μ,𝜈) yields outcomes. The 3 layered distributions symbolise 3 individual species. For N species there are 2N+1 parameters estimated simultaneously here (𝜈 is global). Hyperpriors one level up are good enough here to capture the hierarchical structure. <a href="https://github.com/ericmjl/bayesian-stats-modelling-tutorial">https://github.com/ericmjl/bayesian-stats-modelling-tutorial</a></figcaption></figure><p>If we were to simplify the above chain of dependencies such that only μ depended on a hyperprior (i.e. take the central chain only) for each species we would get the joint posterior:</p><p>P(σ,μ|y) ∝ P(y|σ,μ)P(σ,μ) = P(y|μ)P(μ|σ)P(σ)</p><ul><li>By the definition of a hierarchical model we have a factorised chain of dependencies, one for each distribution in the chain</li><li>The data y only depend μ — when μ is set then the data are independent of all other parameter values. In other words the likelihood function P(y|μ) does not involve σ, by model definition. Similarly the value of μ is independent of other parameters once σ is set.</li></ul><h3>Appendix</h3><p><strong>A.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*BeKNUFXgzz2nwpkxXE0cXA.png" /><figcaption>A binomial likelihood distribution with its Beta <a href="https://en.wikipedia.org/wiki/Conjugate_prior">conjugate prior</a>, both viewed as functions of the parameter x (the probability of success). Empirical data of s successes and <em>f</em> failures is fed in and a distribution of the random variable q is cranked out.</figcaption></figure><p><strong>B.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*2YFskvIgq3h8KHZqF3pzzw.png" /><figcaption>Both calculations are forms of Bayes’s theorem. Natural frequencies can make it easier to infer precision and more intuitive to consider the effects of a small prior. It is clearer here the at the product of a small prior and and a non-insignificant false alarm rate reduces the precision.</figcaption></figure><p><strong>C.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*Uk3nIaiAGxNXdfro_qjd6Q.png" /><figcaption>Taken from “Bayesian Data Analysis” by Kruschke. Notice the similarity for the two different (coin bias) parameters in the posterior distributions in the bottom two graphs that result from the strong dependence between the individual bias parameters (thetas) and their parental hyperprior, in the top two left graphs</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f226ea7d5739" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>