### merge all data setsquestionnaire <-left_join(x = questionnaire_preCAM, y = questionnaire_postCAM, by='PROLIFIC_PID') %>%left_join(., questionnaire_secondPostCAM, by='PROLIFIC_PID') questionnaire$ID.x <-NULLquestionnaire$ID.y <-NULLdim(questionnaire)
[1] 227 60
# change name of ans1names(questionnaire)[names(questionnaire) =="ans1"] <-"adaptiveQuestion"# remove testing data setsquestionnaire <- questionnaire[nchar(questionnaire$PROLIFIC_PID) ==24,]### add prolific dataprolific <- prolific[prolific$Participant.id %in% questionnaire$PROLIFIC_PID,]prolific <- prolific %>%arrange(sapply(Participant.id, function(y) which(y == questionnaire$PROLIFIC_PID)))if(nrow(prolific) ==nrow(questionnaire)){print("prolific data sucessfully added") questionnaire$socio_age <- prolific$Age questionnaire$socio_sex <- prolific$Sex questionnaire$socio_ethnicity <- prolific$Ethnicity.simplified questionnaire$socio_student <- prolific$Student.status questionnaire$socio_employment <- prolific$Employment.status questionnaire$total_min_prolific <- prolific$Time.taken /60## all time outs to NA questionnaire$total_min_prolific[questionnaire$total_min_prolific >1000] <-NA## all expired data to NA questionnaire[questionnaire =="DATA_EXPIRED"] <-NA questionnaire$socio_age <-as.numeric(questionnaire$socio_age)}
[1] "prolific data sucessfully added"
## all missing answers to NAquestionnaire[questionnaire ==""] <-NA## all feedback smaller than 3 characters to NAquestionnaire$feedback_critic[nchar(questionnaire$feedback_critic) <=2] <-NA### save files## save as .xlsx filexlsx::write.xlsx2(x = questionnaire, file ="questionnaire.xlsx")## save as R objectsaveRDS(questionnaire, file ="questionnaire.rds")
get reaction times for single components
Plot time taken (in minutes) by participants for single components of study:
## save ggplot as PDFggsave(filename ="outputs/01_dataPreperation/durations_components.pdf", p)# Calculate the mean duration in seconds for each sender and sort by mean durationtmp <- dat_duration %>%group_by(sender) %>%summarise(N =n(), mean_duration =mean(duration, na.rm =TRUE)) %>%arrange(desc(mean_duration))DT::datatable(tmp, options =list(pageLength =5))
set up CAM data
pre
Load CAM data
setwd("outputs/01_dataPreperation")suppressMessages(read_file("CAMdata.txt") %>%# ... split it into lines ...str_split('\n') %>%first() %>%discard(function(x) x =='') %>%discard(function(x) x =='\r') %>%# ... filter empty rows ...discard(function(x) x =='')) -> dat_CAM_preraw_CAM_pre <-list()for(i in1:length(dat_CAM_pre)){ raw_CAM_pre[[i]] <- jsonlite::fromJSON(txt = dat_CAM_pre[[i]])}
Create CAM files, draw CAMs and compute network indicators
[1] "create_wordlist - use raw words"
[1] 0
[1] 3076
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 225 CAMs...
[1] "== participantCAM in drawnCAM"
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs/01_dataPreperation")setwd("savedCAMs_pre")setwd("png")### remove all files if there are anyif(length(list.files()) >=1){file.remove(list.files())cat('\n! all former .png files have been deleted')}### if no participant ID was provided replace by randomly generated CAM IDif(all(CAMfiles_pre[[3]]$participantCAM.x =="noID")){ CAMfiles_pre[[3]]$participantCAM.x <- CAMfiles_pre[[3]]$CAM.x}### save as .json files, and as .png (igraph)ids_CAMs <-unique(CAMfiles_pre[[3]]$participantCAM.x); length(ids_CAMs)for(i in1:length(ids_CAMs)){save_graphic(filename =paste0("CAM_", i, "_t1")) # paste0(ids_CAMs[i])) CAM_igraph <- CAMdrawn_pre[[c(1:length(CAMdrawn_pre))[names(CAMdrawn_pre) ==paste0(unique(CAMfiles_pre[[3]]$participantCAM.x)[i])]]]plot(CAM_igraph, edge.arrow.size = .7,layout=layout_nicely, vertex.frame.color="black", asp = .5, margin =-0.1,vertex.size =10, vertex.label.cex = .9)dev.off()}setwd("../json")### remove all files if there are anyif(length(list.files()) >=1){file.remove(list.files())cat('\n! all former .json files have been deleted')}for(i in1:length(raw_CAM_pre)){if(!is_empty(raw_CAM_pre[[i]]$nodes)){if(nrow(raw_CAM_pre[[i]]$nodes) >5){write(toJSON(raw_CAM_pre[[i]], encoding ="UTF-8"),paste0(raw_CAM_pre[[i]]$idCAM, ".json")) } }}}
post
Load CAM data
setwd("outputs/01_dataPreperation")suppressMessages(read_file("secondCAMdata.txt") %>%# ... split it into lines ...str_split('\n') %>%first() %>%discard(function(x) x =='') %>%discard(function(x) x =='\r') %>%# ... filter empty rows ...discard(function(x) x =='')) -> dat_CAM_postraw_CAM_post <-list()for(i in1:length(dat_CAM_post)){ raw_CAM_post[[i]] <- jsonlite::fromJSON(txt = dat_CAM_post[[i]])}
Create CAM files, draw CAMs and compute network indicators
[1] "create_wordlist - use raw words"
[1] 0
[1] 3532
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 225 CAMs...
[1] "== participantCAM in drawnCAM"
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs/01_dataPreperation")setwd("savedCAMs_post")setwd("png")### remove all files if there are anyif(length(list.files()) >=1){file.remove(list.files())cat('\n! all former .png files have been deleted')}### if no participant ID was provided replace by randomly generated CAM IDif(all(CAMfiles_post[[3]]$participantCAM.x =="noID")){ CAMfiles_post[[3]]$participantCAM.x <- CAMfiles_post[[3]]$CAM.x}### save as .json files, and as .png (igraph)ids_CAMs <-unique(CAMfiles_post[[3]]$participantCAM.x); length(ids_CAMs)for(i in1:length(ids_CAMs)){save_graphic(filename =paste0("CAM_", i, "_t2")) # paste0(ids_CAMs[i], "_t2")) CAM_igraph <- CAMdrawn_post[[c(1:length(CAMdrawn_post))[names(CAMdrawn_post) ==paste0(unique(CAMfiles_post[[3]]$participantCAM.x)[i])]]]plot(CAM_igraph, edge.arrow.size = .7,layout=layout_nicely, vertex.frame.color="black", asp = .5, margin =-0.1,vertex.size =10, vertex.label.cex = .9)dev.off()}setwd("../json")### remove all files if there are anyif(length(list.files()) >=1){file.remove(list.files())cat('\n! all former .json files have been deleted')}for(i in1:length(raw_CAM_post)){if(!is_empty(raw_CAM_post[[i]]$nodes)){if(nrow(raw_CAM_post[[i]]$nodes) >5){write(toJSON(raw_CAM_post[[i]], encoding ="UTF-8"),paste0(raw_CAM_post[[i]]$idCAM, ".json")) } }}}
identify types of changes (delta CAM)
### set A, B, C, D types# !!! i = 215if (all(unique(CAMfiles_pre[[1]]$participantCAM) ==unique(CAMfiles_post[[1]]$participantCAM))) { vec_type <-c() error <-0 verbose =FALSE## list_newWords_text <-list() list_newWords_value <-list() list_ids <-list() h =1for (i in1:length(unique(CAMfiles_pre[[1]]$participantCAM))) { praeCAM <- CAMfiles_pre[[1]][CAMfiles_pre[[1]]$participantCAM ==unique(CAMfiles_pre[[1]]$participantCAM)[i],] postCAM <- CAMfiles_post[[1]][CAMfiles_post[[1]]$participantCAM ==unique(CAMfiles_post[[1]]$participantCAM)[i],]## to test:# praeCAM$text %in% postCAM$text# postCAM$text %in% praeCAM$text# length(praeCAM$text)# length(postCAM$text)# praeCAM$text# postCAM$text## Typ Aif (all(postCAM$text %in% praeCAM$text) &length(postCAM$text) <length(praeCAM$text)) { vec_type[i] <-"A"if (verbose) {cat("\n i:", i, "type:", vec_type[i], "\n") } error = error +1 }## Typ Bif (all(praeCAM$text %in% postCAM$text) &length(postCAM$text) >length(praeCAM$text)) { vec_type[i] <-"B"if (verbose) {cat("\n i:", i, "type:", vec_type[i], "\n") } error = error +1## get words and values list_newWords_text[[h]] <- postCAM$text[!postCAM$text %in% praeCAM$text] list_newWords_value[[h]] <- postCAM$value[!postCAM$text %in% praeCAM$text] list_ids[[h]] <- postCAM$id[!postCAM$text %in% praeCAM$text] h = h +1 }## Typ Cif (all(praeCAM$text %in% postCAM$text) &all(postCAM$text %in% praeCAM$text)) { vec_type[i] <-"C"if (verbose) {cat("\n i:", i, "type:", vec_type[i], "\n") } error = error +1 }## Typ D# smaller > pr? UE post, post UE pr?if (sum(praeCAM$text %in% postCAM$text) <length(praeCAM$text) &sum(postCAM$text %in% praeCAM$text) <length(postCAM$text)) { vec_type[i] <-"D"if (verbose) {cat("\n i:", i, "type:", vec_type[i], "\n") } error = error +1 }if (error >1) {print("ERROR in (not exclusive logical condition)", i)stop("check your data and adjust this function") } error =0 }}table(vec_type)
vec_type
A B C D
1 145 39 39
barplot(table(unlist(list_newWords_value)))
# sort(table(unlist(list_newWords_text)))dat_newWords <-data.frame(id =unlist(list_ids), text =unlist(list_newWords_text), value =unlist(list_newWords_value))DT::datatable(dat_newWords, options =list(pageLength =5))
merge and save all data
setwd("outputs/01_dataPreperation/final")### add type of changeif(all(questionnaire$PROLIFIC_PID ==unique(CAMfiles_pre[[1]]$participantCAM))){ questionnaire$typeChange <- vec_type}if(all(questionnaire$PROLIFIC_PID == networkIndicators_pre$participantCAM) &all(networkIndicators_pre$participantCAM == networkIndicators_post$participantCAM)){print("all data can be matched")# save questionnaire## save as .xlsx file xlsx::write.xlsx2(x = questionnaire, file ="questionnaire_final.xlsx")## save as R objectsaveRDS(questionnaire, file ="questionnaire_final.rds")# save network indicators pre## save as .xlsx file xlsx::write.xlsx2(x = networkIndicators_pre, file ="networkIndicators_pre_final.xlsx")## save as R objectsaveRDS(networkIndicators_pre, file ="networkIndicators_pre_final.rds")# save network indicators post## save as .xlsx file xlsx::write.xlsx2(x = networkIndicators_post, file ="networkIndicators_post_final.xlsx")## save as R objectsaveRDS(networkIndicators_post, file ="networkIndicators_post_final.rds")# save CAMfiles presaveRDS(CAMfiles_pre, file ="CAMfiles_pre_final.rds")# save CAMfiles postsaveRDS(CAMfiles_post, file ="CAMfiles_post_final.rds")}
[1] "all data can be matched"
get wordlists for raters
setwd("outputs/01_dataPreperation/wordlists_raters")### add type of changeif(all(questionnaire$PROLIFIC_PID ==unique(CAMfiles_pre[[1]]$participantCAM))){}
NULL
if(all(questionnaire$PROLIFIC_PID == networkIndicators_pre$participantCAM) &all(networkIndicators_pre$participantCAM == networkIndicators_post$participantCAM)){print("all data can be matched")# save questionnaire## save as .xlsx file xlsx::write.xlsx2(x = questionnaire, file ="questionnaire_final.xlsx")## save as R objectsaveRDS(questionnaire, file ="questionnaire_final.rds")# save network indicators pre## save as .xlsx file xlsx::write.xlsx2(x = networkIndicators_pre, file ="networkIndicators_pre_final.xlsx")## save as R objectsaveRDS(networkIndicators_pre, file ="networkIndicators_pre_final.rds")# save network indicators post## save as .xlsx file xlsx::write.xlsx2(x = networkIndicators_post, file ="networkIndicators_post_final.xlsx")## save as R objectsaveRDS(networkIndicators_post, file ="networkIndicators_post_final.rds")# save CAMfiles presaveRDS(CAMfiles_pre, file ="CAMfiles_pre_final.rds")# save CAMfiles postsaveRDS(CAMfiles_post, file ="CAMfiles_post_final.rds")}