1) Packages Used in Data Analysis

## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.7     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.0
## ✔ readr   2.1.2     ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:itrak':
## 
##     is_outlier
## The following object is masked from 'package:stats':
## 
##     filter

2) Data Read-In

3) Data Pre-processing

The code below illustrates there are no administrations with <50% accuracy. Thus, no participants excluded here.

#The code below when run illustrates that there are no administrations
#With <50% accuracy. Nothing excluded here.
df %>% 
  group_by(Subject, ExperimentName, Cue) %>% 
  summarise(Percent_Accurate = mean(Accuracy)) %>% 
  filter(Percent_Accurate < 0.50) #No cues at administrations with 
## `summarise()` has grouped output by 'Subject', 'ExperimentName'. You can
## override using the `.groups` argument.
                                  #< 50% accuracy for any timepoint

The code below indicates the overall number of trials and the counts/percents for 1) incorrect trials to be excluded, and2) improbable reaction time trials (i.e., <200ms OR >1500ms) to be excluded. The code immediately following then excludes this data.

df %>% 
  group_by(ExperimentName) %>% 
  summarise(Overall_Trials = n(), #Overall trial counts
            Count_Inc_Trial = sum(ifelse(Accuracy == 0,1,0)), #Incorrect trial count
            Per_Inc_Trial = 1 - mean(Accuracy), #Percent of trials that are incorrect
            Count_Inc_RT = sum(ifelse(RT < 200 | RT > 1500, 1, 0)), 
            #Count of trials whose reaction times are < 200 or > 1500
            Per_Inc_RT = 1 - mean(ifelse(RT < 200 | RT > 1500, 0, 1)))
df <- df %>% 
  filter(Accuracy == 1) %>%  #Exclude incorrect trials
  filter(RT > 200 & RT < 1500) #Exclude RT's <200ms or >1500ms

Maximum & Minimum RT’s after exclusions

## [1] 1495
## [1] 273

The code here calculates Median Absolute Deviation (MADs) and Standard Deviations (SDs) for outlier screening, and compares potential data loss based on each method.

Excluding Folks Based on SD
df <- df %>% 
  filter(RT < SD_Exclude_Score) #Exclude folks whose RT are >3SD above their individual means

4) Attentional Bias (AB) Calculations

The code below first orders the data in numerical order by 1) subject, then 2) trial #. Then, it groups the data per 1) subject, then 2) administration, and finally 3) cue type. Lastly, it runs the summarize_bias() function to calculate mean and trial-level bias scores, which are first stored in a separate dataframe and then bound to the original data.

AB_df <- df %>% 
  arrange(Subject, Trial) %>% 
  group_by(Subject, ExperimentName, Cue) %>% 
  itrak::summarize_bias(data = ., RT = RT, congruent = Probe.tf, method = "nearest")

df <- left_join(df, AB_df, by = c("ExperimentName", "Cue", "Subject"))
Grouped_Output <- df %>% 
  group_by(Subject, ExperimentName, Cue) %>% 
  summarise(Mean_Bias = mean(mean_bias),
            Mean_Toward = mean(mean_toward),
            Mean_Away = mean(mean_away),
            Peak_Toward = mean(peak_toward),
            Peak_Away = mean(peak_away),
            Variability = mean(variability)) %>% 
  arrange(Subject, ExperimentName)
## `summarise()` has grouped output by 'Subject', 'ExperimentName'. You can
## override using the `.groups` argument.
Grouped_Output
glimpse(df)
## Rows: 12,184
## Columns: 26
## $ ExperimentName    <fct> baseline, baseline, baseline, baseline, baseline, ba…
## $ Subject           <dbl> 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 10…
## $ Trial             <dbl> 10, 12, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 26, …
## $ Accuracy          <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ RT                <dbl> 763, 808, 885, 840, 853, 761, 786, 824, 731, 685, 72…
## $ Cue               <fct> opioid, pain, opioid, pain, pain, pain, pain, opioid…
## $ Probe             <fct> incongruent, congruent, congruent, incongruent, inco…
## $ Probe.tf          <lgl> FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE,…
## $ med               <dbl> 547, 547, 547, 547, 547, 547, 547, 547, 547, 547, 54…
## $ MAD               <dbl> 109.7124, 109.7124, 109.7124, 109.7124, 109.7124, 10…
## $ MAD3              <dbl> 329.1372, 329.1372, 329.1372, 329.1372, 329.1372, 32…
## $ MAD_Exclude_Score <dbl> 876.1372, 876.1372, 876.1372, 876.1372, 876.1372, 87…
## $ Mean              <dbl> 573.2624, 573.2624, 573.2624, 573.2624, 573.2624, 57…
## $ SD                <dbl> 138.376, 138.376, 138.376, 138.376, 138.376, 138.376…
## $ SD3               <dbl> 415.128, 415.128, 415.128, 415.128, 415.128, 415.128…
## $ SD_Exclude_Score  <dbl> 988.3903, 988.3903, 988.3903, 988.3903, 988.3903, 98…
## $ mean_bias         <dbl> -15.01746, -17.86447, -15.01746, -17.86447, -17.8644…
## $ mean_toward       <dbl> 111.6176, 119.0000, 111.6176, 119.0000, 119.0000, 11…
## $ mean_away         <dbl> 99.86486, 122.90909, 99.86486, 122.90909, 122.90909,…
## $ peak_toward       <dbl> 299, 383, 299, 383, 383, 383, 383, 299, 383, 299, 29…
## $ peak_away         <dbl> 391, 337, 391, 337, 337, 337, 337, 391, 337, 391, 39…
## $ variability       <dbl> 73.91429, 94.45205, 73.91429, 94.45205, 94.45205, 94…
## $ trials_toward     <int> 34, 30, 34, 30, 30, 30, 30, 34, 30, 34, 34, 30, 34, …
## $ trials_away       <int> 37, 44, 37, 44, 44, 44, 44, 37, 44, 37, 37, 44, 37, …
## $ trials_NA         <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
## $ trials_total      <int> 71, 74, 71, 74, 74, 74, 74, 71, 74, 71, 71, 74, 71, …

ANOVA’s

The code below filters the data to only baseline and post visits (1st and 2nd visits) and then runs several repeated-measures ANOVA’s on each attentional bias DV.

Overall Mean Bias ANOVA

## 
## Error: Subject
##                Df Sum Sq Mean Sq
## ExperimentName  1  565.9   565.9
## 
## Error: Subject:ExperimentName
##                Df Sum Sq Mean Sq
## ExperimentName  1  30081   30081
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  93731   93731
## 
## Error: Subject:ExperimentName:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  75564   75564
## 
## Error: Within
##                      Df  Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1   21955   21955    28.9 7.82e-08 ***
## Cue                   1  299369  299369   394.1  < 2e-16 ***
## ExperimentName:Cue    1  157992  157992   208.0  < 2e-16 ***
## Residuals          7867 5975645     760                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Mean Bias Toward ANOVA

## 
## Error: Subject
##                Df Sum Sq Mean Sq
## ExperimentName  1   8020    8020
## 
## Error: Subject:ExperimentName
##                Df Sum Sq Mean Sq
## ExperimentName  1 683171  683171
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1 100831  100831
## 
## Error: Subject:ExperimentName:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  13059   13059
## 
## Error: Within
##                      Df   Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1   579856  579856  207.83  < 2e-16 ***
## Cue                   1   125452  125452   44.96 2.15e-11 ***
## ExperimentName:Cue    1   145072  145072   52.00 6.08e-13 ***
## Residuals          7867 21949489    2790                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Mean Bias Away ANOVA

## 
## Error: Subject
##                Df Sum Sq Mean Sq
## ExperimentName  1 200808  200808
## 
## Error: Subject:ExperimentName
##                Df  Sum Sq Mean Sq
## ExperimentName  1 1342707 1342707
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  51124   51124
## 
## Error: Subject:ExperimentName:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  237.3   237.3
## 
## Error: Within
##                      Df   Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1   991422  991422  554.94  < 2e-16 ***
## Cue                   1    47653   47653   26.67 2.47e-07 ***
## ExperimentName:Cue    1   156656  156656   87.69  < 2e-16 ***
## Residuals          7867 14054731    1787                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Peak Bias Toward ANOVA

## 
## Error: Subject
##                Df  Sum Sq Mean Sq
## ExperimentName  1 1408322 1408322
## 
## Error: Subject:ExperimentName
##                Df Sum Sq Mean Sq
## ExperimentName  1  43019   43019
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  57464   57464
## 
## Error: Subject:ExperimentName:Cue
##                Df  Sum Sq Mean Sq
## ExperimentName  1 1263995 1263995
## 
## Error: Within
##                      Df    Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1   1478312 1478312  49.003 2.77e-12 ***
## Cue                   1     12515   12515   0.415     0.52    
## ExperimentName:Cue    1    593984  593984  19.690 9.23e-06 ***
## Residuals          7867 237327713   30167                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Peak Bias Away ANOVA

## 
## Error: Subject
##                Df Sum Sq Mean Sq
## ExperimentName  1 305657  305657
## 
## Error: Subject:ExperimentName
##                Df  Sum Sq Mean Sq
## ExperimentName  1 8770519 8770519
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1   1569    1569
## 
## Error: Subject:ExperimentName:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1  87725   87725
## 
## Error: Within
##                      Df    Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1   5131846 5131846  217.54  < 2e-16 ***
## Cue                   1   1418585 1418585   60.13 9.97e-15 ***
## ExperimentName:Cue    1   1339623 1339623   56.79 5.40e-14 ***
## Residuals          7867 185583324   23590                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Variability Bias ANOVA

## 
## Error: Subject
##                Df Sum Sq Mean Sq
## ExperimentName  1  15809   15809
## 
## Error: Subject:ExperimentName
##                Df Sum Sq Mean Sq
## ExperimentName  1 449351  449351
## 
## Error: Subject:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1   5548    5548
## 
## Error: Subject:ExperimentName:Cue
##                Df Sum Sq Mean Sq
## ExperimentName  1   3408    3408
## 
## Error: Within
##                      Df  Sum Sq Mean Sq F value   Pr(>F)    
## ExperimentName        1  255830  255830  208.33  < 2e-16 ***
## Cue                   1     160     160    0.13    0.719    
## ExperimentName:Cue    1   19846   19846   16.16 5.87e-05 ***
## Residuals          7867 9660752    1228                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Means & SD’s for Each Bias, By Condition & Cue Type

## Adding missing grouping variables: `ExperimentName`, `Cue`
## `summarise()` has grouped output by 'ExperimentName'. You can override using
## the `.groups` argument.