# An edgelist is usually formatted as a table where the first two columns contain the IDs of a pair of nodes in the network that have a tie between them.

# Optional additional columns may contain properties of the relationship between the nodes (e.g., the value of a tie).

# Any pair of nodes that does not have a tie between them is usually not included in an edgelist.

# This property is what makes edgelists a more efficient network data storage format than sociomatrices (see below).

# Unobsered edges can be encoded in edgelist format by including "NA" in the value column. 
# The columns in an edgelist table are usually ordered "Ego" (often the person who completed the interview or who was the subject of a focal follow) followed by "Alter" (the person that the focal individual named or interacted with). 

# In the case of undirected network data, the ordering of these columns does not matter, but in directed data, it does.

# `igraph` and `statnet` software will encode directed edgelist data with the arrow pointing from the first to the second column, so if the ties you recorded have reversed directionality from ego to alter, you should flip the order of the columns before converting the data to a network.
# CREATING YOUR EDGELIST
# A critical first step in constructing an edgelist is to ensure that all individuals in the dataset have unique identifiers.

# Note that names, even first and last names together, are frequently not unique identifiers, even in relatively small communities.

# Using some form of ID number or a code generated using a combination of individual characteristics is safer.

# Implementing a good system for obtaining uniquely identifying information about both egos and alters at the beginning of data collection is important for avoiding serious entity resolution problems later on.

# To code up an edgelist from fieldnotes or other unstructured datasets, each time you find a tie between two individuals, simply enter a row with their ID numbers into the edgelist, in the correct order.

# If the same two individuals are observed to interact multiple times, the best procedure is to record an additional edge in your edgelist everytime that interaction is observed, and to maintain an additional column with the date and/or time the interaction was observed, or some other identifying information. It is easy to aggregate or remove these duplicates in R at later stages.

# The columns "Chapter" and "Page" may not be necessary for any analysis I want to do, but they help me find the original data again in the future, in case I needed to double check something, and they also allow me to distinguish duplicate ties between characters.
# Usually, you will save your edgelist as a tab- or comma-delimited file (.txt or .csv) and then import it to R.

hp5edges <- read.table('/Users/rheemh/Dropbox (ASU)/Coding/R/hp5edgelist.txt', sep='\t', header=TRUE)

# take a look
head(hp5edges)
##          X.From.              X.To.
## 1 Alicia Spinnet     Alicia Spinnet
## 2 Alicia Spinnet   Angelina Johnson
## 3 Alicia Spinnet       Fred Weasley
## 4 Alicia Spinnet     George Weasley
## 5 Alicia Spinnet Harry James Potter
## 6 Alicia Spinnet         Katie Bell
# covert to an igraph network
library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
hp5edgesmat <- as.matrix(hp5edges) # igraph wants our data in matrix format
hp5net <- graph_from_edgelist(hp5edgesmat, directed=TRUE)

# extract first names from list of names to make nicer labels.
# FYI this is insane R notation to extract elements from a list.
firsts <- unlist(lapply(strsplit(V(hp5net)$name, " "), '[[', 1))

# let's take a look
plot(hp5net, vertex.shape="none", vertex.label.cex=0.6, edge.arrow.size=0.4, vertex.label=firsts, layout=layout.kamada.kawai)

# The function `simplify()` in `igraph` handily removes self-loops from a network.
hp5netsimple <- simplify(hp5net)
plot(hp5netsimple, vertex.shape="none", vertex.label.cex=0.7,
     edge.arrow.size=0.4, vertex.label=firsts, layout=layout.kamada.kawai)

# A flaw in the edgelist format is that nodes that are isolates are not listed in the edgelist.
# So in the network contains isolates, these must be added afterwards.
# There are several characters who appear in Book 5 who do not have any ties in the network:

book5isolates <- c("Lavender Brown", "Millicent Bulstrode", "Michael Corner", "Roger Davies", "Theodoer Nott", "Zacharias Smith")

hp5netfull <- add_vertices(hp5netsimple, nv=length(book5isolates), attr=list(name=book5isolates))

# note that here we add as many vertices as in our list of isolates, and assign them the attribute "name" which is stored in our list of isolates.

# regenerate our list of first names to update it ot include these new characters.
firsts <- unlist(lapply(strsplit(V(hp5netfull)$name, " "), '[[', 1))

plot(hp5netfull, vertex.shape="none", vertex.label.cex=0.6, edge.arrow.size=0.4, vertex.label=firsts, layout=layout.kamada.kawai)

# A common problem of edgelists is that the same edges may be present more than once. For instance, you might have interviewed both the ego and alter and the same tie might appear more than once. (e.g., Ron said he was friends with Harry, and Harry reported the same thing.)

# If you just want to remove duplicate edges, you can use the same `simplify()` functions used above to remove self-loops.

# But you might prefer to count the number of times an edge appeared and use it as an edge value.

# Let's add some duplicate edges to our Book 5 edgelist, then use the `aggregate()` functions to count occurrences.

hp5newedges <- data.frame(rbind(hp5edges,
                                c("Harry James Potter", "Ronald Weasley"),
                                c("Ronald Weasley", "Harry James Potter"),
                                c("Hermione Granger", "Ronald Weasley"),
                                c("Hermione Granger", "Harry James Potter"),
                                c("Hermione Granger", "Harry James Potter")))

# this takes a list of ones and takes the sum of them for each unique row in the edgelist
(hp5edgeweights <- aggregate(list(count=rep(1, nrow(hp5newedges))), hp5newedges, FUN=sum))
##                    X.From.                  X.To. count
## 1           Alicia Spinnet         Alicia Spinnet     1
## 2         Angelina Johnson         Alicia Spinnet     1
## 3             Fred Weasley         Alicia Spinnet     1
## 4           George Weasley         Alicia Spinnet     1
## 5       Harry James Potter         Alicia Spinnet     1
## 6               Katie Bell         Alicia Spinnet     1
## 7           Alicia Spinnet       Angelina Johnson     1
## 8         Angelina Johnson       Angelina Johnson     1
## 9             Fred Weasley       Angelina Johnson     1
## 10          George Weasley       Angelina Johnson     1
## 11      Harry James Potter       Angelina Johnson     1
## 12              Katie Bell       Angelina Johnson     1
## 13       Anthony Goldstein      Anthony Goldstein     1
## 14         Ernie Macmillan      Anthony Goldstein     1
## 15           Hannah Abbott      Anthony Goldstein     1
## 16  Justin Finch-Fletchley      Anthony Goldstein     1
## 17             Susan Bones      Anthony Goldstein     1
## 18              Terry Boot      Anthony Goldstein     1
## 19               Cho Chang              Cho Chang     1
## 20      Harry James Potter              Cho Chang     1
## 21             Dean Thomas            Dean Thomas     1
## 22            Draco Malfoy           Draco Malfoy     1
## 23           Gregory Goyle           Draco Malfoy     1
## 24         Pansy Parkinson           Draco Malfoy     1
## 25          Vincent Crabbe           Draco Malfoy     1
## 26       Anthony Goldstein        Ernie Macmillan     1
## 27         Ernie Macmillan        Ernie Macmillan     1
## 28           Hannah Abbott        Ernie Macmillan     1
## 29      Harry James Potter        Ernie Macmillan     1
## 30  Justin Finch-Fletchley        Ernie Macmillan     1
## 31             Susan Bones        Ernie Macmillan     1
## 32              Terry Boot        Ernie Macmillan     1
## 33          Alicia Spinnet           Fred Weasley     1
## 34        Angelina Johnson           Fred Weasley     1
## 35            Fred Weasley           Fred Weasley     1
## 36          George Weasley           Fred Weasley     1
## 37           Ginny Weasley           Fred Weasley     1
## 38      Harry James Potter           Fred Weasley     1
## 39        Hermione Granger           Fred Weasley     1
## 40              Katie Bell           Fred Weasley     1
## 41              Lee Jordan           Fred Weasley     1
## 42          Ronald Weasley           Fred Weasley     1
## 43          Alicia Spinnet         George Weasley     1
## 44        Angelina Johnson         George Weasley     1
## 45            Fred Weasley         George Weasley     1
## 46          George Weasley         George Weasley     1
## 47           Ginny Weasley         George Weasley     1
## 48      Harry James Potter         George Weasley     1
## 49        Hermione Granger         George Weasley     1
## 50              Katie Bell         George Weasley     1
## 51              Lee Jordan         George Weasley     1
## 52          Ronald Weasley         George Weasley     1
## 53            Fred Weasley          Ginny Weasley     1
## 54          George Weasley          Ginny Weasley     1
## 55           Ginny Weasley          Ginny Weasley     1
## 56      Harry James Potter          Ginny Weasley     1
## 57        Hermione Granger          Ginny Weasley     1
## 58           Luna Lovegood          Ginny Weasley     1
## 59      Neville Longbottom          Ginny Weasley     1
## 60          Ronald Weasley          Ginny Weasley     1
## 61           Gregory Goyle          Gregory Goyle     1
## 62         Pansy Parkinson          Gregory Goyle     1
## 63          Vincent Crabbe          Gregory Goyle     1
## 64       Anthony Goldstein          Hannah Abbott     1
## 65         Ernie Macmillan          Hannah Abbott     1
## 66           Hannah Abbott          Hannah Abbott     1
## 67  Justin Finch-Fletchley          Hannah Abbott     1
## 68             Susan Bones          Hannah Abbott     1
## 69              Terry Boot          Hannah Abbott     1
## 70          Alicia Spinnet     Harry James Potter     1
## 71        Angelina Johnson     Harry James Potter     1
## 72       Anthony Goldstein     Harry James Potter     1
## 73               Cho Chang     Harry James Potter     1
## 74             Dean Thomas     Harry James Potter     1
## 75         Ernie Macmillan     Harry James Potter     1
## 76            Fred Weasley     Harry James Potter     1
## 77          George Weasley     Harry James Potter     1
## 78           Ginny Weasley     Harry James Potter     1
## 79           Hannah Abbott     Harry James Potter     1
## 80      Harry James Potter     Harry James Potter     1
## 81        Hermione Granger     Harry James Potter     3
## 82  Justin Finch-Fletchley     Harry James Potter     1
## 83              Katie Bell     Harry James Potter     1
## 84           Luna Lovegood     Harry James Potter     1
## 85      Neville Longbottom     Harry James Potter     1
## 86             Padma Patil     Harry James Potter     1
## 87           Percy Weasley     Harry James Potter     1
## 88          Ronald Weasley     Harry James Potter     2
## 89         Seamus Finnigan     Harry James Potter     1
## 90             Susan Bones     Harry James Potter     1
## 91              Terry Boot     Harry James Potter     1
## 92            Fred Weasley       Hermione Granger     1
## 93          George Weasley       Hermione Granger     1
## 94           Ginny Weasley       Hermione Granger     1
## 95      Harry James Potter       Hermione Granger     1
## 96        Hermione Granger       Hermione Granger     1
## 97           Luna Lovegood       Hermione Granger     1
## 98      Neville Longbottom       Hermione Granger     1
## 99          Ronald Weasley       Hermione Granger     1
## 100             Terry Boot       Hermione Granger     1
## 101      Anthony Goldstein Justin Finch-Fletchley     1
## 102        Ernie Macmillan Justin Finch-Fletchley     1
## 103          Hannah Abbott Justin Finch-Fletchley     1
## 104     Harry James Potter Justin Finch-Fletchley     1
## 105 Justin Finch-Fletchley Justin Finch-Fletchley     1
## 106            Susan Bones Justin Finch-Fletchley     1
## 107             Terry Boot Justin Finch-Fletchley     1
## 108         Alicia Spinnet             Katie Bell     1
## 109       Angelina Johnson             Katie Bell     1
## 110           Fred Weasley             Katie Bell     1
## 111         George Weasley             Katie Bell     1
## 112     Harry James Potter             Katie Bell     1
## 113             Katie Bell             Katie Bell     1
## 114           Fred Weasley             Lee Jordan     1
## 115         George Weasley             Lee Jordan     1
## 116     Harry James Potter             Lee Jordan     1
## 117             Lee Jordan             Lee Jordan     1
## 118          Ginny Weasley          Luna Lovegood     1
## 119     Harry James Potter          Luna Lovegood     1
## 120       Hermione Granger          Luna Lovegood     1
## 121          Luna Lovegood          Luna Lovegood     1
## 122     Neville Longbottom          Luna Lovegood     1
## 123         Ronald Weasley          Luna Lovegood     1
## 124          Ginny Weasley     Neville Longbottom     1
## 125     Harry James Potter     Neville Longbottom     1
## 126       Hermione Granger     Neville Longbottom     1
## 127          Luna Lovegood     Neville Longbottom     1
## 128     Neville Longbottom     Neville Longbottom     1
## 129         Ronald Weasley     Neville Longbottom     1
## 130           Draco Malfoy        Pansy Parkinson     1
## 131          Gregory Goyle        Pansy Parkinson     1
## 132        Pansy Parkinson        Pansy Parkinson     1
## 133         Vincent Crabbe        Pansy Parkinson     1
## 134          Parvati Patil          Parvati Patil     1
## 135          Percy Weasley          Percy Weasley     1
## 136           Fred Weasley         Ronald Weasley     1
## 137         George Weasley         Ronald Weasley     1
## 138          Ginny Weasley         Ronald Weasley     1
## 139     Harry James Potter         Ronald Weasley     2
## 140       Hermione Granger         Ronald Weasley     2
## 141          Luna Lovegood         Ronald Weasley     1
## 142     Neville Longbottom         Ronald Weasley     1
## 143          Percy Weasley         Ronald Weasley     1
## 144         Ronald Weasley         Ronald Weasley     1
## 145        Seamus Finnigan        Seamus Finnigan     1
## 146      Anthony Goldstein            Susan Bones     1
## 147        Ernie Macmillan            Susan Bones     1
## 148          Hannah Abbott            Susan Bones     1
## 149 Justin Finch-Fletchley            Susan Bones     1
## 150            Susan Bones            Susan Bones     1
## 151             Terry Boot            Susan Bones     1
## 152      Anthony Goldstein             Terry Boot     1
## 153        Ernie Macmillan             Terry Boot     1
## 154          Hannah Abbott             Terry Boot     1
## 155 Justin Finch-Fletchley             Terry Boot     1
## 156            Susan Bones             Terry Boot     1
## 157             Terry Boot             Terry Boot     1
## 158          Gregory Goyle         Vincent Crabbe     1
## 159        Pansy Parkinson         Vincent Crabbe     1
## 160         Vincent Crabbe         Vincent Crabbe     1
# take a look at the edges that appear more than once
hp5edgeweights[which(hp5edgeweights$count>1),]
##                X.From.              X.To. count
## 81    Hermione Granger Harry James Potter     3
## 88      Ronald Weasley Harry James Potter     2
## 139 Harry James Potter     Ronald Weasley     2
## 140   Hermione Granger     Ronald Weasley     2
# create a network and assign the counts as an edge weight
(hp5netweight <- graph_from_edgelist(as.matrix(hp5edgeweights[,1:2]),directed=TRUE))
## IGRAPH a7f6a56 DN-- 28 160 -- 
## + attr: name (v/c)
## + edges from a7f6a56 (vertex names):
##  [1] Alicia Spinnet    ->Alicia Spinnet    Angelina Johnson  ->Alicia Spinnet   
##  [3] Fred Weasley      ->Alicia Spinnet    George Weasley    ->Alicia Spinnet   
##  [5] Harry James Potter->Alicia Spinnet    Katie Bell        ->Alicia Spinnet   
##  [7] Alicia Spinnet    ->Angelina Johnson  Angelina Johnson  ->Angelina Johnson 
##  [9] Fred Weasley      ->Angelina Johnson  George Weasley    ->Angelina Johnson 
## [11] Harry James Potter->Angelina Johnson  Katie Bell        ->Angelina Johnson 
## [13] Anthony Goldstein ->Anthony Goldstein Ernie Macmillan   ->Anthony Goldstein
## [15] Hannah Abbott     ->Anthony Goldstein
## + ... omitted several edges
(E(hp5netweight)$weight <- hp5edgeweights$count)
##   [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##  [75] 1 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [112] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1
## [149] 1 1 1 1 1 1 1 1 1 1 1 1
# Normally, in addition to your edgelist, you will have a table of attributes for the nodes in your network; variables like age and gender, for example.

# Loading these data is just like importing any other data in R.

attributes <- read.csv("/Users/rheemh/Dropbox (ASU)/Coding/R/hpindividuals.csv", header=TRUE)
head(attributes)
##   id                   name schoolyear gender house
## 1 12         Demelza Robins       1993      2     1
## 2  3       Angelina Johnson       1989      2     1
## 3 34            Lucian Bole       1988      1     4
## 4 13         Dennis Creevey       1994      1     1
## 5 56         Ronald Weasley       1991      1     1
## 6 28 Justin Finch-Fletchley       1991      1     2
V(hp5netfull)
## + 34/34 vertices, named, from c3ecd40:
##  [1] Alicia Spinnet         Angelina Johnson       Fred Weasley          
##  [4] George Weasley         Harry James Potter     Katie Bell            
##  [7] Anthony Goldstein      Ernie Macmillan        Hannah Abbott         
## [10] Justin Finch-Fletchley Susan Bones            Terry Boot            
## [13] Cho Chang              Dean Thomas            Draco Malfoy          
## [16] Pansy Parkinson        Ginny Weasley          Hermione Granger      
## [19] Lee Jordan             Ronald Weasley         Luna Lovegood         
## [22] Neville Longbottom     Gregory Goyle          Vincent Crabbe        
## [25] Padma Patil            Parvati Patil          Percy Weasley         
## [28] Seamus Finnigan        Lavender Brown         Millicent Bulstrode   
## + ... omitted several vertices
# This table appears to contain individuals who are not in the Book 5 network. Let's use the `%in%` operator to extract just the individuals in the Book 5 network from our attributes dataframe.

book5students <- attributes[attributes$name %in% V(hp5netfull)$name,]

# then reorder the attributes to match the order that the individual appear as network vertices.
book5students <- book5students[match(V(hp5netfull)$name, book5students$name), ]

# now we can simply assign the dataframe columns as vertex attributes, e.g.,
V(hp5netfull)$house <- book5students$house

# but let's use a factor to get nice colors
housecolors <- c("firebrick", "darkgoldenrod", "darkslateblue", "darkgreen")
V(hp5netfull)$housecolors <- as.character(factor(book5students$house, levels=1:4, labels=housecolors))

plot(hp5netfull, vertex.shape="none", vertex.label.color=V(hp5netfull)$housecolors, vertex.label.cex=0.6, edge.arrow.size=0.3, vertex.label=firsts, layout=layout.kamada.kawai)

# Network data may also be formatted as a sociomatrix, which is a square matrix where the rows and columns represent individuals in the network and the cell values represent the ties between them (valued or 0/1 for unvalued).

# In general, it is impractical to record data in this format. In most cases, trying to record data in a sociomatric means you will be constantly scrambling to add more columns and rows that will be mostly filled with zeroes.

# The storage requirements for a sociomatrix increase with the square of the number of observed vertices in your network, even if most of the entries in the sociomatrix are zero (as they typically are for even moderately-sized populations). 

# Much better to maintain a list of individuals and edges as they appear.

# Sociomatrices are more useful when there is a non-zero value in most cells (i.e., when the data are not sparse).

# Such is the case when the relationship between nodes involves some kind of distance metric (e.g., physical distance between households or relatedness coefficients).

# Distance matrices like these are often important covariates of other networks (e.g., relatedness and physical distance often correlate with ties of support between individuals), but you will not usually generate such matrices by hand.

# Instead, you will likely generate distance matrices in R or some other software program using calculations based off other data (e.g., latitutde and longitude coordinates).

# Here's how to import a sociomatrix (and get it correctly lined up with your attribute data).

# read in data
hp5df <- read.table("/Users/rheemh/Dropbox (ASU)/Coding/R/hp5matrix.txt", sep="\t", header=FALSE) #note that this file has no row or column names)

# inspect it
head(hp5df)
##                                                                                                                                V1
## 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 2 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 3 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 4 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0
## 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(dim(hp5df))
## [1] 64  1
# R thinks our data frame has only one column. That's not right.

# Taking a look at the data in a spreadsheet viewer suggests maybe this dataset is formatted differently. 

# Let's try a different separator when we read in the data.

# read in data
hp5df <- read.table("/Users/rheemh/Dropbox (ASU)/Coding/R/hp5matrix.txt", sep=" ", header=FALSE)

# inspect
dim(hp5df) # much better
## [1] 64 64
# Sometimes networks may be generated from data on the presence or absence of individuals at certain palce or time.

# Such data should normally be formatted as an affiliation matrix, where individuals appear in the rows and events/places/times in the columns, with values in the cells filled out as appropriate (did the individual attend the event or not).

# To convert an affiliation (person-by-event) matrix to a person-to-person network, simply multiply the affiliation matrix by its transpose.

# Carefully consider what an affiliation matrix means in terms of relationships between persons. Not all group, place, or event affiliations correspond to relationships between persons that re meaning ful with respect to your research question.
# The intergraph package allows you to convert network obejcts from `igraph` to `network` (i.e., `statnet`) format and vice versa as well as to or from formats used by other network platforms such as pajeck.

# I often end up using both `igraph` and `statnet` when I'm working with a network dataset, because different centrality measures are implemented in them, and also because sometimes a network just looks better plotted using one package rather than the other.
library(intergraph)

detach("package:igraph") # don't use igraph and statnet at the same time, they have many functions with the same names
library(statnet)
## Loading required package: tergm
## Loading required package: ergm
## Loading required package: network
## network: Classes for Relational Data
## Version 1.16.1 created on 2020-10-06.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##                     Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
##                     Martina Morris, University of Washington
##                     Skye Bender-deMoll, University of Washington
##  For citation information, type citation("network").
##  Type help("network-package") to get started.
## 
## ergm: version 3.11.0, created on 2020-10-14
## Copyright (c) 2020, Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
##                     Carter T. Butts, University of California -- Irvine
##                     Steven M. Goodreau, University of Washington
##                     Pavel N. Krivitsky, UNSW Sydney
##                     Martina Morris, University of Washington
##                     with contributions from
##                     Li Wang
##                     Kirk Li, University of Washington
##                     Skye Bender-deMoll, University of Washington
##                     Chad Klumb
##                     MichaƂ Bojanowski, Kozminski University
##                     Ben Bolker
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("ergm").
## NOTE: Versions before 3.6.1 had a bug in the implementation of the bd()
## constraint which distorted the sampled distribution somewhat. In
## addition, Sampson's Monks datasets had mislabeled vertices. See the
## NEWS and the documentation for more details.
## NOTE: Some common term arguments pertaining to vertex attribute and
## level selection have changed in 3.10.0. See terms help for more
## details. Use 'options(ergm.term=list(version="3.9.4"))' to use old
## behavior.
## Loading required package: networkDynamic
## 
## networkDynamic: version 0.10.1, created on 2020-01-16
## Copyright (c) 2020, Carter T. Butts, University of California -- Irvine
##                     Ayn Leslie-Cook, University of Washington
##                     Pavel N. Krivitsky, University of Wollongong
##                     Skye Bender-deMoll, University of Washington
##                     with contributions from
##                     Zack Almquist, University of California -- Irvine
##                     David R. Hunter, Penn State University
##                     Li Wang
##                     Kirk Li, University of Washington
##                     Steven M. Goodreau, University of Washington
##                     Jeffrey Horner
##                     Martina Morris, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("networkDynamic").
## 
## tergm: version 3.7.0, created on 2020-10-15
## Copyright (c) 2020, Pavel N. Krivitsky, UNSW Sydney
##                     Mark S. Handcock, University of California -- Los Angeles
##                     with contributions from
##                     David R. Hunter, Penn State University
##                     Steven M. Goodreau, University of Washington
##                     Martina Morris, University of Washington
##                     Nicole Bohme Carnegie, New York University
##                     Carter T. Butts, University of California -- Irvine
##                     Ayn Leslie-Cook, University of Washington
##                     Skye Bender-deMoll
##                     Li Wang
##                     Kirk Li, University of Washington
##                     Chad Klumb
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("tergm").
## Loading required package: ergm.count
## 
## ergm.count: version 3.4.0, created on 2019-05-15
## Copyright (c) 2019, Pavel N. Krivitsky, University of Wollongong
##                     with contributions from
##                     Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("ergm.count").
## NOTE: The form of the term 'CMP' has been changed in version 3.2 of
## 'ergm.count'. See the news or help('CMP') for more information.
## Loading required package: sna
## Loading required package: statnet.common
## 
## Attaching package: 'statnet.common'
## The following object is masked from 'package:base':
## 
##     order
## sna: Tools for Social Network Analysis
## Version 2.6 created on 2020-10-5.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##  For citation information, type citation("sna").
##  Type help(package="sna") to get started.
## Loading required package: tsna
## 
## statnet: version 2019.6, created on 2019-06-13
## Copyright (c) 2019, Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
##                     Carter T. Butts, University of California -- Irvine
##                     Steven M. Goodreau, University of Washington
##                     Pavel N. Krivitsky, University of Wollongong
##                     Skye Bender-deMoll
##                     Martina Morris, University of Washington
## Based on "statnet" project software (statnet.org).
## For license and citation information see statnet.org/attribution
## or type citation("statnet").
## unable to reach CRAN
hp5network <- asNetwork(hp5netfull)
hp5network
##  Network attributes:
##   vertices = 34 
##   directed = TRUE 
##   hyper = FALSE 
##   loops = FALSE 
##   multiple = FALSE 
##   bipartite = FALSE 
##   total edges= 133 
##     missing edges= 0 
##     non-missing edges= 133 
## 
##  Vertex attribute names: 
##     house housecolors vertex.names 
## 
## No edge attributes
# Easy peasy. Note that `igraph` does not support network level attribtues (indicated with %n% in statnet).

# So if you convert an object from `statnet` to `igraph`, you'll lose these.

# Edge and vertex attributes are carried over, however.