Load Libraries

# install.packages("igraph")
library(igraph)
# install.packages("egor")
library(egor)
# install.packages("tidyverse")
library(tidyverse)
# install.packages("dplyr")
library(dplyr)

Load Data

#attributes <- read.csv("ego_alter_attributes.csv", header = TRUE)
#edgelist <- read.csv("EdgeList3.csv", header = TRUE)

Subset Data by Egos and Alters

#egos <- subset(attributes, ego == 1)
#alters <- subset(attributes, ego == 0)

Ego Demographics

#ego_caste_ethnicity <- table(egos$caste_ethnicity)
#print(ego_caste_ethnicity)

#mean(egos$age)
#median(egos$age)
#summary(egos$age)

#table(egos$religion)
#table(egos$religion_importance)
#table(egos$employment)

#mean(egos$householdsize)
#median(egos$householdsize)

#table(egos$householdhead_sex)
#table(egos$householdhead)
#table(egos$maritalstatus)
#table(egos$education)

# Chhaupadi practices

Alter Demographics

Comparisons (Ego vs. Alter)


## Data Cleaning: Replace NAs with 0s



## Network Visualization: Full Network

Network Visualization: Small Subset (First Three Egos)

#setting the working directory
getwd()
## [1] "/Users/aubreemcmahon/Downloads"
setwd("/Users/aubreemcmahon/OneDrive - University of Pittsburgh/SAMIP - K01 HCD Nepal Study (SHARED)/Social Network Analysis/Data/Analysis_RStudio/")

rel <- read.csv("rel1.csv", header = TRUE)
edgelistsmall <- read.csv("EdgeListSmall.csv", header = TRUE)

e2g <- graph_from_data_frame(edgelistsmall, vertices = rel)

color_palette_small <- c("0" = "white", "1" = "orange", "2" = "pink",
                          "3" = "green", "4" = "yellow", "5" = "black",
                          "6" = "purple")

plot(e2g,
     vertex.size = 10,
     vertex.color = rel$relationship,
     edge.arrow.size = 0.5,
     vertex.label.dist = 0.5,
     edge.width = 5,
     layout = layout_with_fr(e2g))

legend("bottomleft",
       legend = names(color_palette_small),
       col = color_palette_small,
       pch = 16,
       pt.cex = 1.5,
       bty = "y")

Network Visualization: Influence

plot(e2g,
     vertex.size = 10,
     vertex.color = rel$relationship,
     edge.arrow.size = 0.5,
     edge.color = E(e2g)$influence,
     vertex.label.dist = 0.5,
     edge.width = 5,
     layout = layout_with_fr(e2g))

legend("bottomleft",
       inset = c(-0.75, 0),
       legend = names(color_palette_small),
       col = color_palette_small,
       pch = 16,
       pt.cex = 1.5,
       bty = "y")