{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c769b8b9",
   "metadata": {},
   "source": [
    "# Agresti exercises 9.27 and 9.33\n",
    "\n",
    "Import libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ab24655",
   "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.api as sm"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2dd24f31",
   "metadata": {},
   "source": [
    "## Agresti exercise 9.27\n",
    "\n",
    "Import UN data for exercise 9.27:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0fa25ec4",
   "metadata": {},
   "outputs": [],
   "source": [
    "UN = pd.read_csv(\"https://asta.math.aau.dk/datasets?file=UN2014.dat\", sep='\\s+')\n",
    "UN.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b0cd962",
   "metadata": {},
   "source": [
    "Answer the exercise by an analysis in Python:\n",
    "\n",
    "1) Start by making relevant plot(s)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3323a98a",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Write plot command(s) here."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f88b50d1",
   "metadata": {},
   "source": [
    "2) Then fit the linear model in Python:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e08ae72a",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Write commands here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2ba41f4",
   "metadata": {},
   "source": [
    "3) Now answer questions (a) - (d)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6989d3b9",
   "metadata": {},
   "source": [
    "## Agresti exercise 9.33"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f197bf34",
   "metadata": {},
   "source": [
    "Import OECD data for exercise 9.33 (also available for download at the website):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fedc08bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "oecd = pd.read_csv(\"https://asta.math.aau.dk/datasets?file=OECD_Agresti_ed5.dat\", sep='\\s+')\n",
    "oecd.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebb692c8",
   "metadata": {},
   "source": [
    "Use a scatter plot to visualize the relevant y and x variables."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a38c104",
   "metadata": {},
   "outputs": [],
   "source": [
    "# write code here using plt.scatter()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "541e680d",
   "metadata": {},
   "source": [
    "Calculate the correlation between x and y:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9cada5e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Use a command like oecd['var1'].corr(oecd['var2']) with the relevant variable names."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cf175a8",
   "metadata": {},
   "source": [
    "Now answer question (a) from the book. Here the following hint may be helpful:\n",
    "To remove a row in a data frame you may use `.drop` .\n",
    "For example if you have a data frame called `oecd` and you want to remove row number 10 you can write:\n",
    "`oecd2 = oecd.drop(oecd.index[9])`\n",
    "(you have to find the relevant index to remove on your own)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "359e682f",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Make commands here"
   ]
  }
 ],
 "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
}
