R/paramSNA.R

#' SNA parameters
#'
#' This function returns a data.frame with four mobility parameters computed for each locality:
#' the degree centralities (degree, in-degree, and out-degree) and the betweenness centralities.
#'
#' Cette fonction 4 paramètres de mobilité pour chaque localité :
#' le degré, le degré entrant et le degré sortant et la centralité d'intermédiarité.
#'
#'
#' @import igraph
#' @export paramSNA
#' @param x the network generated by one of the mobinternat and mobnation functions.
#' @param y the data.frame containing the rawdata and generated by the impcheckdata function. \cr
#' Required columns: "ORIGINE_NOM", "ORIGINE_PAYS", "ORIGINE_LONGITUDE_X", "ORIGINE_LATITUDE_Y",
#' "DESTINATION_NOM", "DESTINATION_PAYS", "DESTINATION_LONGITUDE_X", "DESTINATION_LATITUDE_Y" and "EFFFECTIF"
#'
#' @param mon_pays the reference country between quotation marks, with the same writting than in y.
#' @keywords parameters sna network
#'
paramSNA <- function(x, y, mon_pays){
  Origines <- y[,c("ORIGINE_NOM", "ORIGINE_PAYS", "ORIGINE_LONGITUDE_X", "ORIGINE_LATITUDE_Y")]
  Destinations <- y[,c("DESTINATION_NOM", "DESTINATION_PAYS", "DESTINATION_LONGITUDE_X", "DESTINATION_LATITUDE_Y")]
  names(Origines) <- names(Destinations) <- c("NOM","PAYS","LONGITUDE_X", "LATITUDE_Y")
  Origines$NOM <- as.character(Origines$NOM)
  Origines$PAYS <- as.character(Origines$PAYS)
  Destinations$NOM <- as.character(Destinations$NOM)
  Destinations$PAYS <- as.character(Destinations$PAYS)
  Localites <- unique(rbind(Origines, Destinations))
  deg     <- strength(x, mode="all")
  indeg   <- strength(x, mode="in")
  outdeg  <- strength(x, mode="out")
  betw    <- betweenness(x, directed=T, weights=E(x)$weight)
  betw2   <- edge_betweenness(x, directed=T, weights=E(x)$weight)
  sna     <- Reduce(MyMerge, list(deg, indeg, outdeg, betw))
  names(sna) <- as.factor(c("degree", "indegree", "outdegree", "betweeness"))
  sna     <- data.frame(sna)
  sna$NOM <- row.names(sna)
  sna     <- merge(sna, Localites, by='NOM')
  sna[sna$PAYS == mon_pays,]
}
Pachka/AQCR_SNA_Package documentation built on May 11, 2019, 7:26 p.m.