diff --git a/Schrick-Noah_CG-Analysis.R b/Schrick-Noah_CG-Analysis.R index 0120d2d..c923326 100644 --- a/Schrick-Noah_CG-Analysis.R +++ b/Schrick-Noah_CG-Analysis.R @@ -4,14 +4,8 @@ # Noah L. Schrick - 1492657 library(igraph) -library(sna) -library(Rgraphviz) # Reading graphviz' "dot" files -library(readr) -################# Read in the previously generated networks ################# -# If sourcing: -#setwd(getSrcDirectory()[1]) -# If running: +################## Read in the previously generated networks ################## setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) source("./CG_Files/manual_import.R") @@ -19,6 +13,11 @@ car <- import_networks(1) hipaa <- import_networks(2) pci <- import_networks(3) -car.deg <- degree(car) -hipaa.deg <- degree(hipaa) -pci.deg <- degree(pci) +################################ Centralities ################################ +source("centralities.R") + +#### Katz +car.katz <- katz.cent(car) +hipaa.katz <- katz.cent(hipaa) +pci.katz <- katz.cent(pci) + diff --git a/centralities.R b/centralities.R new file mode 100644 index 0000000..f81e6fc --- /dev/null +++ b/centralities.R @@ -0,0 +1,21 @@ +katz.cent <- function(A, alpha=NULL, beta=NULL){ #NULL sets the default value + if (class(A) == 'igraph'){ + #Error checking. Turn into adj matrix. + A <- get.adjacency(A) + } + + lam.dom <- eigen(A)$values[1] #dom eigenvec + if (is.null(alpha)){ + alpha <- 0.9 * (1/lam.dom) #Set alpha to 90% of max allowed + } + + n <- nrow(A) + if (is.null(beta)){ + beta <- matrix(rep(1/n, n),ncol=1) + } + + #Katz scores + scores <- solve(diag(n) - alpha*A,beta) + + return(scores) +} \ No newline at end of file