{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#"
      ],
      "id": "219d8f9e-aa20-41ba-bf20-c08052a3ad16"
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [],
      "source": [
        "import polars as pl\n",
        "import scipy as sp\n",
        "import numpy as np\n",
        "import patsy as pt \n",
        "import matplotlib.pyplot as plt\n",
        "import statsmodels.api as sm"
      ],
      "id": "6af56769-ac75-437a-9c28-25a9f0e0222b"
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [],
      "source": [
        "url = \"https://roualdes.sfo3.digitaloceanspaces.com/data/finches.csv\"\n",
        "df = pl.read_csv(url)"
      ],
      "id": "a91378c6-0458-4c50-85e4-bea90f308b58"
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/html": [
              "<br/><br/>Notes:<br/>[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.<br/>[2] The condition number is large, 2.72e+03. This might indicate that there are<br/>strong multicollinearity or other numerical problems."
            ]
          }
        }
      ],
      "source": [
        "y, X = pt.dmatrices(\"winglength ~ C(island) * taillength\", data = df.to_pandas())\n",
        "mod = sm.OLS(y, X)\n",
        "fit = mod.fit()\n",
        "fit.summary()"
      ],
      "id": "9f2b8415-aa3d-4118-8a75-059f36f9d73d"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "-   **interaction** term: joins together two predictors\n",
        "-   **OLS**: ordinary least squares: minimize squared residuals\n",
        "-   **adjusted R^2**: correctly penalizes for including predictors that\n",
        "    aren’t good at their job. Only use adjusted $R^2$\n",
        "    -   like R^2 but isn’t guaranteed to go up with extra, useless\n",
        "        predictors. This is a good thing. Use adjusted $R^2$ in place of\n",
        "        R^2 at all times.\n",
        "-   **AIC/BIC**: Akaike/Bayesian **i**nformation **c**riterion. They\n",
        "    attempt to quantify how well your model will predict new (unseen)\n",
        "    data."
      ],
      "id": "149e5e70-3f73-4f9b-988c-c4738a240175"
    }
  ],
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3 (ipykernel)",
      "language": "python"
    },
    "language_info": {
      "name": "python",
      "codemirror_mode": {
        "name": "ipython",
        "version": "3"
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.16"
    }
  }
}