Appendix C. Calculations of rate-based scores for the NIH Toolbox African Languages #' The following code is a function that will read in an NIH Toolbox Assessment Data export #' and then it will calculate the rate-based score for Flanker and/or DCCS for the two NIHTB African language versions #' #' The full path to the data export must be given as the first argument to in the function. #' #' The second argument is an indicator for whether the rate based score should be calculated for Flanker, DCCS, #' or both; the default is to calculate it for both. #' #' The third argument is a boolean operator defaulting to FALSE. It indicates whether or not #' rate based scores should be exported (TRUE) or only kept as a dataframe in R (FALSE). #' If it is set to TRUE, a file names rateScores.csv will be exported in the current working directory. #' Note that this may be different than the folder in which the assessment data export was located. #' #' The rateScore is in number correct per second. library(tidyverse) rateScoring <- function(path, test=c('flanker','dccs','both'), writeCSV=FALSE){ require(tidyverse) test <- tolower(test) if(all(!test %in% c("flanker","dccs","both"))) stop("Input error: only calculates rate-based scores for Flanker or DCCS or both tests.") if(length(test) > 1) test <- "both" assessmentData <- read_csv(path) modData <- assessmentData %>% transmute(PIN=PIN, AsmntName=`Assessment Name`, TestName=case_when(Inst %in% c("NIH Toolbox Dimensional Change Card Sort Test Age 12+ v2.1 (Dholuo)", "NIH Toolbox Dimensional Change Card Sort Test Ages 3-7 v2.1 (Dholuo)", "NIH Toolbox Dimensional Change Card Sort Test Ages 8-11 v2.1 (Dholuo)", "NIH Toolbox Dimensional Change Card Sort Test Age 12+ v2.1 (Swahili)", "NIH Toolbox Dimensional Change Card Sort Test Ages 3-7 v2.1 (Swahili)", "NIH Toolbox Dimensional Change Card Sort Test Ages 8-11 v2.1 (Swahili)") ~ "DCCS", Inst %in% c("NIH Toolbox Flanker Inhibitory Control and Attention Test Age 12+ v2.1 (Dholuo)", "NIH Toolbox Flanker Inhibitory Control and Attention Test Ages 3-7 v2.1 (Dholuo)", "NIH Toolbox Flanker Inhibitory Control and Attention Test Ages 8-11 v2.1 (Dholuo)", "NIH Toolbox Flanker Inhibitory Control and Attention Test Age 12+ v2.1 (Swahili)", "NIH Toolbox Flanker Inhibitory Control and Attention Test Ages 3-7 v2.1 (Swahili)", "NIH Toolbox Flanker Inhibitory Control and Attention Test Ages 8-11 v2.1 (Swahili)") ~ "Flanker", Inst %in% c("NIH Toolbox List Sorting Working Memory Test Age 7+ v2.1 (Dholuo)", "NIH Toolbox List Sorting Working Memory Test Age 7+ v2.1 (Swahili)") ~ "LSWM", Inst %in% c("NIH Toolbox Pattern Comparison Processing Speed Test Age 7+ v2.1 (Dholuo)", "NIH Toolbox Pattern Comparison Processing Speed Test Age 7+ Practice v2.1 (Dholuo)", "NIH Toolbox Pattern Comparison Processing Speed Test Age 7+ v2.1 (Swahili)", "NIH Toolbox Pattern Comparison Processing Speed Test Age 7+ Practice v2.1 (Swahili)") ~ "PCPS", Inst %in% c("NIH Toolbox Picture Sequence Memory Test Age 7 Form A v2.1 (Dholuo)", "NIH Toolbox Picture Sequence Memory Test Age 8+ Form A v2.1 (Dholuo)", "NIH Toolbox Picture Sequence Memory Test Age 7 Form A v2.1 (Swahili)", "NIH Toolbox Picture Sequence Memory Test Age 8+ Form A v2.1 (Swahili)") ~ "PSM", Inst %in% c("NIH Toolbox Touch Screen Tutorial Age 3+ (Dholuo)", "NIH Toolbox Touch Screen Tutorial Age 3+ (Swahili)") ~ "TouchTut", TRUE ~ as.character(Inst)), ItemID=ItemID, Response=Response, ResponseTime=ResponseTime, Score=Score, Position=Position) Flanker_rates <- modData %>% filter(TestName == "Flanker") %>% filter(!str_detect(ItemID, "PRAC")) %>% pivot_wider(id_cols=1:2, names_from=4, values_from=6:7) %>% select(PIN, AsmntName, paste0(rep(c("Score_FLANKER_FISH_","Score_FLANKER_ARROW_","ResponseTime_FLANKER_FISH_","ResponseTime_FLANKER_ARROW_"),each=20), rep(c(paste0("CONGRUENT",1:2),"INCONGRUENT3","CONGRUENT4","INCONGRUENT5", "CONGRUENT6","INCONGRUENT7",paste0("CONGRUENT",8:9),"INCONGRUENT10", paste0("CONGRUENT",11:12),"INCONGRUENT13","CONGRUENT14","INCONGRUENT15", "CONGRUENT16","INCONGRUENT17",paste0("CONGRUENT",18:19),"INCONGRUENT20"),times=2))) DCCS_rates <- modData %>% filter(TestName == "DCCS" & !str_detect(ItemID, "PRAC")) %>% pivot_wider(id_cols=1:2, names_from=4, values_from=6:7) %>% select(PIN, AsmntName, paste0(rep(c("Score_","ResponseTime_"), each=30), c(paste0("DCCSMIXED_SHAPE_REPEAT",1:4),"DCCSMIXED_COLOR_SWITCH5", paste0("DCCSMIXED_SHAPE_REPEAT",6:8),"DCCSMIXED_COLOR_SWITCH9", paste0("DCCSMIXED_SHAPE_REPEAT",10:14),"DCCSMIXED_COLOR_SWITCH15", paste0("DCCSMIXED_SHAPE_REPEAT",16:17),"DCCSMIXED_COLOR_SWITCH18", paste0("DCCSMIXED_SHAPE_REPEAT",19:21),"DCCSMIXED_COLOR_SWITCH22", paste0("DCCSMIXED_SHAPE_REPEAT",23:26),"DCCSMIXED_COLOR_SWITCH27", paste0("DCCSMIXED_SHAPE_REPEAT",28:29),"DCCSMIXED_COLOR_SWITCH30"))) Flanker_rates <- Flanker_rates %>% mutate(Flanker_nCorrect = rowSums(Flanker_rates[,str_detect(colnames(Flanker_rates), "Score")],na.rm=T), Flanker_totTime = rowSums(Flanker_rates[,str_detect(colnames(Flanker_rates),"ResponseTime")],na.rm=T)) %>% mutate(Flanker_rateScore = Flanker_nCorrect/Flanker_totTime) %>% select(PIN, AsmntName, Flanker_nCorrect, Flanker_totTime, Flanker_rateScore) DCCS_rates <- DCCS_rates %>% mutate(DCCS_nCorrect = rowSums(DCCS_rates[,str_detect(colnames(DCCS_rates), "Score")],na.rm=T), DCCS_totTime = rowSums(DCCS_rates[,str_detect(colnames(DCCS_rates),"ResponseTime")],na.rm=T)) %>% mutate(DCCS_rateScore = DCCS_nCorrect/DCCS_totTime) %>% select(PIN, AsmntName, DCCS_nCorrect, DCCS_totTime, DCCS_rateScore) if(test=="flanker"){ output <- Flanker_rates } else if(test == "dccs"){ output <- DCCS_rates } else if(test == "both"){ output <- Flanker_rates %>% full_join(DCCS_rates, by=c('PIN', 'AsmntName')) } if(writeCSV){ write_csv(output, "rateScores.csv") } return(output) } testit <- rateScoring("./2020-11-25 15.24.12 Assessment Data.csv")