{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "20a03edd",
   "metadata": {},
   "source": [
    "# Rock Fries Your Brains\n",
    "\n",
    "To read more about the dataset and see an explorative analysis have a look at the Rmarkdown file `rock-fries-your-brains.Rmd` in the exercises for the first lecture.\n",
    "\n",
    "We load the needed packages for this exercise:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0ef0862",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from scipy import stats"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31213c02",
   "metadata": {},
   "source": [
    "## Load data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "289144a6",
   "metadata": {},
   "source": [
    "In the data, missing values are coded as 999 (but this is handled by the command \n",
    "below that replace 999 by NA). Loading data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5e47318",
   "metadata": {},
   "outputs": [],
   "source": [
    "musik = pd.read_csv(\"https://asta.math.aau.dk/datasets?file=musik.txt\", sep=\"\\t\").replace(999, np.nan)\n",
    "musik.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "778c3f4f",
   "metadata": {},
   "source": [
    "# Change in performance\n",
    "\n",
    "We will study the development of the performance of the mice from\n",
    "week1 to week4:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f2a30ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "musik[\"devel\"] = musik[\"week4\"] - musik[\"week1\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d12992c7",
   "metadata": {},
   "source": [
    "## Mozart\n",
    "\n",
    "First, we will look at the \"Mozart\"-mice, which are coded `group==2`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38498d46",
   "metadata": {},
   "outputs": [],
   "source": [
    "Mozart = musik[musik[\"group\"] == 2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93a9674b",
   "metadata": {},
   "source": [
    "The dataset Mozart only contains data for the \"Mozart-mice\".\n",
    "\n",
    "We want to investigate whether or not their performance has changed\n",
    "from week1 to week4."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44d171e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.boxplot(y=Mozart[\"devel\"])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e3df844",
   "metadata": {},
   "outputs": [],
   "source": [
    "t_stat, p_val = stats.ttest_1samp(Mozart[\"devel\"], popmean=0)\n",
    "print(\"t =\", t_stat, \", p =\", p_val)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7255d840",
   "metadata": {},
   "source": [
    "What do you conclude?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1450773",
   "metadata": {},
   "source": [
    "## Anthrax\n",
    "\n",
    "Make a similar analysis for the anthrax mice.\n",
    "\n",
    "## Control\n",
    "\n",
    "Make a similar analysis for the control mice."
   ]
  }
 ],
 "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
}
