Skip to content

Instantly share code, notes, and snippets.

@sigmaroles
Created September 2, 2021 08:13
Show Gist options
  • Save sigmaroles/bea20c06c4636bbaab3fd5df449064a8 to your computer and use it in GitHub Desktop.
Save sigmaroles/bea20c06c4636bbaab3fd5df449064a8 to your computer and use it in GitHub Desktop.
Anderson_EZ_diffusion_
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Anderson_EZ_diffusion_",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOqrD1OVRO7ibluVFmPnJAS",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/sigmaroles/bea20c06c4636bbaab3fd5df449064a8/anderson_ez_diffusion_.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "1ETyY7UaW5Vy"
},
"source": [
"import numpy as np"
],
"execution_count": 4,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Kzy0AuHUW8Y2"
},
"source": [
"**Given the percent correct and variance in RT, fit the EZ diffusion model** <br>\n",
"(Britt Anderson book, page 134)\n",
"\n",
"parameters: <br>\n",
"pc : proportion correct <br>\n",
"vrt : variance in RT\n",
"\n",
"return values: <br>\n",
"v : drift rate <br>\n",
"a : the separation of our two decision boundaries from the starting point"
]
},
{
"cell_type": "code",
"metadata": {
"id": "QbUYBA63XCRV"
},
"source": [
"def logit(pc):\n",
" return np.log((pc/(1-pc)))"
],
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "is-vvH-QXq11",
"outputId": "826457a7-ea76-4543-b1c7-26edfc53de6d"
},
"source": [
"logit(0.5)"
],
"execution_count": 23,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.0"
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "YM4GNLmpXsCX"
},
"source": [
"def fit_EZ_parameters(pc, vrt, s=0.1):\n",
" # first term\n",
" # sign function: https://numpy.org/doc/stable/reference/generated/numpy.sign.html\n",
" t1 = np.sign(pc-0.5) * s\n",
" # second term\n",
" t2_num = logit(pc) * (pc**2 * logit(pc) - pc*logit(pc) + pc - 0.5)\n",
" t2 = (t2_num/vrt)**0.25\n",
" # calculate the drift rate\n",
" v = t1*t2\n",
" # using drift rate, calculate separation\n",
" a = ((s**2) * logit(pc)) / v\n",
" # done. return results\n",
" return v,a"
],
"execution_count": 19,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "istmZypMYaSI",
"outputId": "4e113258-40ad-4c82-c7dd-ec097e77f819"
},
"source": [
"v1, a1 = fit_EZ_parameters(0.8, 5.83)\n",
"v1, a1"
],
"execution_count": 20,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(0.03692653509562729, 0.37541956144270117)"
]
},
"metadata": {},
"execution_count": 20
}
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "A_YKwnjSgGZd",
"outputId": "f37ebfee-e5f8-4aff-8dbd-f2209fd25ade"
},
"source": [
"v2, a2 = fit_EZ_parameters(0.6, 10.1)\n",
"v2, a2"
],
"execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(0.010192493712627454, 0.39780756264370776)"
]
},
"metadata": {},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "TeKC7klKhGH8"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment