-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cc67c7
commit 5fca638
Showing
116 changed files
with
12,462 additions
and
1,607 deletions.
There are no files selected for viewing
Binary file added
BIN
+48.5 KB
_images/1653eb3ef0ddc25899b3197f96e7367594c4fe180aafd76872786fb91d873f5c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30.7 KB
_images/177d412a04ceb10fa9c484d9973a2e95022cecb8b2182df55c77a05d85cdff8b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20.3 KB
_images/192bba20ecdae7da9fd6a15e53a6077b9e01a9e3fdc7f48b22652b3a789eb867.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+130 KB
_images/193d8b4f98ddb39473f3be68613bbc19c5b61c184e042e365b5f87ac3afadcd9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-29.7 KB
_images/1b9740419120924fb9e3bfd519a61117ca1fbfc349dfd752b92786a539efbb19.png
Binary file not shown.
Binary file added
BIN
+114 KB
_images/1dfd788426c9ce57e6cda198a3dd9423e8494c49e0716c01c5bb02d8d4873750.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.1 KB
_images/1dfe18d065c7cd84fa9f8c77c33fcd0a44aa19182ee4620439b51efec08f3fd4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-15.2 KB
_images/22c1c3084644beeccda4e7381da3acb8d10c048a664f14ceb4c50ca36583c008.png
Binary file not shown.
Binary file removed
BIN
-5.99 KB
_images/234e333f3f94654185f3faa9f97feba09779c36fd9b08afe20ec735e609e96d4.png
Binary file not shown.
Binary file removed
BIN
-11.4 KB
_images/2e3d8beb219883bceb9c616f611e78cfe672ac46328642af2d01cff669be171d.png
Binary file not shown.
Binary file added
BIN
+10 KB
_images/31e2731e5a95bc2c8d59967178a6a385e2b448df6be960a8095a678421c76415.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+100 KB
_images/336e553b1e15c6958c59d00722972a35abb626fae85ff3523b0a40d5ca975f06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.9 KB
_images/3681a00cf3324700010f095221675e9f5da4272b07b810bce1f19ba8856f7fc1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-14.2 KB
_images/368cd8393957ad84ef9c4e00c5e06905d7314f306a9c5e44a5e8fadf92ae183a.png
Binary file not shown.
Binary file added
BIN
+6.04 KB
_images/3b2196e33cc62cd5355a0cc40146bc4e09ba61c5e38c2fae348ccfc7dfb13548.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.5 KB
_images/4224a65fac69276abb3c4935776681bc0f66bdb11e863e715d5e480fd9475302.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-24.8 KB
_images/45666da5d85d1eee587014c83b1b0d0fd478e1e6a12d267500b86e562746c567.png
Binary file not shown.
Binary file removed
BIN
-8.15 KB
_images/48e6f6f246e89e886ce68a26fb833ad5cc01f9bda1ddd94513126cada2cb9700.png
Binary file not shown.
Binary file removed
BIN
-31.7 KB
_images/51d4928fb5d591a7955d1b5f8373cf5dec6a1455213dde233136ef86d9b37ee1.png
Binary file not shown.
Binary file added
BIN
+20.5 KB
_images/578fac1f096b9a2cc93e2d3e9a04dbe5a2bf52af6823d63ffe5aa79f4c45d486.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-15.2 KB
_images/62ba2e79c0bd4b398418659edc46860ad1668e9bef41920a2052e7ecf52e6537.png
Binary file not shown.
Binary file removed
BIN
-10.7 KB
_images/649b4326f67ce9cd1bad270b86a168b435beeaa49407757bfa9b59f49551203c.png
Binary file not shown.
Binary file added
BIN
+26.5 KB
_images/66007abe13528ce102c2b15016aa9fbc57e9e665399407160b4a8624bac71301.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.9 KB
_images/667f3c660c0ddb4edc790c61a2e966ad0188daf5d9a1ae25dca78bc55dc5137a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-20.4 KB
_images/6ae57cd57c2eb686319db6f4eb8ac72be9125de872ca88b6d230e1e655ac13e4.png
Binary file not shown.
Binary file added
BIN
+33.9 KB
_images/7037635c81105b3b63caa1767e533482a4d9d79863285f5b1b3effbb51090082.png
Oops, something went wrong.
Binary file removed
BIN
-8.77 KB
_images/75222ba72d4da78606636f9fa330fb97975d28eace85c044d78b75e66e2c4353.png
Diff not rendered.
Binary file added
BIN
+8.15 KB
_images/75d349e59235c0448022b23e35e53bf0bde5fadc4a0829ebfccad4862d3c5208.png
Oops, something went wrong.
Binary file added
BIN
+32.3 KB
_images/7774bcf673a90801d096af56c75b8ade966e5d4951761b7c8fa5e97f6fef5aee.png
Oops, something went wrong.
Binary file added
BIN
+31.1 KB
_images/77b8dddda53b94cfbb8c1ab358072b2fbff2eb97114c00aa7b281f5ed3b0ebc3.png
Oops, something went wrong.
Binary file added
BIN
+100 KB
_images/80c5529eb521d25833f837d0e232c29b93f5154f6b867f07b377170b6e64debf.png
Oops, something went wrong.
Binary file removed
BIN
-28.5 KB
_images/80c6c3824d8a8799edbb0f340cc28b90bf5d8925c3dbdfa78667d9ade095e1a3.png
Diff not rendered.
Binary file removed
BIN
-23.1 KB
_images/86f4c65cc9db7d0c88f506afc49406bd0ade3ae93bf3875a69bc245227a9e683.png
Diff not rendered.
Binary file added
BIN
+11.3 KB
_images/8762a18fe84e2b0ba0e20403f6454d845785be82407216c4891f275a6f1602c0.png
Oops, something went wrong.
Binary file added
BIN
+10.7 KB
_images/926593044408511881c40a380b122f40852e750b662642f9ce787433f71e3fee.png
Oops, something went wrong.
Binary file added
BIN
+28.8 KB
_images/93b781a05ec28ddc6351a24c5908f716ae99a7f6e8fada7880c48a265bf78c90.png
Oops, something went wrong.
Binary file added
BIN
+40.7 KB
_images/984dd7f8d91a8ed7563622bc958a47fb16fcb896b19c2135f4653157d253f488.png
Oops, something went wrong.
Binary file added
BIN
+8.75 KB
_images/9955cb3ab979ab8221c4f60919b7f132690d4171ea8b126888a3ca62cf27ea6c.png
Oops, something went wrong.
Binary file removed
BIN
-26.7 KB
_images/9fd5360e7d876977cb477810a80f270dbd85191d86aab65f74e3a9086e9d2bf2.png
Diff not rendered.
Binary file added
BIN
+28.8 KB
_images/a1191a35129b911e90ba286cf81891e47b38d1273ed51685304e6edc11f32126.png
Oops, something went wrong.
Binary file removed
BIN
-11.3 KB
_images/a6ba825cb62613bbb9b19e7531f85db0c08cf603cb2442591ec9e9ee382369e0.png
Diff not rendered.
Binary file added
BIN
+11.7 KB
_images/a8664b40fd1f1c5d76f5a759a3956d463793dc66e0976025c62451932b9b49bb.png
Oops, something went wrong.
Binary file added
BIN
+36.5 KB
_images/aa554fd940665088ca108d40500d3437e7d882788ae25b3dc1652c11a54d6f04.png
Oops, something went wrong.
Binary file added
BIN
+23.3 KB
_images/ab84b393ebb4e1b01a697cf1bc37ca509b8b11f82d3487d55fb4cb87099abc3f.png
Oops, something went wrong.
Binary file removed
BIN
-17 KB
_images/b28d68010962f93796c68430f56b4fd2202e9fb21861cd75c5932b76301b42cc.png
Diff not rendered.
Binary file added
BIN
+15.3 KB
_images/b666ee31a98e09ac6daa8364b7185f0a9317d9bd7e5d70b45c12df60132d4083.png
Oops, something went wrong.
Binary file removed
BIN
-16.1 KB
_images/b92e7f6ce01cf87a7552dca25fba905bea4f92617dc1c5240a30cb3fa099eb75.png
Diff not rendered.
Binary file removed
BIN
-26.6 KB
_images/bcfb2439bc15fbc7d378ccad8f002e88312aea6081a9a5a47085a7cf5deac4da.png
Diff not rendered.
Binary file removed
BIN
-30.1 KB
_images/bd2bd272719ce132266d37adb340c89f3c3d5c06a3434e7adfbcb0084e373a28.png
Diff not rendered.
Binary file added
BIN
+24.7 KB
_images/bf7fd9435be6ed01b7b11fbe8242df0666f61e30a04d9f746bcbaee1f946cbc0.png
Oops, something went wrong.
Binary file added
BIN
+14.2 KB
_images/c35dbfab062b61a772db592a5c9640512818003e1017db9f72eb9b82e484ecc8.png
Oops, something went wrong.
Binary file added
BIN
+11.4 KB
_images/c64dd0bf274b681c19946a9eb317bc7cfc915eeb7152b7cea5deae87e904f95f.png
Oops, something went wrong.
Binary file removed
BIN
-39.7 KB
_images/c961c561af9d17021ad227e137826aa831fa034f668dec63cd26fc29dc3aaa07.png
Diff not rendered.
Binary file removed
BIN
-26.3 KB
_images/caa638a3c0703dd601255b9c6714f15b0bb7651c33a5e096f87b79a19ab1117a.png
Diff not rendered.
Binary file removed
BIN
-39.5 KB
_images/d39e6b60d9ac4d4790c082b3889e86bb422068c5aff44e4fcc075fc60a1a6008.png
Diff not rendered.
Binary file added
BIN
+26.1 KB
_images/d3d691c99f489baeb4ffd5ab63652dfe9a4c7a6d103841d9e39f77892f3a5ec3.png
Oops, something went wrong.
Binary file added
BIN
+39.6 KB
_images/d7a4ae8a998f4cb89c56d709ecf787c03178bb6afea6843720bb0a8c4435568b.png
Oops, something went wrong.
Binary file added
BIN
+24.5 KB
_images/d925d1082c879f5cb5872c8d1a7468ca6373c171970feb1e61669388eb0483e6.png
Oops, something went wrong.
Binary file added
BIN
+26.1 KB
_images/d9a3b5f6671ab61689cce12eff733cbe0ed37f1ac3ad727a488eb7ec01998e7b.png
Oops, something went wrong.
Binary file removed
BIN
-31.3 KB
_images/dadfab5ad78222d36e5a0c6495b79548e8c1df1228d8ece7bd71344cca75b162.png
Diff not rendered.
Binary file added
BIN
+15.9 KB
_images/dc3975407047c1d030324b818ec6657508ac98b72cc9712e26b4838e09323ee7.png
Oops, something went wrong.
Binary file removed
BIN
-9.97 KB
_images/de2813702a2bcd8a6afc5394198dd38c45af724236d7fae75f7a6ef8324348c5.png
Diff not rendered.
Binary file removed
BIN
-34.5 KB
_images/e07388f26065ab89313423889d8bb54043efa1b3bc97aa6974c407819bd11d17.png
Diff not rendered.
Binary file added
BIN
+31.3 KB
_images/e5ca810b7a619cd61276e9a555c92d21608dd6ccd46eb9dec891ed031d5dbaed.png
Oops, something went wrong.
Binary file removed
BIN
-23.5 KB
_images/e63a46c024d5db7b2880aeca1cbde9ca9fac69c6095b4a1ef90cf2507306794b.png
Diff not rendered.
Binary file removed
BIN
-23.2 KB
_images/e904336ae6943df01a21ef586cbe3d0f84d273468f29306f87d03e9e0c75845c.png
Diff not rendered.
Binary file added
BIN
+8.9 KB
_images/ebbe265d329064a88633b098c5a55e447392feeed8646eaaee49d53bb22cbc18.png
Oops, something went wrong.
Binary file removed
BIN
-11.7 KB
_images/f4dd33cf27a95e819664fe10fb012825babb0f0fff0019d4ea1564cfd13b583c.png
Diff not rendered.
Binary file added
BIN
+23.2 KB
_images/f5df2a5b34d3ca25ad9b4a183a3d07ad2b72350c579fdd4d58edd4549df0682c.png
Oops, something went wrong.
Binary file removed
BIN
-8.86 KB
_images/fe6bdb18359b5bc084d572c11aa115df8a403c44e1174e56f3e69f2934b98ec7.png
Diff not rendered.
454 changes: 190 additions & 264 deletions
454
_sources/notebooks/46_generalized_linear_models.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "95a6eda2-a640-4817-9eaf-88bad67ca3d9", | ||
"metadata": {}, | ||
"source": [ | ||
"# Chapter 5: Extra code, drafts, and cut material" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b818a09a-90ac-408e-b39c-f30dd038c6fc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1ad57ed2-8583-4d1f-a16c-ddd481ee3e5f", | ||
"metadata": {}, | ||
"source": [ | ||
"## Bayesian p-value" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "48fc8af8-bfee-4239-8ae7-8419c072ed21", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n", | ||
"Auto-assigning NUTS sampler...\n", | ||
"Initializing NUTS using jitter+adapt_diag...\n", | ||
"Multiprocess sampling (4 chains in 4 jobs)\n", | ||
"NUTS: [beta0, beta1, sigma]\n", | ||
"WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n", | ||
"WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n", | ||
"WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n", | ||
"WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" /* Turns off some styling */\n", | ||
" progress {\n", | ||
" /* gets rid of default border in Firefox and Opera. */\n", | ||
" border: none;\n", | ||
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n", | ||
" background-size: auto;\n", | ||
" }\n", | ||
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", | ||
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", | ||
" }\n", | ||
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", | ||
" background: #F44336;\n", | ||
" }\n", | ||
"</style>\n" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
" <div>\n", | ||
" <progress value='12000' class='' max='12000' style='width:300px; height:20px; vertical-align: middle;'></progress>\n", | ||
" 100.00% [12000/12000 00:06<00:00 Sampling 4 chains, 0 divergences]\n", | ||
" </div>\n", | ||
" " | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Sampling 4 chains for 1_000 tune and 2_000 draw iterations (4_000 + 8_000 draws total) took 17 seconds.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import pymc as pm\n", | ||
"import numpy as np\n", | ||
"import arviz as az\n", | ||
"\n", | ||
"# Simulated data\n", | ||
"np.random.seed(42)\n", | ||
"x = np.random.normal(0, 1, 100)\n", | ||
"y = 3 + 2 * x + np.random.normal(0, 1, 100)\n", | ||
"\n", | ||
"# Bayesian Linear Regression Model\n", | ||
"with pm.Model() as model:\n", | ||
" # Priors\n", | ||
" beta0 = pm.Normal(\"beta0\", mu=0, sigma=10)\n", | ||
" beta1 = pm.Normal(\"beta1\", mu=0, sigma=10)\n", | ||
" sigma = pm.HalfNormal(\"sigma\", sigma=1)\n", | ||
" \n", | ||
" # Likelihood\n", | ||
" mu = beta0 + beta1 * x\n", | ||
" y_obs = pm.Normal(\"y_obs\", mu=mu, sigma=sigma, observed=y)\n", | ||
" \n", | ||
" # Sampling\n", | ||
" trace = pm.sample(2000, return_inferencedata=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "623fce90-4525-40df-b2ff-498d801a2a3b", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Sampling: [y_obs]\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
"<style>\n", | ||
" /* Turns off some styling */\n", | ||
" progress {\n", | ||
" /* gets rid of default border in Firefox and Opera. */\n", | ||
" border: none;\n", | ||
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n", | ||
" background-size: auto;\n", | ||
" }\n", | ||
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n", | ||
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n", | ||
" }\n", | ||
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n", | ||
" background: #F44336;\n", | ||
" }\n", | ||
"</style>\n" | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"\n", | ||
" <div>\n", | ||
" <progress value='8000' class='' max='8000' style='width:300px; height:20px; vertical-align: middle;'></progress>\n", | ||
" 100.00% [8000/8000 00:00<00:00]\n", | ||
" </div>\n", | ||
" " | ||
], | ||
"text/plain": [ | ||
"<IPython.core.display.HTML object>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"# Posterior Predictive Check\n", | ||
"# with model:\n", | ||
"# ppc = pm.sample_posterior_predictive(trace) \n", | ||
"# Posterior Predictive Check\n", | ||
"ppc = pm.sample_posterior_predictive(trace, model=model)\n", | ||
" \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "b526666e-ace3-4b0c-af87-bd0fbcb95aad", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Bayesian p-value: 0.4925\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Extract the posterior predictive samples for 'y_obs'\n", | ||
"y_rep = ppc.posterior_predictive[\"y_obs\"].values\n", | ||
"\n", | ||
"# Calculate Bayesian p-value for the slope\n", | ||
"test_stat_observed = np.mean(y) # Example test statistic\n", | ||
"test_stat_rep = np.mean(y_rep, axis=1)\n", | ||
"bayesian_p_value = np.mean(test_stat_rep >= test_stat_observed)\n", | ||
"print(\"Bayesian p-value:\", bayesian_p_value)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d446b936-8610-4914-975e-ada7d078db7e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.