save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs")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")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
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs")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")) } }}}
analyze data
group comparisons
networkIndicators_pre$timepoint <-"pre"networkIndicators_post$timepoint <-"post"networkIndicators <-rbind(networkIndicators_pre, networkIndicators_post)######################################### show which robot was on average perceived more positive (overall data set)########################################summary(networkIndicators$mean_valence_macro[!is.na(networkIndicators$valence_micro_Rettungsroboter)])
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.59091 -0.01923 0.22065 0.13307 0.38846 0.48387
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.76923 -0.25417 -0.05757 0.02136 0.24451 1.05263
######################################### post - pre difference of robot -> average valence########################################hist(networkIndicators_post$mean_valence_macro - networkIndicators_pre$mean_valence_macro)
######################################### post - pre difference of robot -> average number of concepts########################################ggwithinstats(data = networkIndicators,x = timepoint,y = num_nodes_macro)