library(implicitMeasures)
This vignette illustrates how to use the implicitMeasures
package for computing the SC-IAT D score. The illustration is based on the data set included in the package (i.e., raw_data
).
The labels that contains the specification sc_
in theblockcode
variable identify the SC-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 SC-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"
raw_data
contains data from two different SC-IATs, one for the implicit assessment of the positive/negative evaluation of Milk chocolate (sc_milk
), and one for the implicit assessment of the positive/negative evaluation of Dark chocolate (sc_dark
).
Once the SC-IATs blocks have been identified, it is possible to clean the data for computing the D score. Function clean_sciat
allows for cleaning the data set of either just one SC-IAT or to clean the data sets of two SC-IATs concurrently. The labels identifying the test blocks must be specified as a character vector via argument block_sciat_1
and argument block_sciat_2
(use the block_sciat_2
argument only if there is a second SC-IAT). The labels identifying the demographic information (if any) must be passed to the trial_demo
argument, after specifying the column of the data set containing the labels of the demographic information (argument demo_id
).
DON’T USE THE trial_eliminate
ARGUMENT TO ELIMINATE TRIALS EXCEEDING THE RESPONSE TIME WINDOW (rtw).
The labels for identifying the responses beyond the rtw (that have to be eliminated) must be included in the variable identified by thetrial_id
label, but they have to be specified via the non_response
argument in the compute_sciat()
function to actually be deleted.
data("raw_data")
<- clean_sciat(raw_data, sbj_id = "Participant",
sciat_data block_id = "blockcode",
latency_id = "latency",
accuracy_id = "correct",
block_sciat_1 = c("test.sc_dark.Darkbad",
"test.sc_dark.Darkgood"),
block_sciat_2 = c("test.sc_milk.Milkbad",
"test.sc_milk.Milkgood"),
trial_id = "trialcode",
trial_eliminate = c("reminder",
"reminder1"),
demo_id = "blockcode",
trial_demo = "demo")
Since two SC-IATs and demographic data were specified, clean_sciat()
results in a list of 3 elements:
str(sciat_data) # structure of the resulting List
#> List of 3
#> $ sciat1:Classes 'sciat_clean' and 'data.frame': 23328 obs. of 5 variables:
#> ..$ participant: int [1:23328] 4 4 4 4 4 4 4 4 4 4 ...
#> ..$ block : chr [1:23328] "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" ...
#> ..$ trial : Factor w/ 32 levels "age","alert",..: 5 3 5 3 20 3 5 20 5 5 ...
#> ..$ correct : int [1:23328] 1 1 1 1 1 1 1 1 1 1 ...
#> ..$ latency : int [1:23328] 461 1495 639 573 671 643 714 1190 625 517 ...
#> $ sciat2:Classes 'sciat_clean' and 'data.frame': 23328 obs. of 5 variables:
#> ..$ participant: int [1:23328] 4 4 4 4 4 4 4 4 4 4 ...
#> ..$ block : chr [1:23328] "test.sc_milk.Milkbad" "test.sc_milk.Milkbad" "test.sc_milk.Milkbad" "test.sc_milk.Milkbad" ...
#> ..$ trial : Factor w/ 32 levels "age","alert",..: 3 23 3 3 3 23 23 23 20 20 ...
#> ..$ correct : int [1:23328] 1 1 1 1 1 1 1 1 1 1 ...
#> ..$ latency : int [1:23328] 653 990 594 550 818 591 570 620 661 623 ...
#> $ 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 ...
The first two elements (sciat1
and sciat2
) are two data.frame
with class sciat_clean
. They contain the data of the SC-IATs specified in the block_sciat1
and block_sciat2
arguments of the clean_sciat()
function, respectively. The third element (demo
) is a data.frame
that contains the demographic information as specified in the trial_demo
argument of function clean_sciat()
.
Each element of the resulting list can be stored in a separate object.
<- sciat_data[[1]] # extract first SC-IAT data
sciat1 <- sciat_data[[2]] # extract second SC-IAT data
sciat2 <- sciat_data[[3]] # extract demographic information
demo_data
head(sciat1)
#> participant block trial correct latency
#> 23 4 test.sc_dark.Darkbad darkleft 1 461
#> 24 4 test.sc_dark.Darkbad badleft 1 1495
#> 25 4 test.sc_dark.Darkbad darkleft 1 639
#> 26 4 test.sc_dark.Darkbad badleft 1 573
#> 27 4 test.sc_dark.Darkbad goodright 1 671
#> 28 4 test.sc_dark.Darkbad badleft 1 643
head(demo_data)
#> participant latency correct trialcode blockcode response
#> 81001 4 53047 1 gender demo male
#> 81002 4 53047 1 age demo 29
#> 81003 4 53047 1 job demo stud
#> 81004 4 53047 1 edu demo MD
#> 81005 4 21554 1 milk_eval demo 3
#> 81006 4 21554 1 dark_eval demo 4
Once the SC-IAT(s) data have been cleaned with the clean_sciat()
function, it is possible to compute the D score by using function compute_sciat()
.
This function takes three mandatory arguments and one optional argument. The three mandatory arguments are the data set with class sciat_clean
, and the labels identifying the two critical associative conditions (arguments mappingA
and mappingB
). If the SC-IAT administration included a rtw, the label identifying the trials exceeding the threshold must be specified via the (optional) argument non_response
.
# Compute the D-score for the first SC-IAT
<- compute_sciat(sciat1,
d_sciat1 mappingA = "test.sc_dark.Darkbad",
mappingB = "test.sc_dark.Darkgood",
non_response = "alert")
# dataframe containing the SC-IAT D-score of the of the first SC-IAT
str(d_sciat1)
#> Classes 'dsciat' and 'data.frame': 162 obs. of 15 variables:
#> $ participant : chr "100" "101" "102" "103" ...
#> $ n_trial : int 144 144 144 144 144 144 144 144 144 144 ...
#> $ no_response : int 0 0 0 0 0 0 0 0 0 0 ...
#> $ nslow10000 : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ nfast400 : num 0.03 0.05 0.01 0.01 0 0 0.01 0.11 0.02 0.05 ...
#> $ nfast350 : num 0.01 0.01 0 0 0 0 0 0.01 0 0 ...
#> $ out_accuracy : chr "keep" "keep" "keep" "keep" ...
#> $ accuracy.mappingA: num 0.986 0.986 0.958 0.986 1 ...
#> $ accuracy.mappingB: num 0.944 0.986 0.931 0.986 0.931 ...
#> $ RT_mean.mappingA : num 626 785 627 586 885 ...
#> $ RT_mean.mappingB : num 730 913 704 633 1056 ...
#> $ cond_ord : chr "MappingB_First" "MappingB_First" "MappingB_First" "MappingB_First" ...
#> $ legendMappingA : chr "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" "test.sc_dark.Darkbad" ...
#> $ legendMappingB : chr "test.sc_dark.Darkgood" "test.sc_dark.Darkgood" "test.sc_dark.Darkgood" "test.sc_dark.Darkgood" ...
#> $ d_sciat : num -0.413 -0.242 -0.393 -0.288 -0.314 ...
# Compute D-score for the second SC-IAT
<- compute_sciat(sciat2,
d_sciat2 mappingA = "test.sc_milk.Milkbad",
mappingB = "test.sc_milk.Milkgood",
non_response = "alert")
# dataframe containing the SC-IAT D-score of the of the second SC-IAT
head(d_sciat2)
#> participant n_trial no_response nslow10000 nfast400 nfast350 out_accuracy
#> 1 100 144 0 0 0.02 0.01 keep
#> 2 101 144 0 0 0.02 0.00 keep
#> 3 102 144 0 0 0.02 0.00 keep
#> 4 103 144 0 0 0.00 0.00 keep
#> 5 104 144 0 0 0.00 0.00 keep
#> 6 105 144 0 0 0.03 0.01 keep
#> accuracy.mappingA accuracy.mappingB RT_mean.mappingA RT_mean.mappingB
#> 1 0.9436620 0.9722222 695.2269 648.8692
#> 2 0.9861111 1.0000000 917.3706 699.7917
#> 3 0.9583333 0.9166667 757.4988 784.3854
#> 4 0.9861111 0.9722222 640.5077 607.7566
#> 5 1.0000000 0.9861111 849.7500 928.0496
#> 6 1.0000000 1.0000000 540.3099 614.8611
#> cond_ord legendMappingA legendMappingB d_sciat
#> 1 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood 0.16120777
#> 2 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood 0.58453600
#> 3 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood -0.08226841
#> 4 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood 0.24119095
#> 5 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood -0.26484892
#> 6 MappingB_First test.sc_milk.Milkbad test.sc_milk.Milkgood -0.50147795
The compute_sciat()
function results in a data.frame
with class dsciat
containing a number of rows equal to the number of participants, their D score, and a bunch of useful information on their performance (see the documentation for the compute_sciat()
function for further information). The descript_d()
, d_point()
, and d_density()
functions require the object resulting from the compute_sciat()
function to work.
The descriptive statistics of the D score and of the response times in the two critical conditions can be easily obtained with the descript_d()
function:
descript_d(d_sciat1) # Data frame containing SC-IAT D-scores
#> Mean SD Min Max
#> D-Sciat -0.04 0.32 -0.91 0.78
#> RT.MappingA 700.53 125.94 459.56 1299.09
#> RT.MappingB 710.23 125.28 462.28 1218.77
By specifying latex = TRUE
, the descript_d()
function prints the results in LaTeX code
descript_d(d_sciat2, # Data frame containing IAT D-scores
latex = TRUE) # obtain the code for latex tables
#> % latex table generated in R 4.1.2 by xtable 1.8-4 package
#> % Tue Feb 15 18:40:47 2022
#> \begin{table}[ht]
#> \centering
#> \begin{tabular}{rrrrr}
#> \hline
#> & Mean & SD & Min & Max \\
#> \hline
#> D-Sciat & 0.16 & 0.34 & -0.95 & 1.20 \\
#> RT.MappingA & 729.20 & 146.02 & 448.56 & 1686.09 \\
#> RT.MappingB & 681.52 & 109.97 & 485.15 & 1166.36 \\
#> \hline
#> \end{tabular}
#> \end{table}
The implicitMeasures
package comes with several functions for obtaining nice and clear representations of the results at both individual respondent and sample levels. Additionally, it includes functions for plotting SC-IAT D scores resulting from two different SC-IATs.
The d_point()
function plots the SC-IAT D score for each respondent.
d_point(d_sciat1) # Data frame containing SC-IAT D-scores
In case of large sample size the label identifying each respondent is not easy to read, and it can be eliminated by setting x_values = FALSE
. Respondents can be arranged by increasing or decreasing D scores by setting argument order_sbj
equal to "D-increasing"
or "D-decreasing"
, respectively. Descriptive statistics (i.e., \(M_{\text{D-score}}\pm 2sd\)) can be added by setting include_stats = TRUE
. Finally, the color of the points can be changed by using the col_point
argument.
d_point(d_sciat1, # dataframe containing SC-IAT D-scores
order_sbj = "D-increasing", # change respondents' order
x_values = FALSE, # remove respondents' labels
include_stats = TRUE, # include descriptive statistics
col_point = "aquamarine3") # change points color
The d_density()
function plots the distribution of the SC-IAT D scores. It provides different options for choosing the most appropriate representation.
d_density(d_sciat1) # Data frame containing SC-IAT D-scores
The number of bins can be changed with the n_bin
argument. The graph
argument can be used for changing the graphical representation of the data. It is possible to choose an histogram representation (graph = "histogram"
, default), a representation of the density distribution (graph = "density"
), or a violin plot (graph = "violin"
). The col_fill
argument can be used to change the color of the points representing each respondent’s score in the violin plot. Finally, also descriptive statistics (i.e., \(M_{\text{D-score}} \pm 2sd\)) can be added to the graph by setting argument include_stats = TRUE
.
d_density(d_sciat1, # dataframe containing IAT Dscores
graph = "density", # change graphical representation
include_stats = TRUE) # include descriptive statistics
The multi_dsciat()
function plots the distributions of the D scores obtained from two different SC-IATs. This function takes only two mandatory arguments, which are the data frames containing the results of each SC-IAT obtained by using function compute_sciat()
. The type of graphical representation can be changed by using graph
, which is set to "density"
by default. Default representation also contains the lines that indicate the mean of each distribution. These lines can be taken out of the graph by setting dens_mean = FALSE
.
multi_dsciat(d_sciat1, # dataframe containing the results of the first SC-IAT
# dataframe containing the results of the second SC-IAT d_sciat2)
The graph
argument can be set equal to "violin"
(violin plots of the SC-IATs D scores) or "point"
(point representation of both SC-IATs D scores). The labels identifying each SC-IAT can be set with the label_sc1
and label_sc2
arguments (defaults are "SC-IAT 1"
and "SC-IAT 2"
). The values labels of the \(x\)-axis can be removed by setting x-values = FALSE
(suggested in case of large sample size). The gcolors
argument can be used to change the colors of each SC-IAT (default is "dark"
). Other colors options are "greens"
, "blues"
, and "pink"
.
multi_dsciat(d_sciat1, # dataframe containing the results of the first SC-IAT
# dataframe containing the results of the second SC-IAT
d_sciat2, graph = "point", # change graph type
x_values = FALSE, # take out x values
gcolors = "greens", # change color
label_sc1 = "Dark SC-IAT", # change label first SC-IAT
label_sc2 = "Milk SC-IAT") # change label second SC-IAT