Translate data, save CAMs, fix ID matching

Author

Julius Fenn, Eva Buschmeyer

Notes

Remark:

## global variables
consider_Protocol = TRUE
save_CAMs_as_pictures = FALSE

prepare raw data

load packages, raw data, functions

# sets the directory of location of this script as the current directory
# setwd(dirname(rstudioapi::getSourceEditorContext()$path))

########################################
# load packages
########################################
require(pacman)
p_load('tidyverse', 'jsonlite', 'magrittr', 'xlsx',
       'stargazer', 'psych', 'jtools', 'DT', 'ggstatsplot', 
       'lavaan', 
       'regsem', 'MplusAutomation', 'igraph',
       'vroom')


########################################
# load data files
########################################
setwd("data")
# dir()


### load CAM files
# German
suppressMessages(read_file("CAM Data - German.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_German

raw_CAM_German <- list()
for(i in 1:length(dat_CAM_German)){
  raw_CAM_German[[i]] <- jsonlite::fromJSON(txt = dat_CAM_German[[i]])
}
rm(dat_CAM_German)


# English
suppressMessages(read_file("CAM Data - English.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_English

raw_CAM_English <- list()
for(i in 1:length(dat_CAM_English)){
  raw_CAM_English[[i]] <- jsonlite::fromJSON(txt = dat_CAM_English[[i]])
}
rm(dat_CAM_English)


## load file for manually overwriting words
translatedWords <- xlsx::read.xlsx2(file = "wordlistOverall_05.04..xlsx", sheetIndex = 1)

########################################
# load functions
########################################
# print(getwd())
setwd("../functions")
for(i in 1:length(dir())){
  # print(dir()[i])
  source(dir()[i], encoding = "utf-8")
}


setwd("../functions_CAMapp")
for(i in 1:length(dir())){
  # print(dir()[i])
  source(dir()[i], encoding = "utf-8")
}
rm(i)

set up CAM data

CAMs have no ID

# German
for(i in 1:length(raw_CAM_German)){
  print(raw_CAM_German[[i]]$creator)
}
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
# English
for(i in 1:length(raw_CAM_English)){
  print(raw_CAM_English[[i]]$creator)
}
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"
[1] "noID"

set up CAM data German

Create CAM files, draw CAMs and compute network indicators

### create CAM single files (nodes, connectors, merged)
CAMfiles_German <- create_CAMfiles(datCAM = raw_CAM_German, reDeleted = TRUE)
Nodes and connectors, which were deleted by participants were removed. 
 # deleted nodes:  84 
 # deleted connectors:  42
if(consider_Protocol){
  setwd("data")

  text <- readLines("protocol_P01.1G Pre-Processing 20240405_0958 - German.txt", warn = FALSE)
  text <- readLines(textConnection(text, encoding="UTF-8"), encoding="UTF-8")

  if (testIfJson(file = text)) {
    protocol <- rjson::fromJSON(file = "protocol_P01.1G Pre-Processing 20240405_0958 - German.txt")
  
    ## no CAM deleted  
  CAMfiles_German[[1]] <- CAMfiles_German[[1]][CAMfiles_German[[1]]$CAM %in% protocol$currentCAMs,]
  CAMfiles_German[[2]] <- CAMfiles_German[[2]][CAMfiles_German[[2]]$CAM %in% protocol$currentCAMs,]
  CAMfiles_German[[3]] <- CAMfiles_German[[3]][CAMfiles_German[[3]]$CAM.x %in% protocol$currentCAMs,]

  tmp_out <- overwriteTextNodes(protocolDat = protocol,
                                nodesDat = CAMfiles_German[[1]])
  CAMfiles_German[[1]] <- tmp_out[[1]]
  # tmp_out[[2]]
  
  } else{
    print("Invalid protocol uploaded")
  }
}

time 2024-04-05 09:50:58.552522 at index 1 for approximate matching 
time 2024-04-05 09:51:02.169794 at index 2 for approximate matching 
time 2024-04-05 09:51:10.284589 at index 3 for approximate matching 
time 2024-04-05 09:51:19.970006 at index 4 for approximate matching 
time 2024-04-05 09:51:22.299849 at index 5 for approximate matching 
time 2024-04-05 09:51:41.43053 at index 6 for approximate matching 
time 2024-04-05 09:52:18.784777 at index 7 for approximate matching 
time 2024-04-05 09:56:07.494694 at index 8 for search terms 
# remove empty concepts:
CAMfiles_German[[1]]$text[nchar(CAMfiles_German[[1]]$text) < 2]
[1] ""
tmp_ids <- CAMfiles_German[[1]]$id[nchar(CAMfiles_German[[1]]$text) < 2]
table(CAMfiles_German[[1]]$isActive[CAMfiles_German[[1]]$id %in% tmp_ids])

TRUE 
   1 
CAMfiles_German[[1]] <- CAMfiles_German[[1]][!CAMfiles_German[[1]]$id %in% tmp_ids,]






### draw CAMs
CAMdrawn_German <- draw_CAM(dat_merged = CAMfiles_German[[3]],
                     dat_nodes = CAMfiles_German[[1]],ids_CAMs = "all",
                     plot_CAM = FALSE,
                     useCoordinates = TRUE,
                     relvertexsize = 3,
                     reledgesize = 1)
processing 19 CAMs... 
Warning: `graph.data.frame()` was deprecated in igraph 2.0.0.
ℹ Please use `graph_from_data_frame()` instead.
[1] "== ids_CAMs in drawnCAM"
## check for non reasonable words
for(i in 1:length(CAMdrawn_German)){
  if(any(nchar(V(CAMdrawn_German[[i]])$label) < 3)){
    print(V(CAMdrawn_German[[i]])$label)
  }
}

### network indicators
tmp_microIndicator <- NULL # no pre-defined concepts
networkIndicators_German <- compute_indicatorsCAM(drawn_CAM = CAMdrawn_German, 
                                           micro_degree = tmp_microIndicator, 
                                           micro_valence = tmp_microIndicator, 
                                           micro_centr_clo = tmp_microIndicator, 
                                           micro_transitivity = tmp_microIndicator, 
                                           largestClique = FALSE)
Warning: `graph.density()` was deprecated in igraph 2.0.0.
ℹ Please use `edge_density()` instead.
Warning: The `types1` argument of `assortativity()` is deprecated as of igraph 1.6.0.
ℹ Please use the `values` argument instead.
Warning: `assortativity.degree()` was deprecated in igraph 2.0.0.
ℹ Please use `assortativity_degree()` instead.
## check for CAMs who have not changed valence
tmp_ids <- networkIndicators_German$CAM_ID[is.na(networkIndicators_German$assortativity_valence_macro)]
for(i in tmp_ids){
    plot(CAMdrawn_German[[i]], edge.arrow.size = .7,
       layout=layout_nicely, vertex.frame.color="black", asp = .5, margin = -0.1,
       vertex.size = 10, vertex.label.cex = .9)
}

### wordlist
CAMwordlist_German <- create_wordlist(
  dat_nodes =  CAMfiles_German[[1]],
  dat_merged =  CAMfiles_German[[3]],
  useSummarized = TRUE,
  order = "frequency",
  splitByValence = FALSE,
  comments = TRUE,
  raterSubsetWords = NULL,
  rater = FALSE
)
[1] "create_wordlist - use summarized words"
[1] 26
[1] 339
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 19 CAMs... 
[1] "== ids_CAMs in drawnCAM"
DT::datatable(CAMwordlist_German, options = list(pageLength = 5)) 

save CAMs as .json files, and as .png (igraph)

if(save_CAMs_as_pictures){
setwd("outputs")

setwd("savedCAMs_German")
setwd("png")
### remove all files if there are any
if(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 ID

if(all(CAMfiles_German[[3]]$participantCAM.x == "noID")){
  CAMfiles_German[[3]]$participantCAM.x <- CAMfiles_German[[3]]$CAM.x
}

### save as .json files, and as .png (igraph)
ids_CAMs <- unique(CAMfiles_German[[3]]$participantCAM.x); length(ids_CAMs)


for(i in 1:length(ids_CAMs)){
  save_graphic(filename = paste0("CAM", "_t1_", ids_CAMs[i])) #  paste0(ids_CAMs[i]))
  CAM_igraph <- CAMdrawn_German[[c(1:length(CAMdrawn_German))[
    names(CAMdrawn_German) == paste0(unique(CAMfiles_German[[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 any
if(length(list.files()) >= 1){
  file.remove(list.files())
  cat('\n!
      all former .json files have been deleted')
}
for(i in 1:length(raw_CAM_German)){
  if(!is_empty(raw_CAM_German[[i]]$nodes)){
    if(nrow(raw_CAM_German[[i]]$nodes) > 5){
      write(toJSON(raw_CAM_German[[i]], encoding = "UTF-8"),
            paste0(raw_CAM_German[[i]]$idCAM, ".json"))
    }
  }
}
}

set up CAM data English

Create CAM files, draw CAMs and compute network indicators

### create CAM single files (nodes, connectors, merged)
CAMfiles_English <- create_CAMfiles(datCAM = raw_CAM_English, reDeleted = TRUE)
Nodes and connectors, which were deleted by participants were removed. 
 # deleted nodes:  15 
 # deleted connectors:  10
if(consider_Protocol){
  setwd("data")

  text <- readLines("protocol_P01.1E Pre-Processing 20240405_1018 - English.txt", warn = FALSE)
  text <- readLines(textConnection(text, encoding="UTF-8"), encoding="UTF-8")

  if (testIfJson(file = text)) {
    protocol <- rjson::fromJSON(file = "protocol_P01.1E Pre-Processing 20240405_1018 - English.txt")
  
    ## no CAM deleted  
  CAMfiles_English[[1]] <- CAMfiles_English[[1]][CAMfiles_English[[1]]$CAM %in% protocol$currentCAMs,]
  CAMfiles_English[[2]] <- CAMfiles_English[[2]][CAMfiles_English[[2]]$CAM %in% protocol$currentCAMs,]
  CAMfiles_English[[3]] <- CAMfiles_English[[3]][CAMfiles_English[[3]]$CAM.x %in% protocol$currentCAMs,]

  tmp_out <- overwriteTextNodes(protocolDat = protocol,
                                nodesDat = CAMfiles_English[[1]])
  CAMfiles_English[[1]] <- tmp_out[[1]]
  # tmp_out[[2]]
  
  } else{
    print("Invalid protocol uploaded")
  }
}

time 2024-04-05 10:07:57.876021 at index 1 for approximate matching 
time 2024-04-05 10:08:00.246115 at index 2 for approximate matching 
time 2024-04-05 10:08:03.237472 at index 3 for approximate matching 
time 2024-04-05 10:08:07.927706 at index 4 for approximate matching 
time 2024-04-05 10:08:12.808653 at index 5 for approximate matching 
time 2024-04-05 10:08:25.279709 at index 6 for approximate matching 
time 2024-04-05 10:08:35.581476 at index 7 for approximate matching 
time 2024-04-05 10:08:48.259832 at index 8 for approximate matching 
time 2024-04-05 10:09:17.09741 at index 9 for approximate matching 
time 2024-04-05 10:10:09.556336 at index 10 for approximate matching 
time 2024-04-05 10:10:18.656436 at index 11 for approximate matching 
time 2024-04-05 10:10:26.440809 at index 12 for approximate matching 
time 2024-04-05 10:10:31.979511 at index 13 for approximate matching 
time 2024-04-05 10:10:44.914415 at index 14 for approximate matching 
time 2024-04-05 10:10:48.411073 at index 15 for approximate matching 
time 2024-04-05 10:11:36.862477 at index 16 for approximate matching 
time 2024-04-05 10:13:16.610944 at index 17 for search terms 
time 2024-04-05 10:15:13.9348 at index 18 for search terms 
time 2024-04-05 10:16:34.884557 at index 19 for search terms 
# remove empty concepts:
CAMfiles_English[[1]]$text[nchar(CAMfiles_English[[1]]$text) < 2]
character(0)
tmp_ids <- CAMfiles_English[[1]]$id[nchar(CAMfiles_English[[1]]$text) < 2]
table(CAMfiles_English[[1]]$isActive[CAMfiles_English[[1]]$id %in% tmp_ids])
< table of extent 0 >
# CAMfiles_English[[1]] <- CAMfiles_English[[1]][!CAMfiles_English[[1]]$id %in% tmp_ids,]


### draw CAMs
CAMdrawn_English <- draw_CAM(dat_merged = CAMfiles_English[[3]],
                     dat_nodes = CAMfiles_English[[1]],ids_CAMs = "all",
                     plot_CAM = FALSE,
                     useCoordinates = TRUE,
                     relvertexsize = 3,
                     reledgesize = 1)
processing 11 CAMs... 
[1] "== ids_CAMs in drawnCAM"
## check for non reasonable words
for(i in 1:length(CAMdrawn_English)){
  if(any(nchar(V(CAMdrawn_English[[i]])$label) < 3)){
    print(V(CAMdrawn_English[[i]])$label)
  }
}

### network indicators
tmp_microIndicator <- NULL # no pre-defined concepts
networkIndicators_English <- compute_indicatorsCAM(drawn_CAM = CAMdrawn_English, 
                                           micro_degree = tmp_microIndicator, 
                                           micro_valence = tmp_microIndicator, 
                                           micro_centr_clo = tmp_microIndicator, 
                                           micro_transitivity = tmp_microIndicator, 
                                           largestClique = FALSE)


## check for CAMs who have not changed valence
tmp_ids <- networkIndicators_English$CAM_ID[is.na(networkIndicators_English$assortativity_valence_macro)]
for(i in tmp_ids){
    plot(CAMdrawn_English[[i]], edge.arrow.size = .7,
       layout=layout_nicely, vertex.frame.color="black", asp = .5, margin = -0.1,
       vertex.size = 10, vertex.label.cex = .9)
}

### wordlist
CAMwordlist_English <- create_wordlist(
  dat_nodes =  CAMfiles_English[[1]],
  dat_merged =  CAMfiles_English[[3]],
  useSummarized = TRUE,
  order = "frequency",
  splitByValence = FALSE,
  comments = TRUE,
  raterSubsetWords = NULL,
  rater = FALSE
)
[1] "create_wordlist - use summarized words"
[1] 37
[1] 160
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 11 CAMs... 
[1] "== ids_CAMs in drawnCAM"
DT::datatable(CAMwordlist_English, options = list(pageLength = 5)) 

save CAMs as .json files, and as .png (igraph)

if(save_CAMs_as_pictures){
setwd("outputs")

setwd("savedCAMs_English")
setwd("png")
### remove all files if there are any
if(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 ID

if(all(CAMfiles_English[[3]]$participantCAM.x == "noID")){
  CAMfiles_English[[3]]$participantCAM.x <- CAMfiles_English[[3]]$CAM.x
}

### save as .json files, and as .png (igraph)
ids_CAMs <- unique(CAMfiles_English[[3]]$participantCAM.x); length(ids_CAMs)


for(i in 1:length(ids_CAMs)){
  save_graphic(filename = paste0("CAM", "_t1_", ids_CAMs[i])) #  paste0(ids_CAMs[i]))
  CAM_igraph <- CAMdrawn_English[[c(1:length(CAMdrawn_English))[
    names(CAMdrawn_English) == paste0(unique(CAMfiles_English[[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 any
if(length(list.files()) >= 1){
  file.remove(list.files())
  cat('\n!
      all former .json files have been deleted')
}
for(i in 1:length(raw_CAM_English)){
  if(!is_empty(raw_CAM_English[[i]]$nodes)){
    if(nrow(raw_CAM_English[[i]]$nodes) > 5){
      write(toJSON(raw_CAM_English[[i]], encoding = "UTF-8"),
            paste0(raw_CAM_English[[i]]$idCAM, ".json"))
    }
  }
}
}

translate German CAMs to English

raw_CAM_Germany_translated_raw <- raw_CAM_German
CAMfiles_Germany_translated <- CAMfiles_German

raw_CAM_Germany_translated <- list()
h = 1
## keep only non deleted CAMs
for(i in 1:length(raw_CAM_Germany_translated_raw)){
  if(raw_CAM_Germany_translated_raw[[i]]$idCAM %in% CAMfiles_Germany_translated[[1]]$CAM){
    raw_CAM_Germany_translated[[h]] <- raw_CAM_Germany_translated_raw[[i]]
    h = h + 1
  }else{
    print(raw_CAM_Germany_translated_raw[[i]]$nodes$text)
  }
}
[1] "gsd"    "dsfg"   "gfsdf"  "dfsg"   "gsd"    "sfgd"   "gas"    "fdggsf"
[9] ""      
[1] "afsad"  "fa"     "dsf"    "trzerz" "Erz"    "Tür"    "rtzert" "Sofas" 
[1] "dfdsa"   "asd"     "asd"     "afdasdf" "pdf"     "sdaf"    "dfs"    
[8] "fs"     
rm(raw_CAM_Germany_translated_raw)



# translatedWords$Finale.Übersetzung - target variable
DT::datatable(translatedWords, options = list(pageLength = 5))

Overwrite German words to the corresponding English ones

for(i in 1:length(raw_CAM_Germany_translated)) {
  ## get summarized words
  tmp_nodes <-
    CAMfiles_Germany_translated[[1]][CAMfiles_Germany_translated[[1]]$CAM == unique(CAMfiles_Germany_translated[[1]]$CAM)[i], ]
  
  tmpWords_summarized <- tmp_nodes$text
    tmpWords_summarized <-
    str_trim(string = tmpWords_summarized, side = "both")
  # wordlist is not based on summarized words !!!
  # tmpWords_summarized <- str_remove_all(string = tmp_nodes$text_summarized, pattern = "_positive$|_negative$|_neutral$|_ambivalent$")
  
  ## take summarized words
  if (length(tmpWords_summarized) != sum(raw_CAM_Germany_translated[[i]]$nodes$isActive)) {
    print(i)
    # print("ERROR") # removed single concept
    # break
  } else{
    # wordlist is not based on summarized words !!!
    # raw_CAM_Germany_translated[[i]]$nodes$text[raw_CAM_Germany_translated[[i]]$nodes$isActive] <- tmpWords_summarized
  }
  
  ## remove white spaces
  raw_CAM_Germany_translated[[i]]$nodes$text <-
    str_trim(string = raw_CAM_Germany_translated[[i]]$nodes$text, side = "both")
  
  
  tmp <-
    raw_CAM_Germany_translated[[i]]$nodes$text[raw_CAM_Germany_translated[[i]]$nodes$isActive &
                                                 !raw_CAM_Germany_translated[[i]]$nodes$text %in% translatedWords$Finale.Übersetzung]
  # print(tmp)
  
  if (length(tmp) == 0) {
    print(i)
    print("no words founds")
    break
  } else{
    for (j in 1:length(tmpWords_summarized)) {
      cat(
        "\n >>>i:",
        i,
        "j:  ",
        j,
        raw_CAM_Germany_translated[[i]]$nodes$text[raw_CAM_Germany_translated[[i]]$nodes$isActive][j],
        "to",
        translatedWords$Finale.Übersetzung[translatedWords$Words %in% tmpWords_summarized[j]],
        "\n"
      )
      
      raw_CAM_Germany_translated[[i]]$nodes$text[raw_CAM_Germany_translated[[i]]$nodes$isActive][j] <- translatedWords$Finale.Übersetzung[translatedWords$Words %in% tmpWords_summarized[j]]
    }
  }
}

 >>>i: 1 j:   1 Krank sein to Being ill 

 >>>i: 1 j:   2 Was hilft to What helps 

 >>>i: 1 j:   3 Sensibilisieren to sensitise 

 >>>i: 1 j:   4 Eigeninitiative to Own initiative 

 >>>i: 1 j:   5 Grundwissen über Gesundheitssystem to Basic knowledge about healthcare system 

 >>>i: 1 j:   6 MIgrationshintergrund to Migration background 

 >>>i: 1 j:   7 Depression to Depression 

 >>>i: 1 j:   8 Gleichgültigkeit to Indifference 

 >>>i: 2 j:   1 Arten von Hilfe to Types of help 

 >>>i: 2 j:   2 Ärztliche Behandlung to Medical treatment 

 >>>i: 2 j:   3 Freunde an der to Friends at the 

 >>>i: 2 j:   4 Krankenversicherung to health insurance coverage 

 >>>i: 2 j:   5 Sprachbarriere to Language barrier 

 >>>i: 2 j:   6 Keine Freunde to No friends 

 >>>i: 2 j:   7 Familie to Family 

 >>>i: 2 j:   8 Finanziel nicht möglich to Financially not possible 

 >>>i: 2 j:   9 Unterstützung bei der to Support with 

 >>>i: 2 j:   10 Unterstützung im Alltag to Support in everyday life 

 >>>i: 2 j:   11 Unkenntnis des Gesundheitssystems to Ignorance of the healthcare system 

 >>>i: 2 j:   12 Bürokratische Hürden to Bureaucratic hurdles 

 >>>i: 2 j:   13 Kulturelle Unterschiede to Cultural differences 

 >>>i: 3 j:   1 Erste ärztliche Konsultation to First medical consultation 

 >>>i: 3 j:   2 Telefonisch schlecht verfügbar to Poor availability by phone 

 >>>i: 3 j:   3 Auf Termin warten to Waiting for an appointment 

 >>>i: 3 j:   4 Behandlung in Praxis to Treatment in practice 

 >>>i: 3 j:   5 Somatische Symptome to Somatic symptoms 

 >>>i: 3 j:   6 Guten Arzt finden to Find a good doctor 

 >>>i: 3 j:   7 Zusatzkosten to Additional costs 

 >>>i: 3 j:   8 Psychische Symptome to Mental symptoms 

 >>>i: 3 j:   9 Nach Psychotherapeuten suchen to Looking for psychotherapists 

 >>>i: 3 j:   10 Bahdnlung in Praxis to Treatment in practice 

 >>>i: 3 j:   11 Mit Freunden sprechen to Talk to friends 

 >>>i: 3 j:   12 Ärzte im Bekanntenkreis to Doctors in the circle of acquaintances 

 >>>i: 3 j:   13 Locker & Unterschwellig to Easy-going & subliminal 

 >>>i: 3 j:   14 Familiäre Unterstützung to Family support 

 >>>i: 3 j:   15 Nicht immer möglich to Not always possible 

 >>>i: 3 j:   16 Commitment to Commitment 

 >>>i: 3 j:   17 Eigene Kenntnisse Recherche to Own knowledge Research 

 >>>i: 3 j:   18 Ungesundes Coping to Unhealthy coping 

 >>>i: 3 j:   19 Übertriebene Leistung Arbeit to Exaggerated performance Work 

 >>>i: 4 j:   1 Hilfe von Arzt to Help from doctor 

 >>>i: 4 j:   2 Hilfe von Psychologist to Help from psychologist 

 >>>i: 4 j:   3 Medizinische Hilfsmittel to Medical aids 

 >>>i: 4 j:   4 Hilfe von Freunden to Help from friends 

 >>>i: 4 j:   5 Physiotherapeut to Physiotherapist 

 >>>i: 4 j:   6 Operation to Surgery 

 >>>i: 4 j:   7 Stationierung to Stationing 

 >>>i: 4 j:   8 Selbsthilfe to Self-help 

 >>>i: 4 j:   9 Untersuchung to Examination 

 >>>i: 4 j:   10 Arten von Hilfe to Types of help 

 >>>i: 4 j:   11 keine Termine to No appointments 

 >>>i: 4 j:   12 nicht genug Ärzte to Not enough doctors 

 >>>i: 4 j:   13 Diskriminierung to Discrimination 

 >>>i: 4 j:   14 falsche Diagnose to Wrong diagnosis 

 >>>i: 4 j:   15 Anerkennung des Ärztediploms to Recognition of medical diploma 

 >>>i: 4 j:   16 Sprachbarriere to Language barrier 

 >>>i: 4 j:   17 teuer to Expensive 

 >>>i: 4 j:   18 Krankenkassen to health insurance companies 

 >>>i: 4 j:   19 dringend Hilfe to urgent help 

 >>>i: 4 j:   20 Qualität der Hilfe to Quality of help 

 >>>i: 4 j:   21 keine deutsche Freunde to No German friends 

 >>>i: 4 j:   22 Bürokratie to Bureaucracy 

 >>>i: 4 j:   23 Schwierigkeiten und Probleme to Difficulties and problems 

 >>>i: 5 j:   1 Reden to Talk 

 >>>i: 5 j:   2 Hilfe suchen to Seeking help 

 >>>i: 5 j:   3 Unterstützung to Support 

 >>>i: 5 j:   4 Hilfe to Help 

 >>>i: 5 j:   5 Die Sprache to The language 

 >>>i: 5 j:   6 Fehlende Mittel to Lack of resources 

 >>>i: 5 j:   7 mangelnde soziale Unterstützung to Lack of social support 

 >>>i: 5 j:   8 Überforderung to exsessive demands 

 >>>i: 5 j:   9 Ahnungslosigkeit to Cluelessness 

 >>>i: 5 j:   10 Erleichterung to Relief 

 >>>i: 6 j:   1 psychische Hilfe to mental help 

 >>>i: 6 j:   2 körperliche Hilfe to Physical help 

 >>>i: 6 j:   3 Stress to Stress 

 >>>i: 6 j:   4 Kopfschmerzen to Headaches 

 >>>i: 6 j:   5 Terminvereinbarung schwierig to Difficult to make appointment 

 >>>i: 6 j:   6 wenig Termine to Few appointments 

 >>>i: 6 j:   7 keine Neuaufnahme Patienten to No new patient admission 

 >>>i: 6 j:   8 lange Wartezeiten to Long waiting times 

 >>>i: 6 j:   9 Gesundheitsversorgung Ukraine to Healthcare in Ukraine 

 >>>i: 6 j:   10 keine lange Wartezeit to No long waiting time 

 >>>i: 6 j:   11 bessere Medizin to Better medicine 

 >>>i: 6 j:   12 Sport to Sport 

 >>>i: 6 j:   13 Schlafen to Sleeping 

 >>>i: 6 j:   14 > 9 Stunden to > 9 hours 

 >>>i: 6 j:   15 < 7 Stunden to < 7 hours 

 >>>i: 6 j:   16 leckeres& gesundes Essen to Delicious & healthy food 

 >>>i: 6 j:   17 im Bett bleiben to Stay in bed 

 >>>i: 6 j:   18 genug Wasser trinken to Drink enough water 

 >>>i: 7 j:   1 Medikamente to Medication 

 >>>i: 7 j:   2 richtige Diagnose to Correct diagnosis 

 >>>i: 7 j:   3 Kurs in Parapsychologie to Course in parapsychology 

 >>>i: 7 j:   4 Verstehen der Diagnose to Understanding the diagnosis 

 >>>i: 7 j:   5 mit Energien arbeiten to Work with energies 

 >>>i: 7 j:   6 30Jahre keine Medikamente to 30 years no medication 

 >>>i: 7 j:   7 Operation to Surgery 

 >>>i: 7 j:   8 Diagnose in Ukraine to Diagnosis in Ukraine 

 >>>i: 7 j:   9 das hilft to That helps 

 >>>i: 7 j:   10 Termin nach 1Tag to Appointment after 1 day 

 >>>i: 7 j:   11 Helfen im Kulturzentrum to Helping at the cultural center 

 >>>i: 7 j:   12 Arzt Deutschland to Doctor Germany 

 >>>i: 7 j:   13 Reiki to Reiki 

 >>>i: 7 j:   14 Esoterik to Esotericism 

 >>>i: 7 j:   15 Buch Grigori grabovoi to Book by Grigori Grabovoi 

 >>>i: 7 j:   16 häufig lange Wartezeiten to Often long waiting times 

 >>>i: 7 j:   17 Zahnprothese zu teuer to Dentures too expensive 

 >>>i: 7 j:   18 höhere Qualität Deutschland to higher quality Germany 

 >>>i: 7 j:   19 Eigenanteil to Own contribution 

 >>>i: 8 j:   1 keine Arbeit to no work 

 >>>i: 8 j:   2 Stolz von Ehemann to Pride of husband 

 >>>i: 8 j:   3 kein Geld to No money 

 >>>i: 8 j:   4 Sorgen um Mann to Concerns about husband 

 >>>i: 8 j:   5 Konflikt in Beziehung to Conflict in relationship 

 >>>i: 8 j:   6 nicht gut Schlafen to Not sleeping well 

 >>>i: 8 j:   7 immer Nachweis notwendig to always proof necessary 

 >>>i: 8 j:   8 keine Kommunikation Partner to No partner communication 

 >>>i: 8 j:   9 Bürokratie to Bureaucracy 

 >>>i: 8 j:   10 keine Hilfe to No help 

 >>>i: 8 j:   11 viele Minijobs grade to Many minijobs currently 

 >>>i: 8 j:   12 kein Drucker zuhause to No printer at home 

 >>>i: 8 j:   13 Yoga to Yoga 

 >>>i: 8 j:   14 Sport to Sport 

 >>>i: 8 j:   15 drüber reden to Talk about it 

 >>>i: 8 j:   16 Spazieren to Walking 

 >>>i: 8 j:   17 Schlaftee trinken to Drinking sleep tea 

 >>>i: 8 j:   18 Medikamente to Medication 

 >>>i: 8 j:   19 Flüchtlinge wissen nicht to Refugees don't know 

 >>>i: 8 j:   20 Informationen to Information 

 >>>i: 8 j:   21 Sachen die helfen to Things that help 

 >>>i: 9 j:   1 Deutsch lernen to Learning German 

 >>>i: 9 j:   2 gute Arbeit to Good work 

 >>>i: 9 j:   3 Arzt to Doctor 

 >>>i: 9 j:   4 Sport to Sport 

 >>>i: 9 j:   5 das hilft to That helps 

 >>>i: 9 j:   6 Spazieren gehen to Going for a walk 

 >>>i: 9 j:   7 wenig Zeit to Little time 

 >>>i: 9 j:   8 Hilfe durch Bekannte to Help from acquaintances 

 >>>i: 9 j:   9 Projekte to Projects 

 >>>i: 9 j:   10 lange Wartezeit to Long waiting time 

 >>>i: 9 j:   11 Internet to Internet 

 >>>i: 9 j:   12 kein Kontakt Deutsche to No contact with Germans 

 >>>i: 9 j:   13 schwierig to Difficult 

 >>>i: 9 j:   14 Heimweh to Homesickness 

 >>>i: 9 j:   15 neue Kultur to New culture 

 >>>i: 9 j:   16 andere Sprache to different language 

 >>>i: 10 j:   1 Arzt to Doctor 

 >>>i: 10 j:   2 man kann planen to You can plan 

 >>>i: 10 j:   3 Termin vereinbaren to Make an appointment 

 >>>i: 10 j:   4 Bürokratie to Bureaucracy 

 >>>i: 10 j:   5 Gundelfingen to Gundelfingen  

 >>>i: 10 j:   6 Leute helfen uns to People help us 

 >>>i: 10 j:   7 Leute sind nett to People are nice 

 >>>i: 10 j:   8 Sozialgarten to Social garden 

 >>>i: 10 j:   9 Wohnung to Apartment 

 >>>i: 10 j:   10 Natur to Nature 

 >>>i: 10 j:   11 Arbeiten in Fahrradwerkstatt to Working in a bicycle repair shop 

 >>>i: 10 j:   12 nur Deutsch lernen to only learn German 

 >>>i: 10 j:   13 für alteLeute schwer to difficult for old people 

 >>>i: 10 j:   14 Leute sehr nett to People very nice 

 >>>i: 11 j:   1 beim Hausarzt anrufen to Calling the GP 

 >>>i: 11 j:   2 Krankenversicherung & Krankenkasse to Health insurance coverage & health insurance company 

 >>>i: 11 j:   3 Geld von Krankenkasse to Money from health insurance 

 >>>i: 11 j:   4 Sport to Sport 

 >>>i: 11 j:   5 Therapie to Therapy 

 >>>i: 11 j:   6 viele Menschen treffen to Meet many people 

 >>>i: 11 j:   7 Yoga machen to Doing yoga 

 >>>i: 11 j:   8 Stress am Arbeitsplatz to Stress at work 

 >>>i: 11 j:   9 keine Lust arbeiten to No desire to work 

 >>>i: 11 j:   10 Beziehung zu Partnerin to Relationship with partner 

 >>>i: 11 j:   11 ohne Versicherung to Without insurance 

 >>>i: 11 j:   12 gesund Essen to Eat healthily 

 >>>i: 11 j:   13 viel Wasser trinken to Drink a lot of water 

 >>>i: 12 j:   1 Krankenhaus to Hospital 

 >>>i: 12 j:   2 körperliche Schwierigkeit to Physical difficulty 

 >>>i: 12 j:   3 psychische Schwierigkeit to Mental health difficulties 

 >>>i: 12 j:   4 Apotheke to Pharmacy 

 >>>i: 12 j:   5 Arzt to Doctor 

 >>>i: 12 j:   6 Eltern to Parents 

 >>>i: 12 j:   7 Freunde to Friends 

 >>>i: 12 j:   8 Ehefrau to Wife 

 >>>i: 12 j:   9 Verwandte to Relatives 

 >>>i: 12 j:   10 Eltern streiten untereinander to Parents argue among themselves 

 >>>i: 12 j:   11 lange Wartezeit to Long waiting time 

 >>>i: 12 j:   12 wenig Geduld to Little patience 

 >>>i: 12 j:   13 nicht qualifizierter Arzt to not qualified doctor 

 >>>i: 12 j:   14 wenig Behandlungszeit to Little treatment time 

 >>>i: 12 j:   15 fühle mich nichtgut to Don't feel good 

 >>>i: 13 j:   1 Sprachcafé Stadtbücherei to Language café in City library 

 >>>i: 13 j:   2 neue Leute kennenlernen to Meet new people 

 >>>i: 13 j:   3 Reden über Frauenrechte to Talking about women's rights 

 >>>i: 13 j:   4 Freiheit to Freedom 

 >>>i: 13 j:   5 Heimweh to Homesickness 

 >>>i: 13 j:   6 manchmal einsam to Sometimes lonely 

 >>>i: 13 j:   7 Deutsch lernen schwierig to Learning German difficult 

 >>>i: 13 j:   8 alte Leute Dialekt to Old people dialect 

 >>>i: 13 j:   9 Menschen ansprechen to Approach people 

 >>>i: 13 j:   10 Minijob einfach to Mini job simple 

 >>>i: 13 j:   11 Arbeitslos to Unemployed 

 >>>i: 13 j:   12 Diplom nicht anerkannt to Diploma not recognized 

 >>>i: 13 j:   13 traurig to Sad 

 >>>i: 13 j:   14 Freunde vermissen to Miss friends 

 >>>i: 13 j:   15 Kultur sehr anders to Culture very different 

 >>>i: 13 j:   16 Schwierigkeiten to Difficulties 

 >>>i: 13 j:   17 Aufgewachsen im Krieg to Growing up in war 

 >>>i: 13 j:   18 Traumata to traumas 

 >>>i: 13 j:   19 das hilft to That helps 

 >>>i: 13 j:   20 passende Arbeit to Suitable work 

 >>>i: 13 j:   21 Abhängig von Partnerin to Dependent on partner 

 >>>i: 13 j:   22 Trennung von Partnerin to Separation from partner 

 >>>i: 13 j:   23 emotionslos to Emotionless 

 >>>i: 13 j:   24 Sport to Sport 

 >>>i: 13 j:   25 Statusverlust to Loss of status 

 >>>i: 13 j:   26 Psychotherapie to Psychotherapy 

 >>>i: 13 j:   27 keine Kommunikation Familie to No family communication 

 >>>i: 13 j:   28 keine Psychotherapie Muttersprache to No psychotherapy in native language 

 >>>i: 14 j:   1 psychisch to psychic 

 >>>i: 14 j:   2 Eltern in Deutschland to Parents in Germany 

 >>>i: 14 j:   3 Ehemann traurig to Husband sad 

 >>>i: 14 j:   4 Verwandte in Syrien to Relatives in Syria 

 >>>i: 14 j:   5 andere nicht gut to Others not good 

 >>>i: 14 j:   6 Kind krank to Child sick 

 >>>i: 14 j:   7 Sport to Sport 

 >>>i: 14 j:   8 Essen to Food 

 >>>i: 14 j:   9 Spazieren mit Familie to Walking with family 

 >>>i: 14 j:   10 Lesen to Reading 

 >>>i: 14 j:   11 Ausflüge in Deutschland to Trips in Germany 

 >>>i: 14 j:   12 Freunde to Friends 

 >>>i: 14 j:   13 Stress to Stress 

 >>>i: 14 j:   14 körperlich krank to Physically ill 

 >>>i: 14 j:   15 fühle mich schwach to Feel weak 

 >>>i: 14 j:   16 Ehemann hilft to Husband helps 

 >>>i: 14 j:   17 Familie hilft to Family helps 

 >>>i: 14 j:   18 Freunde hilft to Friends help 

 >>>i: 15 j:   1 Stress to Stress 

 >>>i: 15 j:   2 Musik to Music 

 >>>i: 15 j:   3 Singen to Singing 

 >>>i: 15 j:   4 Arzt to Doctor 

 >>>i: 15 j:   5 Mama anrufen to Call mum 

 >>>i: 15 j:   6 Musik selber machen to Make music yourself 

 >>>i: 15 j:   7 Sprachbarriere to Language barrier 

 >>>i: 15 j:   8 kein Dolmetscher to No interpreter 

 >>>i: 15 j:   9 Wo ist Arzt? to Where is the doctor? 

 >>>i: 15 j:   10 Sport to Sport 

 >>>i: 15 j:   11 Welcher Arzt besser? to Which doctor is better? 

 >>>i: 15 j:   12 keine Information Gesundheitssystem to no information healthcare system 

 >>>i: 15 j:   13 Sozialarbeiterin to Social worker 

 >>>i: 15 j:   14 das hilft to That helps 

 >>>i: 15 j:   15 Handy to Mobile phone 

 >>>i: 15 j:   16 nicht selber nachdenken to Not think for oneself 

 >>>i: 15 j:   17 kein Kontakt Kunstszene to No contact art scene 

 >>>i: 15 j:   18 Bürokratie in Deutschland to Bureaucracy in Germany 

 >>>i: 15 j:   19 Schwierigkeiten to Difficulties 

 >>>i: 15 j:   20 Wie funktioniert Familiengericht? to How does family court work? 

 >>>i: 15 j:   21 kulturelle Unterschiede to Cultural differences 

 >>>i: 15 j:   22 Angst vor Gericht to Fear of court 

 >>>i: 16 j:   1 1. Selbsthelfen to 1. Self-help 

 >>>i: 16 j:   2 Medizin to Medicine 

 >>>i: 16 j:   3 Apotheke to Pharmacy 

 >>>i: 16 j:   4 manche mit Rezept to Some with prescription 

 >>>i: 16 j:   5 Selbstdiagnose schwierig to Self-diagnosis difficult 

 >>>i: 16 j:   6 meine Familie bitten to Ask my family 

 >>>i: 16 j:   7 Erfahrungen Freunde fragen to Ask friends for experiences 

 >>>i: 16 j:   8 2.zum Arzt gehen to 2. Go to doctor 

 >>>i: 16 j:   9 Deutsche Freunde to German friends 

 >>>i: 16 j:   10 Termin bekommen schwierig to Difficult to get an appointment 

 >>>i: 16 j:   11 deutsches Gesundheitssystem kompliziert to German healthcare system complicated 

 >>>i: 16 j:   12 nicht jeder Englischkenntnisse to Not everyone English skills 

 >>>i: 16 j:   13 Englischkenntnisse im Gesundheitssystem to English skills in the health system 

 >>>i: 16 j:   14 Notfalltelefon verschiedene Sprachen to Emergency phone various languages 

 >>>i: 16 j:   15 Instructions verschiedene Sprachen to Instructions in various languages 

 >>>i: 16 j:   16 Rathaus to Town hall 

 >>>i: 16 j:   17 Wo Hilfe Nachts? to Where to get help at night? 

 >>>i: 16 j:   18 Arztberatung am Telefon to Doctor consultation by phone 

 >>>i: 16 j:   19 keine einheitliche Plattform to No unified platform 

 >>>i: 16 j:   20 Übersicht fehlt to Lack of overview 

 >>>i: 17 j:   1 viele Briefe to Many letters 

 >>>i: 17 j:   2 Pflegepersonal to Nursing staff 

 >>>i: 17 j:   3 keine Aufklärung Medikation to no information medication 

 >>>i: 17 j:   4 mangelnde Flexibilität Behandlung to Lack of treatment flexibility 

 >>>i: 17 j:   5 Sprachbarriere to Language barrier 

 >>>i: 17 j:   6 hat Patienten angeschrien to shouted at patients 

 >>>i: 17 j:   7 Kein Vertrauen inPflege to No trust in care 

 >>>i: 17 j:   8 schlechte infrastrukturelle Anbindung to poor infrastructural connection 

 >>>i: 17 j:   9 teilweise unhöflich to Sometimes rude 

 >>>i: 17 j:   10 falsche Station? to Wrong ward? 

 >>>i: 17 j:   11 andere Patienten sediert? to other patients sedated? 

 >>>i: 17 j:   12 menschlicher Faktor to Human factor 

 >>>i: 17 j:   13 Sozialarbeiterin to Social worker 

 >>>i: 17 j:   14 keine Informationen Gesundheitsversorgun to no information healthcare 

 >>>i: 17 j:   15 Ehemann ist Pflegebedürftig to Husband needs care 

 >>>i: 17 j:   16 Zuständigkeiten unklar to Unclear responsibilities 

 >>>i: 17 j:   17 Ärzte wenig Zeit to Doctors little time 

 >>>i: 17 j:   18 teilweise Kosten to partly cost 

 >>>i: 17 j:   19 Ablenkung to Distraction 

 >>>i: 17 j:   20 Ukrainisches Kulturzentrum to Ukrainian cultural center 

 >>>i: 17 j:   21 zuhause sein to Being at home 

 >>>i: 17 j:   22 kein Vertrauen Versorgung to no confidence in supply 

 >>>i: 17 j:   23 Schlafschwierigkeiten to sleeping difficulties 

 >>>i: 17 j:   24 Ärzte to Doctors 

 >>>i: 17 j:   25 Rumänischer Pfleger gut to Romanian caregiver good 

 >>>i: 17 j:   26 manche freundlich to Some friendly 

 >>>i: 17 j:   27 (Fehl-)Behandlung Ehemann to (Mis)treatment of husband 

 >>>i: 17 j:   28 lange Wartezeiten to Long waiting times 

 >>>i: 17 j:   29 Bürokratie to Bureaucracy 

 >>>i: 17 j:   30 weitere Schwierigkeiten to further difficulties 

 >>>i: 17 j:   31 Überforderung to exsessive demands 

 >>>i: 17 j:   32 HAUPTPROBLEM: keine Kommunikation to MAIN PROBLEM: no communication 

 >>>i: 18 j:   1 2. Hausarzt to 2. General Practioner 

 >>>i: 18 j:   2 lange Wartezeit to Long waiting time 

 >>>i: 18 j:   3 1. Selbst Medikation to 1. Self-medication 

 >>>i: 18 j:   4 wenn nicht hilft to If it doesn't help 

 >>>i: 18 j:   5 Symptome verschwinden alleine to Symptoms disappear on their own 

 >>>i: 18 j:   6 spazieren gehen to Go for a walk 

 >>>i: 18 j:   7 guten Film anschauen to Watch a good movie 

 >>>i: 18 j:   8 mit Freunden telefonieren to Talk to friends on the phone 

 >>>i: 18 j:   9 Süßigkeiten essen to Eating sweets 

 >>>i: 18 j:   10 Psychische Gesundheit to Mental health 

 >>>i: 18 j:   11 3. Spezieller Arzt to 3. Specialist doctor 

 >>>i: 18 j:   12 nicht Deutsch Muttersprache to Not native German 

 >>>i: 18 j:   13 Angst Termine telefonisch to fear appointments by phone 

 >>>i: 18 j:   14 schon Leute kennen to Already know people 

 >>>i: 18 j:   15 weniger Angst to less anxiety 

 >>>i: 18 j:   16 körperliche Gesundheit to Physical health 

 >>>i: 18 j:   17 Medikation to Medication 

 >>>i: 18 j:   18 Entspannung to Relaxation 

 >>>i: 18 j:   19 Psychotherapeut to Psychotherapist 
[1] 19

 >>>i: 19 j:   1 Fachärztliche Hilfe to Specialist help 

 >>>i: 19 j:   2 Gymnastik to Gymnastics 

 >>>i: 19 j:   3 Massage to Massage 

 >>>i: 19 j:   4 Einschränkungen to Limitations 

 >>>i: 19 j:   5 Wartenzeiten der Terminen to Waiting times for appointments 

 >>>i: 19 j:   6 finanzielle Grenze to Financial limit 

 >>>i: 19 j:   7 Krankenversicherung to health insurance coverage 

 >>>i: 19 j:   8 inkompetentes ärztliches Personal to Incompetent medical staff 

 >>>i: 19 j:   9 Selbstbildung to Self-education 

 >>>i: 19 j:   10 Medicine und Medikamenten to Medicine and medication 

 >>>i: 19 j:   11 Schwimmen to Swimming 

Save files

translated CAM data

Save CAM file to upload on CAM-App / process further:

### get CAM data
writeLines("", "outputs/CAMdata_Germany_translated.txt") # create file
text_connection <- file("outputs/CAMdata_Germany_translated.txt", "a") # open connection to append

for(i in 1:length(raw_CAM_Germany_translated)){
      writeLines(jsonlite::toJSON(x = raw_CAM_Germany_translated[[i]], pretty = FALSE, auto_unbox = FALSE), text_connection)

}

close(text_connection) # close connection

network indicators

setwd("outputs")
# save network indicators German
## save as .xlsx file
xlsx::write.xlsx2(x = networkIndicators_German, file = "networkIndicators_German.xlsx")
## save as R object
saveRDS(networkIndicators_German, file = "networkIndicators_German.rds")
## save as csv object
write.csv2(networkIndicators_German, file = "networkIndicators_German.csv")


# save network indicators English
## save as .xlsx file
xlsx::write.xlsx2(x = networkIndicators_English, file = "networkIndicators_English.xlsx")
## save as R object
saveRDS(networkIndicators_English, file = "networkIndicators_English.rds")
## save as csv object
write.csv2(networkIndicators_English, file = "networkIndicators_English.csv")

clean survey data and get corresponding CAMs IDs

load data

setwd("data_timeStamps")
dir()
[1] "backup"                                     
[2] "data_Englisch_2024-03-30_15-46_changed.xlsx"
[3] "jatos_results_metadata_Deutsch.csv"         
[4] "jatos_results_metadata_Englisch.csv"        
[5] "SoSci_Deutsch&Englisch.xlsx"                
[6] "SoSci_Deutsch&Englisch_English.csv"         
[7] "SoSci_Deutsch&Englisch_German.csv"          
### load data German
# dat_German <- read.xlsx2(file = "data_Deutsch_2024-03-30_15-45.xlsx", sheetIndex = 1)
dat_German <- read.csv2(file = "SoSci_Deutsch&Englisch_German.csv", header = TRUE, fileEncoding="latin1")
dat_German[1,]
  uniqueID                           CASE
1          Interview-Nummer (fortlaufend)
                                                 SERIAL
1 Personenkennung oder Teilnahmecode (sofern verwendet)
                                  REF
1 Referenz (sofern im Link angegeben)
                                      QUESTNNR            MODE
1 Fragebogen, der im Interview verwendet wurde Interview-Modus
                                                      STARTED
1 Zeitpunkt zu dem das Interview begonnen hat (Europe/Berlin)
                           CM03_01.Repr.sentativit.t.Hilfe.
1 Representativity health Ger: Welche Hilfe ich brauche ist
                                        CM06_02..Repr.sentativit.t.Schwierigkeiten.
1 Representativity Barr Ger: M\u0094gliche Schwierigkeiten, Hilfe zu bekommen, sind
  CM05_01..Woran.beim.Zeichnen.gedacht.. CM07_01..Weitere.Ideen.
1               Area Wellbeing Ger: [01]     Weitere Ideen: [01]
  ED03..Highest.Degree. ED04..Country.Degree.                     HS05
1    Highest Degree Ger    Country Degree Ger Satisfaction health 1-10
                           HS06                   HS07
1 Current health 5-1 (sehr gut) Health services (1=Ja)
                       HS08                     IC05
1 Health security (Legende) Informed Consent (1= Ja)
                               LK03                             LK04
1 English knowledge (5-1, sehr gut) German knowledge (5-1, sehr gut)
                    RF02_01
1 Religion/ Faith Ger: [01]
                                                                RF02_01a
1 Religion/ Faith Ger: [01]: Trifft nicht auf mich zu (2=ungl\u0084ubig)
                  SD27                                         SD28
1 Geschlecht (1=weibl) Alter Ger (3=18-34 J.; 4=35-49J.; 12= >50J.)
                          SD29x1                         SD29x2
1 Country of origin Ger: Country Country of origin Ger: Country
                          SD29x3                    SD31_01
1 Country of origin Ger: Country Time in Germany Ger: Jahre
                      SD31_02                         SD38
1 Time in Germany Ger: Monate Besch\u0084ftigung (Legende)
                        SD38_08                      SD32_01
1 Besch\u0084ftigung: Sonstiges Previous countries Ger: [01]
                                         SD32_01a
1 Previous countries Ger: [01]: Kein anderes Land
                                                                                SD33
1 Reason flight Ger: Ausweichoption (negativ) oder Anzahl ausgew\u0084hlter Optionen
                                                                        SD33_01
1 Reason flight Ger: Angst vor gewaltsamen Konflikten oder Krieg (1=Nein; 2=Ja)
                                                                                    SD33_02
1 Reason flight Ger: Angst vor Zwangsrekrutierung zum Milit\u0084r oder bewaffneten Gruppen
                        SD33_03
1 Reason flight Ger: Verfolgung
                                                               SD33_04
1 Reason flight Ger: Diskriminierung (ethnische, religi\u0094se, etc.)
                                                          SD33_05
1 Reason flight Ger: Schlechte pers\u0094nliche Lebensbedingungen
                                                         SD33_06
1 Reason flight Ger: Allgemein wirtschaftliche Situation im Land
                                                           SD33_07
1 Reason flight Ger: Ich wollte zu Familienangeh\u0094rigen ziehen
                                              SD33_08
1 Reason flight Ger: Meine Familie hat mich geschickt
                                                                      SD33_09
1 Reason flight Ger: Weil Familienangeh\u0094rige dieses Land verlassen haben
                                                                 SD33_10
1 Reason flight Ger: Weil Freunde / Bekannte dieses Land verlassen haben
                                  SD33_11  X
1 Reason flight Ger: Sonstige Gr\u0081nde NA
                                                                             SD34
1 Aiming Germany: Ausweichoption (negativ) oder Anzahl ausgew\u0084hlter Optionen
                                                         SD34_01
1 Aiming Germany: Weil schon Leute aus meiner Familie hier leben
                                                      SD34_02
1 Aiming Germany: Weil schon Freunde oder Bekannte hier leben
                                                                            SD34_03
1 Aiming Germany: Weil schon viele andere Menschen aus meinem Heimatland hier leben
                                              SD34_04
1 Aiming Germany: Wegen der Wirtschaft in Deutschland
                                                  SD34_05
1 Aiming Germany: Wegen der Menschenrechte in Deutschland
                                                                        SD34_06
1 Aiming Germany: Wegen des deutschen Bildungssystems (Schule, Ausbildung, Uni)
                                                                SD34_07
1 Aiming Germany: Wegen der staatlichen und sozialen Unterst\u0081tzung
                                                                    SD34_08
1 Aiming Germany: Wegen des Gef\u0081hls, in Deutschland willkommen zu sein
                                             SD34_09
1 Aiming Germany: Wegen des deutschen Asylverfahrens
                                                          SD34_10
1 Aiming Germany: Ich bin zuf\u0084llig nach Deutschland gekommen
                             SD34_11
1 Aiming Germany: Andere Gr\u0081nde
                                             SD34_11a
1 Aiming Germany: Andere Gr\u0081nde (offene Eingabe)
                                                                                   SD35
1 Residence status Ger: Ausweichoption (negativ) oder Anzahl ausgew\u0084hlter Optionen
                                                 SD35_01
1 Residence status Ger: Deutsche Staatsb\u0081rgerschaft
                                                  SD35_02
1 Residence status Ger: Unbefristete Aufenthaltserlaubnis
                                                SD35_03
1 Residence status Ger: Befristete Aufenthaltserlaubnis
                                           SD35_05
1 Residence status Ger: Keine Aufenthaltserlaubnis
                          SD35_06
1 Residence status Ger: Sonstiges
                                          SD35_06a            SD36
1 Residence status Ger: Sonstiges (offene Eingabe) Integration Ger
                                                                               SD37
1 Gefl\u0081chtet?: Ausweichoption (negativ) oder Anzahl ausgew\u0084hlter Optionen
               SD37_01                SD37_02
1 Gefl\u0081chtet?: Ja Gefl\u0081chtet?: Nein
                                                    SD37_03
1 Gefl\u0081chtet?: Falls Sie noch etwas sagen m\u0094chten
                                                                    SD37_03a
1 Gefl\u0081chtet?: Falls Sie noch etwas sagen m\u0094chten (offene Eingabe)
     SE02            SO01_01             SO02                     SO02_05
1 SES Ger Anmerkungen?: [01] Rekrutierungsort Rekrutierungsort: Sonstiges
                          TE01_RV1                 TE02
1 POST/GET-Variable: participantID Technische Probleme?
                             TE02_02
1 Technische Probleme?: Ja, und zwar
                                                        LASTDATA
1 Zeitpunkt als der Datensatz das letzte mal ge\u0084ndert wurde
                                                    FINISHED
1 Wurde die Befragung abgeschlossen (letzte Seite erreicht)?
                                                                                 Q_VIEWER
1 Hat der Teilnehmer den Fragebogen nur angesehen, ohne die Pflichtfragen zu beantworten?
                                          LASTPAGE
1 Seite, die der Teilnehmer zuletzt bearbeitet hat
                                           MAXPAGE
1 Letzte Seite, die im Fragebogen bearbeitet wurde
                                MISSING
1 Anteil fehlender Antworten in Prozent
                                               MISSREL
1 Anteil fehlender Antworten (gewichtet nach Relevanz)
                                TIME_RSI
1 Ausf\u0081ll-Geschwindigkeit (relativ)
dat_German <- dat_German[-1,]

## reformat date
dat_German$STARTED <- ymd_hms(dat_German$STARTED)
dat_German$LASTDATA <- ymd_hms(dat_German$LASTDATA)


### load data English
# dat_English <- read.xlsx2(file = "data_Deutsch_2024-03-30_15-45.xlsx", sheetIndex = 2)
dat_English <- read.csv2(file = "SoSci_Deutsch&Englisch_English.csv", header = TRUE)
dat_English[1,]
  uniqueID                           CASE
1          Interview-Nummer (fortlaufend)
                                                 SERIAL
1 Personenkennung oder Teilnahmecode (sofern verwendet)
                                  REF
1 Referenz (sofern im Link angegeben)
                                      QUESTNNR            MODE
1 Fragebogen, der im Interview verwendet wurde Interview-Modus
                                                      STARTED
1 Zeitpunkt zu dem das Interview begonnen hat (Europe/Berlin)
                                              CM04_01
1 Representativity CAM: My needs when I seek help are
                                                       CM06_01
1 Representativity CAM: Possible problems when I seek help are
                   CM05_01             CM07_01           ED01           ED02
1 Area Wellbeing Ger: [01] Weitere Ideen: [01] Highest Degree Country Degree
                 HS01           HS02            HS03            HS04
1 Satisfaction health Current health Health services Health security
                 HS04_04                       IC01              LK01
1 Health security: Other Informed Consent (deutsch) English knowledge
              LK02               RF01_01
1 German knowledge Religion/ Faith: [01]
                                     RF01_01a       SD01
1 Religion/ Faith: [01]: Does not apply to me Geschlecht
                         SD03                     SD08x1
1 Alter (Kategorien, 5 Jahre) Country of origin: Country
                      SD08x2                     SD08x3                SD21_01
1 Country of origin: Country Country of origin: Country Time in Germany: Years
                            SD21_01a                 SD21_02
1 Time in Germany: Years: No details Time in Germany: Months
                             SD21_02a             SD14                 SD14_08
1 Time in Germany: Months: No details Besch\x84ftigung Besch\x84ftigung: Other
                   SD22_01                                   SD22_01a
1 Previous countries: [01] Previous countries: [01]: No other country
                                                                          SD23
1 Reason flight: Ausweichoption (negativ) oder Anzahl ausgew\x84hlter Optionen
                                         SD23_01
1 Reason flight: Fear of violent conflict or war
                                                                        SD23_02
1 Reason flight: Fear of forced subscription to military or armed organisations
                     SD23_03
1 Reason flight: Persecution
                                                  SD23_04
1 Reason flight: Discrimination (ethnic, religious, etc.)
                                         SD23_05
1 Reason flight: Poor personal living conditions
                                                  SD23_06
1 Reason flight: The country?s general economic situation
                                                          SD23_07
1 Reason flight: I wanted to move to where my family members were
                           SD23_08
1 Reason flight: My family sent me
                                                      SD23_09
1 Reason flight: Because family members had left this country
                                                             SD23_10
1 Reason flight: Because friends/acquaintances had left this country
                       SD23_11
1 Reason flight: Other reasons
                                                                           SD24
1 Aiming Germany: Ausweichoption (negativ) oder Anzahl ausgew\x84hlter Optionen
                                           SD24_01
1 Aiming Germany: Because family members live here
                                                     SD24_02
1 Aiming Germany: Because friends or acquaintances live here
                                                                            SD24_03
1 Aiming Germany: Because a lot of other people from my country of origin live here
                                                       SD24_04
1 Aiming Germany: Because of the economic situation in Germany
                                                        SD24_05
1 Aiming Germany: Because human rights are respected in Germany
                                                                               SD24_06
1 Aiming Germany: Because of the German education system (School, Apprenticeship, Uni)
                                                            SD24_07
1 Aiming Germany: Because of the state and social welfare available
                                                SD24_08
1 Aiming Germany: Because of feeling welcome in Germany
                                                 SD24_09
1 Aiming Germany: Because of the German asylum procedure
                               SD24_10                       SD24_11
1 Aiming Germany: It was a coincidence Aiming Germany: Other reasons
                                                                             SD25
1 Residence status: Ausweichoption (negativ) oder Anzahl ausgew\x84hlter Optionen
                               SD25_01
1 Residence status: German nationality
                                       SD25_02
1 Residence status: Permanent residence status
                                       SD25_03
1 Residence status: Temporary residence status
                                SD25_05                 SD25_06
1 Residence status: No residence status Residence status: Other
                                  SD25_06a        SD26     SD37 SE01
1 Residence status: Other (offene Eingabe) Integration Refugee?  SES
                  SO02_01             SO03                 SO03_05
1 Anmerkungen? Engl: [01] Rekrutierungsort Rekrutierungsort: Other
                          TE01_RV1                      TE03
1 POST/GET-Variable: participantID Technische Probleme? Engl
                                 TE03_02
1 Technische Probleme? Engl: Yes, namely
                                 TIME_SUM
1 Verweildauer gesamt (ohne Ausrei\xe1er)
                                                      LASTDATA
1 Zeitpunkt als der Datensatz das letzte mal ge\x84ndert wurde
                                                    FINISHED
1 Wurde die Befragung abgeschlossen (letzte Seite erreicht)?
                                                                                 Q_VIEWER
1 Hat der Teilnehmer den Fragebogen nur angesehen, ohne die Pflichtfragen zu beantworten?
                                          LASTPAGE
1 Seite, die der Teilnehmer zuletzt bearbeitet hat
                                           MAXPAGE
1 Letzte Seite, die im Fragebogen bearbeitet wurde
                                MISSING
1 Anteil fehlender Antworten in Prozent
                                               MISSREL
1 Anteil fehlender Antworten (gewichtet nach Relevanz)
                              TIME_RSI
1 Ausf\x81ll-Geschwindigkeit (relativ)
dat_English <- dat_English[-1,]

## reformat date
dat_English$STARTED <- ymd_hms(dat_English$STARTED)
dat_English$LASTDATA <- ymd_hms(dat_English$LASTDATA)



head(cbind(dat_German$LASTDATA, dat_German$STARTED, dat_German$LASTDATA - dat_German$STARTED, dat_German$FINISHED))
     [,1]         [,2]         [,3]   [,4]
[1,] "1709295219" "1709294829" "390"  "1" 
[2,] "1709297241" "1709296357" "884"  "1" 
[3,] "1709408244" "1709406728" "1516" "1" 
[4,] "1709410396" "1709409786" "610"  "1" 
[5,] "1709491931" "1709491855" "76"   "0" 
[6,] "1709494991" "1709494240" "751"  "0" 
head(cbind(dat_English$LASTDATA, dat_English$STARTED, dat_English$LASTDATA - dat_English$STARTED, dat_English$FINISHED))
     [,1]         [,2]         [,3]   [,4]
[1,] "1709297775" "1709297580" "195"  "1" 
[2,] "1709301515" "1709299243" "2272" "1" 
[3,] "1709302100" "1709301888" "212"  "1" 
[4,] "1709303666" "1709303109" "557"  "1" 
[5,] "1709304694" "1709304524" "170"  "1" 
[6,] "1709306337" "1709305486" "851"  "1" 
table(dat_German$QUESTNNR)

CAM-study_1a CAM-study_1b 
          19           19 
table(dat_English$QUESTNNR)

CAM-study_1a CAM-study_1b 
          11           11 

match German data

oneHrs <- 60*60 # hour in seconds


vec_CAMid <- c()
vec_date <- c()

for(i in 1:length(raw_CAM_German)){
  vec_CAMid[i] <- raw_CAM_German[[i]]$idCAM
  vec_date[i] <- raw_CAM_German[[i]]$date
}

dat_German$CAM_ID = NA

for(id in unique(dat_German$uniqueID)){
  tmp <- dat_German[dat_German$uniqueID == id,]
  
  tmp_out <- lubridate::as_datetime(vec_date / 1000) - (tmp$LASTDATA[1] - oneHrs)
  
  if(tmp_out[which(tmp_out == min(tmp_out[tmp_out > 0]))] <= 5){
    dat_German$CAM_ID[dat_German$uniqueID == id] <- vec_CAMid[which(tmp_out == min(tmp_out[tmp_out > 0]))]
  }else{
    print(id)
    print(tmp_out[which(tmp_out == min(tmp_out[tmp_out > 0]))])
    print(vec_CAMid[which(tmp_out == min(tmp_out[tmp_out > 0]))])
  }
}
[1] "German3"
Time difference of 2450.228 mins
[1] "51a6ac13-5a57-4934-82b4-8bf7500f3a81"
[1] "German10"
Time difference of 31.711 secs
[1] "68478d58-2579-4465-9619-f52f6c7e6788"
[1] "German11"
Time difference of 9.299 secs
[1] "f9f3f9c5-6fcf-44c5-a9d6-f015082bc201"
names(table(dat_German$CAM_ID))[table(dat_German$CAM_ID) != 2]
character(0)

match English data

vec_CAMid <- c()
vec_date <- c()

for(i in 1:length(raw_CAM_English)){
  vec_CAMid[i] <- raw_CAM_English[[i]]$idCAM
  vec_date[i] <- raw_CAM_English[[i]]$date
}

dat_English$CAM_ID = NA

id = "English1"

for(id in unique(dat_English$uniqueID)){
  tmp <- dat_English[dat_English$uniqueID == id,]
  tmp_out <- lubridate::as_datetime(vec_date / 1000) - (tmp$LASTDATA[1] - oneHrs)
  
  if(tmp_out[which(tmp_out == min(tmp_out[tmp_out > 0]))] <= 5){
    dat_English$CAM_ID[dat_English$uniqueID == id] <- vec_CAMid[which(tmp_out == min(tmp_out[tmp_out > 0]))]
  }else{
    print(id)
    print(tmp_out[which(tmp_out == min(tmp_out[tmp_out > 0]))])
    print(vec_CAMid[which(tmp_out == min(tmp_out[tmp_out > 0]))])
  }
}


names(table(dat_English$CAM_ID))[table(dat_English$CAM_ID) != 2]
character(0)

save data

setwd("outputs/final")

 # sapply(dat_English, function(x){
 #   if(is.character(x)){
 #     Encoding(x) <- "utf-8"
 #   }
 # })  
 
Encoding(dat_English$CM05_01) <- "latin1"
Encoding(dat_English$CM07_01) <- "latin1"
Encoding(dat_English$SO02_01) <- "latin1"

## German
xlsx::write.xlsx2(x = dat_German, file = "dat_German.xlsx")
write.csv2(x = dat_German, file = "dat_German.csv")
saveRDS(object = dat_German, file = "dat_German.rds")

## English
xlsx::write.xlsx2(x = dat_English, file = "dat_English.xlsx") # invalid character coding
write.csv2(x = dat_English, file = "dat_English.csv")
saveRDS(object = dat_English, file = "dat_English.rds")

create wordlist combined

setwd("outputs")
### load CAM files
# German
suppressMessages(read_file("CAMdata_combined.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

raw_CAM <- list()
for(i in 1:length(dat_CAM)){
  raw_CAM[[i]] <- jsonlite::fromJSON(txt = dat_CAM[[i]])
}
rm(dat_CAM)
### create CAM single files (nodes, connectors, merged)
CAMfiles <- create_CAMfiles(datCAM = raw_CAM, reDeleted = TRUE)
Nodes and connectors, which were deleted by participants were removed. 
 # deleted nodes:  98 
 # deleted connectors:  52
# remove empty concepts:
CAMfiles[[1]]$text[nchar(CAMfiles[[1]]$text) < 2]
[1] ""
tmp_ids <- CAMfiles[[1]]$id[nchar(CAMfiles[[1]]$text) < 2]
table(CAMfiles[[1]]$isActive[CAMfiles[[1]]$id %in% tmp_ids])

TRUE 
   1 
CAMfiles[[1]] <- CAMfiles[[1]][!CAMfiles[[1]]$id %in% tmp_ids,]


### draw CAMs
CAMdrawn <- draw_CAM(dat_merged = CAMfiles[[3]],
                     dat_nodes = CAMfiles[[1]],ids_CAMs = "all",
                     plot_CAM = FALSE,
                     useCoordinates = TRUE,
                     relvertexsize = 3,
                     reledgesize = 1)
processing 32 CAMs... 
[1] "== ids_CAMs in drawnCAM"
## check for non reasonable words
for(i in 1:length(CAMdrawn)){
  if(any(nchar(V(CAMdrawn[[i]])$label) < 3)){
    print(V(CAMdrawn[[i]])$label)
  }
}
[1] "dg"     "pdf"    "gd"     "pdf"    "sd"     "dsgfdf" "sd"     "fügst" 
[1] "sgdf" "df"   "sfgd" "sed"  "gfds" "df"   "gdfg" "pdf" 
### network indicators
tmp_microIndicator <- NULL # no pre-defined concepts
networkIndicators <- compute_indicatorsCAM(drawn_CAM = CAMdrawn, 
                                           micro_degree = tmp_microIndicator, 
                                           micro_valence = tmp_microIndicator, 
                                           micro_centr_clo = tmp_microIndicator, 
                                           micro_transitivity = tmp_microIndicator, 
                                           largestClique = FALSE)


## check for CAMs who have not changed valence
tmp_ids <- networkIndicators$CAM_ID[is.na(networkIndicators$assortativity_valence_macro)]
for(i in tmp_ids){
    plot(CAMdrawn[[i]], edge.arrow.size = .7,
       layout=layout_nicely, vertex.frame.color="black", asp = .5, margin = -0.1,
       vertex.size = 10, vertex.label.cex = .9)
}

### wordlist
CAMwordlist <- create_wordlist(
  dat_nodes =  CAMfiles[[1]],
  dat_merged =  CAMfiles[[3]],
  useSummarized = TRUE,
  order = "frequency",
  splitByValence = FALSE,
  comments = TRUE,
  raterSubsetWords = NULL,
  rater = FALSE
)
[1] "create_wordlist - use raw words"
[1] 0
[1] 515
[1] "temporarily suffixes are added, because not all words have been summarized"
processing 32 CAMs... 
[1] "== ids_CAMs in drawnCAM"
DT::datatable(CAMwordlist, options = list(pageLength = 5)) 

wordlist:

DT::datatable(CAMfiles[[1]][,c("participantCAM", "id", "text", "value", "comment")], options = list(pageLength = 5))