{ "cells": [ { "cell_type": "markdown", "id": "domestic-remove", "metadata": {}, "source": [ "(bart_heteroscedasticity)=\n", "# Modeling Heteroscedasticity with BART\n", "\n", ":::{post} January, 2023\n", ":tags: BART, regression\n", ":category: beginner, reference\n", ":author: Juan Orduz\n", ":::" ] }, { "cell_type": "markdown", "id": "72588976-efc3-4adc-bec2-bc5b6ac4b7e1", "metadata": {}, "source": [ "In this notebook we show how to use BART to model heteroscedasticity as described in Section 4.1 of [`pymc-bart`](https://github.com/pymc-devs/pymc-bart)'s paper {cite:p}`quiroga2022bart`. We use the `marketing` data set provided by the R package `datarium` {cite:p}`kassambara2019datarium`. The idea is to model a marketing channel contribution to sales as a function of budget." ] }, { "cell_type": "code", "execution_count": 1, "id": "elect-softball", "metadata": { "tags": [] }, "outputs": [], "source": [ "import os\n", "\n", "import arviz as az\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import pymc as pm\n", "import pymc_bart as pmb" ] }, { "cell_type": "code", "execution_count": 2, "id": "level-balance", "metadata": { "tags": [] }, "outputs": [], "source": [ "%config InlineBackend.figure_format = \"retina\"\n", "az.style.use(\"arviz-darkgrid\")\n", "plt.rcParams[\"figure.figsize\"] = [10, 6]\n", "rng = np.random.default_rng(42)" ] }, { "cell_type": "markdown", "id": "4cae4407", "metadata": {}, "source": [ "## Read Data" ] }, { "cell_type": "code", "execution_count": 3, "id": "21e66b38", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | youtube | \n", "newspaper | \n", "sales | \n", "|
---|---|---|---|---|
0 | \n", "276.12 | \n", "45.36 | \n", "83.04 | \n", "26.52 | \n", "
1 | \n", "53.40 | \n", "47.16 | \n", "54.12 | \n", "12.48 | \n", "
2 | \n", "20.64 | \n", "55.08 | \n", "83.16 | \n", "11.16 | \n", "
3 | \n", "181.80 | \n", "49.56 | \n", "70.20 | \n", "22.20 | \n", "
4 | \n", "216.96 | \n", "12.96 | \n", "70.08 | \n", "15.48 | \n", "