├── BUGS ├── Examples │ ├── Air.odc │ ├── Aligators.odc │ ├── Asia.odc │ ├── Beetles.odc │ ├── BiRats.odc │ ├── Biopsies.odc │ ├── Blockers.odc │ ├── Bones.odc │ ├── Cervix.odc │ ├── Dogs.odc │ ├── Dugongs.odc │ ├── Dyes.odc │ ├── Endo.odc │ ├── Epilepsy.odc │ ├── Equiv.odc │ ├── Eyes.odc │ ├── Hearts.odc │ ├── Ice.odc │ ├── Inhalers.odc │ ├── Jaws.odc │ ├── Kidney.odc │ ├── Leuk.odc │ ├── Leukfr.odc │ ├── Line.odc │ ├── Lsat.odc │ ├── Mice.odc │ ├── Otrees.odc │ ├── OtreesMVN.odc │ ├── Oxford.odc │ ├── Pigs.odc │ ├── Pumps.odc │ ├── Rats.odc │ ├── Ratsx.odc │ ├── Ratsy.odc │ ├── Salm.odc │ ├── Schools.odc │ ├── Seeds.odc │ ├── Stacks.odc │ ├── Stagnant.odc │ ├── Surgical.odc │ ├── Volumei.odc │ ├── Volumeii.odc │ ├── eg05vol1.pdf │ └── eg05vol2.pdf ├── OpenBUGS-3.2.3.tar.gz └── OpenBUGS323setup.zip ├── README.md ├── _config.yml ├── _toc.yml ├── appendixA ├── BUGSVol1.md ├── BUGSVol2.md ├── vol1-10-blocker.ipynb └── vol2-01-dugongs.ipynb ├── backmatter ├── bibliography.md └── latex_reference.md ├── data ├── ants.csv ├── arrhythmia.csv ├── cheese.csv ├── chrysanthemums.csv ├── dental_new.csv ├── dukes.csv ├── fat.tsv ├── gastric.txt ├── georgiakcd.csv ├── growthy.txt ├── hald_data.csv ├── hospitalizations_data.csv ├── iop.csv ├── isoflavon_data.csv ├── magnesiumtw.csv ├── paraguay.csv ├── rasch.txt ├── rats.txt ├── rats_nocenteringY.txt ├── rats_nocenteringx.txt ├── shocks.csv ├── simvastatin_data.tsv ├── sleep_data.csv ├── stagnant_water.csv ├── sunspots.txt ├── terrapins.csv ├── thirddegreeburns.csv ├── vasoconstriction.csv └── wine.data ├── environment.yml ├── favicon ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico └── site.webmanifest ├── images ├── 35q12circuit.jpg ├── 35q13circuit.jpg ├── 35q14figure.jpg ├── 35q15fig.jpg ├── 35q2branch1.jpg ├── 35q2branch2.jpg ├── 35q2branch3.jpg ├── Amanita_Muscaria_in_Eastern_Europe_Lithuania_Wikipedia.jpg ├── amanita-muscaria-sp2.jpg ├── doesnt-look-like-anything-to-me-westworld.gif ├── q17_plot.png ├── q4_plot1.png ├── q4_plot2.png ├── q5_plot.png ├── q7_plot.png └── unit6_graph_theory.jpg ├── intro.md ├── logos └── logo2.png ├── original_examples ├── Codes4Unit1 │ ├── BayesIntro.pdf │ ├── Regression.m │ ├── Regression.odc │ └── winbugs19.pdf ├── Codes4Unit10 │ ├── disasters.odc │ ├── growth.odc │ ├── italywines123.odc │ ├── katla.odc │ ├── lister.odc │ ├── magnesiumTW.odc │ ├── rasch.odc │ ├── raschmodels.pdf │ └── sunspots.odc ├── Codes4Unit2 │ ├── Support │ │ ├── BayesIntro.pdf │ │ ├── bayespicture.pdf │ │ ├── essay.jpg │ │ ├── essayall.pdf │ │ └── price.pdf │ ├── coin.m │ ├── coin.py │ └── coin.r ├── Codes4Unit3 │ ├── alarm.odc │ ├── manufacturingbayes.odc │ └── twoheaded.m ├── Codes4Unit4 │ ├── betaplots.m │ ├── eBay.odc │ └── gammagamma.m ├── Codes4Unit5 │ ├── GIBBS.zip │ ├── albertmc1.m │ ├── albertmc2.m │ ├── disastersmc.m │ ├── gibbs.m │ ├── jeremygibbs.m │ ├── jeremymcmc2.m │ ├── laplace.m │ ├── mcmc1.m │ ├── metro2.m │ ├── norcau.m │ ├── norcau.py │ ├── norcaugibbs.m │ ├── norcaumet.m │ ├── poisson.m │ ├── poissonHM.m │ ├── pumpsbugs.odc │ ├── pumpsmc.m │ ├── randMVN.m │ └── trafficmatrix.m ├── Codes4Unit6 │ ├── DeMere.odc │ ├── Supporting │ │ ├── Aborage.odc │ │ ├── Aboreducation.odc │ │ ├── Aborunionstatus.odc │ │ ├── ISYE 6420 Project Report Marine Otero del Val.pdf │ │ ├── WB.pdf │ │ └── lect2gm.pdf │ ├── alarm.odc │ ├── cheese.odc │ ├── dugongsmissing.odc │ ├── equivalence.odc │ ├── exponential1.odc │ ├── psoriasis.odc │ ├── stressacids.odc │ └── zerotrickjeremy.odc ├── Codes4Unit7 │ ├── Jeremymus.odc │ ├── NHANESmulti.odc │ ├── anovacoagulation.odc │ ├── ants.odc │ ├── arrhythmia.odc │ ├── basichierarchy.odc │ ├── basichierarchy2.odc │ ├── fat1.odc │ ├── fat2d.odc │ ├── fatmulti.odc │ ├── insulin.odc │ ├── isoflavon.odc │ ├── isoflavonopen.odc │ ├── paraguay.odc │ ├── paraguaynocluster.odc │ ├── rats_nocentering.odc │ ├── simvastatin.odc │ └── tasmixture.odc ├── Codes4Unit8 │ ├── example2.odc │ ├── gastric.odc │ ├── ratsignorable1.odc │ ├── ratsignorable2.odc │ └── ratsinformative.odc ├── Codes4Unit9 │ ├── Gesell.odc │ ├── Hald.odc │ ├── Haldssvs.odc │ ├── cumulative2.odc │ ├── deviances.odc │ └── ioannismodelselection.pdf └── stuff │ └── Unit3-DeMere.ipynb ├── references.bib ├── unit1 ├── Unit1-about-this-course.md ├── Unit1-simple-regression.ipynb ├── Unit1-software.md └── Unit1-topics.md ├── unit10 ├── Unit10-disasters.ipynb ├── Unit10-growth.ipynb ├── Unit10-italywines123.ipynb ├── Unit10-katla.ipynb ├── Unit10-lister.ipynb ├── Unit10-magnesiumTW.ipynb ├── Unit10-rasch.ipynb └── Unit10-sunspots.ipynb ├── unit2 ├── Unit2-10flips.ipynb ├── Unit2-bayesianvsclassical.md ├── Unit2-fda.md ├── Unit2-history.md └── Unit2-history2.md ├── unit3 ├── SupplementaryExercises35.ipynb ├── Unit3-Alarm.ipynb ├── Unit3-Bayes-theorem.md ├── Unit3-Emily.ipynb ├── Unit3-ManufacturingBayes.ipynb ├── Unit3-NecessaryProbability.md ├── Unit3-TwoHeadedCoin.ipynb ├── Unit3-bayesnetworks.md ├── Unit3-conditioning1.md ├── Unit3-conditioning2.md └── moreexamples3.md ├── unit4 ├── SupplementaryExercises43.ipynb ├── SupplementaryExercises48.ipynb ├── Unit4-AlphaParticles.ipynb ├── Unit4-BetaPriors.ipynb ├── Unit4-GammaGamma.ipynb ├── Unit4-IQexample.ipynb ├── Unit4-basicdist.ipynb ├── Unit4-conjugatefamilies.ipynb ├── Unit4-crediblesets.ipynb ├── Unit4-eBay.ipynb ├── Unit4-elicitation.ipynb ├── Unit4-estimation.ipynb ├── Unit4-ingredients.ipynb ├── Unit4-jointconditionals.ipynb ├── Unit4-noninform.ipynb ├── Unit4-nonpara.ipynb ├── Unit4-numericalchar.ipynb ├── Unit4-parametric.ipynb ├── Unit4-poissongamma.ipynb ├── Unit4-prediction.ipynb ├── Unit4-samplesize.ipynb ├── Unit4-testing.ipynb ├── bayestheorem.md ├── conjugatecases.md ├── distributions.md ├── empiricalbayes.md ├── moreexamples.md └── priors.md ├── unit5 ├── SupplementaryExercises54.ipynb ├── Unit5-Gibbs3.ipynb ├── Unit5-GibbsSampler.ipynb ├── Unit5-Laplace.ipynb ├── Unit5-Metropolis.ipynb ├── Unit5-Metropolis1.ipynb ├── Unit5-MetropolisHastings.ipynb ├── Unit5-MetropolisHastings2.ipynb ├── Unit5-PumpsMCMC.ipynb ├── Unit5-demo-Laplaces-method.ipynb ├── Unit5-gibbs2.ipynb ├── Unit5-gibbsex3math.ipynb ├── Unit5-gibbsintro.ipynb ├── Unit5-hamiltonian.ipynb ├── Unit5-mcmc.ipynb ├── Unit5-norcau1.ipynb ├── Unit5-numericalapproaches.ipynb ├── Unit5-other-methods.md ├── bayesian-computation.md ├── gibbs-sampling.md ├── metropolis-hastings.md └── other.md ├── unit6 ├── Rob - Graph Theory Background.ipynb ├── Unit6-censoring.ipynb ├── Unit6-customlikelihood.ipynb ├── Unit6-demo-doodle.ipynb ├── Unit6-demo-equivalence.ipynb ├── Unit6-doodlebug.ipynb ├── Unit6-htesting.ipynb ├── Unit6-loadingdata.ipynb ├── Unit6-missingdata.ipynb ├── Unit6-moreaboutpymc.md ├── Unit6-prediction.ipynb └── Unit6-probabilisticprogramming.ipynb ├── unit7 ├── SupplementaryExercises74.ipynb ├── Unit7-anova.ipynb ├── Unit7-arrhythmia.ipynb ├── Unit7-coagulation.ipynb ├── Unit7-demo-factorial.ipynb ├── Unit7-demo-multilevel.ipynb ├── Unit7-demo-multinomial.ipynb ├── Unit7-demo-multiple.ipynb ├── Unit7-demo-regression.ipynb ├── Unit7-factorial.ipynb ├── Unit7-hiddenmixtures.ipynb ├── Unit7-introduction.md ├── Unit7-metaanalysis.ipynb ├── Unit7-multilevel.ipynb ├── Unit7-multinomial.ipynb ├── Unit7-multipleregression.ipynb ├── Unit7-other.ipynb ├── Unit7-priors.ipynb ├── Unit7-regression.ipynb ├── Unit7-why.md ├── hierarchical.ipynb ├── linearmodels.ipynb └── othermodels.ipynb ├── unit8 ├── SupplementaryExercises83.ipynb ├── Unit8-missing.ipynb ├── Unit8-missrats.ipynb ├── Unit8-timetoevent.ipynb ├── Unit8-tte-gastric.ipynb ├── Unit8-tteex1.ipynb └── Unit8-tteex2.ipynb └── unit9 ├── SupplementaryExercises93.ipynb ├── Unit9-cpo.ipynb ├── Unit9-cumulative.ipynb ├── Unit9-cumulative2.ipynb ├── Unit9-deviances.ipynb ├── Unit9-dic.ipynb ├── Unit9-fit-selection-diagnostics.ipynb ├── Unit9-fitsel.ipynb ├── Unit9-gessell.ipynb ├── Unit9-hald.ipynb ├── Unit9-hald2.ipynb └── Unit9-ssvs.ipynb /BUGS/Examples/Air.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Air.odc -------------------------------------------------------------------------------- /BUGS/Examples/Aligators.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Aligators.odc -------------------------------------------------------------------------------- /BUGS/Examples/Asia.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Asia.odc -------------------------------------------------------------------------------- /BUGS/Examples/Beetles.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Beetles.odc -------------------------------------------------------------------------------- /BUGS/Examples/BiRats.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/BiRats.odc -------------------------------------------------------------------------------- /BUGS/Examples/Biopsies.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Biopsies.odc -------------------------------------------------------------------------------- /BUGS/Examples/Blockers.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Blockers.odc -------------------------------------------------------------------------------- /BUGS/Examples/Bones.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Bones.odc -------------------------------------------------------------------------------- /BUGS/Examples/Cervix.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Cervix.odc -------------------------------------------------------------------------------- /BUGS/Examples/Dogs.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Dogs.odc -------------------------------------------------------------------------------- /BUGS/Examples/Dugongs.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Dugongs.odc -------------------------------------------------------------------------------- /BUGS/Examples/Dyes.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Dyes.odc -------------------------------------------------------------------------------- /BUGS/Examples/Endo.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Endo.odc -------------------------------------------------------------------------------- /BUGS/Examples/Epilepsy.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Epilepsy.odc -------------------------------------------------------------------------------- /BUGS/Examples/Equiv.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Equiv.odc -------------------------------------------------------------------------------- /BUGS/Examples/Eyes.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Eyes.odc -------------------------------------------------------------------------------- /BUGS/Examples/Hearts.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Hearts.odc -------------------------------------------------------------------------------- /BUGS/Examples/Ice.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Ice.odc -------------------------------------------------------------------------------- /BUGS/Examples/Inhalers.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Inhalers.odc -------------------------------------------------------------------------------- /BUGS/Examples/Jaws.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Jaws.odc -------------------------------------------------------------------------------- /BUGS/Examples/Kidney.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Kidney.odc -------------------------------------------------------------------------------- /BUGS/Examples/Leuk.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Leuk.odc -------------------------------------------------------------------------------- /BUGS/Examples/Leukfr.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Leukfr.odc -------------------------------------------------------------------------------- /BUGS/Examples/Line.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Line.odc -------------------------------------------------------------------------------- /BUGS/Examples/Lsat.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Lsat.odc -------------------------------------------------------------------------------- /BUGS/Examples/Mice.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Mice.odc -------------------------------------------------------------------------------- /BUGS/Examples/Otrees.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Otrees.odc -------------------------------------------------------------------------------- /BUGS/Examples/OtreesMVN.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/OtreesMVN.odc -------------------------------------------------------------------------------- /BUGS/Examples/Oxford.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Oxford.odc -------------------------------------------------------------------------------- /BUGS/Examples/Pigs.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Pigs.odc -------------------------------------------------------------------------------- /BUGS/Examples/Pumps.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Pumps.odc -------------------------------------------------------------------------------- /BUGS/Examples/Rats.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Rats.odc -------------------------------------------------------------------------------- /BUGS/Examples/Ratsx.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Ratsx.odc -------------------------------------------------------------------------------- /BUGS/Examples/Ratsy.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Ratsy.odc -------------------------------------------------------------------------------- /BUGS/Examples/Salm.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Salm.odc -------------------------------------------------------------------------------- /BUGS/Examples/Schools.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Schools.odc -------------------------------------------------------------------------------- /BUGS/Examples/Seeds.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Seeds.odc -------------------------------------------------------------------------------- /BUGS/Examples/Stacks.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Stacks.odc -------------------------------------------------------------------------------- /BUGS/Examples/Stagnant.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Stagnant.odc -------------------------------------------------------------------------------- /BUGS/Examples/Surgical.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Surgical.odc -------------------------------------------------------------------------------- /BUGS/Examples/Volumei.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Volumei.odc -------------------------------------------------------------------------------- /BUGS/Examples/Volumeii.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/Volumeii.odc -------------------------------------------------------------------------------- /BUGS/Examples/eg05vol1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/eg05vol1.pdf -------------------------------------------------------------------------------- /BUGS/Examples/eg05vol2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/Examples/eg05vol2.pdf -------------------------------------------------------------------------------- /BUGS/OpenBUGS-3.2.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/OpenBUGS-3.2.3.tar.gz -------------------------------------------------------------------------------- /BUGS/OpenBUGS323setup.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/BUGS/OpenBUGS323setup.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A redo of ISYE 6420 code into Python 2 | 3 | Using PyMC, pgmpy, NumPy, and other libraries to redo ISYE 6420: Bayesian Statistics at Georgia Tech in Python. The original course 4 | used Octave and OpenBUGS, and students have been requesting something more modern for years. 5 | 6 | Professor Vidakovic released his code under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/), so I guess this is the same. Is that license meant for code? 7 | 8 | Original course code is all [here](https://www2.isye.gatech.edu/isye6420/supporting.html). 9 | 10 | Contributions and comments are welcome! Feel free to submit a pull request or an issue. 11 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | # Book settings 2 | # Learn more at https://jupyterbook.org/customize/config.html 3 | 4 | title: ISYE 6420 - BUGS to PyMC 5 | author: Georgia Tech ISYE 6420 Staff 6 | logo: logos/logo2.png 7 | copyright: "2024" 8 | 9 | # Force re-execution of notebooks on each build. 10 | # See https://jupyterbook.org/content/execute.html 11 | execute: 12 | execute_notebooks: 'off' 13 | 14 | # Define the name of the latex output file for PDF builds 15 | latex: 16 | latex_documents: 17 | targetname: book.tex 18 | 19 | # Add a bibtex file so that we can create citations 20 | bibtex_bibfiles: 21 | - references.bib 22 | 23 | # Information about where the book exists on the web 24 | repository: 25 | url: https://github.com/areding/6420-pymc # Online location of your book 26 | branch: main # Which branch of the repository should be used when creating links (optional) 27 | 28 | # Add GitHub buttons to your book 29 | # See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository 30 | html: 31 | use_issues_button: true 32 | use_repository_button: true 33 | favicon: "favicon/favicon.ico" 34 | use_multitoc_numbering: false 35 | # comments: 36 | # utterances: 37 | # repo: "areding/6420-pymc" 38 | 39 | launch_buttons: 40 | colab_url: "https://colab.research.google.com" 41 | 42 | sphinx: 43 | config: 44 | html_show_copyright: true 45 | bibtex_reference_style: author_year 46 | language: en 47 | 48 | extra_extensions: 49 | - sphinx_proof 50 | - sphinx_panels 51 | 52 | parse: 53 | myst_enable_extensions: 54 | - colon_fence 55 | - dollarmath 56 | - linkify 57 | - replacements 58 | - smartquotes 59 | - substitution 60 | - amsmath 61 | myst_url_schemes: [mailto, http, https] 62 | myst_dmath_double_inline: true 63 | 64 | only_build_toc_files: true 65 | -------------------------------------------------------------------------------- /appendixA/BUGSVol1.md: -------------------------------------------------------------------------------- 1 | # BUGS Examples, Volume 1 2 | 3 | This appendix will port the original WinBUGS examples volumes [1 (mirror)](https://www2.isye.gatech.edu/isyebayes/bank/eg05vol1.pdf) {cite:t}`spiegelhalter1996vol1` and [2 (mirror)](https://www2.isye.gatech.edu/isyebayes/bank/eg05vol2.pdf){cite:t}`spiegelhalter1996vol2` to PyMC. These were included with WinBUGS. To start with, I'm working off the linked versions (0.5) but may update over time if I find a different source. 4 | 5 | These models are not tested to the level of a published work. They came with the following disclaimer: 6 | 7 | ```{warning} 8 | These worked examples illustrate the use of the BUGS language and sampler in a wide range of problems. They contain a number of useful “tricks”, but are certainly not exhaustive of the models that may be analysed. 9 | 10 | We emphasise that all the results for these examples have been derived in the most naive way: in general a burn-in of 500 iterations and a single long run of 1000 iterations. This is not recommended as a general technique: no tests of convergence have been carried out, and traces of the estimates have not even been plotted. However, comparisons with published results have been made where possible. Times have been measured on a 60 MHz superSPARC: a 60 MHz Pentium PC appears to be about 4 times slower, and a 30 MHz superSPARC about 2 times slower. 11 | 12 | Users are warned to be extremely careful about assuming convergence, especially when using complex models including errors in variables, crossed random effects and intrinsic priors in undirected models. 13 | ``` 14 | 15 | It will be interesting to see what PyMC's convergence diagnostics make of the models. 16 | 17 | ```{tableofcontents} 18 | ``` -------------------------------------------------------------------------------- /appendixA/BUGSVol2.md: -------------------------------------------------------------------------------- 1 | # BUGS Examples, Volume 2 2 | 3 | BUGS 0.5 Examples Volume 2 {cite:ps}`spiegelhalter1996vol2`. 4 | 5 | ```{tableofcontents} 6 | ``` -------------------------------------------------------------------------------- /appendixA/vol1-10-blocker.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 10 - Blocker" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "test" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [] 21 | } 22 | ], 23 | "metadata": { 24 | "language_info": { 25 | "name": "python" 26 | } 27 | }, 28 | "nbformat": 4, 29 | "nbformat_minor": 2 30 | } 31 | -------------------------------------------------------------------------------- /appendixA/vol2-01-dugongs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 01 - Dugongs" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "test." 15 | ] 16 | } 17 | ], 18 | "metadata": { 19 | "language_info": { 20 | "name": "python" 21 | } 22 | }, 23 | "nbformat": 4, 24 | "nbformat_minor": 2 25 | } 26 | -------------------------------------------------------------------------------- /backmatter/bibliography.md: -------------------------------------------------------------------------------- 1 | # Bibliography 2 | 3 | 4 | ```{bibliography} 5 | ``` 6 | -------------------------------------------------------------------------------- /data/ants.csv: -------------------------------------------------------------------------------- 1 | ants,habitat,elevation 2 | 6,1,389 3 | 16,1,8 4 | 18,1,152 5 | 17,1,1 6 | 9,1,210 7 | 15,1,78 8 | 7,1,47 9 | 12,1,491 10 | 14,1,121 11 | 9,1,95 12 | 10,1,274 13 | 10,1,335 14 | 4,1,543 15 | 5,1,323 16 | 7,1,158 17 | 7,1,313 18 | 4,1,468 19 | 6,1,362 20 | 6,1,236 21 | 8,1,30 22 | 6,1,353 23 | 6,1,133 24 | 5,2,389 25 | 6,2,8 26 | 14,2,152 27 | 7,2,1 28 | 4,2,210 29 | 8,2,78 30 | 2,2,47 31 | 3,2,491 32 | 4,2,121 33 | 8,2,95 34 | 8,2,274 35 | 4,2,335 36 | 2,2,543 37 | 7,2,323 38 | 2,2,158 39 | 3,2,313 40 | 3,2,468 41 | 2,2,362 42 | 3,2,236 43 | 2,2,30 44 | 5,2,353 45 | 5,2,133 -------------------------------------------------------------------------------- /data/arrhythmia.csv: -------------------------------------------------------------------------------- 1 | Fibrillation,Age,AorticCrossClampTime,CardiopulmonaryBypassTime,ICUTime,AvgHeartRate,LeftVentricleEjectionFraction,Hypertension,Gender,Diabetes,PreviousMI 2 | 1.0,68.0,64.0,126.0,20.25,85.0,81.0,1.0,1.0,1.0,0.0 3 | 1.0,75.0,111.0,167.0,13.5,50.0,75.0,1.0,1.0,1.0,0.0 4 | 1.0,69.0,63.0,94.0,12.0,74.0,62.0,1.0,0.0,0.0,1.0 5 | 1.0,88.0,95.0,145.0,18.25,102.5,55.0,1.0,1.0,1.0,1.0 6 | 1.0,75.0,82.0,132.0,13.25,90.0,78.0,1.0,1.0,0.0,0.0 7 | 1.0,71.0,14.0,39.0,10.75,88.3,80.0,0.0,1.0,0.0,0.0 8 | 1.0,72.0,80.0,124.0,12.5,88.5,56.0,1.0,0.0,0.0,0.0 9 | 1.0,72.0,85.0,112.0,14.0,91.0,70.0,1.0,0.0,1.0,0.0 10 | 1.0,72.0,97.0,128.0,14.0,89.5,40.0,0.0,1.0,0.0,1.0 11 | 1.0,82.0,88.0,128.0,14.0,77.3,33.0,1.0,0.0,1.0,1.0 12 | 1.0,83.0,49.0,105.0,14.5,79.7,65.0,1.0,1.0,1.0,0.0 13 | 1.0,70.0,87.0,132.0,14.25,71.5,50.0,1.0,1.0,1.0,0.0 14 | 1.0,65.0,98.0,137.0,15.33,89.4,38.0,0.0,0.0,1.0,1.0 15 | 1.0,73.0,47.0,102.0,13.5,86.7,62.0,1.0,0.0,0.0,1.0 16 | 1.0,79.0,108.0,150.0,16.0,86.7,55.0,1.0,1.0,0.0,0.0 17 | 1.0,70.0,83.0,122.0,18.0,74.0,50.0,1.0,0.0,1.0,0.0 18 | 1.0,73.0,81.0,120.0,14.0,68.8,55.0,1.0,0.0,0.0,1.0 19 | 1.0,64.0,0.0,0.0,14.0,86.2,55.0,1.0,0.0,1.0,0.0 20 | 1.0,81.0,79.0,157.0,19.5,98.0,80.0,1.0,0.0,0.0,0.0 21 | 1.0,71.0,81.0,123.0,22.0,97.0,70.0,0.0,0.0,0.0,1.0 22 | 1.0,77.0,107.0,149.0,17.0,75.8,46.0,0.0,0.0,0.0,1.0 23 | 1.0,53.0,120.0,137.0,17.5,96.5,25.0,0.0,0.0,0.0,1.0 24 | 1.0,66.0,86.0,109.0,20.75,72.8,42.5,1.0,0.0,1.0,1.0 25 | 1.0,76.0,61.0,133.0,17.0,82.5,55.0,0.0,0.0,0.0,0.0 26 | 1.0,75.0,97.0,149.0,12.67,93.8,80.0,0.0,0.0,0.0,1.0 27 | 1.0,74.0,70.0,147.0,13.42,95.0,80.0,0.0,0.0,1.0,0.0 28 | 1.0,75.0,72.0,156.0,8.0,82.0,70.0,0.0,1.0,0.0,0.0 29 | 1.0,66.0,98.0,137.0,15.0,90.0,35.0,1.0,0.0,1.0,1.0 30 | 0.0,48.0,102.0,169.0,18.5,76.2,59.0,0.0,0.0,0.0,0.0 31 | 0.0,47.0,81.0,111.0,12.25,70.0,66.0,0.0,0.0,0.0,0.0 32 | 0.0,62.0,76.0,126.0,18.5,101.4,56.0,0.0,1.0,0.0,0.0 33 | 0.0,71.0,82.0,130.0,13.62,97.6,67.0,1.0,1.0,1.0,0.0 34 | 0.0,48.0,132.0,224.0,20.5,103.2,44.0,0.0,0.0,1.0,1.0 35 | 0.0,85.0,91.0,124.0,18.17,76.3,82.0,1.0,0.0,0.0,0.0 36 | 0.0,54.0,44.0,89.0,12.0,87.4,65.0,1.0,1.0,1.0,0.0 37 | 0.0,69.0,124.0,210.0,15.0,81.6,60.0,1.0,0.0,1.0,0.0 38 | 0.0,45.0,105.0,157.0,14.75,96.0,43.0,1.0,0.0,1.0,1.0 39 | 0.0,53.0,67.0,119.0,2.0,94.6,64.0,1.0,0.0,0.0,1.0 40 | 0.0,51.0,23.0,42.0,17.25,74.0,73.0,0.0,1.0,0.0,1.0 41 | 0.0,70.0,93.0,148.0,19.25,73.2,46.0,1.0,0.0,0.0,1.0 42 | 0.0,69.0,55.0,109.0,18.5,109.3,60.0,1.0,1.0,0.0,0.0 43 | 0.0,76.0,67.0,101.0,12.25,97.4,60.0,0.0,0.0,0.0,0.0 44 | 0.0,61.0,105.0,185.0,22.5,98.4,35.0,1.0,0.0,1.0,1.0 45 | 0.0,69.0,153.0,233.0,22.5,66.4,60.0,1.0,0.0,0.0,0.0 46 | 0.0,50.0,84.0,113.0,19.5,97.3,40.0,1.0,0.0,0.0,1.0 47 | 0.0,70.0,107.0,142.0,20.0,82.3,59.0,1.0,0.0,0.0,0.0 48 | 0.0,55.0,116.0,140.0,13.5,70.0,55.0,0.0,0.0,1.0,0.0 49 | 0.0,72.0,100.0,148.0,18.0,80.4,53.0,1.0,0.0,1.0,1.0 50 | 0.0,76.0,77.0,180.0,23.0,93.2,50.0,1.0,0.0,0.0,0.0 51 | 0.0,77.0,63.0,109.0,13.0,87.6,39.0,1.0,0.0,1.0,0.0 52 | 0.0,65.0,78.0,117.0,16.0,59.2,68.0,1.0,0.0,0.0,0.0 53 | 0.0,57.0,67.0,103.0,15.0,79.2,70.0,1.0,1.0,1.0,0.0 54 | 0.0,70.0,107.0,137.0,19.0,66.8,60.0,1.0,1.0,0.0,0.0 55 | 0.0,69.0,193.0,487.0,20.75,104.0,60.0,1.0,0.0,1.0,0.0 56 | 0.0,74.0,90.0,169.0,14.5,94.2,50.0,1.0,1.0,0.0,1.0 57 | 0.0,62.0,71.0,123.0,13.5,66.2,65.0,1.0,0.0,1.0,0.0 58 | 0.0,67.0,72.0,105.0,19.25,76.0,60.0,1.0,1.0,0.0,1.0 59 | 0.0,64.0,139.0,196.0,21.0,77.2,18.0,1.0,0.0,1.0,0.0 60 | 0.0,59.0,55.0,78.0,12.25,88.0,55.0,0.0,0.0,1.0,0.0 61 | 0.0,44.0,47.0,77.0,21.0,107.0,60.0,0.0,0.0,0.0,1.0 62 | 0.0,51.0,77.0,138.0,19.0,99.0,40.0,1.0,0.0,0.0,1.0 63 | 0.0,48.0,113.0,120.0,15.0,82.2,60.0,1.0,0.0,1.0,0.0 64 | 0.0,74.0,0.0,0.0,12.5,79.3,63.0,1.0,1.0,0.0,1.0 65 | 0.0,66.0,80.0,131.0,20.75,88.5,60.0,1.0,0.0,1.0,1.0 66 | 0.0,68.0,94.0,158.0,18.0,88.0,30.0,0.0,0.0,1.0,1.0 67 | 0.0,81.0,90.0,121.0,14.0,81.4,60.0,1.0,1.0,0.0,1.0 68 | 0.0,70.0,87.0,120.0,21.0,81.0,51.0,1.0,0.0,0.0,0.0 69 | 0.0,76.0,72.0,108.0,19.5,91.8,50.0,0.0,0.0,0.0,1.0 70 | 0.0,66.0,112.0,163.0,17.75,89.8,50.0,1.0,0.0,0.0,1.0 71 | 0.0,61.0,82.0,129.0,14.0,76.3,60.0,0.0,0.0,1.0,1.0 72 | 0.0,73.0,46.0,80.0,20.75,80.6,50.0,1.0,1.0,1.0,1.0 73 | 0.0,44.0,87.0,175.0,15.25,97.4,65.0,1.0,1.0,0.0,1.0 74 | 0.0,68.0,102.0,137.0,13.25,71.8,71.0,0.0,0.0,0.0,0.0 75 | 0.0,60.0,99.0,143.0,18.5,85.0,72.0,1.0,0.0,0.0,0.0 76 | 0.0,73.0,61.0,91.0,17.5,85.6,37.0,0.0,1.0,0.0,1.0 77 | 0.0,69.0,50.0,98.0,11.67,84.0,55.0,0.0,0.0,0.0,1.0 78 | 0.0,64.0,63.0,118.0,13.25,97.8,40.0,1.0,0.0,0.0,1.0 79 | 0.0,44.0,75.0,147.0,18.583,111.8,60.0,1.0,0.0,1.0,0.0 80 | 0.0,71.0,51.0,83.0,16.75,102.0,59.0,1.0,0.0,0.0,0.0 81 | 0.0,73.0,68.0,122.0,17.833,78.2,50.0,0.0,1.0,0.0,0.0 82 | 0.0,55.0,44.0,78.0,11.5,94.8,40.0,0.0,0.0,1.0,1.0 83 | -------------------------------------------------------------------------------- /data/cheese.csv: -------------------------------------------------------------------------------- 1 | "","taste","Acetic","H2S","Lactic" 2 | "1",12.3,4.543,3.135,0.86 3 | "2",20.9,5.159,5.043,1.53 4 | "3",39,5.366,5.438,1.57 5 | "4",47.9,5.759,7.496,1.81 6 | "5",5.6,4.663,3.807,0.99 7 | "6",25.9,5.697,7.601,1.09 8 | "7",37.3,5.892,8.726,1.29 9 | "8",21.9,6.078,7.966,1.78 10 | "9",18.1,4.898,3.85,1.29 11 | "10",21,5.242,4.174,1.58 12 | "11",34.9,5.74,6.142,1.68 13 | "12",57.2,6.446,7.908,1.9 14 | "13",0.7,4.477,2.996,1.06 15 | "14",25.9,5.236,4.942,1.3 16 | "15",54.9,6.151,6.752,1.52 17 | "16",40.9,6.365,9.588,1.74 18 | "17",15.9,4.787,3.912,1.16 19 | "18",6.4,5.412,4.7,1.49 20 | "19",18,5.247,6.174,1.63 21 | "20",38.9,5.438,9.064,1.99 22 | "21",14,4.564,4.949,1.15 23 | "22",15.2,5.298,5.22,1.33 24 | "23",32,5.455,9.242,1.44 25 | "24",56.7,5.855,10.199,2.01 26 | "25",16.8,5.366,3.664,1.31 27 | "26",11.6,6.043,3.219,1.46 28 | "27",26.5,6.458,6.962,1.72 29 | "28",0.7,5.328,3.912,1.25 30 | "29",13.4,5.802,6.685,1.08 31 | "30",5.5,6.176,4.787,1.25 32 | -------------------------------------------------------------------------------- /data/chrysanthemums.csv: -------------------------------------------------------------------------------- 1 | 50 g/bu,100 g/bu,200 g/bu,400 g/bu 2 | 13.2,16.0,7.8,21.0 3 | 12.4,12.6,14.4,14.8 4 | 12.8,14.8,20.0,19.1 5 | 17.2,13.0,15.8,15.8 6 | 13.0,14.0,17.0,18.0 7 | 14.0,23.6,27.0,26.0 8 | 14.2,14.0,19.6,21.1 9 | 21.6,17.0,18.0,22.0 10 | 15.0,22.2,20.2,25.0 11 | 20.0,24.4,23.2,18.2 12 | -------------------------------------------------------------------------------- /data/dental_new.csv: -------------------------------------------------------------------------------- 1 | Age8,Age10,Age12,Age14,Girl 2 | 21,20,21.5,23,1 3 | 21,21.5,24,25.5,1 4 | 20.5,24,24.5,26,1 5 | 23.5,24.5,25,26.5,1 6 | 21.5,23,22.5,23.5,1 7 | 20,21,21,22.5,1 8 | 21.5,22.5,23,25,1 9 | 23,23,23.5,24,1 10 | 20,21,22,21.5,1 11 | 16.5,19,19,19.5,1 12 | 24.5,25,28,28,1 13 | 26,25,29,31,0 14 | 21.5,22.5,23,26.5,0 15 | 23,22.5,24,27.5,0 16 | 25.5,27.5,26.5,27,0 17 | 20,23.5,22.5,26,0 18 | 24.5,25.5,27,28.5,0 19 | 22,22,24.5,26.5,0 20 | 24,21.5,24.5,25.5,0 21 | 23,20.5,31,26,0 22 | 27.5,28,31,31.5,0 23 | 23,23,23.5,25,0 24 | 21.5,23.5,24,28,0 25 | 17,24.5,26,29.5,0 26 | 23,24.5,26,30,0 27 | 22,21.5,23.5,25,0 -------------------------------------------------------------------------------- /data/dukes.csv: -------------------------------------------------------------------------------- 1 | ,months,cens,treatment,age,censored 2 | 0,1,True,1,77,1.0 3 | 1,5,True,1,39,5.0 4 | 2,6,False,1,76,inf 5 | 3,6,False,1,57,inf 6 | 4,9,True,1,79,9.0 7 | 5,10,False,1,75,inf 8 | 6,10,False,1,50,inf 9 | 7,10,True,1,72,10.0 10 | 8,12,False,1,71,inf 11 | 9,12,False,1,72,inf 12 | 10,12,False,1,68,inf 13 | 11,12,False,1,64,inf 14 | 12,13,True,1,62,13.0 15 | 13,15,True,1,64,15.0 16 | 14,18,True,1,59,18.0 17 | 15,22,True,1,53,22.0 18 | 16,25,True,1,61,25.0 19 | 17,30,False,1,56,inf 20 | 18,30,True,1,50,30.0 21 | 19,32,True,1,70,32.0 22 | 20,34,False,1,60,inf 23 | 21,36,True,1,50,36.0 24 | 22,40,True,1,60,40.0 25 | 23,40,True,1,57,40.0 26 | 24,44,True,1,61,44.0 27 | 25,3,True,0,75,3.0 28 | 26,3,False,0,55,inf 29 | 27,6,False,0,77,inf 30 | 28,6,False,0,46,inf 31 | 29,6,False,0,72,inf 32 | 30,6,False,0,72,inf 33 | 31,9,False,0,62,inf 34 | 32,9,False,0,75,inf 35 | 33,9,False,0,56,inf 36 | 34,10,True,0,67,10.0 37 | 35,12,True,0,63,12.0 38 | 36,12,True,0,58,12.0 39 | 37,12,True,0,62,12.0 40 | 38,14,True,0,64,14.0 41 | 39,16,False,0,51,inf 42 | 40,17,True,0,47,17.0 43 | 41,17,False,0,48,inf 44 | 42,18,True,0,40,18.0 45 | 43,18,True,0,46,18.0 46 | 44,22,True,0,60,22.0 47 | 45,22,False,0,52,inf 48 | 46,23,True,0,47,23.0 49 | 47,25,True,0,65,25.0 50 | 48,42,False,0,53,inf 51 | -------------------------------------------------------------------------------- /data/georgiakcd.csv: -------------------------------------------------------------------------------- 1 | county,code,deaths,population 2 | APPLING,1,2,30398 3 | ATKINSON,2,0,11261 4 | BACON,3,0,19574 5 | BAKER,4,0,4347 6 | BALDWIN,5,3,58090 7 | BANKS,6,1,23664 8 | BARROW,7,3,56723 9 | BARTOW,8,8,112108 10 | BEN.HILL,9,1,27049 11 | BERRIEN,10,2,30202 12 | BIBB,11,10,211395 13 | BLECKLEY,12,1,19705 14 | BRANTLEY,13,1,24126 15 | BROOKS,14,0,21426 16 | BRYAN,15,1,27349 17 | BULLOCH,16,1,72860 18 | BURKE,17,0,24413 19 | BUTTS,18,2,24606 20 | CALHOUN,19,1,5103 21 | CAMDEN,20,0,46501 22 | CANDLER,21,0,12368 23 | CARROLL,22,7,136784 24 | CATOOSA,23,5,96739 25 | CHARLTON,24,1,14373 26 | CHATHAM,25,21,318800 27 | CHATTAHOOCHEE,26,0,41086 28 | CHATTOOGA,27,1,48209 29 | CHEROKEE,28,11,188914 30 | CLARKE,29,5,146675 31 | CLAY,30,0,3127 32 | CLAYTON,31,15,327928 33 | CLINCH,32,0,11283 34 | COBB,33,23,902837 35 | COFFEE,34,1,52434 36 | COLQUITT,35,1,68264 37 | COLUMBIA,36,4,124750 38 | COOK,37,2,23095 39 | COWETA,38,6,89098 40 | CRAWFORD,39,0,13965 41 | CRISP,40,1,27935 42 | DADE,41,1,30488 43 | DAWSON,42,1,19905 44 | DE.KALB,43,34,760169 45 | DECATUR,44,3,37667 46 | DODGE,45,2,30391 47 | DOOLY,46,0,12180 48 | DOUGHERTY,47,4,124485 49 | DOUGLAS,48,2,152344 50 | EARLY,49,1,16296 51 | ECHOLS,50,0,5022 52 | EFFINGHAM,51,3,49026 53 | ELBERT,52,2,31752 54 | EMANUEL,53,1,34012 55 | EVANS,54,1,13487 56 | FANNIN,55,4,37494 57 | FAYETTE,56,1,118854 58 | FLOYD,57,5,165095 59 | FORSYTH,58,2,94748 60 | FRANKLIN,59,1,35265 61 | FULTON,60,34,765403 62 | GILMER,61,0,30562 63 | GLASCOCK,62,0,4763 64 | GLYNN,63,6,106550 65 | GORDON,64,4,78900 66 | GRADY,65,1,33719 67 | GREENE,66,2,13766 68 | GWINNETT,67,19,689788 69 | HABERSHAM,68,3,61557 70 | HALL,69,5,198574 71 | HANCOCK,70,0,4569 72 | HARALSON,71,2,47386 73 | HARRIS,72,2,30585 74 | HART,73,6,37118 75 | HEARD,74,1,16499 76 | HENRY,75,6,106536 77 | HOUSTON,76,5,165034 78 | IRWIN,77,1,14599 79 | JACKSON,78,1,63383 80 | JASPER,79,0,12334 81 | JEFF.DAVIS,80,0,24818 82 | JEFFERSON,81,0,19101 83 | JENKINS,82,1,12082 84 | JOHNSON,83,1,13392 85 | JONES,84,2,35839 86 | LAMAR,85,0,20135 87 | LANIER,86,0,10232 88 | LAURENS,87,4,63991 89 | LEE,88,0,30498 90 | LIBERTY,89,0,81908 91 | LINCOLN,90,0,10692 92 | LONG,91,0,11095 93 | LOWNDES,92,7,124484 94 | LUMPKIN,93,2,31335 95 | MaaC.DUFFIE,94,1,30293 96 | MaaC.INTOSH,95,0,12208 97 | MACON,96,1,13841 98 | MADISON,97,2,44020 99 | MARION,98,0,7760 100 | MERIWETHER,99,1,28889 101 | MILLER,100,0,11506 102 | MITCHELL,101,2,26257 103 | MONROE,102,0,26540 104 | MONTGOMERY,103,1,12546 105 | MORGAN,104,0,19553 106 | MURRAY,105,2,58628 107 | MUSCOGEE,106,14,272915 108 | NEWTON,107,5,74069 109 | OCONEE,108,1,35172 110 | OGLETHORPE,109,0,16972 111 | PAULDING,110,1,84676 112 | PEACH,111,2,25620 113 | PICKENS,112,3,32264 114 | PIERCE,113,0,27622 115 | PIKE,114,0,18682 116 | POLK,115,3,69471 117 | PULASKI,116,1,13411 118 | PUTNAM,117,3,20631 119 | QUITMAN,118,1,2557 120 | RABUN,119,2,26890 121 | RANDOLPH,120,1,8565 122 | RICHMOND,121,13,272317 123 | ROCKDALE,122,8,107037 124 | SCHLEY,123,0,5773 125 | SCREVEN,124,1,19348 126 | SEMINOLE,125,1,15161 127 | SPALDING,126,5,90876 128 | STEPHENS,127,3,48420 129 | STEWART,128,1,5140 130 | SUMTER,129,0,38357 131 | TALBOT,130,1,6008 132 | TALIAFERRO,131,0,1688 133 | TATTNALL,132,0,31886 134 | TAYLOR,133,0,10792 135 | TELFAIR,134,1,17459 136 | TERRELL,135,1,10683 137 | THOMAS,136,0,57607 138 | TIFT,137,2,62105 139 | TOOMBS,138,1,43300 140 | TOWNS,139,0,15705 141 | TREUTLEN,140,3,9695 142 | TROUP,141,8,90067 143 | TURNER,142,1,13259 144 | TWIGGS,143,0,12591 145 | UNION,144,0,27073 146 | UPSON,146,4,45157 147 | WALKER,147,5,133740 148 | WALTON,148,1,70739 149 | WARE,149,0,65644 150 | WARREN,150,1,5923 151 | WASHINGTON,151,1,22199 152 | WAYNE,152,6,42763 153 | WEBSTER,153,0,2800 154 | WHEELER,154,0,8545 155 | WHITE,155,0,28098 156 | WHITFIELD,156,7,165146 157 | WILCOX,157,0,11644 158 | WILKES,158,1,14223 159 | WILKINSON,159,0,14488 160 | WORTH,160,0,32640 -------------------------------------------------------------------------------- /data/growthy.txt: -------------------------------------------------------------------------------- 1 | 2.100000000000000000e+01 2.000000000000000000e+01 2.150000000000000000e+01 2.300000000000000000e+01 2 | 2.100000000000000000e+01 2.150000000000000000e+01 2.400000000000000000e+01 2.550000000000000000e+01 3 | 2.050000000000000000e+01 2.400000000000000000e+01 2.450000000000000000e+01 2.600000000000000000e+01 4 | 2.350000000000000000e+01 2.450000000000000000e+01 2.500000000000000000e+01 2.650000000000000000e+01 5 | 2.150000000000000000e+01 2.300000000000000000e+01 2.250000000000000000e+01 2.350000000000000000e+01 6 | 2.000000000000000000e+01 2.100000000000000000e+01 2.100000000000000000e+01 2.250000000000000000e+01 7 | 2.150000000000000000e+01 2.250000000000000000e+01 2.300000000000000000e+01 2.500000000000000000e+01 8 | 2.300000000000000000e+01 2.300000000000000000e+01 2.350000000000000000e+01 2.400000000000000000e+01 9 | 2.000000000000000000e+01 2.100000000000000000e+01 2.200000000000000000e+01 2.150000000000000000e+01 10 | 1.650000000000000000e+01 1.900000000000000000e+01 1.900000000000000000e+01 1.950000000000000000e+01 11 | 2.450000000000000000e+01 2.500000000000000000e+01 2.800000000000000000e+01 2.800000000000000000e+01 12 | 2.600000000000000000e+01 2.500000000000000000e+01 2.900000000000000000e+01 3.100000000000000000e+01 13 | 2.150000000000000000e+01 2.250000000000000000e+01 2.400000000000000000e+01 2.750000000000000000e+01 14 | 2.300000000000000000e+01 2.250000000000000000e+01 2.400000000000000000e+01 2.750000000000000000e+01 15 | 2.550000000000000000e+01 2.750000000000000000e+01 2.650000000000000000e+01 2.700000000000000000e+01 16 | 2.000000000000000000e+01 2.350000000000000000e+01 2.250000000000000000e+01 2.600000000000000000e+01 17 | 2.450000000000000000e+01 2.550000000000000000e+01 2.700000000000000000e+01 2.850000000000000000e+01 18 | 2.200000000000000000e+01 2.200000000000000000e+01 2.450000000000000000e+01 2.650000000000000000e+01 19 | 2.400000000000000000e+01 2.150000000000000000e+01 2.450000000000000000e+01 2.550000000000000000e+01 20 | 2.750000000000000000e+01 2.800000000000000000e+01 3.100000000000000000e+01 3.150000000000000000e+01 21 | 2.300000000000000000e+01 2.300000000000000000e+01 2.350000000000000000e+01 2.500000000000000000e+01 22 | 2.150000000000000000e+01 2.350000000000000000e+01 2.400000000000000000e+01 2.800000000000000000e+01 23 | 1.700000000000000000e+01 2.450000000000000000e+01 2.600000000000000000e+01 2.950000000000000000e+01 24 | 2.250000000000000000e+01 2.550000000000000000e+01 2.550000000000000000e+01 2.600000000000000000e+01 25 | 2.300000000000000000e+01 2.450000000000000000e+01 2.600000000000000000e+01 3.000000000000000000e+01 26 | 2.200000000000000000e+01 2.150000000000000000e+01 2.350000000000000000e+01 2.500000000000000000e+01 27 | -------------------------------------------------------------------------------- /data/hald_data.csv: -------------------------------------------------------------------------------- 1 | x1,x2,x3,x4,y 2 | 7,26,6,60,78.5 3 | 1,29,15,52,74.3 4 | 11,56,8,20,104.3 5 | 11,31,8,47,87.6 6 | 7,52,6,33,95.9 7 | 11,55,9,22,109.2 8 | 3,71,17,6,102.7 9 | 1,31,22,44,72.5 10 | 2,54,18,22,93.1 11 | 21,47,4,26,115.9 12 | 1,40,23,34,83.8 13 | 11,66,9,12,113.3 14 | 10,68,8,12,109.4 -------------------------------------------------------------------------------- /data/hospitalizations_data.csv: -------------------------------------------------------------------------------- 1 | Group,0,1,2,3,4,5,6,7,n,Mean,Variance 2 | Control,138,77,46,12,8,4,0,2,287,0.944,1.54 3 | Treatment,147,83,37,13,3,1,1,0,285,0.768,1.02 4 | -------------------------------------------------------------------------------- /data/iop.csv: -------------------------------------------------------------------------------- 1 | LowIOP,Thickness 2 | 1,386 3 | 1,397 4 | 1,397 5 | 0,409 6 | 1,412 7 | 0,419 8 | 0,424 9 | 1,426 10 | 1,428 11 | 1,428 12 | 0,428 13 | 1,431 14 | 0,432 15 | 0,433 16 | 0,434 17 | 1,437 18 | 0,440 19 | 0,441 20 | 0,441 21 | 1,443 22 | 0,445 23 | 0,447 24 | 0,447 25 | 0,447 26 | 0,448 27 | 0,450 28 | 1,451 29 | 0,452 30 | 1,454 31 | 0,454 32 | 0,454 33 | 1,455 34 | 1,455 35 | 1,455 36 | 1,456 37 | 0,457 38 | 0,462 39 | 1,462 40 | 1,463 41 | 1,463 42 | 0,464 43 | 0,466 44 | 0,466 45 | 0,467 46 | 1,467 47 | 0,468 48 | 0,468 49 | 0,468 50 | 0,468 51 | 0,470 52 | 1,471 53 | 0,471 54 | 1,471 55 | 0,472 56 | 0,472 57 | 0,473 58 | 0,474 59 | 1,474 60 | 0,474 61 | 0,475 62 | 0,475 63 | 1,476 64 | 0,476 65 | 0,476 66 | 0,476 67 | 0,479 68 | 0,480 69 | 0,481 70 | 1,481 71 | 1,482 72 | 0,483 73 | 1,484 74 | 0,485 75 | 1,485 76 | 0,487 77 | 0,487 78 | 1,489 79 | 0,490 80 | 0,490 81 | 1,490 82 | 0,490 83 | 0,491 84 | 1,492 85 | 0,492 86 | 0,493 87 | 0,493 88 | 0,493 89 | 0,494 90 | 0,496 91 | 0,496 92 | 0,496 93 | 0,499 94 | 0,501 95 | 0,501 96 | 0,502 97 | 0,502 98 | 1,503 99 | 0,506 100 | 0,507 101 | 0,508 102 | 0,508 103 | 1,508 104 | 0,510 105 | 0,511 106 | 0,513 107 | 0,513 108 | 1,514 109 | 0,514 110 | 0,515 111 | 0,516 112 | 0,516 113 | 0,517 114 | 0,519 115 | 0,520 116 | 0,520 117 | 0,520 118 | 0,523 119 | 0,524 120 | 0,526 121 | 0,526 122 | 0,527 123 | 0,529 124 | 0,529 125 | 0,532 126 | 0,533 127 | 0,536 128 | 0,538 129 | 0,540 130 | 0,541 131 | 0,542 132 | 0,543 133 | 0,549 134 | 0,551 135 | 0,552 136 | 0,558 137 | 0,561 138 | 0,565 139 | 0,565 140 | 0,569 141 | 0,590 -------------------------------------------------------------------------------- /data/magnesiumtw.csv: -------------------------------------------------------------------------------- 1 | D.Magn,N.Magn,D.Controls,N.Controls 2 | 1,40,2,36 3 | 9,135,23,135 4 | 2,200,7,200 5 | 1,48,1,46 6 | 10,150,8,148 7 | 1,59,9,56 8 | 1,25,3,23 9 | 0,22,1,21 10 | 6,76,11,75 11 | 1,27,7,27 12 | 2,89,12,80 13 | 5,23,13,33 14 | 4,130,8,122 15 | 90,1159,118,1157 16 | 4,107,17,108 17 | 2216,29011,2103,29039 -------------------------------------------------------------------------------- /data/rats.txt: -------------------------------------------------------------------------------- 1 | 1.510000000000000000e+02 1.990000000000000000e+02 2.460000000000000000e+02 2.830000000000000000e+02 3.200000000000000000e+02 2 | 1.450000000000000000e+02 1.990000000000000000e+02 2.490000000000000000e+02 2.930000000000000000e+02 3.540000000000000000e+02 3 | 1.470000000000000000e+02 2.140000000000000000e+02 2.630000000000000000e+02 3.120000000000000000e+02 3.280000000000000000e+02 4 | 1.550000000000000000e+02 2.000000000000000000e+02 2.370000000000000000e+02 2.720000000000000000e+02 2.970000000000000000e+02 5 | 1.350000000000000000e+02 1.880000000000000000e+02 2.300000000000000000e+02 2.800000000000000000e+02 3.230000000000000000e+02 6 | 1.590000000000000000e+02 2.100000000000000000e+02 2.520000000000000000e+02 2.980000000000000000e+02 nan 7 | 1.410000000000000000e+02 1.890000000000000000e+02 2.310000000000000000e+02 2.750000000000000000e+02 nan 8 | 1.590000000000000000e+02 2.010000000000000000e+02 2.480000000000000000e+02 2.970000000000000000e+02 nan 9 | 1.770000000000000000e+02 2.360000000000000000e+02 2.850000000000000000e+02 3.500000000000000000e+02 nan 10 | 1.340000000000000000e+02 1.820000000000000000e+02 2.200000000000000000e+02 2.600000000000000000e+02 nan 11 | 1.600000000000000000e+02 2.080000000000000000e+02 2.610000000000000000e+02 3.130000000000000000e+02 nan 12 | 1.430000000000000000e+02 1.880000000000000000e+02 2.200000000000000000e+02 nan nan 13 | 1.540000000000000000e+02 2.000000000000000000e+02 2.440000000000000000e+02 nan nan 14 | 1.710000000000000000e+02 2.210000000000000000e+02 2.700000000000000000e+02 nan nan 15 | 1.630000000000000000e+02 2.160000000000000000e+02 2.420000000000000000e+02 nan nan 16 | 1.600000000000000000e+02 2.070000000000000000e+02 2.480000000000000000e+02 nan nan 17 | 1.420000000000000000e+02 1.870000000000000000e+02 2.340000000000000000e+02 nan nan 18 | 1.560000000000000000e+02 2.030000000000000000e+02 2.430000000000000000e+02 nan nan 19 | 1.570000000000000000e+02 2.120000000000000000e+02 2.590000000000000000e+02 nan nan 20 | 1.520000000000000000e+02 2.030000000000000000e+02 2.460000000000000000e+02 nan nan 21 | 1.540000000000000000e+02 2.050000000000000000e+02 2.530000000000000000e+02 nan nan 22 | 1.390000000000000000e+02 1.900000000000000000e+02 nan nan nan 23 | 1.460000000000000000e+02 1.910000000000000000e+02 nan nan nan 24 | 1.570000000000000000e+02 2.110000000000000000e+02 nan nan nan 25 | 1.320000000000000000e+02 1.850000000000000000e+02 nan nan nan 26 | 1.600000000000000000e+02 nan nan nan nan 27 | 1.690000000000000000e+02 nan nan nan nan 28 | 1.570000000000000000e+02 nan nan nan nan 29 | 1.370000000000000000e+02 nan nan nan nan 30 | 1.530000000000000000e+02 nan nan nan nan 31 | -------------------------------------------------------------------------------- /data/rats_nocenteringY.txt: -------------------------------------------------------------------------------- 1 | 1.510000000000000000e+02 1.990000000000000000e+02 2.460000000000000000e+02 2.830000000000000000e+02 3.200000000000000000e+02 2 | 1.450000000000000000e+02 1.990000000000000000e+02 2.490000000000000000e+02 2.930000000000000000e+02 3.540000000000000000e+02 3 | 1.470000000000000000e+02 2.140000000000000000e+02 2.630000000000000000e+02 3.120000000000000000e+02 3.280000000000000000e+02 4 | 1.550000000000000000e+02 2.000000000000000000e+02 2.370000000000000000e+02 2.720000000000000000e+02 2.970000000000000000e+02 5 | 1.350000000000000000e+02 1.880000000000000000e+02 2.300000000000000000e+02 2.800000000000000000e+02 3.230000000000000000e+02 6 | 1.590000000000000000e+02 2.100000000000000000e+02 2.520000000000000000e+02 2.980000000000000000e+02 3.310000000000000000e+02 7 | 1.410000000000000000e+02 1.890000000000000000e+02 2.310000000000000000e+02 2.750000000000000000e+02 3.050000000000000000e+02 8 | 1.590000000000000000e+02 2.010000000000000000e+02 2.480000000000000000e+02 2.970000000000000000e+02 3.380000000000000000e+02 9 | 1.770000000000000000e+02 2.360000000000000000e+02 2.850000000000000000e+02 3.500000000000000000e+02 3.760000000000000000e+02 10 | 1.340000000000000000e+02 1.820000000000000000e+02 2.200000000000000000e+02 2.600000000000000000e+02 2.960000000000000000e+02 11 | 1.600000000000000000e+02 2.080000000000000000e+02 2.610000000000000000e+02 3.130000000000000000e+02 3.520000000000000000e+02 12 | 1.430000000000000000e+02 1.880000000000000000e+02 2.200000000000000000e+02 2.730000000000000000e+02 3.140000000000000000e+02 13 | 1.540000000000000000e+02 2.000000000000000000e+02 2.440000000000000000e+02 2.890000000000000000e+02 3.250000000000000000e+02 14 | 1.710000000000000000e+02 2.210000000000000000e+02 2.700000000000000000e+02 3.260000000000000000e+02 3.580000000000000000e+02 15 | 1.630000000000000000e+02 2.160000000000000000e+02 2.420000000000000000e+02 2.810000000000000000e+02 3.120000000000000000e+02 16 | 1.600000000000000000e+02 2.070000000000000000e+02 2.480000000000000000e+02 2.880000000000000000e+02 3.240000000000000000e+02 17 | 1.420000000000000000e+02 1.870000000000000000e+02 2.340000000000000000e+02 2.800000000000000000e+02 3.160000000000000000e+02 18 | 1.560000000000000000e+02 2.030000000000000000e+02 2.430000000000000000e+02 2.830000000000000000e+02 3.170000000000000000e+02 19 | 1.570000000000000000e+02 2.120000000000000000e+02 2.590000000000000000e+02 3.070000000000000000e+02 3.360000000000000000e+02 20 | 1.520000000000000000e+02 2.030000000000000000e+02 2.460000000000000000e+02 2.860000000000000000e+02 3.210000000000000000e+02 21 | 1.540000000000000000e+02 2.050000000000000000e+02 2.530000000000000000e+02 2.980000000000000000e+02 3.340000000000000000e+02 22 | 1.390000000000000000e+02 1.900000000000000000e+02 2.250000000000000000e+02 2.670000000000000000e+02 3.020000000000000000e+02 23 | 1.460000000000000000e+02 1.910000000000000000e+02 2.290000000000000000e+02 2.720000000000000000e+02 3.020000000000000000e+02 24 | 1.570000000000000000e+02 2.110000000000000000e+02 2.500000000000000000e+02 2.850000000000000000e+02 3.230000000000000000e+02 25 | 1.320000000000000000e+02 1.850000000000000000e+02 2.370000000000000000e+02 2.860000000000000000e+02 3.310000000000000000e+02 26 | 1.600000000000000000e+02 2.070000000000000000e+02 2.570000000000000000e+02 3.030000000000000000e+02 3.450000000000000000e+02 27 | 1.690000000000000000e+02 2.160000000000000000e+02 2.610000000000000000e+02 2.950000000000000000e+02 3.330000000000000000e+02 28 | 1.570000000000000000e+02 2.050000000000000000e+02 2.480000000000000000e+02 2.890000000000000000e+02 3.160000000000000000e+02 29 | 1.370000000000000000e+02 1.800000000000000000e+02 2.190000000000000000e+02 2.580000000000000000e+02 2.910000000000000000e+02 30 | 1.530000000000000000e+02 2.000000000000000000e+02 2.440000000000000000e+02 2.860000000000000000e+02 3.240000000000000000e+02 31 | -------------------------------------------------------------------------------- /data/rats_nocenteringx.txt: -------------------------------------------------------------------------------- 1 | 8.000000000000000000e+00 2 | 1.500000000000000000e+01 3 | 2.200000000000000000e+01 4 | 2.900000000000000000e+01 5 | 3.600000000000000000e+01 6 | -------------------------------------------------------------------------------- /data/shocks.csv: -------------------------------------------------------------------------------- 1 | Current (milliamps),Number of Responses $y$,Number of Trials $n$,Proportion of Responses $p$ 2 | 0,0,70,0.0 3 | 1,9,70,0.129 4 | 2,21,70,0.3 5 | 3,47,70,0.671 6 | 4,60,70,0.857 7 | 5,63,70,0.9 8 | -------------------------------------------------------------------------------- /data/simvastatin_data.tsv: -------------------------------------------------------------------------------- 1 | apa conc time 2 | 0.062 1 1 3 | 0.517 1 1 4 | 0.261 1 1 5 | 0.154 1 1 6 | 0.071 2 1 7 | 0.472 2 1 8 | 0.903 2 1 9 | 0.565 2 1 10 | 0.068 3 1 11 | 0.474 3 1 12 | 0.063 3 1 13 | 0.059 3 1 14 | 0.066 4 1 15 | 0.670 4 1 16 | 0.076 4 1 17 | 0.080 4 1 18 | 0.055 1 2 19 | 0.054 1 2 20 | 0.056 1 2 21 | 0.063 1 2 22 | 0.055 2 2 23 | 0.060 2 2 24 | 0.057 2 2 25 | 0.056 2 2 26 | 0.059 3 2 27 | 0.070 3 2 28 | 0.090 3 2 29 | 0.064 3 2 30 | 0.447 4 2 31 | 0.091 4 2 32 | 0.079 4 2 33 | 0.071 4 2 34 | 0.055 1 3 35 | 0.059 1 3 36 | 0.062 1 3 37 | 0.062 1 3 38 | 0.067 2 3 39 | 1.234 2 3 40 | 1.086 2 3 41 | 0.188 2 3 42 | 0.092 3 3 43 | 0.096 3 3 44 | 0.123 3 3 45 | 0.091 3 3 46 | 0.086 4 3 47 | 0.076 4 3 48 | 0.082 4 3 49 | 0.080 4 3 50 | 1.028 1 4 51 | 1.067 1 4 52 | 1.128 1 4 53 | 0.855 1 4 54 | 0.075 2 4 55 | 0.076 2 4 56 | 0.090 2 4 57 | 1.209 2 4 58 | 0.091 3 4 59 | 0.218 3 4 60 | 0.618 3 4 61 | 0.093 3 4 62 | 0.248 4 4 63 | 0.094 4 4 64 | 0.215 4 4 65 | 0.401 4 4 66 | 0.607 1 5 67 | 0.104 1 5 68 | 0.163 1 5 69 | 0.109 1 5 70 | 0.068 2 5 71 | 0.143 2 5 72 | 0.108 2 5 73 | 0.075 2 5 74 | 0.098 3 5 75 | 0.122 3 5 76 | 0.837 3 5 77 | 0.142 3 5 78 | 0.108 4 5 79 | 0.105 4 5 80 | 0.093 4 5 81 | 0.580 4 5 82 | 0.067 1 6 83 | 0.093 1 6 84 | 0.165 1 6 85 | 0.076 1 6 86 | 0.347 2 6 87 | 0.106 2 6 88 | 0.170 2 6 89 | 0.097 2 6 90 | 0.115 3 6 91 | 0.085 3 6 92 | 0.076 3 6 93 | 0.085 3 6 94 | 0.290 4 6 95 | 0.090 4 6 96 | 0.518 4 6 97 | 0.071 4 6 98 | -------------------------------------------------------------------------------- /data/stagnant_water.csv: -------------------------------------------------------------------------------- 1 | y,x 2 | 1.12,-1.39 3 | 1.12,-1.39 4 | 0.99,-1.08 5 | 1.03,-1.08 6 | 0.92,-0.94 7 | ,-0.8 8 | 0.81,-0.63 9 | 0.83,-0.63 10 | 0.65,-0.25 11 | 0.67,-0.25 12 | 0.6,-0.12 13 | 0.59, 14 | 0.51,0.01 15 | 0.44,0.11 16 | 0.43,0.11 17 | 0.43,0.11 18 | 0.33,0.25 19 | 0.3,0.25 20 | 0.25,0.34 21 | ,0.34 22 | 0.13,0.44 23 | -0.01,0.59 24 | -0.13,0.7 25 | -0.14,0.7 26 | -0.3,0.85 27 | -0.33, 28 | -0.46,0.99 29 | -0.43,0.99 30 | -0.65,1.19 31 | -------------------------------------------------------------------------------- /data/sunspots.txt: -------------------------------------------------------------------------------- 1 | 1.007999999999999972e+02 2 | 8.159999999999999432e+01 3 | 6.650000000000000000e+01 4 | 3.479999999999999716e+01 5 | 3.060000000000000142e+01 6 | 7.000000000000000000e+00 7 | 1.980000000000000071e+01 8 | 9.250000000000000000e+01 9 | 1.544000000000000057e+02 10 | 1.259000000000000057e+02 11 | 8.479999999999999716e+01 12 | 6.809999999999999432e+01 13 | 3.850000000000000000e+01 14 | 2.280000000000000071e+01 15 | 1.019999999999999929e+01 16 | 2.410000000000000142e+01 17 | 8.290000000000000568e+01 18 | 1.320000000000000000e+02 19 | 1.309000000000000057e+02 20 | 1.180999999999999943e+02 21 | 8.990000000000000568e+01 22 | 6.659999999999999432e+01 23 | 6.000000000000000000e+01 24 | 4.689999999999999858e+01 25 | 4.100000000000000000e+01 26 | 2.130000000000000071e+01 27 | 1.600000000000000000e+01 28 | 6.400000000000000355e+00 29 | 4.099999999999999645e+00 30 | 6.799999999999999822e+00 31 | 1.450000000000000000e+01 32 | 3.400000000000000000e+01 33 | 4.500000000000000000e+01 34 | 4.310000000000000142e+01 35 | 4.750000000000000000e+01 36 | 4.220000000000000284e+01 37 | 2.810000000000000142e+01 38 | 1.009999999999999964e+01 39 | 8.099999999999999645e+00 40 | 2.500000000000000000e+00 41 | 0.000000000000000000e+00 42 | 1.399999999999999911e+00 43 | 5.000000000000000000e+00 44 | 1.219999999999999929e+01 45 | 1.390000000000000036e+01 46 | 3.539999999999999858e+01 47 | 4.579999999999999716e+01 48 | 4.110000000000000142e+01 49 | 3.039999999999999858e+01 50 | 2.389999999999999858e+01 51 | 1.569999999999999929e+01 52 | 6.599999999999999645e+00 53 | 4.000000000000000000e+00 54 | 1.800000000000000044e+00 55 | 8.500000000000000000e+00 56 | 1.660000000000000142e+01 57 | 3.629999999999999716e+01 58 | 4.970000000000000284e+01 59 | 6.250000000000000000e+01 60 | 6.700000000000000000e+01 61 | 7.100000000000000000e+01 62 | 4.779999999999999716e+01 63 | 2.750000000000000000e+01 64 | 8.500000000000000000e+00 65 | 1.319999999999999929e+01 66 | 5.689999999999999858e+01 67 | 1.215000000000000000e+02 68 | 1.383000000000000114e+02 69 | 1.032000000000000028e+02 70 | 8.579999999999999716e+01 71 | 6.320000000000000284e+01 72 | 3.679999999999999716e+01 73 | 2.419999999999999929e+01 74 | 1.069999999999999929e+01 75 | 1.500000000000000000e+01 76 | 4.010000000000000142e+01 77 | 6.150000000000000000e+01 78 | 9.850000000000000000e+01 79 | 1.242999999999999972e+02 80 | 9.590000000000000568e+01 81 | 6.650000000000000000e+01 82 | 6.450000000000000000e+01 83 | 5.420000000000000284e+01 84 | 3.900000000000000000e+01 85 | 2.060000000000000142e+01 86 | 6.700000000000000178e+00 87 | 4.299999999999999822e+00 88 | 2.280000000000000071e+01 89 | 5.479999999999999716e+01 90 | 9.379999999999999716e+01 91 | 9.570000000000000284e+01 92 | 7.720000000000000284e+01 93 | 5.910000000000000142e+01 94 | 4.400000000000000000e+01 95 | 4.700000000000000000e+01 96 | 3.050000000000000000e+01 97 | 1.630000000000000071e+01 98 | 7.299999999999999822e+00 99 | 3.729999999999999716e+01 100 | 7.390000000000000568e+01 101 | -------------------------------------------------------------------------------- /data/terrapins.csv: -------------------------------------------------------------------------------- 1 | Temp,Female,Total 2 | 24,0,21 3 | 26,7,46 4 | 28,19,53 5 | 30,36,38 6 | 32,29,29 -------------------------------------------------------------------------------- /data/thirddegreeburns.csv: -------------------------------------------------------------------------------- 1 | Log(area+1),Survived,Died 2 | 1.35,13,0 3 | 1.6,19,0 4 | 1.75,67,2 5 | 1.85,45,5 6 | 1.95,71,8 7 | 2.05,50,20 8 | 2.15,35,31 9 | 2.25,7,49 10 | 2.35,1,12 11 | -------------------------------------------------------------------------------- /data/vasoconstriction.csv: -------------------------------------------------------------------------------- 1 | y,v,r 2 | 1,3.7,0.825 3 | 1,3.5,1.09 4 | 1,1.25,2.5 5 | 1,0.75,1.5 6 | 1,0.8,3.2 7 | 1,0.7,3.5 8 | 0,0.6,0.75 9 | 0,1.1,1.7 10 | 0,0.9,0.75 11 | 0,0.9,0.45 12 | 0,0.8,0.57 13 | 0,0.55,2.75 14 | 0,0.6,3 15 | 1,1.4,2.33 16 | 1,0.75,3.75 17 | 1,2.3,1.64 18 | 1,3.2,1.6 19 | 1,0.85,1.415 20 | 1,1.7,1.06 21 | 0,1.8,1.8 22 | 1,0.4,2 23 | 0,0.95,1.36 24 | 0,1.35,1.35 25 | 0,1.5,1.36 26 | 0,1.6,1.78 27 | 1,0.6,1.5 28 | 0,1.8,1.5 29 | 1,0.95,1.9 30 | 0,1.9,0.95 31 | 1,1.6,0.4 32 | 0,2.7,0.75 33 | 1,2.35,0.3 34 | 0,1.1,1.83 35 | 1,1.1,2.2 36 | 0,1.2,2 37 | 1,0.8,3.33 38 | 1,0.95,1.9 39 | 0,0.75,1.9 40 | 1,1.3,1.625 41 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: pymc 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - pymc 6 | - jupyterlab 7 | - ca-certificates 8 | - certifi 9 | - openssl 10 | - nb_black 11 | - jax 12 | - numpyro 13 | - blackjax 14 | - nutpie 15 | - polars 16 | - watermark 17 | - libblas[build=*accelerate] 18 | - fsspec 19 | - xlsx2csv 20 | - ipywidgets 21 | - python-graphviz 22 | prefix: /Users/aaron/mambaforge/envs/pymc 23 | -------------------------------------------------------------------------------- /favicon/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/android-chrome-192x192.png -------------------------------------------------------------------------------- /favicon/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/android-chrome-512x512.png -------------------------------------------------------------------------------- /favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/favicon/favicon.ico -------------------------------------------------------------------------------- /favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /images/35q12circuit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q12circuit.jpg -------------------------------------------------------------------------------- /images/35q13circuit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q13circuit.jpg -------------------------------------------------------------------------------- /images/35q14figure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q14figure.jpg -------------------------------------------------------------------------------- /images/35q15fig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q15fig.jpg -------------------------------------------------------------------------------- /images/35q2branch1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q2branch1.jpg -------------------------------------------------------------------------------- /images/35q2branch2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q2branch2.jpg -------------------------------------------------------------------------------- /images/35q2branch3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/35q2branch3.jpg -------------------------------------------------------------------------------- /images/Amanita_Muscaria_in_Eastern_Europe_Lithuania_Wikipedia.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/Amanita_Muscaria_in_Eastern_Europe_Lithuania_Wikipedia.jpg -------------------------------------------------------------------------------- /images/amanita-muscaria-sp2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/amanita-muscaria-sp2.jpg -------------------------------------------------------------------------------- /images/doesnt-look-like-anything-to-me-westworld.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/doesnt-look-like-anything-to-me-westworld.gif -------------------------------------------------------------------------------- /images/q17_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/q17_plot.png -------------------------------------------------------------------------------- /images/q4_plot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/q4_plot1.png -------------------------------------------------------------------------------- /images/q4_plot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/q4_plot2.png -------------------------------------------------------------------------------- /images/q5_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/q5_plot.png -------------------------------------------------------------------------------- /images/q7_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/q7_plot.png -------------------------------------------------------------------------------- /images/unit6_graph_theory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/images/unit6_graph_theory.jpg -------------------------------------------------------------------------------- /intro.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | This repository contains Python translations of the examples from Georgia Tech's [ISYE 6420: Bayesian Statistics](https://www2.isye.gatech.edu/isye6420/), created by Professor Brani Vidakovic and currently taught by Professor Roshan Joseph. It also includes notes on each lecture. 4 | 5 | ## Why? 6 | 7 | We created this site to address some of the most common student complaints and questions. The most frequent source of dissatisfaction was the course's use of OpenBUGS, so we redid the lecture examples in Python and PyMC. 8 | 9 | We also want to supplement the lectures by adding notes that address common questions and provide links for further reading on specific subjects. As an overview course, this class doesn't go too deep on any one topic, but we hope to provide a jumping-off point for students who are interested in going further. 10 | 11 | ## Site structure 12 | 13 | This site was built with [Jupyter Book](https://jupyterbook.org/en/stable/intro.html) and is made up of a combination of Markdown files and Jupyter notebooks. You can download the source for any page in the upper right, or view the entire repository on [Github](https://github.com/areding/6420-pymc). 14 | 15 | All pages match a corresponding lecture on Canvas, except when there are more pages than lectures in a unit, in which case the additional pages will be at the end of the unit. For example, there are only eight lectures in Unit 3 on Canvas. The first eight pages here match the lecture numbers, while the ninth and tenth pages are supplementary problems. 16 | 17 | Any necessary data will either have a download link or, if the data is compact enough, will be included in the code. 18 | 19 | ## Contributors 20 | 21 | [Aaron Reding](https://github.com/areding), current head TA, started taking notes on the lectures and working on PyMC versions of the code as a student in Spring 2020, eventually using those materials to create this site. 22 | 23 | [Greg Schreiter](https://github.com/schr0841) was the head TA for several years and wrote many of the problem solutions as well as compiling the course errata. 24 | 25 | [Jason Naramore](https://github.com/jnaramore), a current TA, has contributed Python code, exercise solutions, and lecture notes. 26 | 27 | [Rob Bennett](https://github.com/rmbennet), a current TA, has contributed Python code, supplementary lecture notes, proofs, and analytical solutions to coding exercises having closed-form solutions. 28 | 29 | [Taylor Bosier](https://github.com/tbosier), a TA in the Fall 2024 semester, contributed code and writing on PyMC best practices. 30 | 31 | Former students [Amanuel Anteneh](https://github.com/amanuelanteneh) and [Anthony Miyaguchi](https://github.com/acmiyaguchi) have contributed code and notes. 32 | 33 | Thank you to everyone who has contributed, both directly and indirectly by asking great questions on the class discussion forums. -------------------------------------------------------------------------------- /logos/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/logos/logo2.png -------------------------------------------------------------------------------- /original_examples/Codes4Unit1/BayesIntro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit1/BayesIntro.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit1/Regression.m: -------------------------------------------------------------------------------- 1 | %if OCTAVE is used 2 | %pkg load statistics 3 | x = [1 2 3 4 5]; 4 | y = [1 3 3 3 5]; 5 | xx=[ones(5,1) x']; 6 | b = regress(y', xx) 7 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit1/Regression.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit1/Regression.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit1/winbugs19.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit1/winbugs19.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/disasters.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/disasters.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/growth.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/growth.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/italywines123.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/italywines123.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/katla.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/katla.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/lister.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/lister.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/magnesiumTW.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/magnesiumTW.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/rasch.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/rasch.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/raschmodels.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/raschmodels.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit10/sunspots.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit10/sunspots.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/Support/BayesIntro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit2/Support/BayesIntro.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/Support/bayespicture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit2/Support/bayespicture.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/Support/essay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit2/Support/essay.jpg -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/Support/essayall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit2/Support/essayall.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/Support/price.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit2/Support/price.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/coin.m: -------------------------------------------------------------------------------- 1 | %COIN 2 | close all 3 | p = 0:0.01:1; 4 | P10T = @(p) 11 * (1-p).^10; % 11 to normalize to a density 5 | figure(1) 6 | plot(p, P10T(p), '-', 'LineWidth',2) 7 | % 8 | quad(P10T, 0, 1) 9 | % 10 | %for the mean 11 | pP10T = @(p) 11 * p .* (1-p).^10; 12 | quad(pP10T, 0, 1) %0.083333 (1/12) 13 | hold on 14 | scatter([0 0],[0 11],200,'r','filled') 15 | scatter([1/12 1/12],[0 P10T(1/12)],200,'g','filled') 16 | % for the median 17 | quad(P10T, 0, 0.061069) %0.50000 18 | scatter([0.061069 0.061069],[0 P10T(0.061069)],... 19 | 200,'b','filled') 20 | title ('Coin'); 21 | xlabel ('p'); 22 | ylabel ('f(p)'); 23 | text (0.05, 11, '\fontsize{14} mode'); 24 | legend ('\fontsize{12} Likelihood','\fontsize{12} MAP',... 25 | '\fontsize{12} Mean','\fontsize{12} Median'); -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/coin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Sep 5 22:18:07 2017 4 | @author: bv20 5 | """ 6 | 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | import scipy.integrate 10 | #COIN 11 | 12 | plt.figure() 13 | p = np.arange(0,1,0.001) 14 | p10t = lambda p: 11 * (1-p)**10 15 | plt.plot(p, p10t(p),label='density') 16 | 17 | area = scipy.integrate.quad(p10t, 0, 1) 18 | print(area) 19 | # 20 | #for the mean 21 | pp10t = lambda p: 11 * p * (1-p)**10 22 | mean=scipy.integrate.quad(pp10t, 0, 1) 23 | print(mean) 24 | # for the median 25 | is05 = scipy.integrate.quad(p10t, 0, 0.0610690893384) 26 | print(is05) 27 | # 28 | plt.scatter((0,0), (0,11), color = 'r', alpha=0.5, s=100, label='mode') 29 | plt.scatter((1/12,1/12), (0,p10t(1/12)), color = 'g', alpha=0.5, s=100, label='mean') 30 | x=(0.06107, 0.06107); y=(0, p10t(0.06107)) 31 | plt.scatter(x, y, color = 'k', alpha=0.5, s=100, label='median') 32 | plt.legend(loc='upper right') 33 | plt.show() 34 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit2/coin.r: -------------------------------------------------------------------------------- 1 | #COIN 2 | p = seq(0,1,0.01) 3 | P10T = function(p) {11 * (1-p)^10} 4 | # 11 to normalize to a density 5 | plot(p, P10T(p),"l") 6 | # 7 | integrate(P10T, lower=0, upper=1) 8 | # 9 | # for the mean 10 | pP10T = function(p) 11 * p * (1-p)^10 11 | integrate(pP10T, lower=0, upper=1) #0.08333333 (1/12) 12 | points(c(0, 0),c(0, 11), pch=16, col="red") 13 | points(c(1/12, 1/12),c(0, P10T(1/12)),pch=16,col="green") 14 | # for the median 15 | integrate(P10T, lower=0, upper=0.061069081) #0.50000 16 | points(c(0.061069081, 0.061069081), 17 | c(0, P10T(0.061069081)), pch=16, col="blue") 18 | legend(0.6,10, #location 19 | c("Mode","Mean","Median"), #labels 20 | cex= 1, #size 21 | pch=c(16,16,16), #filled circle 22 | col=c("red","green","blue")) #color 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit3/alarm.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit3/alarm.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit3/manufacturingbayes.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit3/manufacturingbayes.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit3/twoheaded.m: -------------------------------------------------------------------------------- 1 | % "Two-headed coin" 2 | % 3 | % Out of N coins one is with two heads. A coin is selected 4 | % at random and flipped k times and k times heads appeared. 5 | % What is the probability that the coin with two heads was 6 | % selected? 7 | % 8 | % 9 | clear all 10 | close all 11 | 12 | 13 | disp('Two Headed Coin') 14 | lw = 3; 15 | set(0, 'DefaultAxesFontSize', 16); 16 | fs = 15; 17 | msize = 10; 18 | 19 | 20 | N=1000000; %number of coins N-1 fair, 1 two-headed 21 | % 22 | pro = @(k, N) 2.^k./(2.^k + N - 1); 23 | p=[]; %keep posterior probs here 24 | for k=1:40 25 | p = [p pro(k, N)]; 26 | %or simply: p = [p 2^k/(2^k + N - 1)]; 27 | end 28 | figure(1) 29 | plot((1:40), p, 'linewidth', lw) 30 | hold on 31 | plot((1:40), p, 'o', 'markersize', msize,... 32 | 'MarkerEdgeColor','k',... 33 | 'MarkerFaceColor','g') 34 | 35 | plot(16, p(16), 'ro', 'markersize', msize,... 36 | 'MarkerEdgeColor','k',... 37 | 'MarkerFaceColor','r') 38 | 39 | plot(24, p(24), 'ro', 'markersize', msize,... 40 | 'MarkerEdgeColor','k',... 41 | 'MarkerFaceColor','r') 42 | plot([16,16],[0,1],'r:') 43 | plot([24,24],[0,1],'r:') 44 | ylabel('Posterior probability of a 2H coin') 45 | xlabel('Number of flips all resulting in H') 46 | %print -depsc 'C:\STAT\Probs\Probseps\twoheaded.eps' 47 | 48 | % figure(2) 49 | % op = p./(1-p); 50 | % semilogy((1:40),op, 'linewidth', lw) 51 | % hold on 52 | % semilogy((1:40), op, 'o', 'markersize', msize) 53 | % ylabel(' Posterior Odds') 54 | % xlabel('Number of flips all resulting in H') 55 | %print -depsc 'C:\Springer\Probs\Probseps\twoheaded.eps' 56 | k=[4 16 24 40 70]; 57 | format long 58 | pro(k, N) 59 | % 0.000015999760004 0.061505253229598 0.943748275531347 60 | % 0.999999090507035 0.999999999999999 61 | pro(21,N)-pro(19, N) 62 | % 0.333166719521469 63 | format short 64 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit4/betaplots.m: -------------------------------------------------------------------------------- 1 | 2 | clear all 3 | close all 4 | 5 | disp('BETA PLOTS FOR BAYES') 6 | lw = 2; 7 | set(0, 'DefaultAxesFontSize', 16); 8 | fs = 15; 9 | msize = 10; 10 | % end of preabmle-------------------------------------- 11 | 12 | figure(1) 13 | xx = 0:0.0001:1; 14 | subplot(3,3,1) 15 | yy1 = betapdf(xx, 1/2, 1/2); 16 | plot(xx, yy1, 'linewidth',lw) 17 | text(0.25, 4, '0.5, 0.5') 18 | axis([0 1 0 5]) 19 | subplot(3,3,2) 20 | yy1 = betapdf(xx, 1, 1); 21 | plot(xx, yy1, 'linewidth',lw) 22 | text(0.25, 0.9, '1, 1') 23 | axis([0 1 0 1.1]) 24 | subplot(3,3,3) 25 | yy1 = betapdf(xx, 2, 2); 26 | plot(xx, yy1, 'linewidth',lw) 27 | text(0.35, 1.1, '2, 2') 28 | axis([0 1 0 1.7]) 29 | subplot(3,3,4) 30 | yy1 = betapdf(xx, 10, 10); 31 | plot(xx, yy1, 'linewidth',lw) 32 | text(0.05, 3.1, '10, 10') 33 | subplot(3,3,5) 34 | yy1 = betapdf(xx, 1, 5); 35 | plot(xx, yy1, 'linewidth',lw) 36 | text(0.15, 4.1, '1, 5') 37 | axis([0 1 0 5.5]) 38 | subplot(3,3,6) 39 | yy1 = betapdf(xx, 1, 0.4); 40 | plot(xx, yy1, 'linewidth',lw) 41 | text(0.05, 4.1, '1, 0.4') 42 | axis([0 1 0 5.5]) 43 | subplot(3,3,7) 44 | yy1 = betapdf(xx, 3, 5); 45 | plot(xx, yy1, 'linewidth',lw) 46 | text(0.6, 2, '3, 5') 47 | axis([0 1 0 2.7]) 48 | subplot(3,3,8) 49 | yy1 = betapdf(xx, 50, 30); 50 | plot(xx, yy1, 'linewidth',lw) 51 | text(0.05, 6.1, '50, 30') 52 | axis([0 1 0 8]) 53 | subplot(3,3,9) 54 | yy1 = betapdf(xx, 5000, 3000); 55 | plot(xx, yy1, 'linewidth',lw) 56 | text(0.05, 50, '5000, 3000') 57 | axis([0 1 0 70]) 58 | %print -depsc 'C:\Brani\Courses\bmestatu\BMESBOOK\RVar\betapdfs.eps' 59 | %% 60 | figure(2) 61 | yycoin = betapdf(xx, 500, 500); 62 | plot(xx, yycoin, 'linewidth',lw) 63 | text(0.1, 25, '500, 500') 64 | axis([0 1 0 28]) 65 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit4/eBay.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit4/eBay.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit4/gammagamma.m: -------------------------------------------------------------------------------- 1 | % gammagamma.m 2 | close all 3 | figure(1) 4 | f=@(x,a,b) 1/gamma(a) * x.^(a-1) .* b.^a .* exp(- b * x) 5 | %f=@(x,a,b) gampdf(x, a, 1/b); 6 | xx=0.01:0.001:0.6 ; 7 | plot(xx, f(xx, 4, 29),'k-','linewidth',2) 8 | hold on 9 | plot(xx, 0.857*ones(size(xx)),'r-') 10 | plot(0.0246, f(0.0246, 4, 29), 'o') 11 | plot(0.0246, 0, 'ro') 12 | plot(0.2741, f(0.2741, 4, 29), 'o') 13 | plot(0.2741, 0, 'ro') 14 | plot([0.0246 0.2741],[0 0], 'r-','linewidth',8) 15 | hold off 16 | %% 17 | format long 18 | k=0.857368863848; 19 | a=4; b=29; 20 | ff=@(x) 1/gamma(4) * x.^3 .* 29.^4 .* exp(- 29 * x) - k 21 | a1=fzero(ff, 0.05) %0.0246 22 | a2=fzero( ff, 0.4) %0.2741 23 | gamcdf(a2, 4, 1/29) - gamcdf(a1, 4, 1/29) %0.95 24 | format short 25 | lengthhpd = a2 - a1 %0.24951 26 | %% 27 | % Equi-tailed CS 28 | 29 | [gaminv(0.025, 4, 1/29) gaminv(0.975, 4, 1/29)] 30 | % 0.0376 0.3023 31 | lengtheqt = gaminv(0.975, 4, 1/29) - gaminv(0.025, 4, 1/29) %0.26474 32 | 33 | figure(2) 34 | plot(xx, f(xx, 4, 29),'k-','linewidth',2) 35 | hold on 36 | plot(0.037582, f(0.037582, 4, 29), 'o') 37 | plot(0.037582, 0, 'ro') 38 | plot(0.30232, f(0.30232, 4, 29), 'o') 39 | plot(0.30232, 0, 'ro') 40 | plot([0.037582 0.30232],[0 0], 'r-','linewidth',8) 41 | plot([0.037582 0.30232],[f(0.037582,4,29) f(0.30232,4,29)], ... 42 | 'k-','linewidth',1) 43 | hold off 44 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/GIBBS.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit5/GIBBS.zip -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/albertmc1.m: -------------------------------------------------------------------------------- 1 | % A small company improved a product and 2 | % wants to infer about the proportion of 3 | % potential customers who will buy the product 4 | % if the new product is preferred to the old one. 5 | % The company is certain that this proportion will 6 | % exceed 0.5, i.e. and uses uniform priorn [0.5, 1]. 7 | % Out of 20 customers surweyed, 12 prefer the new product. 8 | % Approximate the posterior for p. 9 | clear all 10 | close all force 11 | %-----------------figure defaults 12 | lw = 2; 13 | set(0, 'DefaultAxesFontSize', 15); 14 | fs = 14; 15 | msize = 5; 16 | randn('seed',3) 17 | %-------------------------------- 18 | nn = 40000; % nn=number of metropolis iterations 19 | s=10; % s = std of normal proposal density 20 | %s=0.1 21 | burn=2000; % burn = burnin amount 22 | %--------------------------------------------- 23 | ps=[]; 24 | thetas=[]; %transformed p's 25 | old = 0; % start, theta_0 26 | for i = 1:nn 27 | prop = old + s*randn(1,1); %proposal from N(theta_old, s^2) 28 | u = rand(1,1); 29 | ep=exp(prop); eo=exp(old); 30 | post_p=((1/2 + ep)^12 * ep)/((1+ep)^22); 31 | post_o=((1/2 + eo)^12 * eo)/((1+eo)^22); 32 | new = old; 33 | if u <= min(post_p/post_o, 1) 34 | new = prop; %accept proposal as 'new' 35 | old = new; % and set 'old' to be the 'new' 36 | % for the next iteration; 37 | end 38 | thetas = [thetas, new]; %collect all theta's 39 | ps=[ps, (1/2+exp(new))/(1+exp(new))]; %back-transformation to p's. 40 | end 41 | figure(1) 42 | subplot(2,1,1) 43 | hist(thetas(1+burn:nn),50) 44 | subplot(2,1,2) 45 | hist(ps(1+burn:nn),50) 46 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working10\Figs\albert21.eps' 47 | %---------------------------------------------------------------------- 48 | figure(2) 49 | plot( (nn-500:nn) , thetas(nn-500:nn),'b-') 50 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working10\Figs\albert22.eps' -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/albertmc2.m: -------------------------------------------------------------------------------- 1 | % Dorn (1954): American Statistician, 8, 7-13. 2 | % 86 lung cancer patients; 86 controls//smokers, nonsmokers 3 | % Cancer Control 4 | % --------------------- 5 | % Smokers 83 72 6 | % --------------------- 7 | % Nonmokers 3 14 8 | %------------------------ 9 | % 10 | % Let p_L and p_C describe proportion of smokers 11 | % in population of lung canncer 12 | % patients and in the control. 13 | % We are interested in making inference about p_L and p_C 14 | % and, in particular, on p_L-p_C. 15 | 16 | 17 | clear all 18 | close all 19 | %-----------------figure defaults 20 | lw = 2; 21 | set(0, 'DefaultAxesFontSize', 18); 22 | fs = 14; 23 | msize = 5; 24 | randn('seed',3) 25 | %--------- 26 | nn = 20000; % nn=number of metropolis iterations 27 | burn=2000; % burn = burnin amount 28 | %--------------------------------------------- 29 | % lokelihood propto p_L^83 * (1-p_L)^3 * p_C^72 * (1-p_C)^14, 30 | % prior p_L^(-1) * (1-p_L)^(-1) * p_C^(-1) * (1-p_C)^(-1), 31 | % alpha=log(p_L/(1-p_L) * (1-p_C)/p_C); 32 | % eta = log(p_L/(1-p_L) * p_C/(1-p_C)); 33 | % -------------------------------------------- 34 | % If ep=exp((eta+alpha)/2); em=exp((eta-alpha)/2); 35 | % then the posterior is proportional to 36 | % ep^83/(1+ep)^86 * em^72/(1+em)^86 * (1-ep)^2/ep * (1+em)^2/em * 37 | % ep/(1-ep)^2 * em/(1+em)^2 = ep^83/(1+ep)^86 * em^72/(1+em)^86 38 | % (as lik*prior*jacobian) 39 | rand('seed',1); randn('seed',1) 40 | alphas=[]; etas=[]; pLs=[]; pCs=[]; 41 | alpha_old = 0; 42 | eta_old = 0; 43 | Sigma=[1 0.5; 0.5 1]; 44 | for i = 1:nn 45 | prop = randMVN(1, [eta_old, alpha_old]', Sigma)'; %proposal from 46 | eta_prop = prop(1); 47 | alpha_prop = prop(2); 48 | u = rand(1,1); 49 | epp=exp((eta_prop+alpha_prop)/2); emp=exp((eta_prop-alpha_prop)/2); 50 | epo=exp((eta_old+alpha_old)/2); emo=exp((eta_old-alpha_old)/2); 51 | post_p = (epp)^83/(1+epp)^86 * (emp)^72/(1+emp)^86; 52 | post_o = (epo)^83/(1+epo)^86 * (emo)^72/(1+emo)^86; 53 | eta_new = eta_old; alpha_new = alpha_old; 54 | if u <= min(post_p/post_o, 1) 55 | eta_new = eta_prop; alpha_new = alpha_prop; 56 | eta_old = eta_prop; alpha_old = alpha_prop; 57 | end 58 | etas=[etas eta_new]; 59 | alphas=[alphas, alpha_new]; %collect all theta's 60 | pLs=[pLs, exp( (eta_new+alpha_new)/2)/(1+exp( (eta_new+alpha_new)/2))]; 61 | pCs=[pCs, exp( (eta_new-alpha_new)/2)/(1+exp( (eta_new-alpha_new)/2))]; 62 | end 63 | figure(1) 64 | plot(etas(burn+1:nn), alphas(burn+1:nn),'.') 65 | xlabel('\eta'); ylabel('\alpha') 66 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working10\Figs\albert31.eps' 67 | figure(2) 68 | plot(pLs(burn+1:nn),pCs(burn+1:nn),'.') 69 | xlabel('p_L'); ylabel('p_C') 70 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working10\Figs\albert32.eps' 71 | figure(3) 72 | hist(pLs(burn+1:nn)-pCs(burn+1:nn),50) 73 | title('Histogram of differences: p_L - p_C') 74 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working10\Figs\albert33.eps' -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/disastersmc.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit5/disastersmc.m -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/gibbs.m: -------------------------------------------------------------------------------- 1 | % 2 | clear all 3 | close all 4 | %-------------------------------- 5 | lw = 2.5; 6 | set(0, 'DefaultAxesFontSize', 16); 7 | fs = 16; 8 | msize = 10; 9 | %---------------------------------------- 10 | disp('Gibbs for Mixture') 11 | rand('seed', 1) %initialize 12 | randn('seed',1) %random number generators 13 | % simulate data--------------------------- 14 | n=400; us = rand(1,n); 15 | for i=1:n 16 | if us(i) < 0.1 17 | x(i) = 2 * randn + 1; %0.1 of N(1,2^2) 18 | elseif us(i) > 0.8 19 | x(i) = 2 * randn + 20; %0.2 of N(20,2^2) 20 | else x(i) = 2 * randn + 9; %0.7 of N(9,2^2) 21 | end 22 | end 23 | x = sort(x); 24 | %fixed (hyper)parameters 25 | k=3; 26 | tau = 12; 27 | alpha = 5; 28 | delta = 30; 29 | gamma = 10; 30 | iterations = 5000; 31 | burn = 1000; 32 | %-------------------------- 33 | % initial parameters 34 | sig2 = 5; 35 | s0=repeat((1:k)', ceil(n/k)); 36 | s1 = s0'; s2 = s1(:); s = s2(1:n); %s is latent variable 37 | w = repeat(1/k, k); %equal weight 38 | mu = repeat(10,k); 39 | % 40 | %---------for iter = 1:iterations 41 | mus=[]; sig2s=[]; ws=[]; 42 | h=waitbar(0,'Simulation in progress'); 43 | for iter=1: burn + iterations 44 | for i=1:n 45 | for j=1:k 46 | sij(i,j)= (s(i)==j); 47 | end 48 | end 49 | nj=sum(sij); 50 | w = (rand_dirichlet(alpha + nj, 1))'; 51 | %--------------------------- 52 | for j = 1:k 53 | sj(j) = sum(x(s==j)); 54 | end 55 | mu = sqrt( 1./( nj/sig2 + 1/tau^2)) .* randn(1,k) + (tau^2.*sj)./(nj*tau^2+sig2); 56 | %--------------------------- 57 | for j = 1:k 58 | sm2j(j) = sum ( (x(s==j) - mu(j)).^2 ); 59 | end 60 | sig2 = 1./rand_gamma( gamma + n/2, delta + 1/2 * sum(sm2j), 1, 1); 61 | %------------------------------------------------------------- 62 | 63 | pr = zeros(n,k); 64 | for i = 1:n 65 | for j=1:k 66 | pr(i,j) = w(j)*exp( - (x(i) - mu(j))^2 /(2 * sig2)); 67 | end 68 | end 69 | tot= repeat((sum(pr'))',3); 70 | pr=pr./tot; 71 | for i=1:n 72 | [aa,bb]=rand_multinomial(1,pr(i,:)); 73 | s(i) = find(bb==1); 74 | end 75 | %-------------------------------------------------------------- 76 | mus=[mus; mu]; 77 | sig2s=[sig2s, sig2]; 78 | ws = [ws; w]; 79 | waitbar(iter/(burn+iterations)) 80 | end 81 | close(h) 82 | muss=mus(burn+1:end, :); 83 | mmu= mean(muss) 84 | sig2ss = sig2s(burn+1: end); 85 | msig2= mean(sig2ss) 86 | wss = ws(burn+1:end, :); 87 | mw = mean(wss) 88 | 89 | figure(1) 90 | subplot(3,1,1) 91 | hist(muss(:,1),50) 92 | subplot(3,1,2) 93 | hist(muss(:,2),50) 94 | subplot(3,1,3) 95 | hist(muss(:,3),50) 96 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working12\Figs\MixGibbs1.eps' 97 | 98 | figure(2) 99 | hist(sig2ss, 50) 100 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working12\Figs\MixGibbs2.eps' 101 | figure(3) 102 | subplot(3,1,1) 103 | hist(wss(:,1),50) 104 | subplot(3,1,2) 105 | hist(wss(:,2),50) 106 | subplot(3,1,3) 107 | hist(wss(:,3),50) 108 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working12\Figs\MixGibbs3.eps' 109 | 110 | % figure(4) 111 | % [fr, ce]= hist(x,30); 112 | % dist=ce(2)-ce(1); 113 | % cee=linspace(-5,25,300); 114 | % hig = fr./(dist*sum(fr)); 115 | % bar(ce,hig); 116 | % hold on 117 | % plot(cee, mw(1)*1/sqrt(2 * pi * msig2)*exp(-1/2*(cee - mmu(1)).^2),'r-','linewidth',lw) 118 | % plot(cee, mw(2)*1/sqrt(2 * pi * msig2)*exp(-1/2*(cee - mmu(2)).^2),'r-','linewidth',lw) 119 | % plot(cee, mw(3)*1/sqrt(2 * pi * msig2)*exp(-1/2*(cee - mmu(3)).^2),'r-','linewidth',lw) 120 | 121 | figure(4) 122 | histo(x,30,0,1) 123 | hold on 124 | cee=linspace(-5,25,300); 125 | est=mw(1).*1./sqrt(2 * pi * msig2).*exp(-1/(2*msig2) * (cee - mmu(1)).^2)+... 126 | mw(2).*1./sqrt(2 * pi * msig2).*exp(-1/(2*msig2) * (cee - mmu(2)).^2)+... 127 | mw(3).*1./sqrt(2 * pi * msig2).*exp(-1/(2*msig2) * (cee - mmu(3)).^2); 128 | plot(cee, est,'b-') 129 | theo = 0.1 * 1./sqrt(2 * pi * 4).*exp(-1/(2*4) * (cee - 1).^2)+... 130 | 0.2 * 1./sqrt(2 * pi * 4).*exp(-1/(2*4) * (cee - 20).^2)+... 131 | 0.7 * 1./sqrt(2 * pi * 4).*exp(-1/(2*4) * (cee - 9).^2); 132 | plot(cee, theo,'r--') 133 | %print -depsc 'C:\Brani\Courses\Bayes\Handouts\Working12\Figs\MixGibbs4.eps' 134 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/jeremygibbs.m: -------------------------------------------------------------------------------- 1 | 2 | close all 3 | clear all 4 | %Random Number Seed 5 | rand('state', 10); 6 | 7 | 8 | y = 98; 9 | %------------------------------------------ 10 | NN = 50000; 11 | mus = []; taus = []; 12 | mu = 110; % set the parameters as prior means 13 | tau = 0.01; % 14 | alpha = 0.01; 15 | beta = 0.8; 16 | for i = 1 : NN 17 | newmu = sqrt((120/tau)/(120+1/tau)) * randn + ... 18 | 120/(120+1/tau) * y + (1/tau)/(120 + 1/tau)*110; 19 | par = beta+1/2 *(y - mu).^2 ; 20 | newtau = gamrnd(alpha + 1/2, 1/par); %par is rate 21 | mus = [mus newmu]; 22 | taus = [taus newtau]; 23 | mu=newmu; 24 | tau=newtau; 25 | end 26 | burn=1000; 27 | mean(mus(burn:end)) 28 | mean(taus(burn:end)) 29 | mean( 1./taus(burn:end)) 30 | 31 | 32 | figure(1) 33 | subplot(211) 34 | hist(mus(burn:end), 60) 35 | xlabel('mu') 36 | subplot(212) 37 | hist(taus(burn:end), 60) 38 | xlabel('tau') 39 | 40 | figure(2) 41 | plot(mus(burn:end), taus(burn:end),'o') -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/jeremymcmc2.m: -------------------------------------------------------------------------------- 1 | 2 | % 3 | % 4 | % 5 | close all force 6 | clear all 7 | 8 | rand('state', 10); 9 | randn('state', 20); 10 | ii = 0; 11 | thetas=[]; 12 | taus=[]; 13 | theta = 100; %set initial as theta=100 14 | tau = 0.001; %set initial 15 | while (length(thetas) < 35000) 16 | ii = ii+1; 17 | % Generate a candidate draw. 18 | thetaprop = theta + 75*tan(pi*rand(1,1)-pi/2); 19 | %tauprop = 1/sqrt(tau) * (- log(rand(1,1))); 20 | % tauprop = max(0.0001, tau + 0.001* randn); 21 | tauprop = abs(tau + 0.0007* randn); 22 | % 23 | y = 98; 24 | num= sqrt(tauprop) * exp(-tauprop/2 *(y - thetaprop)^2 )* ... 25 | exp(- 1/(2* 120) *(thetaprop-110)^2) * ... 26 | exp(-0.01 * tau); 27 | denom= sqrt(tau) * exp(-tau/2*(y - theta)^2 )* ... 28 | exp(- 1/(2 * 120) *(theta-110)^2) * ... 29 | exp(-0.01* tauprop); 30 | f = min(1, num/denom); 31 | %Make a randomized decision to accept the proposal 32 | if (rand(1,1) <= f) 33 | theta = thetaprop; 34 | tau= tauprop; 35 | end 36 | thetas=[thetas theta]; 37 | taus = [taus tau]; 38 | end 39 | figure(1) 40 | subplot(211) 41 | plot(thetas,'-.') 42 | subplot(212) 43 | plot(taus,'-.') 44 | % 45 | burn=15000; 46 | thetass = thetas(burn:end); 47 | tauss = taus(burn:end); 48 | figure(2) 49 | subplot(121) 50 | hist(thetass, 20) 51 | xlabel('\theta') 52 | subplot(122) 53 | hist(tauss, 20) 54 | xlabel('\tau') 55 | 56 | thetahat = mean(thetass) 57 | stdtheta = std(thetass) 58 | [prctile(thetass, 2.5) prctile(thetass, 50) prctile(thetass, 97.5)] 59 | 60 | tauhat = mean(tauss) 61 | stdtau = std(tauss) 62 | sigmahat1 = mean(1./tauss) 63 | sigmahat2 = 1/tauhat -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/laplace.m: -------------------------------------------------------------------------------- 1 | % 2 | % Laplace's Method 3 | % X|theta ~ Ga(r,theta), theta ~ Ga(alpha,beta) 4 | close all 5 | xx = 0:0.01:16; 6 | r=20; alpha = 5; beta = 1; 7 | %observed 8 | x=2; 9 | y1 = gampdf(xx, r + alpha, 1/(beta + x)); 10 | y2 = normpdf(xx, (r-1+alpha)/(beta + x), sqrt(r - 1 + alpha)/(beta + x)); 11 | % 12 | figure(1) 13 | plot(xx, y1, 'r-','linewidth',2) 14 | hold on 15 | plot(xx, y2, 'b-','linewidth',2) 16 | legend('exact posterior','Laplace''s approximation') 17 | %% 18 | % 95% Credible Set 19 | % exact 20 | [gaminv(0.025, r + alpha, 1/(beta + x)) gaminv(0.975, r + alpha, 1/(beta + x))] 21 | % 5.3929 11.9034 22 | % 23 | % approximate (Laplace's method) 24 | [norminv(0.025, (r-1+alpha)/(beta + x), sqrt(r - 1 + alpha)/(beta + x)), ... 25 | norminv(0.975, (r-1+alpha)/(beta + x), sqrt(r - 1 + alpha)/(beta + x))] 26 | % 27 | % 4.7994 11.2006 28 | % 29 | % What exact posterior coverage this approximative CS has? 30 | 31 | gamcdf(11.2006, r + alpha, 1/(beta + x)) - gamcdf( 4.7994, r + alpha, 1/(beta + x)) 32 | % 0.9404 33 | %% 34 | % integral of g 35 | % int_R+ x^(u-1) exp(-v x) dx = gamma(u)/v^u 36 | %exact 37 | gamma(r + alpha) / (beta + x)^(r + alpha) % 7.3228e+11 38 | 39 | % approximation by Laplace's method 40 | sqrt(2 * pi) * (r+alpha-1)^(r + alpha -1/2) /((beta + x)^(r +alpha)) * exp(-(r+alpha -1)) 41 | % 7.2974e+11 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/mcmc1.m: -------------------------------------------------------------------------------- 1 | 2 | % mcmc1 3 | % full conditional distributions available 4 | % 5 | % y_i ~ N(mu, 1/tau), i=1,...,n 6 | % mu ~ N(0,1); 7 | % tau ~ Ga(2,1); 8 | %------------------------------------------ 9 | % This example implements Simple Example 5.2.1 10 | % from Walter Gilks: Full conditional distributions, 11 | % Chapter 5 in MCMC in Practice, Gilks, Richardson, and 12 | % Spiegelhalter, Chapman & Hall pages 75-76. 13 | % Model: y_i \sim N(\mu, \tau^{-1}), i=1, \dots, n 14 | % tau=precision parameter (1/variance) 15 | % Priors: \mu \sim N(0,1); \tau \sim Gamma(2,1) 16 | % DATA simulated, n=200 from N(1,4^2). 17 | % 18 | clear all 19 | close all force 20 | %-----------------figure defaults 21 | lw = 2; 22 | set(0, 'DefaultAxesFontSize', 17); 23 | fs = 14; 24 | msize = 5; 25 | %-------------------------------- 26 | n=30; % sample size 27 | randn('state', 10); 28 | y = 4 * randn(1,n) + 1; 29 | %------------------------------------------ 30 | nn = 10000; 31 | thetas = []; 32 | taus = []; 33 | suma = sum(y) 34 | theta = 0; % set the parameters as prior means 35 | tau = 2; 36 | h=waitbar(0,'Simulation in progress'); 37 | for i = 1 : nn 38 | new_theta = sqrt(1/(1+n*tau)) * randn + (tau * suma)/(1+n*tau); 39 | %new_theta = normrnd( (tau * suma)/(1+n*tau), sqrt(1/(1+n*tau)) ); 40 | par = 1+ 1/2 * sum ( (y - theta).^2 ); 41 | new_tau =gamrnd(2 + n/2, 1/par); 42 | thetas = [thetas new_theta]; 43 | taus = [taus new_tau]; 44 | tau=new_tau; 45 | theta=new_theta; 46 | if i/50==fix(i/50) % Shows wait bar 47 | waitbar(i/nn) 48 | end 49 | end 50 | close(h) 51 | figure(1) 52 | subplot(2,1,1) 53 | plot((nn-500:nn), thetas(nn-500:nn)) 54 | subplot(2,1,2) 55 | plot((nn-500:nn), taus(nn-500:nn)) 56 | % 57 | figure(2) 58 | burnin = 1000; 59 | subplot(2,1,1) 60 | hist(thetas(burnin:nn), 70) 61 | xlabel('\theta') 62 | subplot(2,1,2) 63 | hist(taus(burnin:nn), 70) 64 | xlabel('\tau') 65 | % 66 | figure(3) 67 | plot( thetas(burnin:nn), taus(burnin:nn), '.') 68 | muhat = mean(thetas(burnin:nn)) 69 | tauhat = mean(taus(burnin:nn)) 70 | % 71 | sigma2hat = mean(1./taus(burnin:nn)) 72 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/metro2.m: -------------------------------------------------------------------------------- 1 | % Modified from C. Robert Bayesian Choice 2 | % Springer, 2nd edition Page 305 3 | 4 | % Weibull lifetimes 5 | % f(t|alpha, eta) = alpha eta t^(alpha-1) exp(- eta t^alpha) 6 | % Prior on (alpha, eta) is proportional to 7 | % exp(-alpha) eta^(beta-1) exp(-xi eta) 8 | % As proposal conditional density for alpha' and eta' use 9 | % the product of two exponential densities with means alpha and eta. 10 | close all force 11 | clear all 12 | % 13 | data = [0.200 0.100 0.250];% 14 | 15 | n=length(data); 16 | 17 | alpha = 2; %initial values 18 | eta = 2; 19 | alphas = [alpha]; etas = [eta]; 20 | 21 | 22 | %hyperparameters 23 | beta=2; xi = 2; 24 | 25 | tic 26 | for i = 1:50000 27 | alpha_prop = - alpha * log(rand); 28 | eta_prop = - eta * log(rand); 29 | %-------------------------------------------------------------------------- 30 | prod1 = prod(data); 31 | prod2 = prod( exp( eta * data.^alpha - eta_prop * data.^alpha_prop)); 32 | %-------------------------------------------------------------------------- 33 | rr = (eta_prop/eta)^(beta-1) * exp(alpha - alpha_prop - xi * (eta_prop - eta)) * ... 34 | exp(- alpha/alpha_prop - eta/eta_prop + alpha_prop/alpha + eta_prop/eta) * ... 35 | prod1.^(alpha_prop - alpha) * prod2 * ((alpha_prop * eta_prop)/(alpha * eta))^(n-1); 36 | %-------------------------------------------------------------------------- 37 | rho = min( rr ,1); 38 | if (rand < rho) 39 | alpha = alpha_prop; eta = eta_prop; 40 | end 41 | alphas = [alphas alpha]; 42 | etas = [etas eta]; 43 | end 44 | toc 45 | %Burn in 500 46 | alphas = alphas(500:end); 47 | etas = etas(500:end); 48 | figure(1) 49 | hist(alphas, 50) 50 | xlabel('alpha') 51 | figure(2) 52 | hist(etas, 50) 53 | xlabel('eta') 54 | alpha_B = mean(alphas) 55 | eta_B = mean(etas) 56 | var_alphaB = var(alphas) 57 | var_etaB = var(etas) 58 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/norcau.m: -------------------------------------------------------------------------------- 1 | %norcau 2 | % 3 | x=2; 4 | N=100000; 5 | num = 0; denom = 0; 6 | % 7 | for i=1:N 8 | theta = x + randn; %theta ~ N(x,1) 9 | num = num + theta/(1+theta^2); 10 | denom = denom + 1/(1+theta^2); 11 | end 12 | delta21 = num/denom 13 | 14 | %% 15 | 16 | x=2; 17 | N=100000; 18 | num = 0; denom = 0; 19 | % 20 | for i=1:N 21 | a=randn(2,1); 22 | theta = a(1)/a(2); %theta ~ Ca(0,1) 23 | num = num + theta * exp(-1/2 *(x-theta)^2); 24 | denom = denom + exp(-1/2 *(x-theta)^2); 25 | end 26 | delta22 = num/denom 27 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/norcau.py: -------------------------------------------------------------------------------- 1 | g# -*- coding: utf-8 -*- 2 | """ 3 | Bayes estimator delta(x) for x=2, 4 | for Normal-Cauchy Model 5 | Created on Thu Dec 28 11:56:56 2017 6 | @author: bv20 7 | """ 8 | 9 | from scipy import integrate, inf, exp 10 | x = 2 11 | num = lambda th: th * exp(-0.5*(x-th)**2)/(1+th**2) 12 | denom = lambda th: exp(-0.5*(x-th)**2)/(1+th**2) 13 | delta2 = integrate.quad(num,-inf,inf)[0]/integrate.quad(denom,-inf,inf)[0] 14 | #delta(2) 15 | print(delta2) #1.2821951026935339 16 | 17 | # Errors 18 | 19 | numerator =integrate.quad(num,-inf,inf)[0] #0.9159546679977636 20 | denominator=integrate.quad(denom,-inf,inf)[0] #0.714364503556127 21 | errnum=integrate.quad(num,-inf,inf)[1] #1.0415234856193602e-09 22 | errdenom=integrate.quad(denom,-inf,inf)[1] #1.2022419107752649e-08 23 | 24 | err = delta2 * (errnum/numerator + errdenom/denominator) 25 | print(err) #2.3036713479165735e-08 -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/norcaugibbs.m: -------------------------------------------------------------------------------- 1 | %norcaugibbs.m 2 | clear all 3 | close all force 4 | randn('state',4); 5 | % 6 | x=2; 7 | sigma2 = 1; 8 | tau2 = 1; 9 | mu = 0; 10 | % 11 | theta = 0; 12 | thetas =[theta]; 13 | lambda = 1; 14 | lambdas=[lambda]; 15 | burn =1000; 16 | ntotal = 10000 + burn; 17 | tic 18 | for i = 1: ntotal 19 | theta = (tau2/(tau2 + lambda * sigma2) * x + ... 20 | lambda * sigma2/(tau2 + lambda * sigma2) * mu) + ... 21 | sqrt(tau2 * sigma2/(tau2 + lambda *sigma2)) * randn; 22 | lambda = exprnd( 1/((tau2 + (theta - mu)^2)/(2*tau2))); 23 | thetas =[thetas theta]; 24 | lambdas =[lambdas lambda]; 25 | end 26 | toc 27 | % 28 | mean(thetas(burn+1:end)) 29 | hist(thetas(burn+1:end), 40) -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/norcaumet.m: -------------------------------------------------------------------------------- 1 | %norcaumet.m 2 | % 3 | close all 4 | clear all 5 | 6 | rand('seed',1); 7 | randn('seed',1); 8 | x = 2; %data 9 | theta = 1; % initial value 10 | thetas =[theta]; %save all thetas. 11 | % 12 | 13 | tic 14 | for i = 1:100000 15 | theta_prop = randn + x; %N(x,1). 16 | %-------------------------------------------------------------------------- 17 | r = (1+theta^2)/(1+theta_prop^2); 18 | %-------------------------------------------------------------------------- 19 | rho = min(r ,1); 20 | if (rand < rho) 21 | theta = theta_prop; 22 | end 23 | thetas = [thetas theta]; 24 | end 25 | toc 26 | %Burn in 500 27 | thetas = thetas(500:end); 28 | figure(1) 29 | hist(thetas, 50) 30 | mean(thetas) 31 | var(thetas) 32 | 33 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/poisson.m: -------------------------------------------------------------------------------- 1 | % Generation d'une variable aleatoire de Poisson 2 | % function X = poisson(lambda) 3 | 4 | function X = poisson(lambda); 5 | 6 | T = -1/lambda*log(rand(1)); 7 | X = 1; 8 | 9 | while (T<1), 10 | T = T-1/lambda*log(rand(1)); 11 | X = X+1; 12 | end; 13 | 14 | X = X-1; 15 | 16 | 17 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/poissonHM.m: -------------------------------------------------------------------------------- 1 | % Simulation d'une loi de Poisson 2 | % par une methode de Hastings Metropolis 3 | % Cette methode converge quelque soit la valeur de lambda mais elle 4 | % est particulierement bien adaptee dans le cas ou lambda est grand 5 | 6 | clear; clf; 7 | 8 | lambda = 1000; 9 | 10 | n = ceil(log(sqrt(lambda))/log(2)); 11 | % le deplacement est code sur n bits + un bit de signe 12 | 13 | pond = zeros(1,n); pond(1) = 1; 14 | for i=2:n, pond(i) = 2*pond(i-1); end; 15 | 16 | NHM = 500; % nombre d'iterations de Hastings Metropolis 17 | 18 | % initialisation de l'algorithme de Hastings Metropolis 19 | x = lambda/3; 20 | x_ = x; 21 | 22 | for i=1:NHM, 23 | i 24 | bits = rand(1,n+1)<0.5; 25 | z = (2*bits(1)-1)*sum(bits(2:n+1).*pond); 26 | xnew = x+z; 27 | 28 | ratio = exp(z*log(lambda)+0.5*log(x/xnew)+z*(1-log(x))-(x+z)*log(1+z/x)); 29 | 30 | if (rand(1) < ratio), x = xnew; end; 31 | x_ = [x_ x]; 32 | end; 33 | 34 | 35 | % expression analytique de la densite de probabilite 36 | 37 | range = [max(0,round(lambda-5*sqrt(lambda))):1:round(lambda+5*sqrt(lambda))]; 38 | p = exp(-lambda+range*log(lambda)-log(sqrt(2*pi*range))-range.*(log(range)-ones(size(range)))); 39 | figure(1); 40 | plot3([1:NHM],x_,zeros(1,NHM)); 41 | hold on;grid; 42 | plot3(NHM*ones(size(range)),range,p); 43 | axis([1 NHM 0 max(max(range),max(x_)) 0 max(p)*1.1]); 44 | 45 | H = xlabel('it. #'); set(H,'FontSize',15); 46 | H = ylabel('sampler'); set(H,'FontSize',15); 47 | H = zlabel('Objective distribution'); set(H,'FontSize',15); 48 | 49 | H = title('Hastings Metropolis algorithm'); set(H,'FontSize',18); 50 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/pumpsbugs.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit5/pumpsbugs.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/pumpsmc.m: -------------------------------------------------------------------------------- 1 | %pumps MCMC 2 | X=[5 1 5 14 3 19 1 1 4 22]; 3 | t = [94.32 15.52 62.88 125.76 ... 4 | 5.24 31.44 1.048 1.048 2.096 10.48]; 5 | % data drom Gaver and O'Muircheartaigh, 1987 6 | % 7 | n=10; 8 | c=0.1; 9 | d=1; 10 | % 11 | %Initials 12 | theta = [1 1 1 1 1 1 1 1 1 1]; 13 | beta =1; 14 | % 15 | B=50000; 16 | thetas=[]; betas=[]; 17 | tic 18 | for i = 1:B 19 | for j=1:n 20 | theta(j) = gamrnd(X(j)+1, 1./(beta + t(j)) ); 21 | end 22 | sumthetas = sum(theta); 23 | beta =gamrnd(n + c, 1./(sumthetas + d)); 24 | thetas = [thetas; theta]; 25 | betas = [betas; beta]; 26 | end 27 | burn=1000; 28 | thetasb = thetas(burn+1:end,:); 29 | betasb = betas(burn+1:end); 30 | 31 | thetas_B = mean(thetasb) 32 | beta_B = mean(betasb) 33 | 34 | %std(thetasb) 35 | %std(betasb) 36 | 37 | toc 38 | 39 | 40 | 41 | 42 | % thetas_B = 43 | % 0.0628 0.1189 0.0932 0.1179 0.6074 44 | % 0.6102 0.8718 0.8698 1.4856 1.9504 45 | % 46 | % beta_B = 1.3368 47 | % 48 | % Elapsed time is 36.877535 seconds. 49 | 50 | % mean sd MC_error val2.5pc median val97.5pc start sample 51 | % beta 1.34 0.486 0.002973 0.5896 1.271 2.466 1001 50000 52 | % theta[1] 0.06261 0.02552 1.111E-4 0.02334 0.05914 0.1217 1001 50000 53 | % theta[2] 0.118 0.08349 3.694E-4 0.01431 0.09888 0.3296 1001 50000 54 | % theta[3] 0.09366 0.03829 1.706E-4 0.03439 0.08842 0.1828 1001 50000 55 | % theta[4] 0.1178 0.03048 1.472E-4 0.06595 0.115 0.1848 1001 50000 56 | % theta[5] 0.6116 0.3097 0.001409 0.1632 0.5589 1.361 1001 50000 57 | % theta[6] 0.6104 0.1366 6.453E-4 0.3705 0.6001 0.9058 1001 50000 58 | % theta[7] 0.8686 0.6494 0.003059 0.101 0.7124 2.537 1001 50000 59 | % theta[8] 0.8692 0.6481 0.003354 0.09784 0.7117 2.513 1001 50000 60 | % theta[9] 1.478 0.6897 0.00351 0.4705 1.367 3.128 1001 50000 61 | % theta[10] 1.944 0.4133 0.002022 1.223 1.916 2.83 1001 50000 62 | % 63 | -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/randMVN.m: -------------------------------------------------------------------------------- 1 | function [Y] = randMVN(n, mu, sigma) 2 | % Simulation of multivariate normal 3 | % Usage 4 | % [Y] = rand_MVN(n, mu, sigma) 5 | % Input 6 | % n - number of observations to generate 7 | % mu - dx1 mean column vector 8 | % sigma - dxd covariance matrix 9 | % Output 10 | % Y - an nxd matrix of row vectors with mean mu and covariance sigma 11 | % if mu is a matrix, a matrix of the same size will be returned 12 | % with row Y(i,:) having mean mu(i,:). 13 | % Example 14 | % randMVN(2,[0 0]',[1 0; 0 1]) 15 | % ans = 16 | % -0.7345 0.3719 17 | % -0.1882 0.0322 18 | % Brani 10/20/02 19 | 20 | Ch = chol(sigma)'; 21 | X = randn(n,length(mu)); 22 | Y = X*Ch' + ones(n,1)*mu' ; -------------------------------------------------------------------------------- /original_examples/Codes4Unit5/trafficmatrix.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit5/trafficmatrix.m -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/DeMere.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/DeMere.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/Aborage.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/Aborage.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/Aboreducation.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/Aboreducation.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/Aborunionstatus.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/Aborunionstatus.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/ISYE 6420 Project Report Marine Otero del Val.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/ISYE 6420 Project Report Marine Otero del Val.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/WB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/WB.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/Supporting/lect2gm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/Supporting/lect2gm.pdf -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/alarm.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/alarm.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/cheese.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/cheese.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/dugongsmissing.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/dugongsmissing.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/equivalence.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/equivalence.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/exponential1.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/exponential1.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/psoriasis.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/psoriasis.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/stressacids.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/stressacids.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit6/zerotrickjeremy.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit6/zerotrickjeremy.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/Jeremymus.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/Jeremymus.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/NHANESmulti.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/NHANESmulti.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/anovacoagulation.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/anovacoagulation.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/ants.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/ants.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/arrhythmia.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/arrhythmia.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/basichierarchy.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/basichierarchy.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/basichierarchy2.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/basichierarchy2.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/fat1.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/fat1.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/fat2d.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/fat2d.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/fatmulti.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/fatmulti.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/insulin.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/insulin.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/isoflavon.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/isoflavon.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/isoflavonopen.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/isoflavonopen.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/paraguay.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/paraguay.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/paraguaynocluster.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/paraguaynocluster.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/rats_nocentering.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/rats_nocentering.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/simvastatin.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/simvastatin.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit7/tasmixture.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit7/tasmixture.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit8/example2.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit8/example2.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit8/gastric.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit8/gastric.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit8/ratsignorable1.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit8/ratsignorable1.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit8/ratsignorable2.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit8/ratsignorable2.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit8/ratsinformative.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit8/ratsinformative.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/Gesell.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/Gesell.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/Hald.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/Hald.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/Haldssvs.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/Haldssvs.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/cumulative2.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/cumulative2.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/deviances.odc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/deviances.odc -------------------------------------------------------------------------------- /original_examples/Codes4Unit9/ioannismodelselection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areding/6420-pymc/69002a518c70ad47391fe95db6592b914ab6c399/original_examples/Codes4Unit9/ioannismodelselection.pdf -------------------------------------------------------------------------------- /original_examples/stuff/Unit3-DeMere.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "17f9f64d", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np\n", 11 | "\n", 12 | "%load_ext lab_black\n", 13 | "%load_ext watermark" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "id": "ffac0713", 19 | "metadata": {}, 20 | "source": [ 21 | "# deMere's problem\n", 22 | "\n", 23 | "See [Wikipedia on the Problem of Points](https://en.wikipedia.org/wiki/Problem_of_points#Pascal_and_Fermat).\n", 24 | "\n", 25 | "Adapted from [Unit 6: DeMere.odc](https://raw.githubusercontent.com/areding/6420-pymc/main/original_examples/Codes4Unit6/DeMere.odc).\n", 26 | "\n", 27 | "Not sure where in the course this is from! The professor doesn't mention it in lectures that I've seen. It was in the Codes4Unit6 archive, but I think it fits better here.\n", 28 | "\n", 29 | "- What is more likely when rolling 3 fair dice: sum 11 or sum 12?\n", 30 | "- What is more likely when rolling 300 fair dice: sum 1111 or sum 1112?" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 4, 36 | "id": "a9059d1e", 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "Results with 3 dice\n", 44 | "Simulated probability of rolling 11: 0.124593\n", 45 | "Simulated probability of rolling 12: 0.115399\n", 46 | "\n", 47 | "Results with 300 dice\n", 48 | "Simulated probability of rolls summing to 1111: 0.001628\n", 49 | "Simulated probability of rolls summing to 1112: 0.001478\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "rng = np.random.default_rng(1)\n", 55 | "sims = 1000000\n", 56 | "\n", 57 | "\n", 58 | "def prob_sum(arr, s):\n", 59 | " \"\"\"\n", 60 | " return probability of sum s in (sims, dice)-shaped np array\n", 61 | " \"\"\"\n", 62 | " sims = arr.shape[0]\n", 63 | " return (arr.sum(axis=1) == s).sum() / sims\n", 64 | "\n", 65 | "\n", 66 | "# simulate 3 dice rolls\n", 67 | "rolls_3 = rng.integers(1, 6, (sims, 3), endpoint=True)\n", 68 | "print(\"Results with 3 dice\")\n", 69 | "print(\"Simulated probability of rolling 11:\", prob_sum(rolls_3, 11))\n", 70 | "print(\"Simulated probability of rolling 12:\", prob_sum(rolls_3, 12))\n", 71 | "\n", 72 | "# simulate 300 dice rolls\n", 73 | "rolls_300 = rng.integers(1, 6, (sims, 300), endpoint=True)\n", 74 | "print(\"\\nResults with 300 dice\")\n", 75 | "print(\"Simulated probability of rolls summing to 1111:\", prob_sum(rolls_300, 1111))\n", 76 | "print(\"Simulated probability of rolls summing to 1112:\", prob_sum(rolls_300, 1112))" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 5, 82 | "id": "ae40f91a", 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "Python implementation: CPython\n", 90 | "Python version : 3.10.4\n", 91 | "IPython version : 8.4.0\n", 92 | "\n", 93 | "numpy: 1.22.4\n", 94 | "\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "%watermark -n -u -v -iv" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "9c9c1d9f", 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3 (ipykernel)", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.11.0" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 5 132 | } 133 | -------------------------------------------------------------------------------- /unit1/Unit1-topics.md: -------------------------------------------------------------------------------- 1 | # Topics Covered 2 | This lecture goes over the [topics covered](https://www2.isye.gatech.edu/isye6420/plan.html) in the course. I don't have much to add here, but I do have some notes about each homework and the corresponding units that might be handy. 3 | 4 | **Homework 1** 5 | 6 | Units covered: 1–3 7 | 8 | We start out with a very brief review of probability and an introduction to Bayes' rule. The first homework generally has questions that don't require any calculus, just basic probability rules. They may include circuit problems, use of Bayes' Rule, the Law of Total Probability, sensitivity and specificity, positive or negative predictive value (PPV/NPV), and simple Bayesian networks. These problems can be trickier than they seem at first! 9 | 10 | **Homework 2** 11 | 12 | Lessons covered: 4.1–4.9 13 | 14 | We start to discuss random variables, distributions, and Bayesian inference with conjugate cases. 15 | 16 | **Homework 3** 17 | 18 | Lessons covered: 4.10–4.19 19 | 20 | Here we get into hypothesis testing, ways to describe the posterior, different priors and their effects, and a brief discussion of Empirical Bayes methods. We're still using conjugate cases to find posteriors. 21 | 22 | **Homework 4** 23 | 24 | Unit covered: 5 25 | 26 | This unit we mostly move away from conjugate problems and start discussing MCMC methods for sampling from the posterior. Usually we'll have one Metropolis-Hastings and one Gibbs sampler question. 27 | 28 | **Midterm** 29 | 30 | Units covered: 1–5 31 | 32 | The midterm could include anything from the first half, but tends to focus on Units 4 and 5. 33 | 34 | **Homework 5** 35 | 36 | Units covered: 6–7 37 | 38 | This is where we start using Probabilistic Programming Languages (PPLs) like BUGS, Stan, or PyMC. We start with linear regression and move into hierarchical models. 39 | 40 | **Homework 6** 41 | 42 | Units covered: 8–9 43 | 44 | Unit 8 discusses missing and censored data along with time-to-event models. Unit 9 goes into model building, selection, and checking. 45 | 46 | **Final** 47 | 48 | Units covered: 1–10 49 | 50 | The final is comprehensive but tends to focus on concepts from the second half of the course. 51 | 52 | **Project** 53 | 54 | There's also an open–ended project. It could potentially be based on any part of the course, but most students opt to try out or extend the models from the second half of the course. Some of the most interesting projects I've seen, however, have been based on concepts from the first half, so don't limit yourself! -------------------------------------------------------------------------------- /unit2/Unit2-bayesianvsclassical.md: -------------------------------------------------------------------------------- 1 | # Bayesian vs. Frequentist 2 | 3 | Throughout the course, you'll hear Professor Vidakovic use both "classical" and "frequentist" as catch-all terms for "not Bayesian." Greg Ganderburger has a [great series of posts](https://web.archive.org/web/20221205145106/https://gandenberger.org/2014/07/28/intro-to-statistical-methods-2/) on the differences between frequentist, likelihoodist, and Bayesian methods. I'm linking to the second post in the series for the great Venn diagram at the top, but I recommend the entire thing if you're interested. 4 | 5 | 6 | This Stack Exchange post, "[What's the difference between a confidence interval and a credible interval?](https://stats.stackexchange.com/questions/2272/whats-the-difference-between-a-confidence-interval-and-a-credible-interval)", also has some really good discussion about the topic. We will talk more about confidence intervals versus credible intervals in Unit 4. 7 | -------------------------------------------------------------------------------- /unit2/Unit2-fda.md: -------------------------------------------------------------------------------- 1 | # FDA Recommendations 2 | 3 | The link in the lecture slides is dead, [here's the updated one](https://www.fda.gov/media/71512/download). 4 | 5 | [Bayesian Analysis Reporting Guidelines](https://www.nature.com/articles/s41562-021-01177-7) is a more recent article in Nature with a similar subject, written by John K. Kruschke, author of [Doing Bayesian Data Analysis](https://sites.google.com/site/doingbayesiandataanalysis/). -------------------------------------------------------------------------------- /unit2/Unit2-history.md: -------------------------------------------------------------------------------- 1 | # History of Bayesian Statistics 2 | 3 | These two lectures talk a little bit about Thomas Bayes and the history of Bayesian statistics. 4 | 5 | If you'd like to learn more about where Bayesian statistics fits in with classical, I have a couple of links for you to check out. First, [Bayesian Methods: General Background](https://bayes.wustl.edu/etj/articles/general.background.pdf) takes you from Herodotus to current problems (current in 1996, anyways) over 16 pages. 6 | 7 | Second, check out [this page](https://plato.stanford.edu/entries/statistics/) on the philosophy of statistics from the Stanford Encyclopedia of Philosophy. Knowing this stuff is not at all required but I find it helpful to put the various ideas and how they relate in context. Especially useful are Sections 2 and 4, which discuss the differences between epistemic and physical interpretations of probability and Bayesian statistics. -------------------------------------------------------------------------------- /unit2/Unit2-history2.md: -------------------------------------------------------------------------------- 1 | # Historic Overview Links 2 | 3 | Here are links to the book and essay the professor references in this lecture: 4 | 5 | - [Wikipedia page for *The Doctrine of Chances*](https://en.wikipedia.org/wiki/The_Doctrine_of_Chances) by Abraham de Moivre. Includes links to the original text. 6 | 7 | - [An Essay Towards Solving a Problem in the Doctrine of Chances (abridged version)](https://www.ias.ac.in/article/fulltext/reso/008/04/0080-0088) by Thomas Bayes. -------------------------------------------------------------------------------- /unit3/Unit3-Bayes-theorem.md: -------------------------------------------------------------------------------- 1 | # 4. Bayes' Theorem 2 | 3 | Say we have hypothesis $H_i$ and some data $D$. 4 | 5 | $$P(H_i \mid D) = \frac{P(D \mid H_i)}{P(D)} \times P(H_i)$$ 6 | 7 | We'll update the notation in Unit 4 when we start dealing with continuous distributions, but the structure won't change. $P(H_i)$ represents the prior probability of $H_i$. $P(H_i \mid D)$ the posterior probability, which is the prior updated by $\frac{P(D \mid H_i)}{P(D)}$. 8 | 9 | For now, we can call $P(D \mid H_i)$ the sampling probability. It contains the observed data, which for the moment can be just a number (later it will be the assumed distribution of that data and we'll call it a likelihood). 10 | 11 | Finally we have $P(D)$, which is the marginal probability or normalization factor. This is necessary to normalize the updated sampling probability; otherwise, the posterior will not be limited to between 0 and 1. 12 | 13 | In {cite:t}`jaynes2003`, Bayes' theorem is represented a bit differently: 14 | 15 | $$P(H_i \mid DX) = \frac{P(D \mid H_i X)}{P(D \mid X)} \times P(H_i \mid X)$$ 16 | 17 | This is the same thing! The reason he adds the additional $X$ is to represent the prior information more clearly. Sometimes just representing it as $P(H_i)$ confuses students because it incorrectly gives the impression that it's something completely different than the posterior. 18 | 19 | ```{epigraph} 20 | The left-hand side . . . is generally called a ‘*posterior probability*’, with the same *caveat* that this means only ‘logically later in the particular chain of inference being made’, and not necessarily ‘later in time’. And again the distinction is conventional, not fundamental; one man’s prior probability is another man’s posterior probability. There is really only one kind of probability; our different names for them refer only to a particular way of organizing a calculation. 21 | 22 | -- {cite:t}`jaynes2003` p. 89 23 | ``` -------------------------------------------------------------------------------- /unit3/Unit3-NecessaryProbability.md: -------------------------------------------------------------------------------- 1 | # 1. A Review of Necessary Probability 2 | 3 | As the professor says, there are a lot of ways to introduce the fundamentals of probability. He uses Venn diagrams and set theory for a very brief overview, but assumes students have seen this material before. There are no derivations here, but if you're interested in something more in-depth, I recommend Chapter 2 and Appendix A from {cite:t}`jaynes2003`. Jaynes also points out that Venn diagrams can be misleading. -------------------------------------------------------------------------------- /unit3/Unit3-bayesnetworks.md: -------------------------------------------------------------------------------- 1 | # 7. Bayes Networks 2 | 3 | Bayes networks or belief networks are a type of directed acyclic graph (DAG) model that represent the probabilistic relationships among a set of variables. 4 | 5 | The nodes represent random variables and the edges represent causal relationships between the variables. "Directed" means that the relationships have a direction (from cause to effect), and the acyclic means that it's not possible to start at one node and follow a sequence of edges that leads back to the starting node. 6 | 7 | When we get new evidence (when an unobserved node becomes observed), we update the probabilities throughout the network. This process is called inference. There are various algorithms to perform efficient inference, both exact and sampled. We won't go into them much in this course. The professor uses OpenBUGS in the next lecture, while I've chosen to use Pgmpy. I think with the new pm.Categorical class, it would be fairly easy to redo these in PyMC, but I haven't made it a priority yet. -------------------------------------------------------------------------------- /unit3/Unit3-conditioning1.md: -------------------------------------------------------------------------------- 1 | # 2. Conditioning, Part 1 2 | 3 | ## The queen of spades 4 | 5 | Professor Vidakovic uses this example to demonstrate the concept of independence. Remember, by definition, independence means $P(AB) = P(A)P(B)$. Here we have a standard deck of 52 cards. There are 13 of each suit and 4 queens. Define Event A as drawing a spade and Event B as drawing a queen. $P(AB)$ is then the probability of drawing the queen of spades. This card is unique, so it occurs $1/52$ times. 6 | 7 | If we multiply it out: 8 | 9 | $$P(A)P(B) = \frac{13}{52} \times \frac{4}{52} = \frac{1}{52}$$ 10 | 11 | So $P(AB) = P(A)P(B)$ and the two events are independent. 12 | 13 | But are they still independent if we first remove the two of diamonds from the deck? Let's see: 14 | 15 | 16 | $$P(AB) = \frac{1}{51}$$ 17 | $$P(AB) = P(A)P(B) = \frac{13}{51} \times \frac{4}{51} = \frac{52}{2601}$$ 18 | $$ \frac{1}{51} \neq \frac{52}{2601}$$ 19 | 20 | They are no longer independent! It's easy to follow the math, but the intuition can take time to click. Think about it in terms of the information you have. If there are an equal number of cards left in the deck from each suit, any given suit has the same probability of being a queen. 21 | 22 | In the second case, if you draw a spade, heart, or club, the probability your card is a queen will be different than the probability of a queen given that you drew a diamond. You have slightly more information about diamonds since there are only 12 remaining in the deck. 23 | 24 | So now depending on the suit, a queen might be more likely. In other words, the probability of a queen is no longer independent of the suit. 25 | 26 | 27 | ## Causal independence vs. logical independence 28 | 29 | ```{epigraph} 30 | Quite generally, as the robot’s state of knowledge represented by H and X changes, probabilities conditional on them may change from independent to dependent or vice versa; yet the real properties of the events remain the same. Then one who attributed the property of dependence or independence to the events would be, in effect, claiming for the robot the power of psychokinesis. We must be vigilant against this confusion between reality and a state of knowledge about reality, which we have called the ‘mind projection fallacy’. 31 | 32 | -- {cite:t}`jaynes2003` p. 92 33 | ``` 34 | 35 | Some students have gotten really hung up on this example in past semesters. I think it may be useful to distinguish between physical, causal independence and logical independence. The suit of a card does not physically affect or cause any change in the probability of a queen. Neither does removing the two of diamonds, except for the fact that there are fewer cards to draw from. What we're talking about here is logical independence, which is reflected in the state of our knowledge about the cards. -------------------------------------------------------------------------------- /unit3/Unit3-conditioning2.md: -------------------------------------------------------------------------------- 1 | # 3. Conditioning, Part 2 2 | 3 | ## The law of total probability 4 | 5 | This is a really important formula: 6 | 7 | $$P(A) = \sum_{i=1}^{n} P(A \mid H_i) P(H_i)$$ 8 | 9 | We use this often in homework problems for finding the marginal probability of some event ($P(A)$). You will want to partition your sample space into mutually exclusive, exhaustive hypotheses ($H_i$). Try it out on some of the [supplementary exercises](https://www2.isye.gatech.edu/isye6420/supporting.html)! 10 | 11 | ## Lecture errata 12 | 13 | - There's a mistake at 5:40: $0.94\times 0.3 + 0.95\times 0.5 + 0.97\times 0.2$ equals $0.951$, not $0.957$. -------------------------------------------------------------------------------- /unit3/moreexamples3.md: -------------------------------------------------------------------------------- 1 | # More Examples 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/Unit4-IQexample.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f96148e7-b436-4025-a704-4f43b373c12d", 6 | "metadata": {}, 7 | "source": [ 8 | "# 6. Example: Jeremy's IQ\n", 9 | "\n", 10 | "This example shows how to use the Normal-Normal conjugate pair.\n", 11 | "\n", 12 | "Jeremy, a Georgia Tech student, is modeling his IQ as $\\mathcal{N}(\\theta, 80)$. Our prior on a GT student's mean IQ, $\\theta$, is $\\mathcal{N}(110, 120)$. Jeremy takes an IQ test and scores 98.\n", 13 | "\n", 14 | "Here's our model:\n", 15 | "\n", 16 | "$$\n", 17 | "\\begin{align*}\n", 18 | "X | \\theta &\\sim \\mathcal{N}(\\theta, 80) \\\\\n", 19 | "\\theta &\\sim \\mathcal{N}(110, 120)\n", 20 | "\\end{align*}\n", 21 | "$$\n", 22 | "\n", 23 | "According to the [conjugate table](content:conjugate_table), we can use the Normal-Normal pair as follows:\n", 24 | "\n", 25 | "$$\\theta\\mid X\\sim \\mathcal{N}\\left(\\frac{\\tau^2}{\\tau^2 +\\sigma^2/n}\\bar{X} + \\frac{\\sigma^2/n}{\\tau^2 + \\sigma^2/n}\\mu, \\frac{\\tau^2\\sigma^2/n}{\\tau^2+ \\sigma^2/n}\\right)$$\n", 26 | "\n", 27 | "We know the following from the problem description:\n", 28 | "\n", 29 | "$\\mu = 110, \\tau^2 = 120, \\sigma^2 = 80, n = 1, \\bar{X} = 98$\n", 30 | "\n", 31 | "So:\n", 32 | "\n", 33 | "\n", 34 | "$$\n", 35 | "\\begin{align*}\n", 36 | "\\theta\\mid X &\\sim \\mathcal{N}\\left(\\frac{120}{120 + 80/1}(98) + \\frac{80/1}{120 + 80/1}(110), \\frac{(120)(80)/1}{120 + 80/1}\\right) \\\\\n", 37 | "&\\sim \\mathcal{N}(102.8, 48)\n", 38 | "\\end{align*}\n", 39 | "$$\n", 40 | "\n", 41 | "If we increase $n$ to 5 with the same mean, the posterior mean and variance both go down as the data starts to overwhelm the prior: $\\mathcal{N}(99.4, 14.1)$.\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "id": "889d92a4-83ca-48d4-b358-11842b58e18e", 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [] 51 | } 52 | ], 53 | "metadata": { 54 | "kernelspec": { 55 | "display_name": "Python 3 (ipykernel)", 56 | "language": "python", 57 | "name": "python3" 58 | }, 59 | "language_info": { 60 | "codemirror_mode": { 61 | "name": "ipython", 62 | "version": 3 63 | }, 64 | "file_extension": ".py", 65 | "mimetype": "text/x-python", 66 | "name": "python", 67 | "nbconvert_exporter": "python", 68 | "pygments_lexer": "ipython3", 69 | "version": "3.11.0" 70 | } 71 | }, 72 | "nbformat": 4, 73 | "nbformat_minor": 5 74 | } 75 | -------------------------------------------------------------------------------- /unit4/Unit4-conjugatefamilies.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b028b87a-7166-452b-a37b-423f91e9590b", 6 | "metadata": {}, 7 | "source": [ 8 | "# 5. Conjugate Families\n", 9 | "\n", 10 | "One way to avoid needing to calculate the normalizing constant is to make use of conjugate pairs. These are likelihood-prior pairs where the posterior will be the same family as the prior.\n", 11 | "\n", 12 | "(content:conjugate_table)=\n", 13 | "## Conjugate table\n", 14 | "\n", 15 | "From {cite:t}`vidakovic2017engineering` p. 341. This is not an exhaustive list but it has some of the most common conjugate pairs." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "id": "4bac0e78-ec4e-4bd5-ad09-340118f187ca", 21 | "metadata": {}, 22 | "source": [ 23 | "| Likelihood | Prior | Posterior |\n", 24 | "|:------------|:----------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n", 25 | "| $X_i \\mid \\theta \\sim \\mathcal{N} (\\theta, \\sigma^2)$ | $\\theta \\sim\\mathcal{N}(\\mu, \\tau^2)$ | $\\theta\\mid X\\sim \\mathcal{N}\\left(\\frac{\\tau^2}{\\tau^2 +\\sigma^2/n}\\bar{X} + \\frac{\\sigma^2/n}{\\tau^2 + \\sigma^2/n}\\mu, \\frac{\\tau^2\\sigma^2/n}{\\tau^2+ \\sigma^2/n}\\right)$ |\n", 26 | "| $X_i\\mid \\theta \\sim Bin(m,\\theta)$ | $\\theta \\sim Be(\\alpha,\\beta)$ | $\\theta\\mid X \\sim Be\\left(\\alpha + \\sum_{i=1}^{n}X_i,\\beta + mn - \\sum_{i=1}^{n}X_i\\right)$ |\n", 27 | "| $X_i\\mid \\theta \\sim Poi(\\theta)$ | $\\theta \\sim Ga(\\alpha,\\beta)$ | $\\theta\\mid X \\sim Ga\\left(\\alpha+\\sum_{i=1}^{n}X_i,\\beta+n\\right)$ |\n", 28 | "| $X_i\\mid \\theta \\sim \\mathcal{NB}(m,\\theta)$ | $\\theta \\sim Be(\\alpha,\\beta)$ | $\\theta\\mid X \\sim Be\\left(\\alpha+mn,\\beta+\\sum_{i=1}^{n}X_i\\right)$ |\n", 29 | "| $X_i\\mid \\theta \\sim Ga\\left(1/2,1/2\\theta\\right)$ | $\\theta \\sim IG(\\alpha, \\beta)$ | $\\theta \\mid X \\sim IG\\left(\\alpha + n/2, \\beta + \\frac{1}{2}\\sum_{i=1}^{n}X_i\\right)$ |\n", 30 | "| $X_i\\mid \\theta \\sim U(0,\\theta)$ | $\\theta \\sim Pa(\\theta_0,\\alpha)$ | $\\theta\\mid X \\sim Pa\\left(\\max\\{\\theta_0,X_1,...,X_n\\},\\alpha+n\\right)$ |\n", 31 | "| $X_i\\mid \\theta \\sim \\mathcal{N}(\\mu,\\theta)$ | $\\theta \\sim IG(\\alpha, \\beta)$ | $\\theta\\mid X \\sim IG\\left(\\alpha+n/2,\\beta+\\frac{1}{2}\\sum_{i=1}^{n}(X_i - \\mu)^2\\right)$ |\n", 32 | "| $X_i\\mid \\theta \\sim Ga(\\nu,\\theta)$ | $\\theta \\sim Ga(\\alpha,\\beta)$ | $\\theta \\mid X \\sim Ga\\left(\\alpha +n\\nu, \\beta + \\sum_{i=1}^{n}X_i\\right)$ |\n", 33 | "| $X_i\\mid \\theta \\sim Pa(c,\\theta)$ | $\\theta \\sim Ga(\\alpha,\\beta)$ | $\\theta \\mid X \\sim Ga\\left(\\alpha + n, \\beta + \\sum_{i=1}^{n}\\log\\left(X_i/c\\right)\\right)$ |" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "id": "42dcc855-cae0-4a9b-83d5-d7afd715f556", 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [] 43 | } 44 | ], 45 | "metadata": { 46 | "kernelspec": { 47 | "display_name": "Python 3 (ipykernel)", 48 | "language": "python", 49 | "name": "python3" 50 | }, 51 | "language_info": { 52 | "codemirror_mode": { 53 | "name": "ipython", 54 | "version": 3 55 | }, 56 | "file_extension": ".py", 57 | "mimetype": "text/x-python", 58 | "name": "python", 59 | "nbconvert_exporter": "python", 60 | "pygments_lexer": "ipython3", 61 | "version": "3.11.0" 62 | } 63 | }, 64 | "nbformat": 4, 65 | "nbformat_minor": 5 66 | } 67 | -------------------------------------------------------------------------------- /unit4/Unit4-estimation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b344bc8f-dacd-4f6e-aea6-00095b450f92", 6 | "metadata": {}, 7 | "source": [ 8 | "# 9. Estimation\n", 9 | "\n", 10 | "We've seen some examples now of how to get the posterior distributions of our models. Now we're asking: what is the meaning of the posterior and what can we do with it? We need to be able to summarize it in useful ways and make decisions based on these summaries.\n", 11 | "\n", 12 | "Point estimates are the simplest summary of the posterior. We've already used the posterior mean in previous examples, but let's back up a bit first and think about a more general framework.\n", 13 | "\n", 14 | "## Bayesian decision theory\n", 15 | "\n", 16 | "The professor touches on the concepts of actions and risk from Bayesian decision theory. An action is a specific estimation or decision made based on the posterior distribution. These decisions can be evaluated by considering the loss or error associated with that decision. The Bayes action will be a point estimate that minimizes the chosen loss function.\n", 17 | "\n", 18 | "```{note}\n", 19 | "You'll often see Bayesian literature refer to the \"utility function,\" rather than the loss function. The utility function is the negated loss function; it measures something positive that we want to maximize rather than minimize. For more information on this and other topics in this lecture, see {cite:t}`robert2007bayesian` Chapter 2: Decision-Theoretic Foundations. The author also has hundreds of posts on Stack Exchange under the username [Xi'an](https://stats.stackexchange.com/users/7224/xian).\n", 20 | "```\n", 21 | "\n", 22 | "The lecture goes over some of the most common loss functions and their connections to the posterior median and mode. If you want to see the full derivations for these, [this Statistics Matt video](https://www.youtube.com/watch?v=rMUBrbRRTEA) has them. But in practice, we already know the equations that give means, medians, and modes for many distributions, unless they don't have a closed-form solution. Once we start using MCMC methods, our posteriors will be represented by arrays of samples, so finding an estimate of the mean can be as simple as ```np.mean(samples)```." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "id": "1d334f09-b67a-4b9e-b9af-befa1664139e", 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | } 33 | ], 34 | "metadata": { 35 | "kernelspec": { 36 | "display_name": "Python 3 (ipykernel)", 37 | "language": "python", 38 | "name": "python3" 39 | }, 40 | "language_info": { 41 | "codemirror_mode": { 42 | "name": "ipython", 43 | "version": 3 44 | }, 45 | "file_extension": ".py", 46 | "mimetype": "text/x-python", 47 | "name": "python", 48 | "nbconvert_exporter": "python", 49 | "pygments_lexer": "ipython3", 50 | "version": "3.11.0" 51 | } 52 | }, 53 | "nbformat": 4, 54 | "nbformat_minor": 5 55 | } 56 | -------------------------------------------------------------------------------- /unit4/Unit4-ingredients.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "25a1530a-d066-4c0d-9f96-a18fdf26507d", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# 4. Ingredients for Bayesian Inference" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "99c3e95f-bcd5-4e0d-a907-10d63176037e", 16 | "metadata": {}, 17 | "source": [ 18 | "Let's start with Bayes' theorem again:\n", 19 | "\n", 20 | "$$\\pi(\\theta \\mid x) = \\frac{f(x \\mid \\theta) \\pi(\\theta)}{m(x)}$$\n", 21 | "\n", 22 | "This is the notation we'll use when talking about probability distributions rather than events as we've done in Unit 3.\n", 23 | "\n", 24 | "## $\\pi(\\theta \\mid x)$: the posterior distribution \n", 25 | "\n", 26 | "This is the prior updated by the data and normalized.\n", 27 | "\n", 28 | "## $f(x \\mid \\theta)$: the likelihood \n", 29 | "Contains all the information about our experiment. It's an observed variable, so we describe it with $f(\\cdot)$ rather than $\\pi(\\cdot)$ like the posterior and prior. The likelihood is:\n", 30 | "\n", 31 | "$$L(\\theta;x_1, ..., x_n) = \\prod_{i=1}^{n} f(x_i|\\theta)$$\n", 32 | "\n", 33 | "Where $n$ is the number of datapoints. As the sample size increases, the likelihood tends to dominate the prior, leading to a posterior more influenced by the data. Put another way, as we get more data, our prior beliefs become less important, so the data drives our conclusions.\n", 34 | "\n", 35 | "## $\\pi(\\theta)$: the prior \n", 36 | "Usually we use this to describe the state of our knowledge or expert opinion prior to the experiment. Every unobserved variable in your model is a parameter. For each parameter, you will need to elicit a prior. Some students have criticized using $\\pi(\\cdot)$ to describe both the posterior and the prior, but that is intentional. It's accurately describing what we're doing with Bayes' theorem—updating our priors with new information to form our posterior.\n", 37 | "\n", 38 | "## $m(x)$: the marginal distribution or normalizing constant \n", 39 | "Obtain it by integrating the joint distribution of $x$ and $\\theta$ over all possible values of $\\theta$:\n", 40 | "\n", 41 | "$$m(x) = \\int_{\\Theta} f(x|\\theta) \\pi(\\theta) d\\theta$$\n", 42 | "\n", 43 | "This integral is often intractable, which is why a large portion of this course is devoted to strategies to avoid calculating it. More on that later; but because of this situation, we often just write Bayes' theorem in its proportional form:\n", 44 | "\n", 45 | "$$\\pi(\\theta|x) \\propto f(x|\\theta) \\pi(\\theta)$$\n", 46 | "\n", 47 | "The $\\propto$ means \"proportional to.\" Often this is all you need, whether you're going for a ratio (where the marginal cancels out) or you can recognize the kernel of the posterior." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "id": "3a887746-3e61-4089-8bcc-a92940f0eb59", 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [] 57 | } 58 | ], 59 | "metadata": { 60 | "kernelspec": { 61 | "display_name": "Python 3 (ipykernel)", 62 | "language": "python", 63 | "name": "python3" 64 | }, 65 | "language_info": { 66 | "codemirror_mode": { 67 | "name": "ipython", 68 | "version": 3 69 | }, 70 | "file_extension": ".py", 71 | "mimetype": "text/x-python", 72 | "name": "python", 73 | "nbconvert_exporter": "python", 74 | "pygments_lexer": "ipython3", 75 | "version": "3.11.5" 76 | } 77 | }, 78 | "nbformat": 4, 79 | "nbformat_minor": 5 80 | } 81 | -------------------------------------------------------------------------------- /unit4/Unit4-jointconditionals.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3df002b0-9436-4ca7-ae49-85b0d3380e0c", 6 | "metadata": {}, 7 | "source": [ 8 | "# 3. Joint and Conditional Distributions\n", 9 | "\n", 10 | "\n", 11 | "## Errata\n", 12 | "\n", 13 | "As part of the continuous 2d example, the slide that appears at 10:18 in the lecture has an extra $e$ in the denominator that shouldn't be there. It appears to be a typo as it didn't affect the final result. This is what that slide should look like, with the corrected term in red:\n", 14 | "\n", 15 | "$$\n", 16 | "\\begin{align*}\n", 17 | "f(x, y) &= \\frac{1}{\\pi} e^{-\\frac{5}{2} \\left( y^2 - \\frac{2x}{5}y + \\frac{x^2}{25} - \\frac{x^2}{25} + \\frac{x^2}{5} \\right)}\\\\\n", 18 | "&= \\frac{1}{\\pi} e^{-\\frac{5}{2} \\cdot \\frac{4}{25} x^2} \\cdot e^{-\\frac{5}{2} \\left(y - \\frac{x}{5}\\right)^2}\\\\\n", 19 | "&= \\frac{1}{\\pi} \\cdot e^{-\\frac{2}{5}x^2} \\cdot \\sqrt{2\\pi \\cdot \\frac{1}{5}} \\cdot \\frac{1}{\\sqrt{2\\pi \\cdot \\frac{1}{5}}} e^{-\\frac{1}{2 \\cdot \\frac{1}{5}} \\left(y - \\frac{x}{5}\\right)^2}\\\\\n", 20 | "f(x) &= \\frac{1}{\\sqrt{2\\pi \\cdot \\frac{5}{4}}} \\textcolor{red}{e^{-\\frac{x^2}{2 \\cdot \\frac{5}{4}}}} \\cdot \\int_{\\mathbb{R}} \\frac{1}{\\sqrt{2\\pi \\cdot \\frac{1}{5}}} e^{-\\frac{1}{2 \\cdot \\frac{1}{5}} \\left(y - \\frac{x}{5}\\right)^2} \\, dy\n", 21 | "\\end{align*}\n", 22 | "$$\n", 23 | "\n", 24 | "## Joint Distributions\n", 25 | "\n", 26 | "A joint distribution describes the behavior of two or more random variables simultaneously. If $X = (X_1, X_2, ..., X_n)$ is a vector of random variables, then the joint probability density function (PDF) $f(x_1, x_2, ..., x_n)$ gives the likelihood that $X_1$ takes the value $x_1$, $X_2$ takes the value $x_2$, and so on.\n", 27 | "\n", 28 | "The joint cumulative distribution function (CDF) $F(x_1, x_2, ..., x_n)$ gives the probability that each of $X_1, X_2, ..., X_n$ is less than or equal to $x_1, x_2, ..., x_n$ respectively.\n", 29 | "\n", 30 | "For two dimensions, i.e., when $X = (X_1, X_2)$, we write these as:\n", 31 | "\n", 32 | "- Joint PDF: $f(x_1, x_2)$\n", 33 | "- Joint CDF: $F(x_1, x_2)$\n", 34 | "\n", 35 | "## Conditional Distributions\n", 36 | "\n", 37 | "A conditional distribution describes the behavior of one or more random variables given the values of some other variables. If we want to know the distribution of $X_1$ given the value of $X_2$, written $f(x_1 | x_2)$, its defined as the ratio of the joint distribution to the marginal distribution of $X_2$. The marginal distribution, $f(x_2)$, is obtained by integrating the joint distribution over all values of $X_1$:\n", 38 | "\n", 39 | "$$f(x_1|x_2) = \\frac{f(x_1, x_2)}{f(x_2)}, \\quad \\text{where} \\quad f(x_2) = \\int_{-\\infty}^{\\infty} f(x_1, x_2) dx_1$$" 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3 (ipykernel)", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.11.0" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 5 64 | } 65 | -------------------------------------------------------------------------------- /unit4/Unit4-noninform.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "169c5ccf-7be0-4f4d-b3d3-dec6878fa17b", 6 | "metadata": {}, 7 | "source": [ 8 | "# 15. Non-informative Priors" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "9547e735-1c34-46a9-909b-d46c46983a32", 14 | "metadata": { 15 | "tags": [] 16 | }, 17 | "source": [ 18 | "What if we don't have any prior information at all?\n", 19 | "\n", 20 | "## Objectivism and the search for truly non-informative priors\n", 21 | "\n", 22 | "Priors ideally would be based on prior beliefs or knowledge about the parameter in question. But in reality, we don't always have a strong belief about something, so we might use non-informative priors. That, and criticism from frequentist statisticians, led to people looking for the \"objective\" best non-informative priors, for some definition of objective. These are also sometimes called reference priors.\n", 23 | "\n", 24 | "{cite}`kass1996selection` has an [excellent overview](https://www.stat.cmu.edu/~kass/papers/rules.pdf) of the different methods for selecting reference priors through 1996, including Jeffrey's priors, Zellner's method, Jaynes' principle of maximum entropy, Kullback-Leibler divergence, and more.\n", 25 | "\n", 26 | "```{epigraph}\n", 27 | "At the risk of oversimplification, it seems useful to identify two interpretations of reference priors. The first interpretation asserts that reference priors are formal representations of ignorance. The second asserts that there is no objective, unique prior that represents ignorance. Instead, reference priors are chosen by public agreement, much like units of length and weight. In this interpretation, reference priors are akin to a default option in a computer package. We fall back to the default when there is insufficient information to otherwise define the prior....\n", 28 | "\n", 29 | "The first interpretation was at one time the dominant interpretation and much effort was spent trying to justify one prior or another as being noninformative... For the most part, the mood has shifted towards the second interpretation. In the recent literature, it is rare for anyone to make any claim that a particular prior can logically be defended as being truly noninformative. Instead, the focus is on investigating various priors and comparing them to see if they have any advantages in some practical sense.\n", 30 | "\n", 31 | "-- {cite:t}`kass1996selection`" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "id": "3e89745f-2a62-4758-ad33-f0087761606f", 37 | "metadata": {}, 38 | "source": [ 39 | "I don't want to put words in anyone's mouth, but based on this class, I would say Professor Vidakovic leans towards the objectivist side of Bayesian analysis. We'll almost always use non-informative priors in this class. While this isn't a bad choice for an overview course, I want to make people aware that many influential people in the field today don't recommend using noninformative priors in practice (see also [the prior elicitation section](prior-elicitation) of the previous page. \n", 40 | "\n", 41 | "{cite}`berger2006case` is a good paper on the debate between objective versus subjective Bayesian analysis (link [here](https://www2.stat.duke.edu/~berger/papers/obayes-debate.pdf)). If you only read one paper on this debate, though, I would go with *Beyond subjective and objective in statistics.* {cite}`gelman2017beyond`, available [here](http://www.stat.columbia.edu/~gelman/research/published/gelman_hennig_full_discussion.pdf)." 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "id": "85ebc23d-a83a-45ee-8934-4d881d3e6460", 47 | "metadata": {}, 48 | "source": [ 49 | "## Improper priors\n", 50 | "\n", 51 | "We will occasionally encounter improper priors (especially Jeffrey's priors). An improper prior is a prior distribution whose integral does not integrate to a finite number.\n", 52 | "\n", 53 | "Despite their mathematical irregularity, improper priors can often be used in Bayesian analysis without issue. This is because we seldom integrate priors by themselves; instead, our requirement is that the product of the prior and likelihood function result in a proper posterior distribution.\n" 54 | ] 55 | } 56 | ], 57 | "metadata": { 58 | "kernelspec": { 59 | "display_name": "Python 3 (ipykernel)", 60 | "language": "python", 61 | "name": "python3" 62 | }, 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.11.4" 74 | } 75 | }, 76 | "nbformat": 4, 77 | "nbformat_minor": 5 78 | } 79 | -------------------------------------------------------------------------------- /unit4/Unit4-nonpara.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a34ebdfc-beaa-4a42-8a10-053e7396e379", 6 | "metadata": {}, 7 | "source": [ 8 | "# 19. Non-parametric" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "330c6358-094b-4e8c-a66e-eee2f76cb671", 14 | "metadata": {}, 15 | "source": [ 16 | "In parametric empirical Bayesian methods, as covered in the prior lecture, data is used to estimate the hyperparameters in the prior. This approach to inference assumes that the parameter of interest comes from a known family of distributions. In non-parametric empirical Bayes, however, there is no assumption about the family that the parameters come from. Instead, the marginal of the prior is estimated directly from the data. These parameters are still assumed to be identically and independently distributed, but the distribution family isn't specified.\n", 17 | "\n", 18 | "The non-parametric approach was pioneered by Herbert Robbins. The paper, {cite:t}`robbinsempirical`, is online [here](https://www.jstor.org/stable/2238017).\n", 19 | "\n", 20 | "Empirical Bayes can be practical in certain circumstances, but the professor concludes by hinting at the hierarchical models we'll learn in Unit 7. These models are some of the most interesting and widely useful in the course." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "id": "00f85a27-372a-40a0-82e8-62d1f959227e", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [] 30 | } 31 | ], 32 | "metadata": { 33 | "kernelspec": { 34 | "display_name": "Python 3 (ipykernel)", 35 | "language": "python", 36 | "name": "python3" 37 | }, 38 | "language_info": { 39 | "codemirror_mode": { 40 | "name": "ipython", 41 | "version": 3 42 | }, 43 | "file_extension": ".py", 44 | "mimetype": "text/x-python", 45 | "name": "python", 46 | "nbconvert_exporter": "python", 47 | "pygments_lexer": "ipython3", 48 | "version": "3.11.0" 49 | } 50 | }, 51 | "nbformat": 4, 52 | "nbformat_minor": 5 53 | } 54 | -------------------------------------------------------------------------------- /unit4/Unit4-numericalchar.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "5090586e-7473-4aad-b1d2-e3e3a147b8f9", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# 2. Numerical Characteristics of Random Variables\n", 11 | "\n", 12 | "## Expectation\n", 13 | "\n", 14 | "The expectation (mean) is computed by taking a weighted average of the possible outcomes, with the weights being the probabilities of each outcome. For a discrete random variable $X$ with possible outcomes $x_1, x_2, ..., x_n$ and corresponding probabilities $p_1, p_2, ..., p_n$, the expectation is:\n", 15 | "\n", 16 | "$$E[X] = \\sum_{i=1}^{n}x_i p_i$$\n", 17 | "\n", 18 | "For a continuous random variable with probability density function $f(x)$, the expectation is:\n", 19 | "\n", 20 | "$$E[X] = \\int_{\\mathbb{R}}xf(x)dx$$\n", 21 | "\n", 22 | "A general function $\\phi(X)$ of a random variable $X$ also has an expectation, given by:\n", 23 | "\n", 24 | "$$E[\\phi(X)] = \\sum_{i=1}^{n}\\phi(x_i)p_i$$\n", 25 | "\n", 26 | "for discrete variables, and \n", 27 | "\n", 28 | "$$E[\\phi(X)] = \\int_{\\mathbb{R}}\\phi(x)f(x)dx$$\n", 29 | "\n", 30 | "for continuous variables.\n", 31 | "\n", 32 | "## Variance and standard deviation\n", 33 | "\n", 34 | "The variance of a random variable $X$ can be calculated as:\n", 35 | "\n", 36 | "$$Var(X) = E[(X - E[X])^2] = E[X^2] - (E[X])^2$$\n", 37 | "\n", 38 | "The standard deviation, denoted $\\sigma$, is the square root of the variance. \n", 39 | "\n", 40 | "$$\\sigma = \\sqrt{Var(X)}$$\n", 41 | "\n", 42 | "## Moments\n", 43 | "\n", 44 | "A more generalized way to describe expected value, variance, and other properties of distributions is to look at the moments. I was going to type up a brief explanation, but found [this excellent post](https://gregorygundersen.com/blog/2020/04/11/moments/) by Gregory Gundersen that has the best explanation of the concept I've ever read. We don't often need to look at the higher-order moments in our course, but this post is really worth reading.\n", 45 | "\n", 46 | "## Quantiles\n", 47 | "\n", 48 | "Quantiles are points taken at regular intervals from the cumulative distribution function (CDF) of a random variable. For instance, the $p$-th quantile of a distribution $F$ is the value $\\xi_p$ such that $F(\\xi_p) = p$. \n", 49 | "\n", 50 | "For discrete distributions, $\\xi_p = \\inf \\{ x | \\sum_{x_i \\leq x} p_i \\geq p \\}$.\n", 51 | "\n", 52 | "For continuous distributions, $\\xi_p$ satisfies $\\int_{0}^{\\xi_p} f(x) dx = p$ or $F^{-1} (p) = \\xi_p$.\n", 53 | "\n", 54 | "The median is the $0.5$ quantile.\n", 55 | "\n", 56 | "## Mode\n", 57 | "\n", 58 | "The mode of a distribution is the most probable value. For a discrete random variable, it is the value $x_i$ that maximizes the probability mass function, $P(X=x_i)$. For a continuous random variable, it is the value that maximizes the density function." 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "id": "a10f0664-a46d-4754-82b6-1ce73b68c581", 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [] 68 | } 69 | ], 70 | "metadata": { 71 | "kernelspec": { 72 | "display_name": "Python 3 (ipykernel)", 73 | "language": "python", 74 | "name": "python3" 75 | }, 76 | "language_info": { 77 | "codemirror_mode": { 78 | "name": "ipython", 79 | "version": 3 80 | }, 81 | "file_extension": ".py", 82 | "mimetype": "text/x-python", 83 | "name": "python", 84 | "nbconvert_exporter": "python", 85 | "pygments_lexer": "ipython3", 86 | "version": "3.11.0" 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 5 91 | } 92 | -------------------------------------------------------------------------------- /unit4/Unit4-poissongamma.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "28b584ae-4792-4da3-ad65-b563aed0e826", 6 | "metadata": {}, 7 | "source": [ 8 | "# 8. Poisson–Gamma Model\n", 9 | "\n", 10 | "\n", 11 | "## Lecture errata\n", 12 | "\n", 13 | "At 1:39 in the video, the likelihood should be proportional to $\\lambda^{16} e^{-6\\lambda}$. The lecture version is missing the 6.\n", 14 | "\n", 15 | "## Model\n", 16 | "\n", 17 | "Here we have another [conjugate](content:conjugate_table) model. The Poisson likelihood describes the number of marked cells on some plates.\n", 18 | "\n", 19 | "$$\n", 20 | "\\begin{align*}\n", 21 | "X_i | \\lambda &\\sim Poi(\\lambda) \\\\\n", 22 | "\\lambda &\\sim Ga(\\alpha, \\beta)\n", 23 | "\\end{align*}\n", 24 | "$$\n", 25 | "\n", 26 | "This time there are two new wrinkles. One, we're not given the gamma prior parameters directly. Instead we want a mean of 4 and a variance of $1/4$.\n", 27 | "\n", 28 | "[We know](content:gamma_dist) that the gamma distribution's mean is $\\alpha/\\beta$ and the variance is $\\alpha/\\beta^2$, so we use that knowledge to solve for the parameters $\\alpha=64, \\beta=16$.\n", 29 | "\n", 30 | "$\\sum_{i=1}^n X_i = 2 + 0 + 1 + 5 + 7 + 1 = 16, n=6$\n", 31 | "\n", 32 | "So, \n", 33 | "\n", 34 | "$$\n", 35 | "\\begin{align*}\n", 36 | "\\lambda \\mid X_i &\\sim Ga(\\alpha + \\sum_{i=1}^n X_i, \\beta + n) \\\\\n", 37 | "&\\sim Ga(64 + 16, 16 + 6) \\\\ \n", 38 | "&\\sim Ga(80, 22)\n", 39 | "\\end{align*}\n", 40 | "$$\n", 41 | "\n", 42 | "Our posterior mean is $\\alpha/\\beta = 3.64$." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "id": "882490cc-088e-4291-911e-cb94455b317f", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [] 52 | } 53 | ], 54 | "metadata": { 55 | "kernelspec": { 56 | "display_name": "Python 3 (ipykernel)", 57 | "language": "python", 58 | "name": "python3" 59 | }, 60 | "language_info": { 61 | "codemirror_mode": { 62 | "name": "ipython", 63 | "version": 3 64 | }, 65 | "file_extension": ".py", 66 | "mimetype": "text/x-python", 67 | "name": "python", 68 | "nbconvert_exporter": "python", 69 | "pygments_lexer": "ipython3", 70 | "version": "3.11.0" 71 | } 72 | }, 73 | "nbformat": 4, 74 | "nbformat_minor": 5 75 | } 76 | -------------------------------------------------------------------------------- /unit4/Unit4-prediction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2c1a50b7-1800-4f92-83b0-a34e77ea19ee", 6 | "metadata": {}, 7 | "source": [ 8 | "# 13. Prediction\n", 9 | "\n", 10 | "## Lecture errata\n", 11 | "\n", 12 | "The formula for the Gamma prior has a typo, it should be:\n", 13 | "\n", 14 | "$$\\pi(\\lambda) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\lambda^{\\alpha -1}e^{-\\beta \\lambda}$$\n", 15 | "\n", 16 | "## Prior and posterior predictive distributions\n", 17 | "\n", 18 | "Please see Greg's notes on the subject, which will be linked under the lecture video on Canvas." 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "7bd1ac5b-ea50-40fe-8ee1-e909ed1c83c2", 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3 (ipykernel)", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.11.0" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 5 51 | } 52 | -------------------------------------------------------------------------------- /unit4/bayestheorem.md: -------------------------------------------------------------------------------- 1 | # Bayes' Theorem 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/conjugatecases.md: -------------------------------------------------------------------------------- 1 | # Bayesian Inference in Conjugate Cases 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/distributions.md: -------------------------------------------------------------------------------- 1 | # Probability Distributions 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/empiricalbayes.md: -------------------------------------------------------------------------------- 1 | # Empirical Bayes 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/moreexamples.md: -------------------------------------------------------------------------------- 1 | # More Examples 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit4/priors.md: -------------------------------------------------------------------------------- 1 | # Priors 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit5/Unit5-gibbs2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "2027125f-9695-4cf7-9be5-4c7af3e9f9d2", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 12. Conjugate Gamma-Poisson Model" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "id": "b6cd903e-3525-4bb0-a4f5-14535cc43826", 20 | "metadata": {}, 21 | "source": [ 22 | "The professor cites {cite:t}`conjugatelikelihoods1993` as the source of this example." 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "id": "c72c5c6e-01b1-491b-9994-6741d6f5c7be", 28 | "metadata": { 29 | "editable": true, 30 | "slideshow": { 31 | "slide_type": "" 32 | }, 33 | "tags": [] 34 | }, 35 | "source": [ 36 | "\n", 37 | "## Model\n", 38 | "We'll model the number of failures for each pump $i$ using a Poisson distribution, with the rate parameter $\\theta_i$ modified by a time factor $t_i$ to add a linear time dependency to the rate:\n", 39 | "\n", 40 | "$$x_i \\mid \\theta_i \\sim \\text{Pois}(\\theta_i t_i)$$\n", 41 | "\n", 42 | "So the likelihood is proportional to:\n", 43 | "\n", 44 | "$$f(x_i \\mid \\theta_i) \\propto \\prod_{i=1}^{n}\\theta_i^{x_i} e^{-\\theta_i t_i}$$\n", 45 | "\n", 46 | "We then place a Gamma prior on the rate of failure for each pump, but we're fixing the shape parameter $\\alpha$ at 1, so it reduces to an Exponential distribution:\n", 47 | "\n", 48 | "$$ \\theta_i \\mid \\beta \\sim \\text{Exp}(\\beta) \\propto \\beta e^{-\\beta \\theta_i}$$\n", 49 | "\n", 50 | "Our prior on $\\beta$ is another Gamma distribution:\n", 51 | "\n", 52 | "$$ \\beta \\sim \\text{Ga}(c, d) \\propto \\beta^{c-1}e^{-d\\beta}$$" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "3e197675-39c6-4d10-861d-be37ad75a711", 58 | "metadata": {}, 59 | "source": [ 60 | "The joint distribution:\n", 61 | "\n", 62 | "$$ \\pi(x, \\theta, \\beta) \\propto \\prod_{i=1}^n \\theta_i^{x_i} e^{-\\theta_i t_i} \\cdot \\beta e^{-\\beta \\theta_i} \\cdot \\beta^{c-1} e^{-d\\beta} $$\n", 63 | "\n", 64 | "### Full Conditionals\n", 65 | "\n", 66 | "**For each $\\theta_i$:**\n", 67 | "\n", 68 | " $$ \\pi(\\theta_i \\mid \\theta_{\\neq i}, \\beta, x) \\sim \\text{Gamma}(x_i + 1, \\beta + t_i) $$\n", 69 | "\n", 70 | "**For $\\beta$:**\n", 71 | "\n", 72 | " $$ \\pi(\\beta \\mid \\theta, x) \\sim \\text{Gamma}(n + c, \\sum_{i=1}^{n} \\theta_i + d) $$\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "id": "055e4f77-a2e8-41bb-9a2f-f995f25014f7", 78 | "metadata": {}, 79 | "source": [ 80 | "Implementation is on the next page." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "id": "c4bff8a9-5126-4239-af91-06ee985c325c", 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [] 90 | } 91 | ], 92 | "metadata": { 93 | "kernelspec": { 94 | "display_name": "Python 3 (ipykernel)", 95 | "language": "python", 96 | "name": "python3" 97 | }, 98 | "language_info": { 99 | "codemirror_mode": { 100 | "name": "ipython", 101 | "version": 3 102 | }, 103 | "file_extension": ".py", 104 | "mimetype": "text/x-python", 105 | "name": "python", 106 | "nbconvert_exporter": "python", 107 | "pygments_lexer": "ipython3", 108 | "version": "3.11.5" 109 | } 110 | }, 111 | "nbformat": 4, 112 | "nbformat_minor": 5 113 | } 114 | -------------------------------------------------------------------------------- /unit5/Unit5-hamiltonian.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "07902b1b-76eb-4965-ae86-64a0d4cf93e9", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 16. Hamiltonian Monte Carlo\n", 15 | "\n", 16 | "```{note}\n", 17 | "This page is not covered in the lectures. I would like to add it eventually for those who are interested since PyMC and Stan use variants of this algorithm. In the meantime, please see [*A Conceptual Introduction to Hamiltonian Monte Carlo*](https://arxiv.org/abs/1701.02434) {cite:t}`betancourt2018conceptual`.\n", 18 | "```" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "ddba0486-03ff-49fe-956a-88484d093f18", 25 | "metadata": { 26 | "editable": true, 27 | "slideshow": { 28 | "slide_type": "" 29 | }, 30 | "tags": [] 31 | }, 32 | "outputs": [], 33 | "source": [] 34 | } 35 | ], 36 | "metadata": { 37 | "kernelspec": { 38 | "display_name": "Python 3 (ipykernel)", 39 | "language": "python", 40 | "name": "python3" 41 | }, 42 | "language_info": { 43 | "codemirror_mode": { 44 | "name": "ipython", 45 | "version": 3 46 | }, 47 | "file_extension": ".py", 48 | "mimetype": "text/x-python", 49 | "name": "python", 50 | "nbconvert_exporter": "python", 51 | "pygments_lexer": "ipython3", 52 | "version": "3.11.4" 53 | } 54 | }, 55 | "nbformat": 4, 56 | "nbformat_minor": 5 57 | } 58 | -------------------------------------------------------------------------------- /unit5/Unit5-norcau1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "53773b60-365c-49a9-a1db-1fd03800dc83", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 2. Normal–Cauchy Example" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "id": "6c7b865b-75be-43f3-b60c-a10f704ca29e", 20 | "metadata": {}, 21 | "source": [ 22 | "Professor Vidakovic already has a Python implementation of this available: [norcau.py](https://raw.githubusercontent.com/areding/6420-pymc/main/original_examples/Codes4Unit5/norcau.py). I've cleaned it up a bit below to remove some deprecation warnings and unnecessary repetition of some calculations." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 5, 28 | "id": "26f2ada3-5666-4490-bf2b-b0caf71abe63", 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "δ(2) = 1.2821951026935339\n", 36 | "Relative error: 2.3036713373086032e-08\n" 37 | ] 38 | } 39 | ], 40 | "source": [ 41 | "from scipy.integrate import quad\n", 42 | "from numpy import exp, inf\n", 43 | "\n", 44 | "x = 2\n", 45 | "\n", 46 | "num = lambda th: th * exp(-0.5 * (x - th) ** 2) / (1 + th**2)\n", 47 | "denom = lambda th: exp(-0.5 * (x - th) ** 2) / (1 + th**2)\n", 48 | "\n", 49 | "# quadrature function returns integral and absolute error\n", 50 | "numerator, num_err = quad(num, -inf, inf)\n", 51 | "denominator, denom_err = quad(denom, -inf, inf)\n", 52 | "\n", 53 | "delta2 = numerator / denominator\n", 54 | "print(f\"δ(2) = {delta2}\")\n", 55 | "\n", 56 | "# computation of relative error: ratio of the absolute error to the value of the integral itself.\n", 57 | "relative_error = delta2 * ((num_err / numerator) + (denom_err / denominator))\n", 58 | "\n", 59 | "print(f\"Relative error: {relative_error}\")" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "id": "450811ee-52a7-4f23-a81d-38fa51dbb2ec", 65 | "metadata": {}, 66 | "source": [ 67 | "Assuming the errors for each individual integral calculation are uncorrelated, the [error](https://en.wikipedia.org/wiki/Propagation_of_uncertainty) for $f$ should be given by:\n", 68 | "\n", 69 | "$$\\frac{\\Delta f}{f} = \\sqrt{\\left(\\frac{\\Delta a}{a}\\right)^2 + \\left(\\frac{\\Delta b}{b}\\right)^2}$$\n", 70 | "\n", 71 | "In the code above, $f$ is ```delta2```, $a$ is ```numerator```, and $b$ is ```denominator```. $\\Delta_a$ and $\\Delta_b$ are ```num_err``` and ```denom_err```, respectively.\n", 72 | "\n", 73 | "However, students have pointed out that instead of using the square root of the sum of squares, the professor used the simpler form:\n", 74 | "\n", 75 | "$$\n", 76 | "\\frac{\\Delta f}{f} = \\frac{\\Delta a}{a} + \\frac{\\Delta b}{b}\n", 77 | "$$\n", 78 | "\n", 79 | "It was probably just a simplification under the assumption that the errors in the numerator and the denominator are small and the terms $(\\Delta_a / a)^2$ and $(\\Delta_b / b)^2$ are negligible.\n" 80 | ] 81 | } 82 | ], 83 | "metadata": { 84 | "kernelspec": { 85 | "display_name": "Python 3 (ipykernel)", 86 | "language": "python", 87 | "name": "python3" 88 | }, 89 | "language_info": { 90 | "codemirror_mode": { 91 | "name": "ipython", 92 | "version": 3 93 | }, 94 | "file_extension": ".py", 95 | "mimetype": "text/x-python", 96 | "name": "python", 97 | "nbconvert_exporter": "python", 98 | "pygments_lexer": "ipython3", 99 | "version": "3.11.4" 100 | } 101 | }, 102 | "nbformat": 4, 103 | "nbformat_minor": 5 104 | } 105 | -------------------------------------------------------------------------------- /unit5/Unit5-numericalapproaches.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "56165b62-3cb4-4954-b5f5-bae2085aacd4", 6 | "metadata": {}, 7 | "source": [ 8 | "# 1. Numerical Approaches\n", 9 | "\n", 10 | "\n", 11 | "## Lecture errata\n", 12 | "\n", 13 | "There is an error in the exponential terms when sampling from the Cauchy distribution at slide 7, which appears at 4:46. The exponents in the numerator and denominator were accidentally dropped from the last version of the expression. This is how it should be:\n", 14 | "\n", 15 | "$$\\delta_B(x) \\approx \\frac{\\sum_{i=1}^{N} \\theta_i e^{-\\frac{1}{2}(\\theta_i - x)^2}}{\\sum_{i=1}^{N} e^{-\\frac{1}{2}(\\theta_i - x)^2}}$$\n", 16 | "\n", 17 | "\n", 18 | "## Moving beyond conjugate cases\n", 19 | "\n", 20 | "When we move beyond conjugate cases, we might possess the posterior in an analytical form due to Bayes' theorem. However, this will not represent any recognizable distribution, irrespective of how we manipulate it. Many normalizing constants lack a closed-form solution. As illustrated in lessons 2 and 4 of this unit, we can attempt to numerically approximate these constants, but this method can be imprecise or computationally intractable. The time complexity increases exponentially with the number of parameters, as shown in section 2.1 of {cite}`Blei_2017`, linked [here](https://arxiv.org/pdf/1601.00670.pdf).\n", 21 | "\n", 22 | "\n", 23 | "```{seealso}\n", 24 | "[This article by Michael Betancourt](https://betanalpha.github.io/assets/case_studies/probabilistic_computation.html) for an overview of probabilistic computation.\n", 25 | "```\n", 26 | "\n", 27 | "The second half of this course concentrates more on modeling rather than the specific method used to get the posterior, but in order to do that, we need to choose a method for sampling from or approximating the posterior. There are [many methods](https://areding.github.io/6420-pymc/unit5/Unit5-other-methods.html) out there, but we're going to focus on Markov Chain Monte Carlo (MCMC). These algorithms have a lot of advantages, including a relatively easy algorithm to implement and understand.\n", 28 | "\n", 29 | "Specifically, we will learn the basics of the Metropolis-Hastings and Gibbs sampling algorithms.\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "id": "6c01ec8b-c71a-4391-8ef3-d7ac31d9981a", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [] 39 | } 40 | ], 41 | "metadata": { 42 | "kernelspec": { 43 | "display_name": "Python 3 (ipykernel)", 44 | "language": "python", 45 | "name": "python3" 46 | }, 47 | "language_info": { 48 | "codemirror_mode": { 49 | "name": "ipython", 50 | "version": 3 51 | }, 52 | "file_extension": ".py", 53 | "mimetype": "text/x-python", 54 | "name": "python", 55 | "nbconvert_exporter": "python", 56 | "pygments_lexer": "ipython3", 57 | "version": "3.11.4" 58 | } 59 | }, 60 | "nbformat": 4, 61 | "nbformat_minor": 5 62 | } 63 | -------------------------------------------------------------------------------- /unit5/Unit5-other-methods.md: -------------------------------------------------------------------------------- 1 | # 17. Going Further 2 | 3 | These are not currently part of the course, but I would love to dive into them eventually! 4 | 5 | ## Variational inference 6 | 7 | https://www.pymc.io/projects/docs/en/stable/api/vi.html 8 | 9 | https://arxiv.org/abs/1603.00788 10 | 11 | ## Particle-based methods 12 | 13 | Thanks to [Rob McAdam](https://www.robpmcadam.com/), a student in the Fall 2021 class, for the tip! 14 | 15 | https://arxiv.org/abs/2107.10731 16 | 17 | https://arxiv.org/abs/1608.04471 18 | 19 | ## Integrated Nested Laplace Approximation (INLA) 20 | 21 | [Advanced Spatial Modeling with Stochastic Partial Differential Equations Using R and INLA](https://becarioprecario.bitbucket.io/spde-gitbook/ch-INLA.html) -------------------------------------------------------------------------------- /unit5/bayesian-computation.md: -------------------------------------------------------------------------------- 1 | # Bayesian Computation 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit5/gibbs-sampling.md: -------------------------------------------------------------------------------- 1 | # Gibbs Sampling 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit5/metropolis-hastings.md: -------------------------------------------------------------------------------- 1 | # The Metropolis Algorithm 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit5/other.md: -------------------------------------------------------------------------------- 1 | # Other Algorithms 2 | 3 | ```{tableofcontents} 4 | ``` -------------------------------------------------------------------------------- /unit6/Unit6-demo-doodle.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "editable": true, 7 | "slideshow": { 8 | "slide_type": "" 9 | }, 10 | "tags": [] 11 | }, 12 | "source": [ 13 | "# Joint Probability Graphs" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "This is a placeholder for now. The original lecture is \"Creating a Doodle Running Doodleplot,\" so it's safe to skip." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "editable": true, 28 | "slideshow": { 29 | "slide_type": "" 30 | }, 31 | "tags": [] 32 | }, 33 | "outputs": [], 34 | "source": [] 35 | } 36 | ], 37 | "metadata": { 38 | "kernelspec": { 39 | "display_name": "Python 3 (ipykernel)", 40 | "language": "python", 41 | "name": "python3" 42 | }, 43 | "language_info": { 44 | "codemirror_mode": { 45 | "name": "ipython", 46 | "version": 3 47 | }, 48 | "file_extension": ".py", 49 | "mimetype": "text/x-python", 50 | "name": "python", 51 | "nbconvert_exporter": "python", 52 | "pygments_lexer": "ipython3", 53 | "version": "3.11.4" 54 | } 55 | }, 56 | "nbformat": 4, 57 | "nbformat_minor": 4 58 | } 59 | -------------------------------------------------------------------------------- /unit6/Unit6-doodlebug.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "editable": true, 7 | "slideshow": { 8 | "slide_type": "" 9 | }, 10 | "tags": [] 11 | }, 12 | "source": [ 13 | "# Creating a Graphical Model\n", 14 | "\n", 15 | "```{note}\n", 16 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 17 | "```\n", 18 | "\n", 19 | "The corresponding lecture here is called \"Creating a Doodle Running Doodleplot.\" I'm not going to talk about that. In fact, this lecture can safely be skipped unless you are, for some reason, determined to use DoodleBUGS in this class. I don't think I've ever seen anyone do that, but maybe you will!" 20 | ] 21 | } 22 | ], 23 | "metadata": { 24 | "kernelspec": { 25 | "display_name": "Python 3 (ipykernel)", 26 | "language": "python", 27 | "name": "python3" 28 | }, 29 | "language_info": { 30 | "codemirror_mode": { 31 | "name": "ipython", 32 | "version": 3 33 | }, 34 | "file_extension": ".py", 35 | "mimetype": "text/x-python", 36 | "name": "python", 37 | "nbconvert_exporter": "python", 38 | "pygments_lexer": "ipython3", 39 | "version": "3.11.4" 40 | } 41 | }, 42 | "nbformat": 4, 43 | "nbformat_minor": 4 44 | } 45 | -------------------------------------------------------------------------------- /unit6/Unit6-moreaboutpymc.md: -------------------------------------------------------------------------------- 1 | # More About PyMC 2 | 3 | 4 | ```{note} 5 | This page is a stub. It will be updated over summer 2023 with supplementary lecture notes. 6 | ``` 7 | 8 | 9 | The original lecture was "More About WinBUGS" and went over basic links and stuff to the relevant documentation and related packages. I'll do the same here with PyMC. 10 | 11 | 12 | ## Relevant links 13 | 14 | 15 | 16 | ## Overview of the Unit 6 Demos 17 | 18 | -------------------------------------------------------------------------------- /unit7/Unit7-anova.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "695ab09f-d9c2-4226-bda8-b888855af2f2", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 6. Analysis of Variance\n", 15 | "\n", 16 | "## One-Way ANOVA\n", 17 | "\n", 18 | "In an ANOVA model, we are trying to discern whether the means of multiple treatment groups are equivalent or different. The null hypothesis is that the mean of all treatment groups are equal:\n", 19 | "\n", 20 | "$$\\begin{align*}\n", 21 | "H_0 & : \\mu_1 = \\mu_2 = ... = \\mu_a \\\\\n", 22 | "H_1 & : \\text{one or more groups have a different } \\mu\n", 23 | "\\end{align*}$$\n", 24 | "\n", 25 | "The ANOVA model is defined as\n", 26 | "\n", 27 | "$$\\begin{align*}\n", 28 | "y_{ij} & \\sim N(\\mu_i, \\sigma^2) \\\\\n", 29 | "\\mu_i & = \\mu + a_i, \\space i = 1,...,a \\space ; j = 1,...,n_i\n", 30 | "\\end{align*}$$\n", 31 | "\n", 32 | "where $i$ represents the treatment group and $j$ is the sample number. Variance $\\sigma^2$ is assumed to be common among all groups. $\\mu$ is the grand mean of all the data, and $a_i$ is the treatment effect of the $i$th group. Now we can re-define the null hypothesis as:\n", 33 | "\n", 34 | "$$\\begin{align*}\n", 35 | "H_0 & : a_1 = a_2 = ... = a_a \\\\\n", 36 | "\\end{align*}$$\n", 37 | "\n", 38 | "which basically is interpreted as the difference in treatment groups is equal to zero. In the model, we will need to use one of 2 constraints to have an acceptable degrees of freedom. In the sum-to-zero (STZ) constraint, the sum of $a$'s are equal to zero. Or, we can set one of the $a$'s, say $a_1$, to zero.\n", 39 | "\n", 40 | "In classical statistics, an ANOVA table is built and an F-test is used to determine if $H_0$ is rejected. In the case where $H_0$ is rejected, we then would need to make additional models for each comparison of treatment groups to further analyze treatment effects.\n", 41 | "\n", 42 | "The Bayesian approach to ANOVA is to set priors on $\\mu$, $a_1,a_2,...,a_a$, and $\\sigma^2$. The Bayesian model is constructed as:\n", 43 | "\n", 44 | "$$ \n", 45 | "\\begin{align*}\n", 46 | "y_i & \\sim N(\\mu_i,\\sigma^2) && \\text{likelihood}\\\\ \\\\\n", 47 | "\\mu & \\sim N(0,\\sigma_0^2) && \\text{prior: grand mean}\\\\\n", 48 | "\\mu_i & = \\mu + a_i && \\text{deterministic relationship}\\\\\n", 49 | "a_i & \\sim N(0,\\sigma_i^2) && \\text{prior: } a_i\\\\\n", 50 | "\\tau &\\sim Ga(0.001,0.001) && \\text{prior: } \\tau\\\\\n", 51 | "\\sigma^2 & = 1/\\tau && \\text{deterministic relationship}\\\\ \\\\\n", 52 | "\\text{Subject to: } & \\sum a_i = 0 && \\text{STZ constraint}\\\\\n", 53 | "\\end{align*}\n", 54 | "$$\n", 55 | "\n", 56 | "Here $\\sigma_0^2$ and $\\sigma_i^2$ are representing prior variances of the grand mean and treatment groups, respectively. Non-informative variances might be something like $\\sigma_0^2 = 1000$. To assess $H_0$, we will look at the posterior distributions of the $a_i$'s to see if they are significantly different than zero. If we want to compare treatment groups, we can calculate their difference in the Bayesian model, and then look at the posterior distribution of the difference to see if it's significantly different than zero." 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "id": "b4c3f553", 62 | "metadata": {}, 63 | "source": [ 64 | "## Authors\n", 65 | "\n", 66 | "Jason Naramore, August 2024." 67 | ] 68 | } 69 | ], 70 | "metadata": { 71 | "kernelspec": { 72 | "display_name": "Python 3 (ipykernel)", 73 | "language": "python", 74 | "name": "python3" 75 | }, 76 | "language_info": { 77 | "codemirror_mode": { 78 | "name": "ipython", 79 | "version": 3 80 | }, 81 | "file_extension": ".py", 82 | "mimetype": "text/x-python", 83 | "name": "python", 84 | "nbconvert_exporter": "python", 85 | "pygments_lexer": "ipython3", 86 | "version": "3.11.4" 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 5 91 | } 92 | -------------------------------------------------------------------------------- /unit7/Unit7-factorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8ae70a69-9320-4d65-9458-d5af15ce46fe", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 8. Factorial Designs\n", 15 | "\n", 16 | "## Factorial Designs (Two-way ANOVA)\n", 17 | "\n", 18 | "In two-way ANOVA we are looking at the treament effects based on 2 factors. The model is defined as:\n", 19 | "\n", 20 | "$$\\begin{align*}\n", 21 | "y_{ijk} & = \\mu + \\alpha_i + \\beta_j + (\\alpha \\beta )_{ij} + \\epsilon_{ijk} \\\\\n", 22 | "\\mu_i & = \\mu + \\alpha_i + \\beta_j + (\\alpha \\beta )_{ij} \\\\\n", 23 | "\\epsilon_{ijk} & \\sim N(0,\\sigma^2)\n", 24 | "\\end{align*}$$\n", 25 | "\n", 26 | "where $\\alpha_i$ represents the treatment effects of Factor 1 with levels $i=1,2,...,a$ and $\\beta_j$ represents the treatment effect of Factor 2 with levels $j=1,2,...,b$. Notice there is also an interaction term $(\\alpha \\beta )_{ij}$. Like one-way ANOVA, $\\mu$ is the grand mean of $y$ for all data. $\\epsilon$ is the error, and assumed to be normally distributed with a common variance $\\sigma^2$.\n", 27 | "\n", 28 | "Again, like one-way ANOVA, we need to use either sum-to-zero (STZ) or corner constraints to have an acceptable degrees of freedom. STZ constraints involve setting $\\sum\\alpha_i = 0$, $\\sum\\beta_i = 0$, and $\\sum(\\alpha \\beta)_{ij} = 0$. Corner constraints involve setting $\\alpha_1 = 0$, $\\beta_1 = 0$, $(\\alpha \\beta)_{1j} = (\\alpha \\beta)_{i1} = 0$.\n", 29 | "\n", 30 | "The first null hypothesis to test is the interaction terms $H_{01}: (\\alpha \\beta)_{ij} = 0$. If $H_{01}$ is not rejected, then we can proceed to test the null hypotheses of the main effects $H_{02}: \\alpha_i = 0$ and $H_{03}: \\beta_i = 0$.\n", 31 | "\n", 32 | "The Bayesian model can be constructed as :\n", 33 | "\n", 34 | "$$ \\begin{align*}\n", 35 | "y_{ij} & \\sim N(\\mu_{ij},\\sigma^2) && \\text{likelihood}\\\\ \\\\\n", 36 | "\\mu & \\sim N(0,\\sigma_0^2) && \\text{prior: grand mean}\\\\\n", 37 | "\\mu_{ij} & = \\mu + \\alpha_i + \\beta_j + (\\alpha \\beta )_{ij} && \\text{deterministic relationship}\\\\\n", 38 | "\\alpha_i & \\sim N(0,\\sigma_i^2) && \\text{prior: } \\alpha_i\\\\\n", 39 | "\\beta_j & \\sim N(0,\\sigma_j^2) && \\text{prior: } \\beta_j\\\\\n", 40 | "\\tau &\\sim Ga(0.001,0.001) && \\text{prior: } \\tau\\\\\n", 41 | "\\sigma^2 & = 1/\\tau && \\text{deterministic relationship}\\\\ \\\\\n", 42 | "\\text{Subject to: } & \\sum \\alpha_i = 0 && \\text{STZ constraint for } \\alpha\\\\\n", 43 | " & \\sum \\beta_i = 0 && \\text{STZ constraint for } \\beta\\\\\n", 44 | " & \\sum (\\alpha \\beta)_{ij} = 0 && \\text{STZ constraint for } \\alpha \\beta \\text{ interaction}\\\\\n", 45 | "\\end{align*}$$\n", 46 | "\n", 47 | "$\\sigma_0^2$, $\\sigma_i^2$, anf $\\sigma_j^2$ are representing prior variances of the grand mean and treatment groups for each factor. Non-informative variances might be something like $\\sigma_0^2 = \\sigma_i^2 = \\sigma_j^2 = 1000$.\n", 48 | "\n", 49 | "## Authors\n", 50 | "\n", 51 | "Jason Naramore, August 2024." 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "id": "f8e8f5c8-2eed-4992-ba9d-c33dddc24717", 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [] 61 | } 62 | ], 63 | "metadata": { 64 | "kernelspec": { 65 | "display_name": "Python 3 (ipykernel)", 66 | "language": "python", 67 | "name": "python3" 68 | }, 69 | "language_info": { 70 | "codemirror_mode": { 71 | "name": "ipython", 72 | "version": 3 73 | }, 74 | "file_extension": ".py", 75 | "mimetype": "text/x-python", 76 | "name": "python", 77 | "nbconvert_exporter": "python", 78 | "pygments_lexer": "ipython3", 79 | "version": "3.11.4" 80 | } 81 | }, 82 | "nbformat": 4, 83 | "nbformat_minor": 5 84 | } 85 | -------------------------------------------------------------------------------- /unit7/Unit7-introduction.md: -------------------------------------------------------------------------------- 1 | # 1. Introduction to Hierarchical Models 2 | 3 | In his introductory textbook *A Student’s Guide to Bayesian Statistics* {cite:t}`lambert2018student` Ben Lambert provides a great introduction to the concept of hierarchial models with an example. We will go over a modified version of this example here. 4 | Hierarchical models can be seen as a compromise between two other types of models. The first is what Lambert calls 'fully pooled' models and the second are called 'heterogenous' models. Let's look to a specific example to compare and contrast the two models. 5 | 6 | ## Fully pooled versus heterogenous models 7 | 8 | Imagine that we are in the state of Georgia and are analyzing math SAT test scores from 100 schools in the state. For each school we have the scores for $N$ randomly selected senior students. Suppose we want to estimate the average SAT score of a randomly chosen senior student from Georgia. 9 | 10 | ### Fully pooled model 11 | For this model we simply ignore what school each score came from and aggregate or 'pool' all the data together. 12 | After looking at a plot of the pooled data we decide to model the scores as being normally distributed 13 | 14 | $$ 15 | S_{ij} \sim \mathcal{N}(\mu, \sigma^2) 16 | $$ 17 | 18 | with average $\mu$ and variance $\sigma^2$ 19 | where $S_{ij}$ denotes the test score of student $i$ who attends school $j$. While this method does yield the quantity we are after (the average score of a randomly chosen senior from the state of Georgia) it arrives at this answer without adequately accounting for the variation of scores *between schools*. Therefore it's likely that our posterior distribution is far too narrow. In the example Lambert gives he shows this to be the case using a posterior predictive check. 20 | 21 | ### Heterogenous model 22 | After recognizing the disadvantages of simply pooling the data we decide to try to take the inter-school variation into account in our model. To do this we decide to use a model that estimates a separate average and variance for each school 23 | 24 | $$ 25 | S_{ij} \sim \mathcal{N}(\mu_j, \sigma^2_j) 26 | $$ 27 | 28 | where $\mu_j$ and $ \sigma^2_j$ are the estimated average and variance for school $j$. While this model will certainly take the inter-school variation into account the disadvantage is that it's not clear how we can get an estimate for the average SAT score at the state level which is what we were after in the first place. 29 | 30 | ## Hierarchical model 31 | Hierarchical models can be seen as a middle ground between these two models. The pooled model does not fully take the inter-school variation into account and this is not realistic since there are certainly differences between schools that can effect student test scores such as the amount of funding the school receives. The heterogenous model does capture the variation of scores for each school but it treats each school as independent from all the others. This is not realistic either since there should be some relation between the schools given that they are all in the state of Georgia which has it's own Department of Education which determines certain state-wide public school polices. Hierarchical models allow us to build in this relation between schools while also accounting for inter-school score variation. 32 | 33 | For the case of the Georgia schools we can decide that the average score $\mu_j$ for school $j$ is drawn from a state level distribution of averages 34 | 35 | $$ 36 | \mu_j \sim \mathcal{N}(\bar{\mu}, \bar{\sigma^2}) 37 | $$ 38 | 39 | and put a non-informative prior on the variance of scores for school $j$ 40 | 41 | $$ 42 | \sigma_j^2 \sim \text{InverseGa}(0.001, 0.001). 43 | $$ 44 | 45 | Here $\bar{\mu}$ is the average of the average test scores across all of the schools in Georgia and $\bar{\sigma}^2$ is the variance of the school averages around $\bar{\mu}$ and we can place non-informative priors on them 46 | 47 | $$ 48 | \bar{\mu} \sim \mathcal{N}(1000, 10), \quad \bar{\sigma}^2 \sim \text{InverseGa}(0.001, 0.001). 49 | $$ 50 | 51 | This model allows us to capture the fact that the average test scores for schools are related to each other in some way while also taking into account that there will be variations in the average test scores between schools. Note that we set the mean of the normal distribution for $\bar{\mu}$ to be 1000 since the range of SAT test scores is $[400,1600]$. 52 | 53 | ## Non-spatially separated groups 54 | In the above example our data come in groups (the schools from Georgia) that are separated spatially however the groups that our data come in need not only be separated spatially. These groups can also be separated temporally such as the case from Gelfand et al (1990) we will cover later in this section or spatio-temporally in the case of a meta-analysis of different studies. 55 | 56 | 57 | ## Authors 58 | 59 | [Amanuel Anteneh](https://github.com/amanuelanteneh), June 2024. 60 | -------------------------------------------------------------------------------- /unit7/Unit7-multilevel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c7864e32-6d61-4533-8aa7-ab28f3ebdd05", 6 | "metadata": {}, 7 | "source": [ 8 | "# 18. Multilevel Models\n", 9 | "\n", 10 | "In multilevel models, we can model the parameters to be associated by group. Random effects models and mixed effects models are both examples of multilevel models.\n", 11 | "\n", 12 | "For example, we could have $J$ intercepts in the following linear model that are associated with the students at school $j$:\n", 13 | "\n", 14 | "$$\\begin{align*}\n", 15 | "y_i & = \\alpha_{j(i)} + \\beta x_i + \\epsilon_i, \\text{ for students } i = 1, .. , n\\\\\n", 16 | "\\alpha_j & = a + b \\mu_j + \\eta_j \\text{ for schools } j = 1, ..., J \\\\\n", 17 | "\\end{align*}$$\n", 18 | "\n", 19 | "Advantages of multilevel models can be to learn about treatment effects that vary by group. This type of model allows us to \"borrow strength\" from all of the data to make inferences about smaller sample-size groups.\n", 20 | "\n", 21 | "We also may be able to achieve better fitting models, by accounting for the uncertainty at different levels. Another example is with $Poission(\\lambda)$ regression:\n", 22 | "\n", 23 | "$$ \\begin{align*}\n", 24 | "y_{i} & \\sim Poisson(\\lambda_i)\\\\\n", 25 | "\\lambda_i & = \\text{exp}(\\beta_{0} + \\beta_{1} x_{i1} + ... + \\beta_k x_{ik})\n", 26 | "\\end{align*}$$\n", 27 | "\n", 28 | "One of the model assumptions is that the expection and variance of $y_i$ are equal. However, many times in real-life data the variance is larger. In order to account for the higher than expected variance, we can add the random effect term $\\xi_{j(i)}$ to the linear equation of covariates. This new term can act as a \"sponge\" to collect the excess variance, possibly for a better fitting model.\n", 29 | "\n", 30 | "\n", 31 | "## Authors\n", 32 | "\n", 33 | "Jason Naramore, August 2024." 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "id": "1c7f9988-e713-48e9-bd6f-fb1a869a270f", 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [] 43 | } 44 | ], 45 | "metadata": { 46 | "kernelspec": { 47 | "display_name": "Python 3 (ipykernel)", 48 | "language": "python", 49 | "name": "python3" 50 | }, 51 | "language_info": { 52 | "codemirror_mode": { 53 | "name": "ipython", 54 | "version": 3 55 | }, 56 | "file_extension": ".py", 57 | "mimetype": "text/x-python", 58 | "name": "python", 59 | "nbconvert_exporter": "python", 60 | "pygments_lexer": "ipython3", 61 | "version": "3.11.8" 62 | } 63 | }, 64 | "nbformat": 4, 65 | "nbformat_minor": 5 66 | } 67 | -------------------------------------------------------------------------------- /unit7/Unit7-other.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "49ae4686-8e0c-4796-b68e-a3fb293633c6", 6 | "metadata": {}, 7 | "source": [ 8 | "# 14. Generalized Linear Models\n", 9 | "\n", 10 | "In Generalized Linear Models, we are modeling $y$ as a linear combination of $x$ predictors, like linear regression. But, rather than assuming $y$ is normally distributed, we can define $y$ to be of other distributions within the exponential family. In this case, we need to use a *link* function.\n", 11 | "\n", 12 | "## Logistic Regression\n", 13 | "\n", 14 | "In logistic regression, the response is binary (or binomial). The typical link function is called *logit* and is defined as $\\log(\\frac{p}{1-p})$. A binary response (0 or 1) is used to fit the model, and then predictions are interpreted as a probability $p$ between 0 and 1. The equation is:\n", 15 | "\n", 16 | "$$ \\log(\\frac{p}{1-p}) = \\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k $$\n", 17 | "\n", 18 | "In the format above, the response is in the form of log-odds (logit). Equivalently, we can take the inverse logit on both sides of the equation to have the response in terms of $p$:\n", 19 | "\n", 20 | "$$ p = \\text{invlogit}(\\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k )$$\n", 21 | "\n", 22 | "where the inverse logit is $\\frac{e^p}{1+e^p}$. The Bayesian model is constructed as:\n", 23 | "\n", 24 | "$$ \\begin{align*}\n", 25 | "y_{ij} & \\sim Bern(p) && \\text{likelihood}\\\\ \\\\\n", 26 | "p & = \\text{invlogit}(\\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k) && \\text{deterministic relationship}\\\\\n", 27 | "\\beta_j & \\sim N(0,\\sigma_j^2) && \\text{prior: } \\beta_j, \\space j = 0 \\text{ to } k \\\\\n", 28 | "\\end{align*}$$\n", 29 | "\n", 30 | "Other common link functions for logistic regression are probit and complementary log-log, which may be used to test different fits due to their shapes.\n", 31 | "\n", 32 | "## Possion Regression\n", 33 | "\n", 34 | "Poisson regression is used when the response is in the form of counts, we use a log-link function. The model is:\n", 35 | "\n", 36 | "$$ \\log(\\lambda) = \\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k $$\n", 37 | "\n", 38 | "or equivalently:\n", 39 | "\n", 40 | "$$ \\lambda = e^{\\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k} $$\n", 41 | "\n", 42 | "where $\\lambda$ is the rate parameter of the Poisson distribution. The Bayesian model is:\n", 43 | "\n", 44 | "$$ \\begin{align*}\n", 45 | "y_{ij} & \\sim Poisson(\\lambda) && \\text{likelihood}\\\\ \\\\\n", 46 | "\\lambda & = \\text{exp}(\\beta_0 + \\beta_1 x_1 + ... + \\beta_k x_k) && \\text{deterministic relationship}\\\\\n", 47 | "\\beta_j & \\sim N(0,\\sigma_j^2) && \\text{prior: } \\beta_j, \\space j = 0 \\text{ to } k \\\\\n", 48 | "\\end{align*}$$\n" 49 | ] 50 | } 51 | ], 52 | "metadata": { 53 | "kernelspec": { 54 | "display_name": "Python 3 (ipykernel)", 55 | "language": "python", 56 | "name": "python3" 57 | }, 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.11.8" 69 | } 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 5 73 | } 74 | -------------------------------------------------------------------------------- /unit7/Unit7-regression.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3ea0d6ad-a4b7-4002-9395-4c3c0b4046da", 6 | "metadata": {}, 7 | "source": [ 8 | "# 10. Simple Linear Regression\n", 9 | "\n", 10 | "The simple linear regression model is:\n", 11 | "\n", 12 | "$$\\begin{align*}\n", 13 | "y_i & = \\beta_0 + \\beta_1 x_{i1} + \\epsilon_i, i = 1 , ... , n \\\\\n", 14 | "\\epsilon_i & \\overset{iid}{\\sim} N (0,\\sigma^2) \\end{align*} $$\n", 15 | "\n", 16 | "where data is in the form of paired $x_{i1}$ and $y_i$ values from $i = 1,2,...,n$. $\\beta_1$ and $\\beta_0$ are the slope and intercept, respectively. The goal is to find the best fit line for predicting $y$ based on $x$. The best fit line is almost never perfect, so one of the typical assumptions is that the error $\\epsilon$ about the $\\hat{y}$ fit is normally distributed.\n", 17 | "\n", 18 | "Classical statistics has an elegant approach to solving this problem. We can find the estimate of $\\hat{\\beta}_1 = \\frac{SXY}{SXX}$, where\n", 19 | "\n", 20 | "$$SXY = \\sum_{i=1}^n (x_i - \\bar{x}) (y_i - \\bar{y}) $$\n", 21 | "$$SXX = \\sum_{i=1}^n (x_i - \\bar{x})^2 $$\n", 22 | "\n", 23 | "and then find $\\hat{\\beta}_0 = \\bar{y} - \\hat{\\beta_1} \\bar{x} $. Furthermore, we can assess the model fit using $R^2$, which is found using SSE, SSR, and SST. $R^2$ is the variance in $y$ explained by the model.\n", 24 | "\n", 25 | "$$\\begin{align*}\n", 26 | "SSE & = \\sum_{i=1}^n (y_i - \\hat{y}_i)^2 \\\\\n", 27 | "SSR & = \\sum_{i=1}^n (\\hat{y}_i - \\bar{y})^2 \\\\\n", 28 | "SST & = \\sum_{i=1}^n (y_i - \\bar{y})^2 \\\\\n", 29 | "R^2 & = \\frac{SSR}{SST} = 1 - \\frac{SSE}{SST} \\\\\n", 30 | "\\end{align*}$$\n", 31 | "\n", 32 | "In the Bayesian model for simple linear regression, we set priors for $\\beta_0$, $\\beta_1$, and $\\sigma^2$:\n", 33 | "\n", 34 | "$$ \\begin{align*}\n", 35 | "y_{ij} & \\sim N(\\mu,\\sigma^2) && \\text{likelihood}\\\\ \\\\\n", 36 | "\\mu & = \\beta_0 + \\beta_1 x && \\text{deterministic relationship}\\\\\n", 37 | "\\beta_0 & \\sim N(0,\\sigma_0^2) && \\text{prior: } \\beta_0\\\\\n", 38 | "\\beta_1 & \\sim N(0,\\sigma_1^2) && \\text{prior: } \\beta_1\\\\\n", 39 | "\\tau & \\sim Ga(a,b) && \\text{prior: } \\tau\\\\\n", 40 | "\\sigma^2 & = 1/\\tau && \\text{deterministic relationship}\\\\\n", 41 | "\\end{align*}$$\n", 42 | "\n", 43 | "Typical non-informative priors for $\\beta_0$ and $\\beta_1$ are centered at zero, with a wide standard deviation. A non-informative prior for $\\tau$ could be $Ga(a = 0.001, b = 0.001)$. In `PyMC` we can define a Normal distribution with either the $\\tau$ or $\\sigma$ parameter, so we could define the $\\sigma^2$ distribution directly instead of using a deterministic relationship to $\\tau$. Other possible non-negative priors for $\\sigma^2$ might be Inverse-Gamma, Half-Normal, or Half-flat.\n", 44 | "\n", 45 | "\n", 46 | "## Authors\n", 47 | "\n", 48 | "Jason Naramore, July 2024.\n" 49 | ] 50 | } 51 | ], 52 | "metadata": { 53 | "kernelspec": { 54 | "display_name": "Python 3 (ipykernel)", 55 | "language": "python", 56 | "name": "python3" 57 | }, 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.11.8" 69 | } 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 5 73 | } 74 | -------------------------------------------------------------------------------- /unit7/Unit7-why.md: -------------------------------------------------------------------------------- 1 | # 2. Reasons to Use Hierarchical Models 2 | 3 | 4 | ```{note} 5 | This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture. 6 | ``` -------------------------------------------------------------------------------- /unit7/hierarchical.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "35575631", 6 | "metadata": {}, 7 | "source": [ 8 | "# Hierarchical Models\n", 9 | "\n", 10 | "```{tableofcontents}\n", 11 | "```" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "id": "f403ba94", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [] 21 | } 22 | ], 23 | "metadata": { 24 | "kernelspec": { 25 | "display_name": "Python 3 (ipykernel)", 26 | "language": "python", 27 | "name": "python3" 28 | }, 29 | "language_info": { 30 | "codemirror_mode": { 31 | "name": "ipython", 32 | "version": 3 33 | }, 34 | "file_extension": ".py", 35 | "mimetype": "text/x-python", 36 | "name": "python", 37 | "nbconvert_exporter": "python", 38 | "pygments_lexer": "ipython3", 39 | "version": "3.11.0" 40 | } 41 | }, 42 | "nbformat": 4, 43 | "nbformat_minor": 5 44 | } 45 | -------------------------------------------------------------------------------- /unit7/linearmodels.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7c8ff83f", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# Linear Models\n", 11 | "\n", 12 | "```{tableofcontents}\n", 13 | "```" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "id": "bd9507e1", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [] 23 | } 24 | ], 25 | "metadata": { 26 | "kernelspec": { 27 | "display_name": "Python 3 (ipykernel)", 28 | "language": "python", 29 | "name": "python3" 30 | }, 31 | "language_info": { 32 | "codemirror_mode": { 33 | "name": "ipython", 34 | "version": 3 35 | }, 36 | "file_extension": ".py", 37 | "mimetype": "text/x-python", 38 | "name": "python", 39 | "nbconvert_exporter": "python", 40 | "pygments_lexer": "ipython3", 41 | "version": "3.11.0" 42 | } 43 | }, 44 | "nbformat": 4, 45 | "nbformat_minor": 5 46 | } 47 | -------------------------------------------------------------------------------- /unit7/othermodels.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "a321ee74", 6 | "metadata": {}, 7 | "source": [ 8 | "# Other Models\n", 9 | "\n", 10 | "```{tableofcontents}\n", 11 | "```" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": null, 17 | "id": "207a397a", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [] 21 | } 22 | ], 23 | "metadata": { 24 | "kernelspec": { 25 | "display_name": "Python 3 (ipykernel)", 26 | "language": "python", 27 | "name": "python3" 28 | }, 29 | "language_info": { 30 | "codemirror_mode": { 31 | "name": "ipython", 32 | "version": 3 33 | }, 34 | "file_extension": ".py", 35 | "mimetype": "text/x-python", 36 | "name": "python", 37 | "nbconvert_exporter": "python", 38 | "pygments_lexer": "ipython3", 39 | "version": "3.11.0" 40 | } 41 | }, 42 | "nbformat": 4, 43 | "nbformat_minor": 5 44 | } 45 | -------------------------------------------------------------------------------- /unit8/Unit8-missing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "7be80440", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 1. Missing Data\n", 15 | "\n", 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "dad7f555-04cd-43c3-a3a1-6d245c3b8c00", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3 (ipykernel)", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.11.4" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /unit8/Unit8-tteex1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f9d542ef-75ee-47d6-9d61-b3624c4643f4", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 4. Time-to-event Models: Example 1\n", 15 | "\n", 16 | "```{note}\n", 17 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 18 | "```" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "2a64b47e-1d95-409d-aa74-eae37e2ca162", 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3 (ipykernel)", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.11.4" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 5 51 | } 52 | -------------------------------------------------------------------------------- /unit9/Unit9-cpo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1a549b39-51d5-49ec-bdad-e7b8a4ff97de", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 5. Conditional Predictive Ordinate\n", 15 | "\n", 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "5ecf65ea-0582-4d38-9c11-19410d1ac307", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3 (ipykernel)", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.11.4" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /unit9/Unit9-cumulative.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cc5d3ed0-8ab5-46b5-82f5-7b3768ee0ef9", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 7. Using the Empirical CDF and the Probability Integral Transform\n", 15 | "\n", 16 | "This lecture is about a goodness-of-fit test based on the [Probability Integral Transform](https://en.wikipedia.org/wiki/Probability_integral_transform). If you have a random variable $X$ and you apply its own cumulative distribution function (CDF) to it: \n", 17 | "\n", 18 | "$$Y = F_X(X)$$\n", 19 | "\n", 20 | "the resulting random variable $Y$ will be $U(0, 1)$-distributed. We can use this idea to check our model's fit by taking our sample's response variable values and running them through the posterior CDF.\n", 21 | "\n", 22 | "We only have samples from our posterior rather than an actual CDF function, so we'll need to use the Empirical CDF (ECDF).\n", 23 | "\n", 24 | "## The Empirical CDF\n", 25 | "\n", 26 | "Remember the CDF is the function that maps a maps a number $x$ to the probability that the random variable $X$ takes on a value less than or equal to $x$:\n", 27 | "\n", 28 | "$$F_X(x) = p(X \\le x)$$\n", 29 | "\n", 30 | "So the ECDF is just the probability that some number $x$ is less than \n", 31 | "\n", 32 | "$$F_X(X=x) = \\frac{1}{n}\\sum\\limits_{i=1}^{n}\\mathbf{1}(X_i \\le x)$$\n", 33 | "\n", 34 | "where $\\mathbf{1}(X_i \\le x)$ is an indicator function that evaluates to 1 if $(X_i \\le x)$ is true, otherwise 0 ({cite:t}`vidakovic2017engineering`). In other words, we count the number of samples less than $x$ and divide by $n$ to get the probability.\n", 35 | "\n", 36 | "## The test(s)\n", 37 | "\n", 38 | "Once we've evaluated the ECDF at each original $y$ value from our sample's response variable, we need some way to compare the output of $F_X(x)$ to a standard uniform distribution. Professor Vidakovic notes that values extremely close to 0 or 1 will indicate outliers. In the next lecture, he also applies a transformation to the values to make the outliers stand out more:\n", 39 | "\n", 40 | "$$ \\log\\left(\\frac{p}{1-p}\\right)^2$$\n", 41 | "\n", 42 | "This is the square of the logit function. The purpose of the logit function is to map probabilities to real values. He then squares that to make extreme values stand out more.\n", 43 | "\n", 44 | "The Arviz library ({cite:t}`arviz_2019`) has a function called [```plot_ecdf```](https://python.arviz.org/en/stable/_modules/arviz/plots/ecdfplot.html#plot_ecdf) based on {cite:t}`PITecdf_fittest`. This paper explains the above process really well and outlines a graphical check based on these ideas.\n", 45 | "\n", 46 | "On the next page, we'll check out how to put these ideas into practice with PyMC.\n" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "id": "882ff3ed-18c0-4635-a158-d386420c23e3", 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [] 56 | } 57 | ], 58 | "metadata": { 59 | "kernelspec": { 60 | "display_name": "Python 3 (ipykernel)", 61 | "language": "python", 62 | "name": "python3" 63 | }, 64 | "language_info": { 65 | "codemirror_mode": { 66 | "name": "ipython", 67 | "version": 3 68 | }, 69 | "file_extension": ".py", 70 | "mimetype": "text/x-python", 71 | "name": "python", 72 | "nbconvert_exporter": "python", 73 | "pygments_lexer": "ipython3", 74 | "version": "3.11.5" 75 | } 76 | }, 77 | "nbformat": 4, 78 | "nbformat_minor": 5 79 | } 80 | -------------------------------------------------------------------------------- /unit9/Unit9-dic.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "3e119ec7-1f50-4e26-8604-2e2db5d7a76c", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 2. Deviance Information Criterion\n", 15 | "\n", 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "18368931-9fcd-4ef6-afee-a42a53d94c78", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3 (ipykernel)", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.11.4" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /unit9/Unit9-fit-selection-diagnostics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8120168f", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 1. Model Fit, Selection, and Diagnostics\n", 15 | "\n", 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "id": "dcbbec84-263e-433b-8b97-fd20e79f1197", 25 | "metadata": {}, 26 | "source": [ 27 | "Papers to check out:\n", 28 | "\n", 29 | "https://arxiv.org/abs/1307.5928\n", 30 | "\n", 31 | "https://arxiv.org/abs/1507.04544?context=stat" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "id": "a9567541-8ca6-4983-b7f5-03146f23551d", 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3 (ipykernel)", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.11.4" 60 | } 61 | }, 62 | "nbformat": 4, 63 | "nbformat_minor": 5 64 | } 65 | -------------------------------------------------------------------------------- /unit9/Unit9-fitsel.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "5fa02b4b-1b2c-4609-a35e-79b56decb368", 6 | "metadata": { 7 | "editable": true, 8 | "slideshow": { 9 | "slide_type": "" 10 | }, 11 | "tags": [] 12 | }, 13 | "source": [ 14 | "# 3. Model Fit and Selection\n", 15 | "\n", 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "e552058c-7891-45e2-8651-ada4b2549431", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3 (ipykernel)", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.11.4" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | -------------------------------------------------------------------------------- /unit9/Unit9-ssvs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0be75ca1-87f0-478b-a6ce-4cb2519b1d78", 6 | "metadata": {}, 7 | "source": [ 8 | "# 9. Stochastic Search Variable Selection" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "24a8d47e-25bb-4c6e-ad33-cb4bc34c7e6a", 14 | "metadata": {}, 15 | "source": [ 16 | "\n", 17 | "```{note}\n", 18 | "This page is a stub. I will try to update it over the semester with supplementary lecture notes—if you would like to request a certain page be finished first, please make an Ed Discussion post with your questions about the lecture.\n", 19 | "```" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "id": "c416cb3a-5a71-4b7f-ab78-1641af24ff57", 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3 (ipykernel)", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.11.4" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 5 52 | } 53 | --------------------------------------------------------------------------------