################# IDs who have not participated yettmp_dat <- questionnaire_t1[questionnaire_t1$country =="USA"& (questionnaire_t1$classes_conspiracy =="1"| questionnaire_t1$classes_conspiracy =="3"),]tmp_dat <- tmp_dat$PROLIFIC_PID[!tmp_dat$PROLIFIC_PID %in% questionnaire_USA$PROLIFIC_PID]write.xlsx2(x = tmp_dat, file ="outputs/PROLIFIC_PIDs_USA_notParticipated.xlsx")
compute mean variables for scales
for Germany
######################################### number of items for each scale########################################sum(str_detect(string =colnames(questionnaire_Germany), pattern ="^Biospheric"))
######################################### reverse code all items#> see negative correlation between single items######################################### items van der Linden - Biospheric Values 2015psych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^Biospheric")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="Biospheric Values scale")
# items van der Linden - Risk Perception 2015psych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^Risk")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="Risk Perception scale")
# policy items psych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^policyItems")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="policyItems scale")
# items van der Linden - concern climate changepsych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^concernClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="concern climate change scale")
# items van der Linden - how likely climate change harmfulpsych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^probabilityClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="how likely climate change harmful scale")
# items van der Linden - concern climate changepsych::cor.plot(r =cor(questionnaire_Germany[, str_detect(string =colnames(questionnaire_Germany),pattern ="^concernClimate|^probabilityClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="concern climate change plus how likely climate change harmful scale")
######################################### number of items for each scale########################################sum(str_detect(string =colnames(questionnaire_USA), pattern ="^Biospheric"))
######################################### reverse code all items#> see negative correlation between single items######################################### items van der Linden - Biospheric Values 2015psych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^Biospheric")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="Biospheric Values scale")
# items van der Linden - Risk Perception 2015psych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^Risk")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="Risk Perception scale")
# policy items psych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^policyItems")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="policyItems scale")
# items van der Linden - concern climate changepsych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^concernClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="concern climate change scale")
# items van der Linden - how likely climate change harmfulpsych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^probabilityClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="how likely climate change harmful scale")
# items van der Linden - concern climate changepsych::cor.plot(r =cor(questionnaire_USA[, str_detect(string =colnames(questionnaire_USA),pattern ="^concernClimate|^probabilityClimate")], use ="pairwise.complete.obs"),upper =FALSE, xlas =2, main ="concern climate change plus how likely climate change harmful scale")
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs")setwd("savedCAMs_Germany")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_Germany[[3]]$participantCAM.x =="noID")){ CAMfiles_Germany[[3]]$participantCAM.x <- CAMfiles_Germany[[3]]$CAM.x}### save as .json files, and as .png (igraph)ids_CAMs <-unique(CAMfiles_Germany[[3]]$participantCAM.x); length(ids_CAMs)for(i in1:length(ids_CAMs)){save_graphic(filename =paste0(ids_CAMs[i])) CAM_igraph <- CAMdrawn_Germany[[c(1:length(CAMdrawn_Germany))[names(CAMdrawn_Germany) ==paste0(unique(CAMfiles_Germany[[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_Germany)){if(!is_empty(raw_CAM_Germany[[i]]$nodes)){if(nrow(raw_CAM_Germany[[i]]$nodes) >5){write(toJSON(raw_CAM_Germany[[i]], encoding ="UTF-8"),paste0(raw_CAM_Germany[[i]]$idCAM, ".json")) } }}}
for USA
setwd("outputs")suppressMessages(read_file("CAMdata_USA.txt") %>%# ... split it into lines ...str_split('\n') %>%first() %>%# ... filter empty rows ...discard(function(x) x =='') %>%discard(function(x) x =='\r')) -> dat_CAM_USAraw_CAM_USA <-list()for(i in1:length(dat_CAM_USA)){ raw_CAM_USA[[i]] <- jsonlite::fromJSON(txt = dat_CAM_USA[[i]])}
Create CAM files, draw CAMs and compute network indicators
save_CAMs_as_pictures =FALSEif(save_CAMs_as_pictures){setwd("outputs")setwd("savedCAMs_USA")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_USA[[3]]$participantCAM.x =="noID")){ CAMfiles_USA[[3]]$participantCAM.x <- CAMfiles_USA[[3]]$CAM.x}### save as .json files, and as .png (igraph)ids_CAMs <-unique(CAMfiles_USA[[3]]$participantCAM.x); length(ids_CAMs)for(i in1:length(ids_CAMs)){save_graphic(filename =paste0(ids_CAMs[i])) CAM_igraph <- CAMdrawn_USA[[c(1:length(CAMdrawn_USA))[names(CAMdrawn_USA) ==paste0(unique(CAMfiles_USA[[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_USA)){if(!is_empty(raw_CAM_USA[[i]]$nodes)){if(nrow(raw_CAM_USA[[i]]$nodes) >5){write(toJSON(raw_CAM_USA[[i]], encoding ="UTF-8"),paste0(raw_CAM_USA[[i]]$idCAM, ".json")) } }}}
merge data
dim(questionnaire_Germany)
[1] 75 47
dim(questionnaire_USA)
[1] 49 47
## order according to variable namesquestionnaire_Germany <- questionnaire_Germany[ , order(names(questionnaire_Germany))]questionnaire_USA <- questionnaire_USA[ , order(names(questionnaire_USA))]## add CAM network indicatorsquestionnaire_CAM_Germany <-cbind(questionnaire_Germany, networkIndicators_Germany)questionnaire_CAM_Germany$country.x <-NULLquestionnaire_CAM_Germany$country.y <-NULLquestionnaire_CAM_Germany$country <-"Germany"questionnaire_CAM_USA <-cbind(questionnaire_USA, networkIndicators_USA)questionnaire_CAM_USA$country.x <-NULLquestionnaire_CAM_USA$country.y <-NULLquestionnaire_CAM_USA$country <-"USA"colnames(questionnaire_CAM_Germany)[74:77] <-colnames(questionnaire_CAM_USA)[74:77]if(all(colnames(questionnaire_CAM_Germany) ==colnames(questionnaire_CAM_USA))){print("questionnaires, CAM data sets can be merged!") questionnaireCAMs <-rbind(questionnaire_CAM_Germany, questionnaire_CAM_USA)}
[1] "questionnaires, CAM data sets can be merged!"