{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a1247f30",
   "metadata": {},
   "source": [
    "# Week 2 Lab (Part 1): Matching Law\n",
    "\n",
    "This lab explores the Generalized Matching Equation (GME) using data from ten\n",
    "hypothetical participants. The GME in log-ratio form is:\n",
    "\n",
    "$$\\log\\left(\\frac{B_1}{B_2}\\right) = a \\cdot \\log\\left(\\frac{R_1}{R_2}\\right) + \\log b$$\n",
    "\n",
    "- $B_1/B_2$: response ratio\n",
    "- $R_1/R_2$: reinforcer ratio\n",
    "- $a$: sensitivity (slope)\n",
    "- $\\log b$: bias (intercept)\n",
    "\n",
    "Your job, as a researcher would: fit the GME to each participant, then look for\n",
    "group-level trends. Code cells are blank for you to fill in."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23c1bcdf",
   "metadata": {},
   "source": [
    "## Setup and load the data\n",
    "\n",
    "Import your libraries, then load all ten participant files (`gme_data_P01.csv` ... `gme_data_P10.csv`) into a dictionary keyed by participant id. The files sit in this notebook's folder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "680d0e4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import libraries and load gme_data_P01.csv ... gme_data_P10.csv\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06bd4ab9",
   "metadata": {},
   "source": [
    "## Task 1: Combine the data and compute log ratios\n",
    "\n",
    "Concatenate all participants into one DataFrame. Add 1 to every behavior and reinforcer count to avoid `log(0)`, then compute the log response ratio and log reinforcer ratio."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8904bf63",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Concatenate, add 1 to counts, compute log_response_ratio and log_reinforcer_ratio\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21b3d0de",
   "metadata": {},
   "source": [
    "## Task 2: Fit the GME for each participant\n",
    "\n",
    "For each participant, regress the log response ratio on the log reinforcer ratio with `scipy.stats.linregress`. Record sensitivity (slope), bias (intercept), and R-squared, and plot each participant's data with the fitted line and the perfect-matching line."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ce33480",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Loop participants: linregress(log_reinforcer_ratio -> log_response_ratio), record a, log b, R2, and plot\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f8999d0",
   "metadata": {},
   "source": [
    "## Task 3: Build the group summary table\n",
    "\n",
    "Collect the per-participant parameters into a tidy summary table sorted by participant."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3aca3a69",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Assemble a summary DataFrame of a, log b, and R2 per participant\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cc37e2e",
   "metadata": {},
   "source": [
    "## Task 4: Visualize the group-level parameters\n",
    "\n",
    "Plot the distribution of sensitivity, bias, and R-squared across participants (a bar plot with the individual points overlaid works well)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dff5132",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Bar + swarm plot of the parameter distributions across participants\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e006fe6",
   "metadata": {},
   "source": [
    "## Wrap-up\n",
    "\n",
    "Interpret your results: Are participants matching, undermatching, or overmatching (what do the sensitivity values say)? Is there systematic bias? How well does the GME describe these data overall?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
