{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Regression Plots" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-08-27T06:59:13.406751Z", "iopub.status.busy": "2026-08-27T06:59:13.406524Z", "iopub.status.idle": "2026-08-27T06:59:14.008944Z", "shell.execute_reply": "2026-08-27T06:59:14.007444Z" } }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-08-27T06:59:14.011334Z", "iopub.status.busy": "2026-08-27T06:59:14.010793Z", "iopub.status.idle": "2026-08-27T06:59:15.573488Z", "shell.execute_reply": "2026-08-27T06:59:15.572582Z" } }, "outputs": [], "source": [ "from statsmodels.compat import lzip\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "import statsmodels.api as sm\n", "from statsmodels.formula.api import ols\n", "\n", "plt.rc(\"figure\", figsize=(16, 8))\n", "plt.rc(\"font\", size=14)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Duncan's Prestige Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load the Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use a utility function to load any R dataset available from the great Rdatasets package." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-08-27T06:59:15.575913Z", "iopub.status.busy": "2026-08-27T06:59:15.575552Z", "iopub.status.idle": "2026-08-27T06:59:15.614822Z", "shell.execute_reply": "2026-08-27T06:59:15.613980Z" } }, "outputs": [], "source": [ "prestige = sm.datasets.get_rdataset(\"Duncan\", \"carData\", cache=True).data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-08-27T06:59:15.616849Z", "iopub.status.busy": "2026-08-27T06:59:15.616629Z", "iopub.status.idle": "2026-08-27T06:59:15.627247Z", "shell.execute_reply": "2026-08-27T06:59:15.626646Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | type | \n", "income | \n", "education | \n", "prestige | \n", "
|---|---|---|---|---|
| rownames | \n", "\n", " | \n", " | \n", " | \n", " |
| accountant | \n", "prof | \n", "62 | \n", "86 | \n", "82 | \n", "
| pilot | \n", "prof | \n", "72 | \n", "76 | \n", "83 | \n", "
| architect | \n", "prof | \n", "75 | \n", "92 | \n", "90 | \n", "
| author | \n", "prof | \n", "55 | \n", "90 | \n", "76 | \n", "
| chemist | \n", "prof | \n", "64 | \n", "86 | \n", "90 | \n", "