{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e7340abd",
   "metadata": {},
   "source": [
    "# Week 2 Lab (Part 2): Delay Discounting\n",
    "\n",
    "Fit discounting models to participant indifference points and compare them.\n",
    "\n",
    "- Hyperbolic (Mazur): $V = A / (1 + kD)$\n",
    "- Hyperboloid (Rachlin): $V = A / (1 + kD)^{s}$\n",
    "- Area Under the Curve (AUC): a model-free index of discounting\n",
    "\n",
    "Each row of `participant_data.csv` is one participant's indifference points across\n",
    "seven delays for a given Amount and Commodity. Fit the models, then look for trends\n",
    "in discounting across amount, commodity, and gain vs. loss."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61fec607",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "Import `numpy`, `pandas`, plotting libraries, `curve_fit` from `scipy.optimize`, `simpson` from `scipy.integrate` (for AUC), and `r2_score`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee3a0268",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import libraries (include curve_fit, simpson, r2_score)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c0a976f",
   "metadata": {},
   "source": [
    "## Task 1: Load and reshape the data\n",
    "\n",
    "Load `participant_data.csv` and melt the `delay_*` columns into long form, with one row per (participant, amount, commodity, delay). Convert the delay labels to integers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "506d71bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load participant_data.csv and melt delay_* columns to long form\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3167cdf",
   "metadata": {},
   "source": [
    "## Task 2: Define the discounting models\n",
    "\n",
    "Write the hyperbolic and hyperboloid functions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b242289a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define hyperbolic(D, A, k) and hyperboloid(D, A, k, s)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eeb3899a",
   "metadata": {},
   "source": [
    "## Task 3: Fit both models and compute AUC\n",
    "\n",
    "Loop over each (participant, amount, commodity) group. Fit the hyperbolic and hyperboloid models with `curve_fit` (holding `A` fixed at the task amount), record the recovered parameters and R-squared, and compute AUC on normalized delays and values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51b3a212",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Group by (participant, amount, commodity); fit both models with curve_fit; compute AUC\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "032d0cb6",
   "metadata": {},
   "source": [
    "## Task 4: Write a helper to plot fits\n",
    "\n",
    "Create a function that plots observed indifference points with the fitted hyperbolic and hyperboloid curves for a sample of participants in a chosen commodity/amount."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9f3cbda",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define plot_discounting_fits(df, fit_df, commodity, amount, ...)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06d922f8",
   "metadata": {},
   "source": [
    "## Task 5: Plot fits across tasks\n",
    "\n",
    "Use the helper to inspect fits for a few commodity/amount combinations, including a gain and a loss."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b127ec26",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Call plot_discounting_fits for a few commodity/amount combinations\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79d705f1",
   "metadata": {},
   "source": [
    "## Task 6: Compare parameters across tasks\n",
    "\n",
    "Compare discount rate (`k`), the hyperboloid exponent (`s`), AUC, and model R-squared across the different amount/commodity tasks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb91d6e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Melt k and r2 by model; box+strip plots of k, s, AUC, R2 across tasks\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebbe183f",
   "metadata": {},
   "source": [
    "## Wrap-up\n",
    "\n",
    "Interpret the trends: Does discounting (k / AUC) change with amount (a magnitude effect)? With commodity? Between gains and losses (sign effect)? Does the hyperboloid's extra parameter meaningfully improve fit over the hyperbolic?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
