Skip to content

Commit

Permalink
add data
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Jul 4, 2024
1 parent 8d900a1 commit bc3e4f1
Show file tree
Hide file tree
Showing 32 changed files with 15,837 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.12"
# cache: "pip"

- name: Install dependencies
run: |
Expand All @@ -38,7 +37,6 @@ jobs:

- name: Install Julia dependencies
run: |
julia --project=@quarto -e 'import Pkg; Pkg.add("QuartoNotebookRunner")'
julia -e 'import Pkg; Pkg.add("Plots")'
julia -e '# import Pkg; Pkg.add("CSV"); Pkg.add("DataFrames")'
julia -e '# import Pkg; Pkg.add("Turing"); Pkg.add("Distributions")'
Expand Down
1 change: 1 addition & 0 deletions content/.jupyter_cache/__version__.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
1,915 changes: 1,915 additions & 0 deletions content/.jupyter_cache/executed/7090acf5defd63a6a9d492b3789a7814/base.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file added content/.jupyter_cache/global.db
Binary file not shown.
16 changes: 16 additions & 0 deletions content/.quarto/_freeze/1_introduction/execute-results/html.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions content/.quarto/_freeze/4_rt/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "26c45ef47fe7e81fdb051963e24f2bf1",
"result": {
"engine": "jupyter",
"markdown": "# Reaction Times\n\n\nThis repository contain the following vignettes:\n\n- [**Drift Diffusion Model (DDM) in R: A Tutorial**](https://dominiquemakowski.github.io/easyRT/articles/ddm.html)\n- [**Ex-Gaussian models in R: A Tutorial**](https://dominiquemakowski.github.io/easyRT/articles/exgaussian.html)\n\n## Descriptive Models (ExGaussian, LogNormal, Wald)\n\n### Modelling RT with a Bayesian Linear Model\n\n#### The Data\n\n::: {#718393b9 .cell execution_count=1}\n``` {.julia .cell-code}\nusing Downloads, CSV, DataFrames\nusing Turing, Distributions\nusing CairoMakie\n\ndf = CSV.read(Downloads.download(\"https://raw.githubusercontent.com/RealityBending/DoggoNogo/main/study1/data/data_game.csv\"), DataFrame)\nfirst(df, 10)\n```\n\n::: {.cell-output .cell-output-display execution_count=2}\n```{=html}\n<div><div style = \"float: left;\"><span>10×9 DataFrame</span></div><div style = \"clear: both;\"></div></div><div class = \"data-frame\" style = \"overflow-x: scroll;\"><table class = \"data-frame\" style = \"margin-bottom: 6px;\"><thead><tr class = \"header\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">Row</th><th style = \"text-align: left;\">RT</th><th style = \"text-align: left;\">ISI</th><th style = \"text-align: left;\">Trial</th><th style = \"text-align: left;\">Participant</th><th style = \"text-align: left;\">Session</th><th style = \"text-align: left;\">Threshold</th><th style = \"text-align: left;\">Feedback</th><th style = \"text-align: left;\">Feedback_N_Positive</th><th style = \"text-align: left;\">Feedback_N_Negative</th></tr><tr class = \"subheader headerLastRow\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\"></th><th title = \"Float64\" style = \"text-align: left;\">Float64</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th><th title = \"Int64\" style = \"text-align: left;\">Int64</th><th title = \"String7\" style = \"text-align: left;\">String7</th><th title = \"String3\" style = \"text-align: left;\">String3</th><th title = \"String7\" style = \"text-align: left;\">String7</th><th title = \"String15\" style = \"text-align: left;\">String15</th><th title = \"Int64\" style = \"text-align: left;\">Int64</th><th title = \"Int64\" style = \"text-align: left;\">Int64</th></tr></thead><tbody><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">1</td><td style = \"text-align: right;\">0.517</td><td style = \"text-align: right;\">1.638</td><td style = \"text-align: right;\">1</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">NA</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">0</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">2</td><td style = \"text-align: right;\">0.433</td><td style = \"text-align: right;\">2.282</td><td style = \"text-align: right;\">2</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.475</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">1</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">3</td><td style = \"text-align: right;\">0.533</td><td style = \"text-align: right;\">0.739</td><td style = \"text-align: right;\">3</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.494</td><td style = \"text-align: left;\">Negative</td><td style = \"text-align: right;\">2</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">4</td><td style = \"text-align: right;\">0.35</td><td style = \"text-align: right;\">0.602</td><td style = \"text-align: right;\">4</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.458</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">0</td><td style = \"text-align: right;\">1</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">5</td><td style = \"text-align: right;\">0.517</td><td style = \"text-align: right;\">1.951</td><td style = \"text-align: right;\">5</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.47</td><td style = \"text-align: left;\">Negative</td><td style = \"text-align: right;\">1</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">6</td><td style = \"text-align: right;\">0.383</td><td style = \"text-align: right;\">0.952</td><td style = \"text-align: right;\">6</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.456</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">0</td><td style = \"text-align: right;\">1</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">7</td><td style = \"text-align: right;\">0.383</td><td style = \"text-align: right;\">0.875</td><td style = \"text-align: right;\">7</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.445</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">1</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">8</td><td style = \"text-align: right;\">0.417</td><td style = \"text-align: right;\">2.662</td><td style = \"text-align: right;\">8</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.442</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">2</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">9</td><td style = \"text-align: right;\">0.367</td><td style = \"text-align: right;\">2.8</td><td style = \"text-align: right;\">9</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.433</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">3</td><td style = \"text-align: right;\">0</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">10</td><td style = \"text-align: right;\">0.417</td><td style = \"text-align: right;\">0.258</td><td style = \"text-align: right;\">10</td><td style = \"text-align: left;\">S002</td><td style = \"text-align: left;\">S1</td><td style = \"text-align: left;\">0.432</td><td style = \"text-align: left;\">Positive</td><td style = \"text-align: right;\">4</td><td style = \"text-align: right;\">0</td></tr></tbody></table></div>\n```\n:::\n:::\n\n\n#### The Model\n\n::: {#cb030c10 .cell execution_count=2}\n``` {.julia .cell-code code-fold=\"false\"}\n@model function model_linear(rt; isi=nothing)\n\n # Set priors on variance, intercept and effect of ISI\n σ² ~ truncated(Normal(0, 1); lower=0)\n intercept ~ truncated(Normal(0, 1); lower=0)\n slope_isi ~ Normal(0, 0.5)\n\n for i in 1:length(rt)\n μ = intercept + slope_isi * isi[i]\n rt[i] ~ Normal(μ, σ²)\n end\nend\n\nmodel = model_linear(df.RT, isi=df.ISI)\nchain_linear = sample(model, NUTS(), 200)\n\n# Summary (95% CI)\nquantile(chain_linear; q=[0.025, 0.975])\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Info: Found initial step size\n└ ϵ = 0.003125\n\rSampling: 0%|█ | ETA: 0:00:54\rSampling: 100%|█████████████████████████████████████████| Time: 0:00:01\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=3}\n\n::: {.ansi-escaped-output}\n```{=html}\n<pre>Quantiles\n <span class=\"ansi-bold\"> parameters </span> <span class=\"ansi-bold\"> 2.5% </span> <span class=\"ansi-bold\"> 97.5% </span>\n <span class=\"ansi-bright-black-fg\"> Symbol </span> <span class=\"ansi-bright-black-fg\"> Float64 </span> <span class=\"ansi-bright-black-fg\"> Float64 </span>\n σ² 0.0662 0.0741\n intercept 0.3432 0.3485\n slope_isi -0.0215 -0.0188\n</pre>\n```\n:::\n\n:::\n:::\n\n\n::: {.callout-tip title=\"Code Tip\"}\nWe first initialize the model by passing the `RT` and `ISI` columns.\n:::\n\n#### Posterior Predictive Check\n\n::: {#c0d701ef .cell execution_count=3}\n``` {.julia .cell-code}\npred = predict(model_linear([(missing) for i in 1:length(df.RT)]; isi=df.ISI), chain_linear)\npred = Array(pred)\n```\n:::\n\n\n::: {#5a9bdace .cell fig-height='7' fig-width='10' execution_count=4}\n``` {.julia .cell-code}\nf = Figure()\nax = Axis(f[1, 1], title=\"Predicted Data by Linear Model\",\n xlabel=\"RT (s)\",\n ylabel=\"Distribution\",\n yticksvisible=false,\n xticksvisible=false,\n yticklabelsvisible=false)\n\nCairoMakie.density!(df.RT, color=\"grey\")\nfor i in 1:length(chain_linear)\n lines!(ax, Makie.KernelDensity.kde(pred[:, i]), color=\"orange\", alpha=0.1)\nend\nCairoMakie.ylims!(ax, (0, nothing))\nf\n```\n\n::: {.cell-output .cell-output-stderr}\n```\n┌ Warning: Found `resolution` in the theme when creating a `Scene`. The `resolution` keyword for `Scene`s and `Figure`s has been deprecated. Use `Figure(; size = ...` or `Scene(; size = ...)` instead, which better reflects that this is a unitless size and not a pixel resolution. The key could also come from `set_theme!` calls or related theming functions.\n└ @ Makie C:\\Users\\domma\\.julia\\packages\\Makie\\VRavR\\src\\scenes.jl:220\n```\n:::\n\n::: {.cell-output .cell-output-display execution_count=5}\n![](4_rt_files/figure-html/cell-5-output-2.svg){}\n:::\n:::\n\n\n### The Problem with Linear Models\n\nReaction time (RTs) have been traditionally modeled using traditional linear models and their derived statistical tests such as *t*-test and ANOVAs. Importantly, linear models - by definition - will try to predict the *mean* of the outcome variable by estimating the \"best fitting\" *Normal* distribution. In the context of reaction times (RTs), this is not ideal, as RTs typically exhibit a non-normal distribution, skewed towards the left with a long tail towards the right. This means that the parameters of a Normal distribution (mean $\\mu$ and standard deviation $\\sigma$) are not good descriptors of the data.\n\n![](media/rt_normal.gif)\n\n> Linear models try to find the best fitting Normal distribution for the data. However, for reaction times, even the best fitting Normal distribution (in red) does not capture well the actual data (in grey).\n\nA popular mitigation method to account for the non-normality of RTs is to transform the data, using for instance the popular *log-transform*. \nHowever, this practice should be avoided as it leads to various issues, including loss of power and distorted results interpretation [@lo2015transform; @schramm2019reaction].\nInstead, rather than applying arbitrary data transformation, it would be better to swap the Normal distribution used by the model for a more appropriate one that can better capture the characteristics of a RT distribution.\n\n\n### Shifted LogNormal Models\n\nOne of the obvious candidate alternative to the log-transformation would be to use a model with a Log-transformed Normal distribution.\n\n\n### Wald\n\nMoe from statistical models that *describe* to models that *generate* RT-like data.\n\n### Generative Models (DDM)\n\nUse DDM as a case study to introduce generative models\n\n### Other Models (LBA, LNR)\n\n\n## Additional Resources\n\n- [**Lindelov's overview of RT models**](https://lindeloev.github.io/shiny-rt/): An absolute must-read.\n- [**De Boeck & Jeon (2019)**](https://www.frontiersin.org/articles/10.3389/fpsyg.2019.00102/full): A paper providing an overview of RT models.\n- [https://github.com/vasishth/bayescogsci](https://github.com/vasishth/bayescogsci)\n\n",
"supporting": [
"4_rt_files"
],
"filters": [],
"includes": {
"include-in-header": [
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\" integrity=\"sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==\" crossorigin=\"anonymous\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js\" integrity=\"sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==\" crossorigin=\"anonymous\" data-relocate-top=\"true\"></script>\n<script type=\"application/javascript\">define('jquery', [],function() {return window.jQuery;})</script>\n"
]
}
}
}
Loading

0 comments on commit bc3e4f1

Please sign in to comment.