{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Regression Plots" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-19T16:35:47.410004Z", "iopub.status.busy": "2024-04-19T16:35:47.409719Z", "iopub.status.idle": "2024-04-19T16:35:49.035488Z", "shell.execute_reply": "2024-04-19T16:35:49.034772Z" } }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-19T16:35:49.041145Z", "iopub.status.busy": "2024-04-19T16:35:49.040164Z", "iopub.status.idle": "2024-04-19T16:35:51.894091Z", "shell.execute_reply": "2024-04-19T16:35:51.893399Z" } }, "outputs": [], "source": [ "from statsmodels.compat import lzip\n", "import numpy as np\n", "import matplotlib.pyplot as plt\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": "2024-04-19T16:35:51.900087Z", "iopub.status.busy": "2024-04-19T16:35:51.897938Z", "iopub.status.idle": "2024-04-19T16:35:52.122073Z", "shell.execute_reply": "2024-04-19T16:35:52.121372Z" } }, "outputs": [], "source": [ "prestige = sm.datasets.get_rdataset(\"Duncan\", \"carData\", cache=True).data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-19T16:35:52.125585Z", "iopub.status.busy": "2024-04-19T16:35:52.125172Z", "iopub.status.idle": "2024-04-19T16:35:52.135241Z", "shell.execute_reply": "2024-04-19T16:35:52.134615Z" } }, "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", "