library(ggplot2) library(ggtext) library(here) library(dplyr) here::here() source("coefficients/agreement.CI.R") source("coefficients/agreement.coefficients.R") # Look at the number of revisions per referent (Action_code) and participant fullLogs <- read.csv("logs/all_logs.csv", sep=",", stringsAsFactors=F) revisedTrials <- fullLogs[fullLogs$Phase == "Revision", ] revisedTrials$Action_code <- factor(revisedTrials$Action_code) levels(revisedTrials$Action_code) <- list(VS1="SEL_SubC_CF", VS2="SEL_SubC_CM", VS3="SEL_SubC_CL", VS4="SEL_SubC_SL", VS5="SEL_SubC_SM", VS6="SEL_SubC_SR", VS7="SEL_SubC_G", VM1="MAN_M_SC", VM2="MAN_D_SubC", VM3="MAN_C_S", GS1="SEL_SupC_C", GS2="SEL_SupC_R", GS3="SEL_SupC_CS", GS4="SEL_SupC_CMC", GS5="SEL_SupC_CMNC", GS6="SEL_SupC_RS", GS7="SEL_SupC_RMC", GS8="SEL_SupC_RMNC", GS9="SEL_SupC_SVC", GS10="SEL_SupC_SVR", GM1="MAN_C_M", GM2="MAN_M_C", GM3="MAN_M_R", GM4="MAN_D_SupC", GM5="MAN_D_SupCC", GM6="MAN_D_SupCR", GM7="MAN_S_C", GM8="MAN_F_C") countRevisionsReferents <- revisedTrials %>% count(Action_code) summary(countRevisionsReferents) countRevisionsReferents countRevisionsParticipants <- revisedTrials %>% count(Participant) summary(countRevisionsParticipants) countRevisionsParticipants # use modsOrSigns = "signs" for analyses regarding sign proposals, or modsOrSigns = "modalities" for analyses regarding modality proposals #modsOrSigns = "signs" modsOrSigns = "modalities" data <- read.csv(paste("logs/",modsOrSigns,".csv",sep=""), sep=";", stringsAsFactors=F) rightorder = c("VS1","VS2","VS3","VS4","VS5","VS6","VS7","VM1","VM2","VM3","GS1","GS2","GS3","GS4","GS5","GS6","GS7","GS8","GS9","GS10","GM1","GM2","GM3","GM4","GM5","GM6","GM7","GM8") data$X <- factor(data$X, ordered = TRUE, levels = rightorder) data <- data[order(data$X), ] data$X <- as.character(data$X) #full dataset gestures <- data[, seq(2, ncol(data), by=1)] names(gestures) <- paste0("P", 1:ncol(gestures)) # Agreement on Gestures percent <- jack.CI.random.raters(gestures, percent.agreement) kappa <- jack.CI.random.raters(gestures, fleiss.kappa) alpha <- jack.CI.random.raters(gestures, krippen.alpha) printCI(" Percent agreement", percent) printCI(" Fleiss' Kappa", kappa) printCI("Krippendorf's alpha", alpha) # Chance Agreement and Bias chance.gestures <- jack.CI.random.raters(gestures, chance.agreement) printCI("Chance agreement (Gestures)", chance.gestures) # Agreement over Individual Referents refs <- list() # referents list k <- list() # Kappa estimates l <- list() # Lower bounds of 95% CI u <- list() # Upper bounds of 95% CI for(index in 1:nrow(gestures)){ # Construct the jackknife CI for Fleiss' Kappa of each referent ci <- jack.CI.random.raters.fleiss.kappa.for.item(gestures, index) refs[index] <- data[index, 1] k[index] <- ci[1] l[index] <- ci[2] u[index] <- ci[3] } # Create a data frame with all the estimates fleiss.df <- data.frame(Referent = as.character(refs), Kappa = as.double(k), Low = as.double(l), Upper = as.double(u)) # Sort the referents by their agreement values fleiss.df <- fleiss.df[with(fleiss.df, order(-Kappa)),] referents <- fleiss.df$Referent offset=0.5 a=0.01 colorLabels <- "black" yOffset <- 0.9 plot <- ggplot(fleiss.df, aes(x = Referent, y = Kappa)) + geom_hline(yintercept = 0, color = "red", size = .2) + geom_point(size = 1.8, color = "#0000aa", shape = 1) + scale_x_discrete(name ="Referent", limits = rightorder) + scale_y_continuous(breaks =seq(-1, 1, by=0.2),limits = c(-1,1)) + theme_bw() + geom_errorbar(aes(ymax = Upper, ymin = Low), width=0.01, color = "#0000aa") + theme(axis.text.x = element_text(angle=48, vjust=1, hjust=1)) + theme(panel.border = element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_line(colour="#000000", size=0.03), text = element_text(size = 20) ) + geom_vline(xintercept = 7.5, color = colorLabels, linetype="dotted", size = 1.5) + geom_vline(xintercept = 10.5, color = colorLabels, linetype="dotted", size = 1.5) + geom_vline(xintercept = 20.5, color = colorLabels, linetype="dotted", size = 1.5) + geom_richtext(x = 3.75, y = -yOffset, angle=90, label = "Value Selections", colour = colorLabels, size = 6, hjust = 0) + geom_richtext(x = 9, y = -yOffset, angle=90, label = "Value Manipulations", colour = colorLabels, size = 6, hjust = 0) + geom_richtext(x = 15.5, y = -yOffset, angle=90, label = "Grid Selections", colour = colorLabels, size = 6, hjust = 0) + geom_richtext(x = 24.5, y = -yOffset, angle=90, label = "Grid Manipulations", colour = colorLabels, size = 6, hjust = 0) print(plot) results = c() for(i in 1:28){ results=c(results,fleiss.df$Kappa[which(fleiss.df$Referent==rightorder[i])]) } write.csv(data.frame(results,row.names = rightorder),paste("results_",modsOrSigns,".csv",sep="")) print("Fleiss' Kappa overall -- descriptive statistics:") summary(results) print(paste("standard deviation:", sd(results))) ############################ ### pairwise comparisons ### ############################ indices = seq(1, 28, by=1) # comparisons between individual referents fleiss.pe <- fleiss.chance.agreement.raw.noinference(gestures) fleiss.pooled <- function(ratings) {generic.kappa(ratings, fleiss.pe)} for (index in indices){ propsReferent1 <- gestures[indices[index],] for (ind in indices){ if(ind > index) { propsReferent2 <- gestures[indices[ind],] diff.Kappa <- jack.CI.diff.random.raters(propsReferent1, propsReferent2, fleiss.pooled) if(!(diff.Kappa[2] < 0 && diff.Kappa[3] > 0) && diff.Kappa[1]>0.1) { print(paste("Comparing ", rightorder[index], " with ", rightorder[ind], ":")) printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) } } } } # comparisons between groups propsReferentVS <- gestures[indices[1:7],] propsReferentVM <- gestures[indices[8:10],] propsReferentGS <- gestures[indices[11:20],] propsReferentGM <- gestures[indices[21:28],] diff.Kappa <- jack.CI.diff.random.raters(propsReferentVS, propsReferentVM, fleiss.pooled) print("Comparing VS and VW") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) diff.Kappa <- jack.CI.diff.random.raters(propsReferentVS, propsReferentGS, fleiss.pooled) print("Comparing VS and GS") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) diff.Kappa <- jack.CI.diff.random.raters(propsReferentVS, propsReferentGM, fleiss.pooled) print("Comparing VS and GM") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) diff.Kappa <- jack.CI.diff.random.raters(propsReferentVM, propsReferentGS, fleiss.pooled) print("Comparing VM and GS") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) diff.Kappa <- jack.CI.diff.random.raters(propsReferentVM, propsReferentGM, fleiss.pooled) print("Comparing VM and GM") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa) diff.Kappa <- jack.CI.diff.random.raters(propsReferentGS, propsReferentGM, fleiss.pooled) print("Comparing GS and GM") printCI("Difference in Fleiss' Kappa (pooled pe)", diff.Kappa)