# sets the directory of location of this script as the current directory# setwd(dirname(rstudioapi::getSourceEditorContext()$path))### load packagesrequire(pacman)p_load('tidyverse', 'jsonlite', 'magrittr', 'xlsx','stargazer', 'psych', 'jtools', 'DT', 'ggstatsplot', 'lavaan', 'regsem', 'MplusAutomation', 'igraph')### list data filessetwd("data")folders <-list.files(pattern ="^study_result.*")### create data files### get CAM datawriteLines("", "CAMdata.txt") # create filetext_connection <-file("CAMdata.txt", "a") # open connection to append### get pre CAM datawriteLines("", "preCAM.txt") # create filetext_connection_pre <-file("preCAM.txt", "a") # open connection to append### get post CAM datawriteLines("", "postCAM.txt") # create filetext_connection_post <-file("postCAM.txt", "a") # open connection to appendfor(i in1:length(folders)){setwd(folders[i])if(length(dir()) ==3){# print(i)### CAM datasetwd(dir()[2]) tmp <- jsonlite::fromJSON(txt ="data.txt")writeLines(jsonlite::toJSON(x = tmp), text_connection)setwd("..")### pre CAM datasetwd(dir()[1]) tmp <- jsonlite::fromJSON(txt ="data.txt")writeLines(jsonlite::toJSON(x = tmp), text_connection_pre)setwd("..")### post CAM datasetwd(dir()[3]) tmp <- jsonlite::fromJSON(txt ="data.txt")writeLines(jsonlite::toJSON(x = tmp), text_connection_post)setwd("..") }setwd("..")}close(text_connection) # close connection CAMclose(text_connection_pre) # close connectionclose(text_connection_post) # close connection### move files to output folder# copy files (not overwritten)tmp_file_from <-getwd()setwd("../outputs/01_dataPreperation")file.copy(from =paste0(tmp_file_from, "/CAMdata.txt"), to =paste0(getwd(), "/CAMdata.txt"))
[1] FALSE
file.copy(from =paste0(tmp_file_from, "/preCAM.txt"), to =paste0(getwd(), "/preCAM.txt"))
[1] FALSE
file.copy(from =paste0(tmp_file_from, "/postCAM.txt"), to =paste0(getwd(), "/postCAM.txt"))
### merge all data sets# remove one missingquestionnaire_preCAM <- questionnaire_preCAM[questionnaire_preCAM$PROLIFIC_PID %in% questionnaire_postCAM$PROLIFIC_PID, ]questionnaire_postCAM$ID <-NULLquestionnaire <-left_join(questionnaire_preCAM, questionnaire_postCAM, by="PROLIFIC_PID")## all missing answers to NAquestionnaire[questionnaire ==""] <-NA## all feedback smaller than 3 characters to NAquestionnaire$feedback_critic[nchar(questionnaire$feedback_critic) <=2] <-NAdim(questionnaire)
[1] 192 41
### save files## save as .xlsx filexlsx::write.xlsx2(x = questionnaire, file ="questionnaire.xlsx")## save as R objectsaveRDS(questionnaire, file ="questionnaire.rds")
4 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))
4.1 set up CAM data
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 <-list()for(i in1:length(dat_CAM_pre)){ raw_CAM[[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] 6336
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 192 CAMs...
[1] "== participantCAM in drawnCAM"
4.1.2 save CAMs as .json files, and as .png (igraph)
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs/01_dataPreperation")setwd("savedCAMs")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[[3]]$participantCAM.x =="noID")){ CAMfiles[[3]]$participantCAM.x <- CAMfiles[[3]]$CAM.x}### save as .json files, and as .png (igraph)ids_CAMs <-unique(CAMfiles[[3]]$participantCAM.x); length(ids_CAMs)for(i in1:length(ids_CAMs)){save_graphic(filename =paste0("CAM", ids_CAMs[i])) # paste0(ids_CAMs[i])) CAM_igraph <- CAMdrawn[[c(1:length(CAMdrawn))[names(CAMdrawn) ==paste0(unique(CAMfiles[[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)){if(!is_empty(raw_CAM[[i]]$nodes)){if(nrow(raw_CAM[[i]]$nodes) >5){if(raw_CAM[[i]]$creator %in% questionnaire$PROLIFIC_PID){ # only if not deleted previouslywrite(toJSON(raw_CAM[[i]], encoding ="UTF-8"),paste0(raw_CAM[[i]]$creator, ".json")) } } }}}
## answers of participantsDT::datatable(questionnaire[,c("PROLIFIC_PID", "multiplePositive", "multipleNegative")], options =list(pageLength =5))
any basal attributes missing?
Question: Fallen Ihnen weitere Eigenschaften ein, die Sie als relevant oder negativ für die Beschreibung neuer Materialsysteme erachten, die in der Liste nicht aufgeführt sind, so können Sie diese gerne in folgenden Textfeldern ergänzen:
## answers of participantsDT::datatable(questionnaire[,c("PROLIFIC_PID", "openQuestion_missedPositive", "openQuestion_missedNegative")], options =list(pageLength =5))
5.1.4 basal attributes: ethical most relevant
Question: Welche drei Begriffe sind aus Ihrer Sicht in moralischer Hinsicht am “relevantesten”?
## answers of participantsDT::datatable(questionnaire[,c("PROLIFIC_PID", "multipleEthic")], options =list(pageLength =5))
argument for choosen basal attributes
Question: Bitte begründen Sie kurz die Auswahl der ethisch relevanten Begriffe:
## answers of participantsDT::datatable(questionnaire[,c("PROLIFIC_PID", "openQuestion_Ethic")], options =list(pageLength =5))
5.1.5 outcome questions
Question: Sollte die Entwicklung innovativer Materialsysteme mit öffentlichen Mitteln gefördert werden?
table(questionnaire$outcome_research)
no unsure yes
4 32 156
Question: Sollten die Erforschung und Entwicklung solcher innovativer Materialsysteme verboten werden?
table(questionnaire$outcome_prohibition)
no unsure yes
182 7 3
Question: Wären Sie bereit, Produkte zu kaufen, die innovative Materialsysteme enthalten?
table(questionnaire$outcome_buy)
no unsure yes
2 85 105
if yes to previous question
Question: An welche möglichen Produkte haben Sie gedacht?
## answers of participantsDT::datatable(questionnaire[,c("PROLIFIC_PID", "outcome_buy_text")], options =list(pageLength =5))
5.2 co-variation of basal attributes
Compare the probability that two concepts are connected in randomly generated networks to drawn CAMs:
## get average number of drawn concepts (here fixed)numConcepts <-mean(networkIndicators$num_nodes_macro)## get average densitynumDensity <-mean(networkIndicators$density_macro)## simply get the average probability that two concepts are connected:g <- igraph::random.graph.game(n = numConcepts, p.or.m = numDensity)plot(g)
are.connected(g, 1, 2)
[1] FALSE
#> whereby each edge to be drawn has the identical probability in the Erdős–Rényi modelvec_booleanConnected <-c()# vec_booleanConnected2 <- c()for(i in1:10000){ g <- igraph::random.graph.game(n = numConcepts, p.or.m = numDensity) vec_booleanConnected[i] <-are.connected(g, 1, 2)# vec_booleanConnected2[i] <- are.connected(g, 22, 26)}baselineProbability <-mean(vec_booleanConnected)baselineProbability
[1] 0.0387
# mean(vec_booleanConnected2)
This baseline probability can be compared to all possible combinations of drawn concepts: