Generalized Relational Similarities of Bipartite Graphs

Author

Omar Lizardo

Published

August 15, 2023

Setup

    knitr::opts_chunk$set(include = TRUE, echo = TRUE, warning = FALSE, message = FALSE)
    library(expm)
Loading required package: Matrix

Attaching package: 'expm'
The following object is masked from 'package:Matrix':

    expm
    library(factoextra)
Loading required package: ggplot2
Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
    library(ggpubr)
    library(here)
here() starts at C:/Users/Omar Lizardo/Google Drive/UCLA/mysite
    library(sjPlot)
Install package "strengejacke" from GitHub (`devtools::install_github("strengejacke/strengejacke")`) to load all sj-packages at once!
    library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ lubridate 1.9.2     ✔ tibble    3.2.1
✔ purrr     1.0.1     ✔ tidyr     1.3.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ tidyr::expand() masks Matrix::expand()
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
✖ tidyr::pack()   masks Matrix::pack()
✖ tidyr::unpack() masks Matrix::unpack()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
    source("https://github.com/olizardo/Two-Mode-Relational-Similarity/blob/main/Functions/gen.sim.corr.abs.R?raw=true")
     source("https://github.com/olizardo/Two-Mode-Relational-Similarity/blob/main/Functions/tm.corr.dist.R?raw=true")

Data

    A <- matrix(
         c(
          1, 1, 1, 1, 1,  1, 0, 1, 1,  0, 0, 0, 0, 0, 
          1, 1, 1, 0, 1,  1, 1, 1, 0,  0, 0, 0, 0, 0, 
          0, 1, 1, 1, 1,  1, 1, 1, 1,  0, 0, 0, 0, 0, 
          1, 0, 1, 1, 1,  1, 1, 1, 0,  0, 0, 0, 0, 0, 
          0, 0, 1, 1, 1,  0, 1, 0, 0,  0, 0, 0, 0, 0, 
          0, 0, 1, 1, 1,  1, 0, 1, 0,  0, 0, 0, 0, 0, 
          0, 0, 0, 1, 1,  1, 1, 1, 0,  0, 0, 0, 0, 0, 
          0, 0, 0, 1, 1,  0, 1, 1, 1,  0, 0, 0, 0, 0, 
          
          0, 0, 0, 0, 0,  0, 1, 1, 1,  0, 0, 1, 0, 0, 
          0, 0, 0, 0, 0,  0, 0, 1, 1,  1, 0, 1, 0, 0, 
          0, 0, 0, 0, 0,  0, 0, 1, 1,  1, 0, 1, 1, 1,
          0, 0, 0, 0, 0,  0, 1, 1, 1,  1, 0, 1, 1, 1,
          0, 0, 0, 0, 0,  0, 1, 0, 1,  1, 1, 1, 1, 1,
          0, 0, 0, 0, 0,  0, 1, 1, 0,  1, 1, 1, 0, 0,
          0, 0, 0, 0, 0,  0, 0, 0, 1,  0, 1, 0, 0, 0,
          0, 0, 0, 0, 0,  0, 0, 0, 1,  0, 1, 0, 0, 0, 
          
          0, 0, 0, 0, 0,  1, 0, 1, 1,  0, 0, 0, 0, 0,
          0, 0, 0, 0, 0,  0, 0, 1, 1,  0, 0, 0, 0, 0),
          ncol = 14, byrow = TRUE)
     w <- c("EVELYN", "LAURA", "THERESA", "BRENDA", "CHARLOTTE", "FRANCES", "ELEANOR", "RUTH", "VERNE", "MYRA", "KATHERINE", "SYLVIA", "NORA", "HELEN", "OLIVIA", "FLORA", "PEARL", "DOROTHY")
     e <- paste("E", c(1:14), sep = "")
     rownames(A) <- w
     colnames(A) <- e
     P <- matrix(0, nrow(A), nrow(A))
     rownames(P) <- w
     colnames(P) <- w
     G <- matrix(0, ncol(A), ncol(A))
     rownames(G) <- e
     colnames(G) <- e
     At <- t(A)
     s1 <- cbind(P, A)
     s2 <- cbind(At, G)
     B <- rbind(s1, s2)
     B2 <- B%*%B
     sim.res <- gen.sim.corr.abs(B)
     mds.res <- get.mds(sim.res$col.sims) 
     mds.res[, 2] <- mds.res[, 2] * 10000
     clus.res <- get.clus(mds.res, k = 6)
     p <- get.plot(clus.res)
     p

    save_plot("C:/Users/Omar Lizardo/OneDrive/Desktop/grs-bipart.png", width = 30, height = 25)
png 
  2