workshops/CUGcode.R

#Set working directory
library(networksS17)

#load package and data
library(sna)
library(network)

#Enron Email Dataset
#a large database of 619,446 emails generated by 158 employees of Enron Corporation
#acquired by the Federal Energy Regulatory Commision after the company's collapse
#Read http://ceas.cc/2004/168.pdf for more information about the data

#read the dataset
enronraw <- read.table("inst/extdata/Email-Enron.txt") #read an edgelist from text file

# since the network is so loarge use subset of the data
# only using emails between nodes 51-100.
enron <- as.matrix(enronraw[enronraw[,1] %in% 51:100 & enronraw[,2] %in% 51:100, ])

# Initialize a 50 node network
net <- network.initialize(50)

# Set matching vertex names
network.vertex.names(net) <- as.character(51:100)

# convert edge list to character type to make it easy to match in edges
enron[,1] <- as.character(enron[,1])
enron[,2] <- as.character(enron[,2])

# Add in edges
net[enron] <- 1

# Set seed for replicability
set.seed(1234)
# Example of a conditional uniform graph test
# test for transitivity in the network (gtrans in the SNA package)
# control for dyad distribution via dyad.census option
# Null distribution constructed using 500 draws
system.time(cugResults <- cug.test(net, gtrans, cmode = "dyad.census", reps = 500))

# Look at results with just p-values
cugResults

# visualize results
plot(cugResults)
Hershberger/networksS17 documentation built on May 7, 2019, 4:02 a.m.