Skip to content

Instantly share code, notes, and snippets.

@MaxGhenis
Created March 6, 2022 06:11
Show Gist options
  • Save MaxGhenis/6605bcca4db42bf16463459c13476fec to your computer and use it in GitHub Desktop.
Save MaxGhenis/6605bcca4db42bf16463459c13476fec to your computer and use it in GitHub Desktop.
OpenFisca US demo.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "OpenFisca US demo.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyPUR76aaChhJyDYM+mEkvnl",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/MaxGhenis/6605bcca4db42bf16463459c13476fec/openfisca-us-demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# OpenFisca US tutorial\n",
"\n",
"OpenFisca US is [PolicyEngine](https://policyengine.org)'s open source tax and benefit microsimulation model.\n",
"\n",
"This tutorial will teach you how to construct a household, calculate variables, and simulate a range of scenarios, using California's SNAP program as a case study. \n",
"\n",
"*See https://openfisca.us for full documentation.*\n",
"\n",
"## Installation\n",
"\n",
"OpenFisca US is available on PyPI."
],
"metadata": {
"id": "WSwNepc-Tuui"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_wQ1Ld9hEMvC",
"outputId": "40fd6c43-d691-4de7-e975-7f1d1e525b40"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: openfisca-us in /usr/local/lib/python3.7/dist-packages (0.35.3)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (2.23.0)\n",
"Requirement already satisfied: openfisca-us-data>=0.1.2 in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.1.4)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (4.62.3)\n",
"Requirement already satisfied: OpenFisca-Tools<1.0.0,>=0.3.0 in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.5.0)\n",
"Requirement already satisfied: microdf-python in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (0.3.0)\n",
"Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (1.3.5)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (3.13)\n",
"Requirement already satisfied: OpenFisca-Core[web-api]>=35.0.0 in /usr/local/lib/python3.7/dist-packages (from openfisca-us) (35.7.8)\n",
"Requirement already satisfied: nptyping==1.4.4 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.4.4)\n",
"Requirement already satisfied: numpy<1.21,>=1.11 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.20.3)\n",
"Requirement already satisfied: sortedcontainers==2.2.2 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.2.2)\n",
"Requirement already satisfied: pytest<6.0.0,>=4.4.1 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (5.4.3)\n",
"Requirement already satisfied: dpath<3.0.0,>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.0.6)\n",
"Requirement already satisfied: psutil<6.0.0,>=5.4.7 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (5.4.8)\n",
"Requirement already satisfied: typing-extensions==3.10.0.2 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.10.0.2)\n",
"Requirement already satisfied: numexpr<=3.0,>=2.7.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.8.1)\n",
"Requirement already satisfied: flask==1.1.4 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.1.4)\n",
"Requirement already satisfied: gunicorn<21.0.0,>=20.0.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (20.1.0)\n",
"Requirement already satisfied: flask-cors==3.0.10 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.0.10)\n",
"Requirement already satisfied: werkzeug<2.0.0,>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.0.1)\n",
"Requirement already satisfied: markupsafe==2.0.1 in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.0.1)\n",
"Requirement already satisfied: itsdangerous<2.0,>=0.24 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.1.0)\n",
"Requirement already satisfied: Jinja2<3.0,>=2.10.1 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (2.11.3)\n",
"Requirement already satisfied: click<8.0,>=5.1 in /usr/local/lib/python3.7/dist-packages (from flask==1.1.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (7.1.2)\n",
"Requirement already satisfied: Six in /usr/local/lib/python3.7/dist-packages (from flask-cors==3.0.10->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.15.0)\n",
"Requirement already satisfied: typish>=1.7.0 in /usr/local/lib/python3.7/dist-packages (from nptyping==1.4.4->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.9.3)\n",
"Requirement already satisfied: setuptools>=3.0 in /usr/local/lib/python3.7/dist-packages (from gunicorn<21.0.0,>=20.0.0->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (57.4.0)\n",
"Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from numexpr<=3.0,>=2.7.0->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (21.3)\n",
"Requirement already satisfied: wheel in /usr/local/lib/python3.7/dist-packages (from OpenFisca-Tools<1.0.0,>=0.3.0->openfisca-us) (0.37.1)\n",
"Requirement already satisfied: tables in /usr/local/lib/python3.7/dist-packages (from openfisca-us-data>=0.1.2->openfisca-us) (3.7.0)\n",
"Requirement already satisfied: h5py in /usr/local/lib/python3.7/dist-packages (from openfisca-us-data>=0.1.2->openfisca-us) (3.1.0)\n",
"Requirement already satisfied: pytest-dependency in /usr/local/lib/python3.7/dist-packages (from openfisca-us-data>=0.1.2->openfisca-us) (0.5.1)\n",
"Requirement already satisfied: synthimpute in /usr/local/lib/python3.7/dist-packages (from openfisca-us-data>=0.1.2->openfisca-us) (0.1)\n",
"Requirement already satisfied: pathlib in /usr/local/lib/python3.7/dist-packages (from openfisca-us-data>=0.1.2->openfisca-us) (1.0.1)\n",
"Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (8.12.0)\n",
"Requirement already satisfied: pluggy<1.0,>=0.12 in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (0.13.1)\n",
"Requirement already satisfied: importlib-metadata>=0.12 in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (4.11.1)\n",
"Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (1.11.0)\n",
"Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (21.4.0)\n",
"Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (0.2.5)\n",
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=0.12->pytest<6.0.0,>=4.4.1->OpenFisca-Core[web-api]>=35.0.0->openfisca-us) (3.7.0)\n",
"Requirement already satisfied: cached-property in /usr/local/lib/python3.7/dist-packages (from h5py->openfisca-us-data>=0.1.2->openfisca-us) (1.5.2)\n",
"Requirement already satisfied: matplotlib-label-lines in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (0.5.1)\n",
"Requirement already satisfied: seaborn in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (0.11.2)\n",
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from microdf-python->openfisca-us) (3.2.2)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (1.3.2)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (2.8.2)\n",
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (3.0.7)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->microdf-python->openfisca-us) (0.11.0)\n",
"Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->openfisca-us) (2018.9)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (2.10)\n",
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (3.0.4)\n",
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (1.24.3)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->openfisca-us) (2021.10.8)\n",
"Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.7/dist-packages (from seaborn->microdf-python->openfisca-us) (1.4.1)\n",
"Requirement already satisfied: statsmodels in /usr/local/lib/python3.7/dist-packages (from synthimpute->openfisca-us-data>=0.1.2->openfisca-us) (0.10.2)\n",
"Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from synthimpute->openfisca-us-data>=0.1.2->openfisca-us) (1.0.2)\n",
"Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->synthimpute->openfisca-us-data>=0.1.2->openfisca-us) (3.1.0)\n",
"Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->synthimpute->openfisca-us-data>=0.1.2->openfisca-us) (1.1.0)\n",
"Requirement already satisfied: patsy>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from statsmodels->synthimpute->openfisca-us-data>=0.1.2->openfisca-us) (0.5.2)\n"
]
}
],
"source": [
"!pip install openfisca-us"
]
},
{
"cell_type": "markdown",
"source": [
"# Constructing households\n",
"\n",
"To calculate taxes and benefits, first define the household via:\n",
"1. The `IndividualSim` constructor.\n",
"2. The `add_person` method.\n",
"\n",
"Let's start with a single person with \\$1,000 monthly employment income (inputs and outputs are all annual)."
],
"metadata": {
"id": "_uvPNJyRPd3q"
}
},
{
"cell_type": "code",
"source": [
"from openfisca_us import IndividualSim\n",
"\n",
"sim = IndividualSim(year=2022)\n",
"sim.add_person(name=\"person\", employment_income=1000 * 12)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "P5NsStTGEQjI",
"outputId": "e7b088bc-d115-4370-9d83-a62cc5b3d754"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/openfisca_core/parameters/config.py:17: LibYAMLWarning: libyaml is not installed in your environment. This can make OpenFisca slower to start. Once you have installed libyaml, run 'pip uninstall pyyaml && pip install pyyaml --no-cache-dir' so that it is used in your Python environment.\n",
"\n",
" warnings.warn(\" \".join(message), LibYAMLWarning)\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Calculating variables\n",
"\n",
"Now we can calculate any variables in the [`openfisca_us/variables` folder](https://github.com/PolicyEngine/openfisca-us/tree/master/openfisca_us/variables) via the `calc` method.\n",
"\n",
"For example, let's recover `employment_income`:"
],
"metadata": {
"id": "1RTLMDrwRC33"
}
},
{
"cell_type": "code",
"source": [
"sim.calc(\"employment_income\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2f04mTDDRlIH",
"outputId": "856f2b8b-0b61-40b3-8372-df33b1d8f0d3"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([12000.], dtype=float32)"
]
},
"metadata": {},
"execution_count": 3
}
]
},
{
"cell_type": "markdown",
"source": [
"**Exercise 1: Calculate SNAP**\n",
"\n",
"Calculate three SNAP-related variables:\n",
"1. `snap_normal_allotment`, which they would receive outside of Covid.\n",
"2. `snap_emergency_allotment`, which bumps up eligible households to the maximum allotment during the pandemic.\n",
"3. `snap`, which sums the two.\n",
"\n",
"Print them as monthly amounts."
],
"metadata": {
"id": "lpDCSx4oR6cR"
}
},
{
"cell_type": "code",
"source": [
"# SOLUTION\n",
"\n",
"print(\n",
" \"SNAP normal allotment: \",\n",
" round(sim.calc(\"snap_normal_allotment\")[0] / 12),\n",
")\n",
"print(\n",
" \"SNAP emergency allotment: \",\n",
" round(sim.calc(\"snap_emergency_allotment\")[0] / 12),\n",
")\n",
"print(\"Total SNAP: \", round(sim.calc(\"snap\")[0] / 12))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "qhUZ2jU0RBPl",
"outputId": "1d5043e7-3867-411d-8943-47de6c8cbb37"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"SNAP normal allotment: 60\n",
"SNAP emergency allotment: 190\n",
"Total SNAP: 250\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Households with multiple people\n",
"\n",
"To create households with multiple people, we need to assign them to a household unit.\n",
"US tax and benefit programs group people in different ways, and SNAP uses a *SPM unit*, or a group of people that cohabit and share resources (SPM stands for the Supplemental Poverty Measure).\n",
"\n",
"Let's now model a two-person household, still with \\$1,000 monthly employment income, and group them with the `add_spm_unit` method.\n",
"This also enables us to add SPM-unit-level characteristics, like housing costs (which affect SNAP benefits)."
],
"metadata": {
"id": "9GHwdDfrTd8F"
}
},
{
"cell_type": "code",
"source": [
"sim = IndividualSim(year=2022)\n",
"sim.add_person(name=\"parent\", employment_income=1000 * 12)\n",
"sim.add_person(name=\"child\")\n",
"sim.add_spm_unit(\n",
" name=\"spm_unit\", members=[\"parent\", \"child\"], housing_cost=600 * 12\n",
")"
],
"metadata": {
"id": "6q3mH6bLa8IA"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Now let's recalculate SNAP."
],
"metadata": {
"id": "UytFo1Kabas2"
}
},
{
"cell_type": "code",
"source": [
"print(\n",
" \"SNAP normal allotment: \",\n",
" round(sim.calc(\"snap_normal_allotment\")[0] / 12),\n",
")\n",
"print(\n",
" \"SNAP emergency allotment: \",\n",
" round(sim.calc(\"snap_emergency_allotment\")[0] / 12),\n",
")\n",
"print(\"Total SNAP: \", round(sim.calc(\"snap\")[0] / 12))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "EMcis19qbfyy",
"outputId": "a33ba784-62f1-4466-d8b0-ebaa615ad6f8"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"SNAP normal allotment: 354\n",
"SNAP emergency allotment: 105\n",
"Total SNAP: 459\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Exercise 2: Customize a household**\n",
"\n",
"Create a new household with a different number of people, or different income or housing costs.\n",
"Recalculate SNAP."
],
"metadata": {
"id": "ey1n_m0ybjTw"
}
},
{
"cell_type": "code",
"source": [
"### SOLUTION\n",
"\n",
"# Varies."
],
"metadata": {
"id": "lMLmzrqybyYy"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Scenario analysis\n",
"\n",
"Suppose we want to explore a range of inputs, rather than manually specifying one or two.\n",
"We can apply techniques like list comprehension, but openfisca-us makes it easier with the `vary` method.\n",
"\n",
"When we call `sim.vary`, subsequent `calc` calls calculate over the range of inputs specified in `vary`.\n",
"\n",
"Let's vary employment income, going up to \\$3,000 per month in increments of \\$10 per month."
],
"metadata": {
"id": "pkPuMdkJb01b"
}
},
{
"cell_type": "code",
"source": [
"sim.vary(\"employment_income\", max=3000 * 12, step=10 * 12)"
],
"metadata": {
"id": "xXkUlKRZcpCb"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Now when we call `calc`, we get an array rather than a scalar. Let's start by recovering employment income again."
],
"metadata": {
"id": "l5dyC7fAcsQl"
}
},
{
"cell_type": "code",
"source": [
"sim.calc(\"employment_income\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2H9VdE3hfX4t",
"outputId": "d6ad54c4-c52c-4552-995a-91b15d90ed30"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[ 0., 120., 240., 360., 480., 600., 720., 840.,\n",
" 960., 1080., 1200., 1320., 1440., 1560., 1680., 1800.,\n",
" 1920., 2040., 2160., 2280., 2400., 2520., 2640., 2760.,\n",
" 2880., 3000., 3120., 3240., 3360., 3480., 3600., 3720.,\n",
" 3840., 3960., 4080., 4200., 4320., 4440., 4560., 4680.,\n",
" 4800., 4920., 5040., 5160., 5280., 5400., 5520., 5640.,\n",
" 5760., 5880., 6000., 6120., 6240., 6360., 6480., 6600.,\n",
" 6720., 6840., 6960., 7080., 7200., 7320., 7440., 7560.,\n",
" 7680., 7800., 7920., 8040., 8160., 8280., 8400., 8520.,\n",
" 8640., 8760., 8880., 9000., 9120., 9240., 9360., 9480.,\n",
" 9600., 9720., 9840., 9960., 10080., 10200., 10320., 10440.,\n",
" 10560., 10680., 10800., 10920., 11040., 11160., 11280., 11400.,\n",
" 11520., 11640., 11760., 11880., 12000., 12120., 12240., 12360.,\n",
" 12480., 12600., 12720., 12840., 12960., 13080., 13200., 13320.,\n",
" 13440., 13560., 13680., 13800., 13920., 14040., 14160., 14280.,\n",
" 14400., 14520., 14640., 14760., 14880., 15000., 15120., 15240.,\n",
" 15360., 15480., 15600., 15720., 15840., 15960., 16080., 16200.,\n",
" 16320., 16440., 16560., 16680., 16800., 16920., 17040., 17160.,\n",
" 17280., 17400., 17520., 17640., 17760., 17880., 18000., 18120.,\n",
" 18240., 18360., 18480., 18600., 18720., 18840., 18960., 19080.,\n",
" 19200., 19320., 19440., 19560., 19680., 19800., 19920., 20040.,\n",
" 20160., 20280., 20400., 20520., 20640., 20760., 20880., 21000.,\n",
" 21120., 21240., 21360., 21480., 21600., 21720., 21840., 21960.,\n",
" 22080., 22200., 22320., 22440., 22560., 22680., 22800., 22920.,\n",
" 23040., 23160., 23280., 23400., 23520., 23640., 23760., 23880.,\n",
" 24000., 24120., 24240., 24360., 24480., 24600., 24720., 24840.,\n",
" 24960., 25080., 25200., 25320., 25440., 25560., 25680., 25800.,\n",
" 25920., 26040., 26160., 26280., 26400., 26520., 26640., 26760.,\n",
" 26880., 27000., 27120., 27240., 27360., 27480., 27600., 27720.,\n",
" 27840., 27960., 28080., 28200., 28320., 28440., 28560., 28680.,\n",
" 28800., 28920., 29040., 29160., 29280., 29400., 29520., 29640.,\n",
" 29760., 29880., 30000., 30120., 30240., 30360., 30480., 30600.,\n",
" 30720., 30840., 30960., 31080., 31200., 31320., 31440., 31560.,\n",
" 31680., 31800., 31920., 32040., 32160., 32280., 32400., 32520.,\n",
" 32640., 32760., 32880., 33000., 33120., 33240., 33360., 33480.,\n",
" 33600., 33720., 33840., 33960., 34080., 34200., 34320., 34440.,\n",
" 34560., 34680., 34800., 34920., 35040., 35160., 35280., 35400.,\n",
" 35520., 35640., 35760., 35880., 36000.],\n",
" [ 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0., 0., 0., 0.,\n",
" 0., 0., 0., 0., 0.]], dtype=float32)"
]
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "markdown",
"source": [
"Since `employment_income` is person-level, `calc` returns a two-row array. `vary` varies the first person's variable by default, so the child's income stays fixed at zero.\n",
"\n",
"### Calculating SNAP as income varies\n",
"\n",
"Now we can calculate normal SNAP allotments.\n",
"Each value corresponds to the varied employment income above.\n",
"\n",
"For example, at \\$0 employment income, the household will get \\$5,508 in annual benefits.\n",
"At \\$3,000 monthly employment income, they are not eligible for any SNAP benefits.\n",
"Since `snap_normal_allotment` is at the SPM unit level, `calc` now returns a one-row array."
],
"metadata": {
"id": "KRzYPtrhfZRV"
}
},
{
"cell_type": "code",
"source": [
"sim.calc(\"snap_normal_allotment\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fgR_DjJPcwxA",
"outputId": "aea45821-39a0-44a9-b659-6fd434fe6d0e"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5508. ,\n",
" 5508. , 5508. , 5508. , 5508. , 5508. , 5502.6 ,\n",
" 5459.4 , 5416.2 , 5373. , 5329.8 , 5286.6 , 5243.4 ,\n",
" 5200.2 , 5157. , 5113.8 , 5070.6 , 5027.4 , 4984.2 ,\n",
" 4941. , 4897.8 , 4854.6 , 4811.4 , 4768.2 , 4725. ,\n",
" 4681.8 , 4638.6 , 4595.4 , 4552.2 , 4509. , 4465.8 ,\n",
" 4422.6 , 4379.4 , 4336.2 , 4293. , 4249.8 , 4206.6 ,\n",
" 4163.4 , 4120.2 , 4077. , 4033.7998, 3990.6 , 3947.4 ,\n",
" 3904.2 , 3861. , 3817.7998, 3774.6 , 3731.4 , 3688.2 ,\n",
" 3645. , 3601.7998, 3558.6 , 3515.4 , 3472.2 , 3429. ,\n",
" 3385.7998, 3342.5999, 3299.4 , 3256.2 , 3213. , 3169.7998,\n",
" 3126.5999, 3083.4 , 3040.2 , 2997. , 2953.7998, 2910.5999,\n",
" 2867.4 , 2824.2 , 2781. , 2737.7998, 2694.5999, 2651.4 ,\n",
" 2608.2 , 2565. , 2521.7998, 2478.5999, 2435.4 , 2392.2 ,\n",
" 2348.9998, 2305.7998, 2262.5999, 2219.4 , 2176.2 , 2132.9998,\n",
" 2089.7998, 2046.5999, 2003.3999, 1960.2 , 1916.9998, 1873.7998,\n",
" 1830.5999, 1787.3999, 1744.2 , 1700.9998, 1657.7998, 1614.5999,\n",
" 1571.3999, 1528.2 , 1484.9998, 1441.7998, 1398.5996, 1355.3999,\n",
" 1312.1997, 1269. , 1225.7998, 1184.3999, 1155.5996, 1126.7998,\n",
" 1098. , 1069.1997, 1040.3999, 1011.5996, 982.7998, 954. ,\n",
" 925.1997, 896.3999, 867.5996, 838.7998, 810. , 781.1997,\n",
" 752.3999, 723.5996, 694.7998, 666. , 637.1997, 608.3999,\n",
" 579.5996, 550.7998, 522. , 493.1997, 464.3999, 435.5996,\n",
" 406.7998, 378. , 349.1997, 320.3999, 291.5996, 262.7998,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 240. , 240. , 240. ,\n",
" 240. , 240. , 240. , 0. , 0. , 0. ,\n",
" 0. , 0. , 0. , 0. , 0. , 0. ,\n",
" 0. ]], dtype=float32)"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "markdown",
"source": [
"**Exercise 3: Visualization**\n",
"\n",
"Use your preferred data visualization library to create a plot of employment income on the x axis and normal (non-Covid) SNAP benefits on the y axis.\n",
"\n",
"*Hint: `IndividualSim.calc` returns a list of all households' values. Since we're only working with one household, extract the first with `calc(x)[0]`.*"
],
"metadata": {
"id": "75v5UVbAb7dU"
}
},
{
"cell_type": "code",
"source": [
"### SOLUTION\n",
"\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"\n",
"LABELS = dict(\n",
" employment_income=\"Monthly employment income\",\n",
" snap_normal_allotment=\"Monthly normal SNAP allotment\",\n",
")\n",
"\n",
"df = pd.DataFrame(\n",
" dict(\n",
" employment_income=sim.calc(\"employment_income\")[0],\n",
" snap_normal_allotment=sim.calc(\"snap_normal_allotment\")[0],\n",
" )\n",
")\n",
"\n",
"fig = px.line(\n",
" df,\n",
" \"employment_income\",\n",
" \"snap_normal_allotment\",\n",
" labels=LABELS,\n",
" title=\"Normal SNAP allotment for a two-person household in California with $600 monthly housing costs\",\n",
")\n",
"fig.update_layout(xaxis_tickformat=\"$,\", yaxis_tickformat=\"$,\")\n",
"fig.show()"
],
"metadata": {
"id": "y2mz3743LfNS",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 542
},
"outputId": "cd5f91e8-af9d-44fc-fea2-2398997c7298"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
"<html>\n",
"<head><meta charset=\"utf-8\" /></head>\n",
"<body>\n",
" <div> <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script> <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
" <script src=\"https://cdn.plot.ly/plotly-2.8.3.min.js\"></script> <div id=\"5ea841d6-a518-4ff3-9f2a-ec65fcb52d3c\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"5ea841d6-a518-4ff3-9f2a-ec65fcb52d3c\")) { Plotly.newPlot( \"5ea841d6-a518-4ff3-9f2a-ec65fcb52d3c\", [{\"hovertemplate\":\"Monthly employment income=%{x}<br>Monthly normal SNAP allotment=%{y}<extra></extra>\",\"legendgroup\":\"\",\"line\":{\"color\":\"#636efa\",\"dash\":\"solid\"},\"marker\":{\"symbol\":\"circle\"},\"mode\":\"lines\",\"name\":\"\",\"orientation\":\"v\",\"showlegend\":false,\"x\":[0.0,120.0,240.0,360.0,480.0,600.0,720.0,840.0,960.0,1080.0,1200.0,1320.0,1440.0,1560.0,1680.0,1800.0,1920.0,2040.0,2160.0,2280.0,2400.0,2520.0,2640.0,2760.0,2880.0,3000.0,3120.0,3240.0,3360.0,3480.0,3600.0,3720.0,3840.0,3960.0,4080.0,4200.0,4320.0,4440.0,4560.0,4680.0,4800.0,4920.0,5040.0,5160.0,5280.0,5400.0,5520.0,5640.0,5760.0,5880.0,6000.0,6120.0,6240.0,6360.0,6480.0,6600.0,6720.0,6840.0,6960.0,7080.0,7200.0,7320.0,7440.0,7560.0,7680.0,7800.0,7920.0,8040.0,8160.0,8280.0,8400.0,8520.0,8640.0,8760.0,8880.0,9000.0,9120.0,9240.0,9360.0,9480.0,9600.0,9720.0,9840.0,9960.0,10080.0,10200.0,10320.0,10440.0,10560.0,10680.0,10800.0,10920.0,11040.0,11160.0,11280.0,11400.0,11520.0,11640.0,11760.0,11880.0,12000.0,12120.0,12240.0,12360.0,12480.0,12600.0,12720.0,12840.0,12960.0,13080.0,13200.0,13320.0,13440.0,13560.0,13680.0,13800.0,13920.0,14040.0,14160.0,14280.0,14400.0,14520.0,14640.0,14760.0,14880.0,15000.0,15120.0,15240.0,15360.0,15480.0,15600.0,15720.0,15840.0,15960.0,16080.0,16200.0,16320.0,16440.0,16560.0,16680.0,16800.0,16920.0,17040.0,17160.0,17280.0,17400.0,17520.0,17640.0,17760.0,17880.0,18000.0,18120.0,18240.0,18360.0,18480.0,18600.0,18720.0,18840.0,18960.0,19080.0,19200.0,19320.0,19440.0,19560.0,19680.0,19800.0,19920.0,20040.0,20160.0,20280.0,20400.0,20520.0,20640.0,20760.0,20880.0,21000.0,21120.0,21240.0,21360.0,21480.0,21600.0,21720.0,21840.0,21960.0,22080.0,22200.0,22320.0,22440.0,22560.0,22680.0,22800.0,22920.0,23040.0,23160.0,23280.0,23400.0,23520.0,23640.0,23760.0,23880.0,24000.0,24120.0,24240.0,24360.0,24480.0,24600.0,24720.0,24840.0,24960.0,25080.0,25200.0,25320.0,25440.0,25560.0,25680.0,25800.0,25920.0,26040.0,26160.0,26280.0,26400.0,26520.0,26640.0,26760.0,26880.0,27000.0,27120.0,27240.0,27360.0,27480.0,27600.0,27720.0,27840.0,27960.0,28080.0,28200.0,28320.0,28440.0,28560.0,28680.0,28800.0,28920.0,29040.0,29160.0,29280.0,29400.0,29520.0,29640.0,29760.0,29880.0,30000.0,30120.0,30240.0,30360.0,30480.0,30600.0,30720.0,30840.0,30960.0,31080.0,31200.0,31320.0,31440.0,31560.0,31680.0,31800.0,31920.0,32040.0,32160.0,32280.0,32400.0,32520.0,32640.0,32760.0,32880.0,33000.0,33120.0,33240.0,33360.0,33480.0,33600.0,33720.0,33840.0,33960.0,34080.0,34200.0,34320.0,34440.0,34560.0,34680.0,34800.0,34920.0,35040.0,35160.0,35280.0,35400.0,35520.0,35640.0,35760.0,35880.0,36000.0],\"xaxis\":\"x\",\"y\":[5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5508.0,5502.60009765625,5459.39990234375,5416.2001953125,5373.0,5329.7998046875,5286.60009765625,5243.39990234375,5200.2001953125,5157.0,5113.7998046875,5070.60009765625,5027.39990234375,4984.2001953125,4941.0,4897.7998046875,4854.60009765625,4811.39990234375,4768.2001953125,4725.0,4681.7998046875,4638.60009765625,4595.39990234375,4552.2001953125,4509.0,4465.7998046875,4422.60009765625,4379.39990234375,4336.2001953125,4293.0,4249.7998046875,4206.60009765625,4163.39990234375,4120.2001953125,4077.0,4033.7998046875,3990.60009765625,3947.39990234375,3904.199951171875,3861.0,3817.7998046875,3774.60009765625,3731.39990234375,3688.199951171875,3645.0,3601.7998046875,3558.60009765625,3515.39990234375,3472.199951171875,3429.0,3385.7998046875,3342.599853515625,3299.39990234375,3256.199951171875,3213.0,3169.7998046875,3126.599853515625,3083.39990234375,3040.199951171875,2997.0,2953.7998046875,2910.599853515625,2867.39990234375,2824.199951171875,2781.0,2737.7998046875,2694.599853515625,2651.39990234375,2608.199951171875,2565.0,2521.7998046875,2478.599853515625,2435.39990234375,2392.199951171875,2348.999755859375,2305.7998046875,2262.599853515625,2219.39990234375,2176.199951171875,2132.999755859375,2089.7998046875,2046.599853515625,2003.39990234375,1960.199951171875,1916.999755859375,1873.7998046875,1830.599853515625,1787.39990234375,1744.199951171875,1700.999755859375,1657.7998046875,1614.599853515625,1571.39990234375,1528.199951171875,1484.999755859375,1441.7998046875,1398.599609375,1355.39990234375,1312.19970703125,1269.0,1225.7998046875,1184.39990234375,1155.599609375,1126.7998046875,1098.0,1069.19970703125,1040.39990234375,1011.599609375,982.7998046875,954.0,925.19970703125,896.39990234375,867.599609375,838.7998046875,810.0,781.19970703125,752.39990234375,723.599609375,694.7998046875,666.0,637.19970703125,608.39990234375,579.599609375,550.7998046875,522.0,493.19970703125,464.39990234375,435.599609375,406.7998046875,378.0,349.19970703125,320.39990234375,291.599609375,262.7998046875,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,240.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],\"yaxis\":\"y\",\"type\":\"scatter\"}], {\"template\":{\"data\":{\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"choropleth\"}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"contour\"}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"contourcarpet\"}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmap\"}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmapgl\"}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2d\"}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2dcontour\"}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"mesh3d\"}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"parcoords\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}],\"scatter\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter\"}],\"scatter3d\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter3d\"}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattercarpet\"}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergeo\"}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergl\"}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattermapbox\"}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolar\"}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolargl\"}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterternary\"}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"surface\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}]},\"layout\":{\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"autotypenumbers\":\"strict\",\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"geo\":{\"bgcolor\":\"white\",\"lakecolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"showlakes\":true,\"showland\":true,\"subunitcolor\":\"white\"},\"hoverlabel\":{\"align\":\"left\"},\"hovermode\":\"closest\",\"mapbox\":{\"style\":\"light\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"bgcolor\":\"#E5ECF6\",\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"gridwidth\":2,\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\"}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"ternary\":{\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"bgcolor\":\"#E5ECF6\",\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"title\":{\"x\":0.05},\"xaxis\":{\"automargin\":true,\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"zerolinewidth\":2},\"yaxis\":{\"automargin\":true,\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"zerolinewidth\":2}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Monthly employment income\"},\"tickformat\":\"$,\"},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Monthly normal SNAP allotment\"},\"tickformat\":\"$,\"},\"legend\":{\"tracegroupgap\":0},\"title\":{\"text\":\"Normal SNAP allotment for a two-person household in California with $600 monthly housing costs\"}}, {\"responsive\": true} ).then(function(){\n",
" \n",
"var gd = document.getElementById('5ea841d6-a518-4ff3-9f2a-ec65fcb52d3c');\n",
"var x = new MutationObserver(function (mutations, observer) {{\n",
" var display = window.getComputedStyle(gd).display;\n",
" if (!display || display === 'none') {{\n",
" console.log([gd, 'removed!']);\n",
" Plotly.purge(gd);\n",
" observer.disconnect();\n",
" }}\n",
"}});\n",
"\n",
"// Listen for the removal of the full notebook cells\n",
"var notebookContainer = gd.closest('#notebook-container');\n",
"if (notebookContainer) {{\n",
" x.observe(notebookContainer, {childList: true});\n",
"}}\n",
"\n",
"// Listen for the clearing of the current output cell\n",
"var outputEl = gd.closest('.output');\n",
"if (outputEl) {{\n",
" x.observe(outputEl, {childList: true});\n",
"}}\n",
"\n",
" }) }; </script> </div>\n",
"</body>\n",
"</html>"
]
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"## Learn more\n",
"\n",
"Visit https://openfisca.us for examples of other programs, calculating marginal tax rates, and more."
],
"metadata": {
"id": "qBEWQxKycI5i"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment