Dprime and SDT
Function to compute Accuracy for SDT (hit,miss,cr,fa) and dprime:
Function to compute Accuracy for SDT (hit,miss,cr,fa) and dprime:
# Function where x is Target (1 present 0 absent) and y is accuracy (1 correct 0 incorrect trial)
SDT_Classifier <- function(x, y) {
performance <-rep(NA, length(x)) #define empty performance vector
performance[x ==1 & y == 1] <- "Hit"
performance[x==0 & y == 1] <- "Cr"
performance[x== 1 & y == 0 ] <- "Miss"
performance[x== 0 & y == 0] <- "FA"
return(performance)
}
Performance_vector <- SDT_Classifier(df$Target, df$ACC) #this applies the function and #generates a vector that you can bind on the df
newdf <- cbind(df, Performance_vector)
#Now you can use the awesome dplyr to compute the performance rate per participant/per #condition.
library(dplyr)
Perf_Rate <- newdf %>%
group_by(SubjID, Condition) %>%
summarise(no_Hit = sum(Performance_vector == "Hit"),
no_Fa = sum(Performance_vector == "FA"),
no_Miss= sum(Performance_vector == "Miss"),
no_CR = sum(Performance_vector == "Cr"))
After that as a resource for computing dprime and criterion I suggest the awesome package Psycho (Makowski, 2018).
#here an example, his function dprime computes parametric and non parametric dprime and #Criterion
library(psycho)
dprime <- dprime(Perf_Rate$no_Hit,Perf_Rate$no_Fa,Perf_Rate$no_Miss,Perf_Rate$no_CR)
Perf_Rate <- cbind(Perf_Rate, dprime) #bind this to your dataframe.