Skip to content

Instantly share code, notes, and snippets.

@ltur1
Created March 23, 2026 15:31
Show Gist options
  • Select an option

  • Save ltur1/17743159df968b2d8fe44d58aadb2b54 to your computer and use it in GitHub Desktop.

Select an option

Save ltur1/17743159df968b2d8fe44d58aadb2b54 to your computer and use it in GitHub Desktop.
---
title: "Preparing Experimental Data for Analysis"
subtitle: "R + Quarto RevealJS"
author: "Elena Peden, Lylla Turco, Chloe Lockwood, Julianna Ross"
date: "3/23/26"
format:
revealjs:
theme: simple
template-partials:
- title-slide.html
css: pooh-theme.css
slide-number: true
incremental: true
center: false
transition: fade
code-line-numbers: true
execute:
echo: true
message: false
warning: false
---
## Attentional Blink
- Attentional blink is a brief lapse in attention that occurs after a person detects one target stimulus, making it harder to notice a second target that follows shortly afterward.
- In rapid streams of visual information, attention becomes temporarily occupied with processing the first target, so the second target is often missed if it appears too soon.
- As the time between the two targets increases, it is generally expected that detection rates of the second target will improve
------------------------------------------------------------------------
## Instructions
:::: incremental
::: {style="font-size: 0.55em;"}
- A sequence of 19 letters appeared, with each new letter replacing the previous one
- Each letter was shown for 100 milliseconds
- Participants waited until the sequence ended before responding
- Participants reported whether they saw:
- ::::: columns
::: {.column width="50%"}
- J
- K
:::
::: {.column width="50%"}
- Both
- Neither
:::
:::::
- The experiment included 60 total trials Procedures:
- Each trial presented a sequence of 19 letters at 100 ms per letter
- The sequence may or may not have included the target letters J and/or K
- Participants responded after each sequence indicating which targets they saw
- The position of J and K varied across trials
- The key focus was how accurately participants detected the second target letter
- Specifically, accuracy was compared based on the number of letters between the first and second targets
:::
::::
------------------------------------------------------------------------
## Data Pipeline
- This data from this task gives us evidence for the "Attentional Blink" which is the phenomenon in which there is a brief time after paying attention to one stimulus when attention cannot be focused on a subsequent stimulus.
- While we know the data shows this, we can't tell that just from looking at thousands of data points. (111,246 to be exact) That's where the data pipeline comes in.
## Data Pipeline
This process follows a structure of Rearranging ⇝ Cleaning/Conditioning ⇝ Exploring ⇝ Comprehending
::::: columns
::: {.column width="50%" style="font-size: 0.75em"}
- Rearranging: convert raw logs to tidy trial rows
- Cleaning: remove or repair invalid observations
- Conditioning: apply exclusion rules tied to design
- Exploring: check distributions, outliers, and group patterns
- Comprehending: interpret patterns and assess model readiness
:::
::: {.column width="50%"}
Like Pooh bear, we are trying to find the honey in our raw data honeycomb.
![](Img/honey_in_the_honeycomb.jpeg)
:::
:::::
------------------------------------------------------------------------
## Raw Data Structure
- Columns in raw export:
- `Trial`
- `First Target`
- `Second Target`
- `Separation`(Independent Variable)
- `Response`(Dependent Variable)
- `randgator` (Participant ID)
------------------------------------------------------------------------
## Prepping the Data
Goal: set ourselves up for success with coding later
```{r, echo = FALSE}
library("tidyverse")
library("forcats")
library("janitor")
data_file <-"attentional_blink_rgtr.csv"
data_set <- read_csv(data_file)
```
```{r}
attentional_blink <- data_set %>% clean_names()
```
Example: First Target ➙ first_target
- This formats data so there are no capitals, spaces, etc.
------------------------------------------------------------------------
## Recoding
**First:** simplify the labels
```{r}
lutboth<-c("K only"="K","Both"="KJ","J only"="J","Neither"="")
```
ex: K only ⇾ K
**Second:** apply to the table
```{r}
attentional_blink$targ_resp<-lutboth[attentional_blink$response]
```
------------------------------------------------------------------------
## Score the Data
**Goal:** Make a new data frame with binary values so data can be plotted
```{r}
ab_per<-attentional_blink %>% rowwise %>%
mutate(first =
if_else(str_sub(targ_resp,1)==first_target,1,0),
second =
if_else(str_sub(targ_resp,-1)==second_target,1,0))
```
This code does 2 things:
- `first` : compares the first character of the response to the first target
- `second` : compares the last character of the response to the second target
------------------------------------------------------------------------
## Trouble with Both
- In the earlier code, we can have a problem when the participant recognizes both stimuli
- Both is coded as KJ but what happens if J was the first target?
- J gets compared to K and is scored `0` and K is compared to J and scored `0` as well
- We need to override that code
------------------------------------------------------------------------
## Trouble with Both
------------------------------------------------------------------------
## Exploration
```{r}
```
------------------------------------------------------------------------
## Interpretation
- Where are the largest deviations from expected behavior?
- Do we see an attentional blink pattern by separation?
- Are there participants with unusual response profiles?
------------------------------------------------------------------------
## Model Compatibility
- Data now satisfy key modeling assumptions:
- One row per trial
- Consistent factor levels
- Exclusions documented and reproducible
- Derived variables aligned to design
------------------------------------------------------------------------
## Takeaways
- Most research effort is in preprocessing
- Conditioning decisions shape inference
- Quarto + R makes this workflow explicit and reproducible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment