#start with clean workspace 
rm(list=ls())
getwd()
#> [1] "C:/Users/ninab/OneDrive/Documenten/GitHub/labjournal"

1 packages

library(data.table) 
library(tidyverse) 
require(stringi)
require(RSiena)

2 load data

getwd()
#> [1] "C:/Users/ninab/OneDrive/Documenten/GitHub/labjournal"
load("./data/descriptives/RU_dfv2.RData")
load("./data/descriptives/RUpub_dfv2.RData")

3 network based on publications

Constructing three networks: (1) pubs from the years 2016, 2017, (2) pubs from the years 2018, 2019 and (3) pubs from the years 2020, 2021 and 2022.

network2016_2017 <- matrix(NA, nrow=nrow(soc_df), ncol=nrow(soc_df))
network2018_2019 <- matrix(NA, nrow=nrow(soc_df), ncol=nrow(soc_df))
network2020_2022 <- matrix(NA, nrow=nrow(soc_df), ncol=nrow(soc_df))
#select publications of the corresponding time era
pubs_sel <- socpub_df %>%
    filter(year>=2016 & year<=2017)

# to do: we gebruiken nu str_detect, maar wrs moeten we een exact match gebruiken. 

#fill the matrix
for (ego in 1: nrow(soc_df)) {
  name_ego <- soc_df$lastname_pubs[ego] #which ego? 
  pubs_sel2 <- pubs_sel[pubs_sel$gs_id==soc_df$gs_id[ego],] #selecteer de publicaties van ego
  for (alter in 1:nrow(soc_df)){
    name_alter <- soc_df$last_name[alter] #which alter? 
    network2016_2017[ego,alter] <- as.numeric(sum(str_detect(pubs_sel2$author, name_alter)) > 1)  #did alter publish with ego
  }
}
#select publications of the corresponding time era
pubs_sel <- socpub_df %>%
    filter(year>=2018 & year<=2019)

# to do: we gebruiken nu str_detect, maar wrs moeten we een exact match gebruiken. 

#fill the matrix
for (ego in 1: nrow(soc_df)) {
  name_ego <- soc_df$lastname_pubs[ego] #which ego? 
  pubs_sel2 <- pubs_sel[pubs_sel$gs_id==soc_df$gs_id[ego],] #selecteer de publicaties van ego
  for (alter in 1:nrow(soc_df)){
    name_alter <- soc_df$last_name[alter] #which alter? 
    network2018_2019[ego,alter] <- as.numeric(sum(str_detect(pubs_sel2$author, name_alter)) > 1)  #did alter publish with ego
  }
}
#select publications of the corresponding time era
pubs_sel <- socpub_df %>%
    filter(year>=2020 & year<=2022)

# to do: we gebruiken nu str_detect, maar wrs moeten we een exact match gebruiken. 

#fill the matrix
for (ego in 1: nrow(soc_df)) {
  name_ego <- soc_df$lastname_pubs[ego] #which ego? 
  pubs_sel2 <- pubs_sel[pubs_sel$gs_id==soc_df$gs_id[ego],] #selecteer de publicaties van ego
  for (alter in 1:nrow(soc_df)){
    name_alter <- soc_df$last_name[alter] #which alter? 
    network2020_2022[ego,alter] <- as.numeric(sum(str_detect(pubs_sel2$author, name_alter)) > 1)  #did alter publish with ego
  }
}

alle adjacency matrix in een array stoppen.

net_soc_array <- array(data = c(network2016_2017, network2018_2019, network2020_2022), dim=c(dim(network2020_2022),3))
save(network2020_2022, file="./data/descriptives/RU_network2020_2022.RData")
save(network2018_2019, file="./data/descriptives/RU_network2018_2019.RData")
save(network2016_2017, file="./data/descriptives/RU_network2016_2017.RData")
save(net_soc_array, file="./data/descriptives/RU_net_array.RData")

making the array symmetrical

net1 <- net_soc_array[,,1]
net1 <- net1 + t(net1)
net1[net1==2] <- 1

net2 <- net_soc_array[,,2]
net2 <- net2 + t(net2)
net2[net2==2] <- 1

net3 <- net_soc_array[,,3]
net3 <- net3 + t(net3)
net3[net3==2] <- 1


net_soc_array <- array(data = c(net1, net2, net3), dim=c(dim(net1),3))
save(net_soc_array, file = "./data/descriptives/RU_net_array_sym.RData")
LS0tDQp0aXRsZTogIlJVIEFycmF5Ig0KYXV0aG9yOiAiYnk6IE5pbmEgQnJhbnRlbiINCmJpYmxpb2dyYXBoeTogcmVmZXJlbmNlcy5iaWINCi0tLQ0KDQoNCg0KYGBge3IsIGluc3RhbGwgcmVtb3RlbHksIGdsb2JhbHNldHRpbmdzLCBlY2hvPUZBTFNFLCB3YXJuaW5nPUZBTFNFLCByZXN1bHRzPSdoaWRlJywgZXZhbD1GQUxTRX0NCmluc3RhbGwucGFja2FnZXMoInJlbW90ZXMiKQ0KcmVtb3Rlczo6aW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