{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5196f507",
   "metadata": {},
   "source": [
    "# Agresti exercises 13.7 and 13.8\n",
    "\n",
    "First the needed packages are imported:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69161ef2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import statsmodels.formula.api as smf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a8b39ee",
   "metadata": {},
   "source": [
    "## Exercise 13.7\n",
    "\n",
    "Import data (this data set includes the variable `New`):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f238f216",
   "metadata": {},
   "outputs": [],
   "source": [
    "HousePriceFull = pd.read_csv('https://asta.math.aau.dk/datasets?file=HousePriceFull.txt', sep='\\t')\n",
    "HousePriceFull.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27b4fb69",
   "metadata": {},
   "source": [
    "First interpret the following plots:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a24aecff",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.boxplot(x='New', y='Price', data=HousePriceFull)\n",
    "plt.show()\n",
    "\n",
    "sns.boxplot(x='New', y='Size', data=HousePriceFull)\n",
    "plt.show()\n",
    "\n",
    "sns.scatterplot(x='Size', y='Price', hue='New', data=HousePriceFull, palette='tab10', s=50)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5bcb565",
   "metadata": {},
   "source": [
    "Fit the linear model corresponding to Table 13.17:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e1d3dd3",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Write commands here to fit the model and produce a summary table."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cc7069b",
   "metadata": {},
   "source": [
    "Write the prediction equation with appropriate notation:\n",
    "$$\n",
    "\\hat y = ???\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8523b996",
   "metadata": {},
   "source": [
    "Plot the two regression lines:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5396b3e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write commands here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "571efbd5",
   "metadata": {},
   "source": [
    "## Agresti exercise 13.8\n",
    "\n",
    "Make the relevant plot(s):\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a29c1f31",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write commands here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e52dfc8",
   "metadata": {},
   "source": [
    "Fit the linear model corresponding to Table 13.18 in Agresti:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f6ab0d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Write commands here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37c090bf",
   "metadata": {},
   "source": [
    "Write the prediction equations for old and new houses:\n",
    "$$\n",
    "\\hat y_{old} = ???\\\\\n",
    "\\hat y_{new} = ???\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42b94486",
   "metadata": {},
   "source": [
    "Is the interaction significant?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
