{"id":2872,"date":"2023-01-25T14:23:29","date_gmt":"2023-01-25T14:23:29","guid":{"rendered":"http:\/\/optimumsportsperformance.com\/blog\/?p=2872"},"modified":"2023-01-25T14:23:29","modified_gmt":"2023-01-25T14:23:29","slug":"bayesian-linear-regression-getting-started-with-pymc3","status":"publish","type":"post","link":"https:\/\/optimumsportsperformance.com\/blog\/bayesian-linear-regression-getting-started-with-pymc3\/","title":{"rendered":"Bayesian Linear Regression: Getting started with PyMC3"},"content":{"rendered":"<p>Previously I&#8217;ve used {<strong>rstanarm<\/strong>}, {<strong>brms<\/strong>}, and <strong>Stan<\/strong> for fitting Bayesian models. However, as I continue to work on improving my Python skills, I figured I&#8217;d try and delve into the <strong>PyMC3<\/strong> framework for fitting such models. This article will go through the following steps:<\/p>\n<ol>\n<li>Fitting the model<\/li>\n<li>Making a point estimate prediction<\/li>\n<li>Making a point estimate prediction with uncertainty<\/li>\n<li>Calculating a posterior predictive distribution<\/li>\n<\/ol>\n<p>I&#8217;ve covered the last three steps in a prior blog on <span style=\"color: #0000ff;\"><strong><a style=\"color: #0000ff;\" href=\"https:\/\/optimumsportsperformance.com\/blog\/making-predictions-with-a-bayesian-regression-model\/\">making predictions with a Bayesian model<\/a><\/strong><\/span>. I know there are probably functions available in <strong>PyMC3<\/strong> that can do these things automatically (just as there are in {<strong>rstanarm<\/strong>}) but instead of falling back on those, I create the posterior distributions here using <strong>numpy<\/strong> and build them myself.<\/p>\n<p>The entire code and data are available on my <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/github.com\/pw2\/Bayesian-Regression-with-PyMC3\/tree\/main\/Linear%20Regression%20with%20PyMc3\">GITHUB page<\/a><\/span><\/strong>, where I also have the model coded in {<strong>rstanarm<\/strong>}, for anyone interested in seeing the steps in a different code language.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Loading Libraries &amp; Data<\/strong><\/span><\/p>\n<p>The data I&#8217;ll be using is the {<strong>mtcars<\/strong>} data set, which is available in R. I&#8217;ve saved a copy in .csv format so that I can load it into my Jupyter notebook.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport pandas as pd\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt \r\nimport seaborn as sns\r\nimport pymc3 as pm\r\nimport arviz as az \r\nimport os\r\n\r\n# load mtcars\r\nd = pd.read_csv('mtcars.csv')\r\nd.head()\r\n<\/pre>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2873\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM.png\" alt=\"\" width=\"934\" height=\"388\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM.png 934w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM-300x125.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM-768x319.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.37.30-AM-624x259.png 624w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Exploratory Data Analysis<\/strong><\/span><\/p>\n<p>The model will regress mpg on engine weight (wt). Let&#8217;s plot and describe those two variables so that we have a sense for what we might be working with.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2874\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM.png\" alt=\"\" width=\"475\" height=\"314\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM.png 1000w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM-300x198.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM-768x507.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.30-AM-624x412.png 624w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><\/a> <a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2875\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM.png\" alt=\"\" width=\"485\" height=\"356\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM.png 798w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM-300x220.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM-768x564.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.39.38-AM-624x458.png 624w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Linear Regression<\/strong><\/span><\/p>\n<p>Before fitting the Bayesian model, I want to fit a simple regression model to see what the coefficients look like.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport statsmodels.api as sm\r\n\r\nx = d&#x5B;'wt']\r\ny = d&#x5B;'mpg']\r\n\r\nx = sm.add_constant(x)\r\n\r\nfit = sm.OLS(y, x).fit()\r\n\r\nfit.summary()\r\n<\/pre>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2877\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM-1024x904.png\" alt=\"\" width=\"479\" height=\"423\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM-1024x904.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM-300x265.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM-768x678.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM-624x551.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.42.27-AM.png 1060w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/a><\/p>\n<p>We can see that for every one unit increase in engine weight the miles per gallon decrease, on average, by about 5.3.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Bayesian Regression (PyMC3)<\/strong><\/span><\/p>\n<p>Fitting a Bayesian regression model in PyMC3 requires us to specify some priors. For this model I&#8217;ll use a prior intercept of 40 \u00b1 10 and a prior beta for the <strong>wt<\/strong> variable of 0 \u00b1 10. The thing to note here is that the priors I&#8217;m specifying priors were created by first looking at the data that has been collected (which is technically cheating). Normally we would have priors <em><strong>BEFORE<\/strong><\/em> collecting our data (using prior published research, data from a pilot study, prior intuition, etc) and then combine the prior with the observations to obtain a posterior distribution. However, the aim here is to understand how to code the model, so I&#8217;ll use these priors. I&#8217;ll write a longer blog on priors and what they do to a model in the coming weeks.<\/p>\n<p>Some notes on fitting the model in <strong>PyMC3<\/strong>:<\/p>\n<ul>\n<li>The model is named &#8216;<strong>fit_b<\/strong>&#8216;<\/li>\n<li>We specify the intercept as variable &#8216;<strong>a<\/strong>&#8216;<\/li>\n<li>The beta coefficient for wt is called &#8216;<strong>b<\/strong>&#8216;<\/li>\n<li>Both the intercept and slope re fit with normally distributed priors<\/li>\n<li>Finally, &#8216;<strong>e<\/strong>&#8216; represents the model error and it is fit with a a Half Cauchy prior<\/li>\n<li>Once the priors are set, the model is specified (<strong>y_pred<\/strong>) as <strong><em>mu = a + b * wt + e<\/em><\/strong><\/li>\n<li>The <strong>trace_b<\/strong> object stores our posterior samples, 2000 of them of which the first 1000 will be discarded because they are there to allow the model to tune itself<\/li>\n<\/ul>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">, sd = e, observed = d&#x5B;'mpg'])\r\n    \r\n    trace_b = pm.sample(2000, tune = 1000)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Once the model has been fit we plot the trace plots to see how well it performed.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2878\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM-1024x556.png\" alt=\"\" width=\"625\" height=\"339\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM-1024x556.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM-300x163.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM-768x417.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM-624x339.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.54.01-AM.png 1300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>We can also directly call the mean and standard deviation values of our fitted model, which are relatively similar to what we saw with the linear regression model above.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2879\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM.png\" alt=\"\" width=\"490\" height=\"175\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM.png 986w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM-300x107.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM-768x274.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.55.09-AM-624x223.png 624w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Point Predictions<\/strong><\/span><\/p>\n<p>Next, we want to make a single point prediction for the mpg would expect, on average, when wt\u00a0 is a specific value (in this example we will use wt = 3.3).<\/p>\n<p>To do this, we simply store the average value of the posterior coefficients from our Bayesian regression and apply the specified model:<\/p>\n<blockquote><p>mu = a + b * new_wt<\/p><\/blockquote>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2880\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM.png\" alt=\"\" width=\"454\" height=\"293\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM.png 806w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM-300x194.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM-768x495.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-5.58.11-AM-624x403.png 624w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/a><\/p>\n<p>A car with an engine weight of 3.3 would get, on average, 19.7 mpg.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Point Prediction with Uncertainty<\/strong><\/span><\/p>\n<p>The point estimate is interesting (I guess), but there is uncertainty around that estimate as point predictions are never exact. We can compliment this point estimate by unveiling the uncertainty around it. The point prediction \u00b1 uncertainty interval informs us of the average value of\u00a0 mpg along with the uncertainty of the coefficients in our model.<\/p>\n<p>To do this, we create a random sample of 1000 values from the posterior distributions for our model intercept and beta coefficient. Each of these 1000 values represent a potential intercept and slope that would be consistent with our data, which shows us the uncertainty that we have in our estimates. When we use the model equation, multiplying each of these 1000 values by the new_wt value we obtain 1000 possible predicted values of mpg given a weight of 3.3.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2881\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM-1024x466.png\" alt=\"\" width=\"625\" height=\"284\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM-1024x466.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM-300x137.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM-768x350.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM-624x284.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.04.38-AM.png 1344w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>With this posterior distribution we can then plot a histogram of the results and obtain summary statistics such as the mean, standard deviation, and 90% credible interval.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2882\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM-1024x815.png\" alt=\"\" width=\"532\" height=\"423\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM-1024x815.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM-300x239.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM-768x611.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM-624x496.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.05.50-AM.png 1320w\" sizes=\"auto, (max-width: 532px) 100vw, 532px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Posterior Predictive Distribution<\/strong><\/span><\/p>\n<p>Finally, instead of just knowing the average predicted value of mpg \u00b1 uncertainty for the population, we might be interested in knowing what the predicted value of mpg would be for a new car in the population with a wt of 3.3. For that, we calculate the posterior predictive distribution. The uncertainty in this predictive distribution will be larger than the point prediction with uncertainty because we are using the posterior model error added to our prediction.<\/p>\n<p>First, similar to the model coefficients, we have to get the random draws of our error term, which we will call sigma.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2883\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM.png\" alt=\"\" width=\"862\" height=\"146\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM.png 862w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM-300x51.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM-768x130.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.08.33-AM-624x106.png 624w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/a><\/p>\n<p>Next, we run the model as we did in step 2 above; however, we also add to each of the 1000 posterior predictions the sigma value by taking a random draw from a normal distribution with a mean of 0 and standard deviation equal to the sigma sample values.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\npred_dist = intercept_sample + beta_sample * new_wt_rep + np.random.normal(loc = 0, scale = sigma_sample, size = 1000)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Finally, we plot the distribution of our predicted values along with the mean, standard deviation, and 90% credible interval. Notice that these values are larger than what we obtained in step 2 because we are now taking into account additional uncertainty about the new wt observation.<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2884\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM-1024x765.png\" alt=\"\" width=\"625\" height=\"467\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM-1024x765.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM-300x224.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM-768x574.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM-624x466.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2023\/01\/Screen-Shot-2023-01-25-at-6.13.55-AM.png 1362w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Wrapping Up<\/strong><\/span><\/p>\n<p>That&#8217;s a brief intro to Bayesian regression with <strong>PyMC3. <\/strong>There are a lot more things that we can do with <strong>PyMC3 <\/strong>and it&#8217;s available functions. My goal is to put together more blog articles on Bayesian modeling with both R and Python so show their flexibility. If you spot any errors, please let me know.<\/p>\n<p>The data and full code (along with a companion code in {<strong>rstanarm<\/strong>}) is available on my <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/github.com\/pw2\/Bayesian-Regression-with-PyMC3\/tree\/main\/Linear%20Regression%20with%20PyMc3\">GITHUB page<\/a><\/span><\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously I&#8217;ve used {rstanarm}, {brms}, and Stan for fitting Bayesian models. However, as I continue to work on improving my Python skills, I figured I&#8217;d try and delve into the PyMC3 framework for fitting such models. This article will go through the following steps: Fitting the model Making a point estimate prediction Making a point [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,48],"tags":[],"class_list":["post-2872","post","type-post","status-publish","format-standard","hentry","category-bayesian-model-building","category-model-building-in-python"],"_links":{"self":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/comments?post=2872"}],"version-history":[{"count":1,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2872\/revisions"}],"predecessor-version":[{"id":2885,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2872\/revisions\/2885"}],"wp:attachment":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/media?parent=2872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/categories?post=2872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/tags?post=2872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}