Outliers

R function to identify outliers at y SDs above or below the group mean across conditions

This R function will take a vector X which correspond to your DV of interest. Y corresponds to the no. of SDs above or below we want to use. We assume that X is a vector from a matrix that represent the mean value per subject across conditions.


#Compute matrix per subject across condition using dplyr:

SubjMeans <- RawData %>%
             group_by(SubjID) %>% #group data by the subj variable
             summarise(aveRT = mean(RT[Acc==1]), avecorr = mean(Acc)) #compute mean RT accurate trials and mean accuracy


#define Outliers function

Out_Classifier <- function(x,y) {
  performance <-rep(NA, length(x))  #Performance empty vector
 
 for (i in  1:length(x)) {
    if(x[i] > mean(x)+(sd(x)*y)){
      performance[i] <- "slow"
    }
    else if (x[i] < mean(x)-(sd(x)*y)){
      performance[i] <- "Inaccurate/fast"
    }
    else {performance[i] <- "OK"
    }
  }
  print(performance)
}


#Apply functions to your variables

Out_Classifier(SubjMeans$aveRT) #will return a vector with a string depending on the performance of each subj.
Out_Classifier(SubjMeans$Acc)