This vignette illustrates how to use implicitMeasures
package to compute the SC-IAT D by using the raw_data
data set.
Labels containing the sc_
specification in the blockcode
variable identity 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 assessment of the Milk chocolate preference (identified by the label sc_milk
), and one for the assessment of the Dark chocolate preference (identified by the label sc_dark
).
Once the SC-IATs blocks have been identified, it is possible to prepare and clean the data for computing the D. Since the data set contains data from two SC-IATs, it is possible to separate them in two different data sets. Demographic information (label demo
in blockcode
variable) are available as well, and they can be extracted and stored in a separate data frame. It is not mandatory to have two SC-IATs or the demographic information, the function can work with just the first (and only) SC-IAT blocks specified.
data("raw_data")
sciat_data <- clean_sciat(raw_data, sbj_id = "Participant",
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")
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 (and that hence have to be eliminated) must be included in the variable identified by trial_id
, but they have to be specified via the non_response
in the Dsciat()
function to actually be deleted.
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
and 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 the clean_sciat()
function.
Each of the List
elements can be stored in a separate object.
sciat1 <- sciat_data[[1]] # extract first SC-IAT data
sciat2 <- sciat_data[[2]] # extract second SC-IAT data
demo_data <- sciat_data[[3]] # extract demographic information
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) have been prepared and cleaned through the clean_sciat()
function, it is possible to compute the D by means of the Dsciat()
function.
This function works by specifying the data set on which the D has to be computed (data
) and the labels identifying the two critical conditions (mappingA
and mappingB
). If a rtw was included in the SC-IAT administration, the labels for the responses exceeding the threshold must be specified via the non_response
argument.
# Compute the D for the first SC-IAT
d_sciat1 <- Dsciat(sciat1,
mappingA = "test.sc_dark.Darkbad",
mappingB = "test.sc_dark.Darkgood",
non_response = "alert")
# dataframe containing the SC-IAT D of the of the first SC-IAT
str(d_sciat1)
#> Classes 'dsciat' and 'data.frame': 162 obs. of 15 variables:
#> $ participant : Factor w/ 162 levels "100","101","102",..: 1 2 3 4 5 6 7 8 9 10 ...
#> $ 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 for the second SC-IAT
d_sciat2 <- Dsciat(sciat2,
mappingA = "test.sc_milk.Milkbad",
mappingB = "test.sc_milk.Milkgood",
non_response = "alert")
# dataframe containing the SC-IAT D of the of the second SC-IAT
head(d_sciat2)
#> participant n_trial no_response nslow10000 nfast400 nfast350
#> 1 100 144 0 0 0.02 0.01
#> 2 101 144 0 0 0.02 0.00
#> 3 102 144 0 0 0.02 0.00
#> 4 103 144 0 0 0.00 0.00
#> 5 104 144 0 0 0.00 0.00
#> 6 105 144 0 0 0.03 0.01
#> out_accuracy accuracy.mappingA accuracy.mappingB RT_mean.mappingA
#> 1 keep 0.9436620 0.9722222 695.2269
#> 2 keep 0.9861111 1.0000000 917.3706
#> 3 keep 0.9583333 0.9166667 757.4988
#> 4 keep 0.9861111 0.9722222 640.5077
#> 5 keep 1.0000000 0.9861111 849.7500
#> 6 keep 1.0000000 1.0000000 540.3099
#> RT_mean.mappingB cond_ord legendMappingA
#> 1 648.8692 MappingB_First test.sc_milk.Milkbad
#> 2 699.7917 MappingB_First test.sc_milk.Milkbad
#> 3 784.3854 MappingB_First test.sc_milk.Milkbad
#> 4 607.7566 MappingB_First test.sc_milk.Milkbad
#> 5 928.0496 MappingB_First test.sc_milk.Milkbad
#> 6 614.8611 MappingB_First test.sc_milk.Milkbad
#> legendMappingB d_sciat
#> 1 test.sc_milk.Milkgood 0.16120777
#> 2 test.sc_milk.Milkgood 0.58453600
#> 3 test.sc_milk.Milkgood -0.08226841
#> 4 test.sc_milk.Milkgood 0.24119095
#> 5 test.sc_milk.Milkgood -0.26484892
#> 6 test.sc_milk.Milkgood -0.50147795
The Dsciat()
function results in a data.frame
with class dsciat
containing a number of rows equal to the number of participants, their D, and a bunch of useful information on their performance (see the documentation for the Dsciat()
function for further information on the resulting data frame). Functions dscr_d()
, d_plot()
, d_distr()
, and sc_grp()
require the object resulting from the Dsciat()
function to work.
The descriptive statistics of the D can be easily obtained by means of the descript_d()
function:
descript_d(d_sciat1)
#> 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
The descriptive statistics of the response times in the two critical conditions are reported as well.
By specifying latex = TRUE
, the dscr_d()
function prints the results in Latex:
descript_d(d_sciat2, latex = TRUE)
#> % latex table generated in R 3.6.1 by xtable 1.8-4 package
#> % Fri Aug 02 13:46:16 2019
#> \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}
implicitMeasures
provides the users with different functions for plotting the results, either at the individual or at the sample level. Furthermore, it gives the chance to plot the D for multiple SC-IATs.
d_plot()
plots the D for each participant. Participants can be arranged in different ways by means of the order_sbj
argument. In the default representation, they follow the order they had in the original data frame. By setting the order_sbj
argument equal to either D-increasing
or D-decreasing
, they are arranged by increasing or decreasing D, respectively. The values labels of the x-axis can be removed by setting x_values = FALSE
(suggested in case of big sample size). The include_stats
(default = FALSE
) argument plots the descriptive statics of the D (mean +/- 2sd).
# change respondents order, remove x-values
d_plot(d_sciat1, order_sbj = "D-increasing",
x_values = FALSE)
# change respondents order, remove x-values, add descriptive statistics
d_plot(d_sciat1, order_sbj = "D-increasing",
x_values = FALSE, include_stats = TRUE)
Points color can be changed as well by using the argument col_point
.
d_distr()
plots the distribution of the Ds. It provides different options for choosing the most appropriate distribution by means of the graph
argument, that can be set equal to histogram
(histogram plot, default), density
(density plot), or violin
(violin plot). Descriptive statistics can be added as well (include_stats = TRUE
). The filling color for the histogram and the density plot can be modified by means of the col_fill
argument (e.g., col_fill = "seagreen"
). The col_point
argument can be used to change the color of the points in the violin plot (e.g., col_fill = "royalblue"
).
# change graph and add descriptive statistics
d_distr(d_sciat1, graph = "density", include_stats = TRUE)
#change graph and add descriptive statistics
d_distr(d_sciat1, graph = "violin", include_stats = TRUE)
multi_dsciat()
plots the distributions of the Ds from two different SC-IATs. It provides different options for choosing the most appropriate graphical representation by using the graph
argument and setting it equal to density
(density plot, default), violin
(violin plot), or point
(point plot). The labels differentiating the two SC-IATs can be set by means of the label_sc1
and label_sc2
arguments (default 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 big sample size). The default palette of the graph is dark
. Palette can be changed via gcolors
argument (available palettes are greens
, blues
, and pinks
). dens_mean
add the mean to the density plot (default is TRUE
).
# remove mean adn change color
multi_dsciat(d_sciat1, d_sciat2, dens_mean = FALSE,
gcolors = "pinks")
# change graph and labels for the two SC-IATs, remove x-values
multi_dsciat(d_sciat1, d_sciat2, graph = "point",
x_values = FALSE, gcolors = "greens",
label_sc1 = "Dark SC-IAT",
label_sc2 = "Milk SC-IAT")