Author: Ottavia M. Epifania
Date: 2026-08-20

# IAT-example

#### Ottavia M. Epifania

#### 2026-08-20

    library(implicitMeasures)

This vignette illustrates how to use the `implicitMeasures` package for computing the IAT D score. The illustration is based on the data set `raw_data` that comes with the package.

### First thing first: Import and explore data

Labels containing specification `.iat` in variable `blockcode` identify IAT blocks.

    data("raw_data")
    # explore the dataframe
    str(raw_data)
    #> 'data.frame':    84726 obs. of  6 variables:
    #>  $ Participant: int  4 4 4 4 4 4 4 4 4 4 ...
    #>  $ latency    : int  2592 628 808 783 2059 1114 608 663 771 676 ...
    #>  $ correct    : int  1 1 1 1 1 1 1 1 1 1 ...
    #>  $ trialcode  : Factor w/ 32 levels "age","alert",..: 31 5 3 20 3 20 5 3 20 3 ...
    #>  $ blockcode  : Factor w/ 13 levels "demo","practice.iat.Milkbad",..: 4 4 4 4 4 4 4 4 4 4 ...
    #>  $ response   : Factor w/ 46 levels "","0","1","19",..: 43 43 43 43 43 43 43 43 43 43 ...
    # explore the levels of the blockcode variable to identify the IAT blocks
    levels(raw_data$blockcode)
    #>  [1] "demo"                      "practice.iat.Milkbad"
    #>  [3] "practice.iat.Milkgood"     "practice.sc_dark.Darkbad"
    #>  [5] "practice.sc_dark.Darkgood" "practice.sc_milk.Milkbad"
    #>  [7] "practice.sc_milk.Milkgood" "test.iat.Milkbad"
    #>  [9] "test.iat.Milkgood"         "test.sc_dark.Darkbad"
    #> [11] "test.sc_dark.Darkgood"     "test.sc_milk.Milkbad"
    #> [13] "test.sc_milk.Milkgood"

Once the IAT blocks have been identified, it is possible to clean the IAT data by using the `clean_iat()` function. Since the data set also includes respondents’ demographic information (`demo` in the `blockcode` variable), it is possible to extract and store these information in a separate data frame:

    iat_cleandata <- clean_iat(raw_data, sbj_id = "Participant",
                              block_id = "blockcode",
                              mapA_practice = "practice.iat.Milkbad",
                              mapA_test = "test.iat.Milkbad",
                              mapB_practice = "practice.iat.Milkgood",
                              mapB_test = "test.iat.Milkgood",
                              latency_id = "latency",
                              accuracy_id = "correct",
                              trial_id = "trialcode",
                              trial_eliminate = c("reminder", "reminder1"),
                              demo_id = "blockcode",
                              trial_demo = "demo")

Since also the demographic data has been specified, `clean_iat()` results in a list of 3 elements:

    str(iat_cleandata)
    #> List of 3
    #>  $ data_keep     :Classes 'iat_clean' and 'data.frame':  19440 obs. of  8 variables:
    #>   ..$ participant   : int [1:19440] 4 4 4 4 4 4 4 4 4 4 ...
    #>   ..$ latency       : int [1:19440] 1282 1299 1435 1089 967 648 967 615 729 642 ...
    #>   ..$ correct       : int [1:19440] 1 1 1 1 1 1 1 1 1 1 ...
    #>   ..$ block_original: chr [1:19440] "practice.iat.Milkbad" "practice.iat.Milkbad" "practice.iat.Milkbad" "practice.iat.Milkbad" ...
    #>   ..$ condition     : chr [1:19440] "MappingA" "MappingA" "MappingA" "MappingA" ...
    #>   ..$ block_pool    : chr [1:19440] "practice" "practice" "practice" "practice" ...
    #>   ..$ block         : chr [1:19440] "practice_MappingA" "practice_MappingA" "practice_MappingA" "practice_MappingA" ...
    #>   ..$ trial_id      : Factor w/ 32 levels "age","alert",..: 20 6 20 6 20 6 20 6 20 23 ...
    #>  $ data_eliminate:'data.frame':  64638 obs. of  6 variables:
    #>   ..$ Participant: int [1:64638] 4 4 4 4 4 4 4 4 4 4 ...
    #>   ..$ latency    : int [1:64638] 2592 628 808 783 2059 1114 608 663 771 676 ...
    #>   ..$ correct    : int [1:64638] 1 1 1 1 1 1 1 1 1 1 ...
    #>   ..$ trialcode  : Factor w/ 32 levels "age","alert",..: 31 5 3 20 3 20 5 3 20 3 ...
    #>   ..$ blockcode  : Factor w/ 13 levels "demo","practice.iat.Milkbad",..: 4 4 4 4 4 4 4 4 4 4 ...
    #>   ..$ response   : Factor w/ 46 levels "","0","1","19",..: 43 43 43 43 43 43 43 43 43 43 ...
    #>  $ demo          :'data.frame':  3726 obs. of  6 variables:
    #>   ..$ participant: int [1:3726] 4 4 4 4 4 4 4 4 4 4 ...
    #>   ..$ latency    : int [1:3726] 53047 53047 53047 53047 21554 21554 11266 11266 11266 11266 ...
    #>   ..$ correct    : int [1:3726] 1 1 1 1 1 1 1 1 1 1 ...
    #>   ..$ trialcode  : Factor w/ 32 levels "age","alert",..: 19 1 21 8 22 4 10 11 12 13 ...
    #>   ..$ blockcode  : Factor w/ 13 levels "demo","practice.iat.Milkbad",..: 1 1 1 1 1 1 1 1 1 1 ...
    #>   ..$ response   : Factor w/ 46 levels "","0","1","19",..: 33 15 41 34 16 20 1 1 1 1 ...

`data_keep` is a `data.frame` with class `iat_clean`. It contains the data set for the `compute_iat()` function.

`data_eliminate` is a `data.frame` that contains all the discarded blocks and trials.

`demo` is a `data.frame` that contains all the trials identified as `demo` in the `blockcode` variable.

Store the first `data_keep` element in a data frame for the `compute_iat()` function.

    iat_data <- iat_cleandata[[1]]
    head(iat_data)
    #>       participant latency correct       block_original condition block_pool
    #> 60914           4    1282       1 practice.iat.Milkbad  MappingA   practice
    #> 60915           4    1299       1 practice.iat.Milkbad  MappingA   practice
    #> 60916           4    1435       1 practice.iat.Milkbad  MappingA   practice
    #> 60917           4    1089       1 practice.iat.Milkbad  MappingA   practice
    #> 60918           4     967       1 practice.iat.Milkbad  MappingA   practice
    #> 60919           4     648       1 practice.iat.Milkbad  MappingA   practice
    #>                   block  trial_id
    #> 60914 practice_MappingA goodright
    #> 60915 practice_MappingA darkright
    #> 60916 practice_MappingA goodright
    #> 60917 practice_MappingA darkright
    #> 60918 practice_MappingA goodright
    #> 60919 practice_MappingA darkright

### Compute IAT D score

Once that IAT data have been cleaned with the `clean_iat()` function, it is possible to compute the D score by using the `compute_iat()` function.

This function only takes two arguments. The first argument is the data frame with class `iat_clean`, the second argument is a character specifying the D score algorithm for the computation. To compute multiple D score algorithms at the same time, use the`multi_dscore()` function.

    dscore <- compute_iat(iat_data, Dscore = "d3")
    str(dscore)
    #> Classes 'dscore' and 'data.frame':   162 obs. of  23 variables:
    #>  $ participant               : int  4 6 8 11 14 17 18 19 20 21 ...
    #>  $ n_trial                   : int  120 120 120 120 120 120 120 120 120 120 ...
    #>  $ nslow10000                : num  0 0 0 0 0 0 0 0 0 0 ...
    #>  $ nfast400                  : num  0 0 0 0.01 0.07 0.04 0 0.05 0 0 ...
    #>  $ nfast300                  : num  0 0 0 0 0 0 0 0 0 0 ...
    #>  $ accuracy.practice_MappingA: num  1 0.95 0.7 0.9 0.95 0.9 0.95 0.95 0.85 0.9 ...
    #>  $ accuracy.practice_MappingB: num  1 1 0.85 0.95 1 1 1 0.85 1 0.85 ...
    #>  $ accuracy.test_MappingA    : num  1 0.9 1 0.95 0.9 0.925 0.95 0.95 0.8 0.9 ...
    #>  $ accuracy.test_MappingB    : num  1 1 0.85 0.95 1 0.95 1 0.975 0.975 0.9 ...
    #>  $ accuracy.MappingA         : num  1 0.917 0.9 0.933 0.917 ...
    #>  $ accuracy.MappingB         : num  1 1 0.85 0.95 1 ...
    #>  $ RT_mean.MappingA          : num  1037 1179 954 1297 852 ...
    #>  $ RT_mean.MappingB          : num  788 596 926 731 604 ...
    #>  $ mean_practice_MappingA    : num  1070 1224 1504 1608 821 ...
    #>  $ mean_test_MappingA        : num  1021 1157 679 1141 867 ...
    #>  $ mean_practice_MappingB    : num  889 611 1108 702 637 ...
    #>  $ mean_test_MappingB        : num  737 589 836 745 587 ...
    #>  $ d_practice_d3             : num  -0.647 -1.274 -0.584 -1.114 -0.514 ...
    #>  $ d_test_d3                 : num  -0.878 -1.226 0.508 -0.816 -0.672 ...
    #>  $ dscore_d3                 : num  -0.762 -1.25 -0.038 -0.965 -0.593 ...
    #>  $ cond_ord                  : chr  "MappingA_First" "MappingB_First" "MappingB_First" "MappingA_First" ...
    #>  $ legendMappingA            : chr  "practice.iat.Milkbad_and_test.iat.Milkbad" "practice.iat.Milkbad_and_test.iat.Milkbad" "practice.iat.Milkbad_and_test.iat.Milkbad" "practice.iat.Milkbad_and_test.iat.Milkbad" ...
    #>  $ legendMappingB            : chr  "practice.iat.Milkgood_and_test.iat.Milkgood" "practice.iat.Milkgood_and_test.iat.Milkgood" "practice.iat.Milkgood_and_test.iat.Milkgood" "practice.iat.Milkgood_and_test.iat.Milkgood" ...

The `compute_iat()` function results in a `data.frame` with class `dscore` containing a number of rows equal to the number of participants. The columns contain the D score and otehr useful information on the performance of each respondent (see the documentation of the `compute_iat()` function for further details). The `IAT_rel()`, `descript_d()`, `d_point()`, and `d_density()` functions require the object resulting from function `compute_iat()`.

The IAT D is computed as such that positive scores indicate slower response times in condition identified by Mapping B.

### IAT descriptive statistics and reliability

The `summary` method applied to the S3 object with class `dscore` returns basic descriptive statistics on the computed scores, as well as the label of the specific algorithm:

    summary(dscore)
    #> $general
    #>        measure value
    #> 1 Participants   162
    #> 2 Total trials 19440
    #>
    #> $statistics
    #>                   measure         mean           sd
    #> 1 Response time Mapping A 1042.4673352 302.39824527
    #> 2 Response time Mapping B  781.4131790 253.06935999
    #> 3      Accuracy Mapping A    0.9316592   0.05958240
    #> 4      Accuracy Mapping B    0.9655245   0.05919172
    #> 5              D-score D3   -0.5649519   0.54394891
    #>
    #> $algorithm
    #> [1] "D3"
    #>
    #> attr(,"class")
    #> [1] "summary_dscore" "list"

The `IAT_rel()` function computes the reliability of the IAT by correlating the D score obtained from practice blocks with the D score obtained from test blocks (see Gawronski et al. 2017 for further details):

    IAT_rel(dscore)
    #> $`Test-practice Reliability`
    #> [1] 0.65
    #>
    #> $`Number of participants`
    #> [1] 162
    #>
    #> attr(,"class")
    #> [1] "IAT_rel"

### Plotting the results

The `implicitMeasures` package comes with several functions for obtaining clear representations of the results at both individual respondent and sample levels by using the `plot` method on the S3 object of class `dscore`.

The default graphical representation is the histogram of the sample scores, depicted on the x-axis.

    plot(dscore) # Data frame containing IAT D scores

The `graph` argument controls the specific type of graphical representation that is illustrated. For instance, `graph = "points"` allows for obtaing the representation of the individual scores.

    plot(dscore, graph = "points",
           order_sbj = "D-decreasing", # change respondents order
           x_values = FALSE, # remove respondents' labels
           include_stats = TRUE, # include descriptive statistics
           col_point = "lightskyblue") # change points color

# Multiple D scores

The `multi_dscore()` function computes multiple D score algorithms. The D score algorithms that can be computed depend on the IAT administration. If the IAT administration included a feedback strategy (i.e., built-in correction), only D1 and D2 algorithms should be computed. If the IAT administration did not include a feedback strategy, then algorithms D3, D4, D5, and D6 should be computed. An exhaustive and detailed illustration of the D score algorithms is provided in the “Implicit Measures” vignette. To specify the algorithms that can be computed, argument `ds` must be set equal to either `"built-in"` (for the computation of D1 and D2) or `error-inflation` (for the computation of all other algorithms). Nonetheless, the function allows y default to compute all algorithms.

    multi_scores <- multi_dscore(iat_data, # object with class "iat_clean"
                                 algorithms  = "error-inflation") # string specifying the
                                                # algorithms to compute

The scores can be graphically compared by using the `plot` method, returning either the boxplots of the scores for each algorithm (default) or the by investigating the score of each respondent according to different algorithms, hence allowing for the investigation of potential inversions.

    plot(multi_scores)

    plot(multi_scores, graph = "individual")

# References

Gawronski, Bertram, Mike Morrison, Curtis E Phills, and Silvia Galdi. 2017. “Temporal Stability of Implicit and Explicit Measures: A Longitudinal Analysis.” Personality and Social Psychology Bulletin 43 (3): 300–312. https://doi.org/10.1177/0146167216684131.