Genova / Italian universities / Data

Converting data into Pajek two-mode temporal network

> wdir <- "C:/Users/vlado/docs/papers/2022/ifcs2022/genova/data"
> setwd(wdir)
> library(jsonlite)
> source("https://raw.githubusercontent.com/bavla/Rnet/master/R/Pajek.R")
> recode <- function(y){
+     ifile <- paste("IDs",y,".csv",sep="")
+     nfile <- paste("Net",y,".csv",sep="")
+     T <- read.csv(ifile); A <- read.csv(nfile)
+     m <- rep(NA,max(T$Id)); m[T$Id] <- T$Label
+     s <<- c(s,m[A$Source]); t <<- c(t,m[A$Target])
+     w <<- c(w,A$Weight); p <<- c(p,rep(y,nrow(A)))
+ }
> Y <- c(2008,2011,2014,2017)
> s <- t <- w <- p <- c()
> for(y in Y) recode(y)
> M <- matrix(unlist(strsplit(gsub(" - ","/",gsub("NA","?",t)),"-")),ncol=2,byrow=TRUE)
> v1 <- M[,1]; v2 <- M[,2]
> uvrwt2net(s,v1,w=w,r=p,Net="genovaR.net",twomode=TRUE)
> uvrwt2net(s,v1,w=w,r=v2,t=p,Net="genovaRT.net",twomode=TRUE)

In Pajek I produced projections to both modes and computed the corresponding Salton indices that I visualized using 1/2-skeletons and used for clustering.

Constructing a 4-dimensional array and saving it in JSON

> S <- factor(s); T <- factor(v1); R <- factor(v2); Y <- factor(p)
> SN <- levels(S); TN <- levels(T); RN <- levels(R); YN <- levels(Y)
> W <- array(0,dim=c(length(SN),length(TN),length(RN),length(YN)),
+   dimnames = list(SN,TN,RN,YN))
> for(i in 1:length(S)) W[S[i],T[i],R[i],Y[i]] <- w[i]
> W[1:2,1:2,,1]
...
, , Social sciences, journalism and information

   Bicocca Bocconi
AG       1       0
AL       6       2
>
> data <- list(title="Student mobility data in Italian universities 2008, 2011, 2014, 2017",
+   by=c("VG Genova","G Giordano","G Ragozini","MP Vitale"),
+   creator="V. Batagelj", date=date(), 
+   modes=c("province","university","programme","year"),
+   names=list(prov=SN,univ=TN,prog=RN,year=YN),M=W)
> write(toJSON(data),"genova.json")

Reading the JSON file and adding names

> D <- fromJSON("genova.json")
> str(D)
List of 7
 $ title  : chr "Student mobility data in Italian universities 2008, 2011, 2014, 2017"
 $ by     : chr [1:4] "VG Genova" "G Giordano" "G Ragozini" "MP Vitale"
 $ creator: chr "V. Batagelj"
 $ date   : chr "Fri Nov  4 21:22:19 2022"
 $ modes  : chr [1:4] "province" "university" "programme" "year"
 $ names  :List of 4
  ..$ prov: chr [1:107] "AG" "AL" "AN" "AO" ...
  ..$ univ: chr [1:79] "Bicocca" "Bocconi" "Cà Foscari" "Campus Biomedico" ...
  ..$ prog: chr [1:11] "?" "Agriculture, forestry, fisheries and veterinary" "Arts and humanities" ...
  ..$ year: chr [1:4] "2008" "2011" "2014" "2017"
 $ M      : int [1:107, 1:79, 1:11, 1:4] 0 0 0 0 0 0 0 0 0 0 ...
> A <- D$M
> dimnames(A) <- D$names
> A[1:2,1:2,,1]
...
, , prog = Social sciences, journalism and information

    univ
prov Bicocca Bocconi
  AG       1       0
  AL       6       2
>

Compact JSON representation

> data <- list(title="Student mobility data in Italian universities 2008, 2011, 2014, 2017",
+   by=c("VG Genova","G Giordano","G Ragozini","MP Vitale"),
+   creator="V. Batagelj", date=date(), 
+   waynames=list(prov="province",univ="university",prog="programme",year="year"),
+   nodes=list(prov=data.frame(ID=SN),univ=data.frame(ID=TN),
+     prog=data.frame(ID=RN),year=data.frame(ID=YN)),
+   links=data.frame(link=cbind(S,T,R,Y),w=w))
> write(toJSON(data),"genovaMN.json")

Reading compact JSON representation

> MN <- fromJSON("genovaMN.json")
> str(MN)
List of 7
 $ title   : chr "Student mobility data in Italian universities 2008, 2011, 2014, 2017"
 $ by      : chr [1:4] "VG Genova" "G Giordano" "G Ragozini" "MP Vitale"
 $ creator : chr "V. Batagelj"
 $ date    : chr "Sun Nov  6 22:31:11 2022"
 $ waynames:List of 4
  ..$ prov: chr "province"
  ..$ univ: chr "university"
  ..$ prog: chr "programme"
  ..$ year: chr "year"
 $ nodes   :List of 4
  ..$ prov:'data.frame':	107 obs. of  1 variable:
  .. ..$ ID: chr [1:107] "AG" "AL" "AN" "AO" ...
  ..$ univ:'data.frame':	79 obs. of  1 variable:
  .. ..$ ID: chr [1:79] "Bicocca" "Bocconi" "Cà Foscari" "Campus Biomedico" ...
  ..$ prog:'data.frame':	11 obs. of  1 variable:
  .. ..$ ID: chr [1:11] "?" "Agriculture, forestry, fisheries and veterinary" "Arts and humanities" ...
  ..$ year:'data.frame':	4 obs. of  1 variable:
  .. ..$ ID: chr [1:4] "2008" "2011" "2014" "2017"
 $ links   :'data.frame':	37205 obs. of  5 variables:
  ..$ link.S: int [1:37205] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ link.T: int [1:37205] 1 1 1 1 2 3 4 5 5 5 ...
  ..$ link.R: int [1:37205] 4 5 9 11 4 3 9 3 5 9 ...
  ..$ link.Y: int [1:37205] 1 1 1 1 1 1 1 1 1 1 ...
  ..$ w     : int [1:37205] 4 1 1 1 11 1 1 1 1 1 ...
> 
vlado/work/2m/mwn/genova/data.txt · Last modified: 2022/11/23 04:08 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki