Frequentist vs Bayesian Definitions of probability (vidhya)
What
What is Bayes theorm
- A formula for combining prior beliefs with observed evidence to obtain a "posterior" distribution (Metaa)
- It is central to Bayesian statistics, where one infers a posterior over the parameters of a statistical model given the observed data.
Why
Why do we need Bayes's theorem?
- To update the probability of a hypothesis, , in light of some body of data. (Tb p.23)
- It is diachronic — something is happening over time; in this case the probability of the hypotheses changes, over time, as we see new data. (Tb p.23)
Why do we need Posterior probability?
- In short, the place where you are stuck if asking such a q is to know why we need inferential prob instead of descriptive prob. (bayesian - Why would I use Bayes' Theorem if I can directly compute the posterior probability? - Mathematics Stack Exchange)
- In finance, Bayes' theorem can be used to update a previous belief once new information is obtained.
- Prior probability represents what is originally believed before new evidence is introduced, and posterior probability takes this new information into account. (Investopedia)
How
- We use the product of prior and likelihood to arrive at a posterior via P(w | x) ∝ P(x | w)P(w). H (Dive into Deep Learning )
There are a few components constitute the formula. The photos below delivers the same meaning in different wording :
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fb5462ba6-86eb-4be2-8521-5c52a1c9c9f1%2FUntitled.png%3Ftable%3Dblock%26id%3D1edc6791-93f3-4052-bdc7-cdb075c77642%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DkNdV0H8WMOlAVqqybb9-9zWss2IoGIDS-29vlM5VOY8?table=block&id=1edc6791-93f3-4052-bdc7-cdb075c77642&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F9544fc76-d8e0-4c55-9267-fe69e4d9bbfa%2FUntitled.png%3Ftable%3Dblock%26id%3Dc2b611ce-5f1c-4680-a4cf-958661523604%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DETLTzdNdPMsMx31-jCeMMqtsMFPaGSfjBRyrJjPv3Yo?table=block&id=c2b611ce-5f1c-4680-a4cf-958661523604&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F5ea0b387-00f1-4aa8-ad05-c9d531f47792%2FUntitled.png%3Ftable%3Dblock%26id%3Ddde747db-a31a-433d-aa04-e14d39fe0563%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3Dbr0RWEUeAWWCwp9yaM1SfDeN0xTGM594DcSQz54dUnQ?table=block&id=dde747db-a31a-433d-aa04-e14d39fe0563&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fc5fd199e-d1f7-4825-a7cd-bafed42eb75b%2FUntitled.png%3Ftable%3Dblock%26id%3D858abbfa-2ff7-466a-915d-9147ed051e28%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DCe-RX1aUfFU7mXYMt-Xfp-b6BTStsTQXIf_M6SF1EFk?table=block&id=858abbfa-2ff7-466a-915d-9147ed051e28&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F6d2302d2-4020-445c-ab8a-a976609671ff%2F64qw76m3.bmp%3Ftable%3Dblock%26id%3D252ad60b-aec5-42f1-bc0c-17fc51f60921%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DZQmI7Sv6zUIyIbrCYf4UaXOHb8WyI7elCj2SrEd_vCs?table=block&id=252ad60b-aec5-42f1-bc0c-17fc51f60921&cache=v2)
but in terms of the diachronic interpretation: (TB)
Posterior
: The probability of the hypothesis after we see the data- Something we want to compute
Prior
: The probability of the hypothesis before we see the data- Aka.
- (It is subjective.) Sometimes can be computed but often time cannot. Because reasonable people use different background information or because they interpret the same information differently.
- That's why people called it Prior — like holding some useful knowledge in prior.
Likelihood
: The probability of the data under the hypothesis- Easiest part to compute
The normalizing constant : The probability of the data under any hypothesis
Example : Cancer prediction (vidhya)
Scenario
The patients were tested thrice (three-times) before the oncologist concluded that they had cancer. The general belief is that 1.48 out of a 1000 people have breast cancer in the US at that particular time when this test was conducted. The patients were tested over multiple tests. Three sets of test were done and the patient was only diagnosed with cancer if she tested positive in all three of them.
Identify the components
Posterior : The probability of having cancer given that he tested positive on the first test — (Something we want to compute)
Prior :
0.00148
— (The general belief is that 1.48 out of a 1000 people having cancer — something we know before we observe the data — our prior knowledge.)Likelihood :
0.93
— The probability of people having cancer given that they are tested positiveThe normalizing constant :
0.011332
— The prob of people tested +ve, regardless they have cancer or notLet’s examine the test in detail :
- Sensitivity of the test (93%) – true positive Rate
- Specificity of the test (99%) – true negative Rate
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ff3337be8-c594-47e4-8cea-3726c384d68c%2FUntitled.png%3Ftable%3Dblock%26id%3Daa7d8e1f-b6fc-4f7e-8b75-e3473871ec8b%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DaoAMb8EvewAcjJWCHbIU8pt88subk9JdAHUrUzJ2TVo?table=block&id=aa7d8e1f-b6fc-4f7e-8b75-e3473871ec8b&cache=v2)
Q1. The probability of having cancer given that he tested positive on the first test
So, let's hit up with a conditional prob first. We want to calculate P (cancer|+)
![.0013468 / [ (.0013468) + (.99852*.01) = .11885](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F2f089ce2-2715-48fe-947e-12654ef10bbb%2FUntitled.png%3Ftable%3Dblock%26id%3Dccc799fe-c116-4af7-a27c-3a8fdc52267c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DpFLJ8aSmcrSn5w0NGKxIFU-dwsL9_gU3VBFyDcnP-bE?table=block&id=ccc799fe-c116-4af7-a27c-3a8fdc52267c&cache=v2)
![To calculate the probability of testing positive, the person can have cancer and test positive or he may not have cancer and still test positive.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fdc11e026-5fd8-455a-8bfb-9f7b2fe6ab12%2FUntitled.png%3Ftable%3Dblock%26id%3D4e4cf4f9-f5a8-420a-b688-9685217c314a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3D2xJg1EBg72zMlRL2p5e9MLEW_m9VaFKdyz3WLnXeFZ4?table=block&id=4e4cf4f9-f5a8-420a-b688-9685217c314a&cache=v2)
Q2. The probability of having cancer given the patient tested positive in the second test ( as we see the data, update the Baye's rules)
Now remember we will only do the second test if she tested positive in the first one. Therefore now the person is no longer a randomly sampled person but a specific case. We know something about her.
Hence
- (changed) Hence, the prior probabilities should change. We update the prior probability with the posterior from the previous test.
- (unchanged) Nothing would change in the sensitivity and specificity of the test since we’re doing the same test again. Look at the probability tree below.
![The tree depicts the left description](https://www.notion.so/image/https%3A%2F%2Fcdn.analyticsvidhya.com%2Fwp-content%2Fuploads%2F2017%2F03%2F13105441%2FCP5.png?table=block&id=ca3adfda-d0cf-4e93-a956-14050cbecdf9&cache=v2)
So, let’s calculate again the probability of having cancer given she tested positive in the second test.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fe61737a3-efd6-4b06-91ba-152aa857e116%2FUntitled.png%3Ftable%3Dblock%26id%3D7e5b7555-51fb-4bd0-b3cb-061ab9c53d01%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DNp7XY-8S0ccPXEG4y8S56KMbJmDU6A0EgLblXpaLoEc?table=block&id=7e5b7555-51fb-4bd0-b3cb-061ab9c53d01&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F9102a9d3-5e23-40f6-b5e4-b4e70cd8fb6d%2FUntitled.png%3Ftable%3Dblock%26id%3D469a99cb-fef4-449d-98b2-9688b1ba4411%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DgVFHmhufq_7KMT3rrry3PFaxrIaNNuM_eHYsldqN5vk?table=block&id=469a99cb-fef4-449d-98b2-9688b1ba4411&cache=v2)
Example 2 : Sci-fic
(from here)
Chinese Version (Here)
What is prior posterior conflict? (34:05 in ETC2420 lecture 11)
Bayesian models are predicated on your choice of prior. Our data is updating our prior distribution to get a posterior distribution.
- If you have set your prior particularly badly, you can end up with like really bad values, which can end up with problems.
Your prior information (i.e. previously thought of as reasonable values for the parameters ) doesn't contain any values of the parameters that are reasonable for producing the actual data that you see.
This phenomena is called a prior posterior conflict.
(How) What is the way to know if the prior is good
Method 1 : overlapping pr not?
By looking at whether or not your prior and posterior are overlapping, you can see if your prior is reasonable.
- If it does, this is a bad thing. That indicates that your prior reasoning is wrong; or it could mean that your data is wrong.
- Wrong is in a sense that data can be corrupted in a variety of ways like the data entry staff input the data with error.
![The right one is called cauchy distribution](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fbb810159-29dc-4449-a040-02702f50f8b5%2FUntitled.png%3Ftable%3Dblock%26id%3D50e15c5c-cef2-42ae-aa38-e416ed0d115c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3Dma36Ks70yYRUiRUqdVuHKtfh4GYXpH0QCrOhdfN7Zg4?table=block&id=50e15c5c-cef2-42ae-aa38-e416ed0d115c&cache=v2)
Method 2 : Posterior predictive checking (45:00 in ETC2420 lecture 11)
- Is also a graphical model evaluation or so called visual inspection.
- You are using the samples to conduct graphical checks to see whether the predictive distributions (e.g. bayesian models) fits to the observed data.
![Check to see whether big features of the data are appropriately captured.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ffcc4d21f-fd20-404f-85d1-0920c0b13372%2FUntitled.png%3Ftable%3Dblock%26id%3D1c6962e5-1e2f-4f0c-b7f4-c3ac1e3e15f2%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DoQrY_xsofoll57bwyAqCsfP1Kkc0LtnD1LYclzMvQk0?table=block&id=1c6962e5-1e2f-4f0c-b7f4-c3ac1e3e15f2&cache=v2)
- Informal inference, meaning you cannot do a hypo testing; however, you can understand that what is good or bad about your model.
Another example is from here p.31.
- We do that for many, many credible parameter values to create representative distributions of what data would look like according to the model.
- The predicted weight values are summarized by vertical bars that show the range of the 95% most credible predicted weight values. The dot at the middle of each bar shows the mean of the predicted weight values.
- By visual inspection of the graph, we can see that the actual data appear to be well described by the predicted data. The actual data do not appear to deviate systematically from the trend or band predicted from the model.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F17cddb39-9a5f-462f-b31f-4ce9f57b9f16%2FUntitled.png%3Ftable%3Dblock%26id%3D18088305-1dbc-4641-bb6c-e71120b16133%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3D_1oOWH97xfs6NGOVqXo6XX9OF3wuK09iWhul1t2yMmw?table=block&id=18088305-1dbc-4641-bb6c-e71120b16133&cache=v2)
- If the actual data did appear to deviate systematically from the predicted form, then we could contemplate alternative descriptive models.
- For example, the actual data might appear to have a nonlinear trend. In that case, we could expand the model to include nonlinear trends. It is straightforward to do this in Bayesian software, and easy to estimate the parameters that describe nonlinear trends.
- We could also examine the distributional properties of the data. For example, if the data appear to have outliers relative to what is predicted by a normal distribution, we could change the model to use a heavy-tailed distribution, which again is straightforward in Bayesian software.
Difference between OLS model and Bayesian Regression
![here p.31](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F8110cf5f-a508-4919-ba4d-e81d49ceaf56%2FUntitled.png%3Ftable%3Dblock%26id%3De05641c3-f144-4ca9-a871-83496e162bfc%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725818400000%26signature%3DzFWs2kqrsOU4VvGB4UJGkG7U9OFyz0aTp8VZHNY4Z-Y?table=block&id=e05641c3-f144-4ca9-a871-83496e162bfc&cache=v2)
Instead of showing only point estimate, we can draw a range of lines, with each one representing a different estimate of the model parameters.
As the number of datapoints increases, the lines begin to overlap because there is less uncertainty in the model parameters.
Reference
( Metaa ) Bayes' rule - Metacademy
(Tb) thinkbayes.pdf
Extra source from Di cook : Statistical Thinking using Randomisation and Simulation