Skip to content

Instantly share code, notes, and snippets.

@sdaza
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdaza/7794e824c5f90e381414 to your computer and use it in GitHub Desktop.
Save sdaza/7794e824c5f90e381414 to your computer and use it in GitHub Desktop.
Example ERGM (dyadic cov)
###########
# Example
##########
library(igraph)
actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David",
"Esmeralda"),
age=c(48,33,45,34,21),
gender=c("F","M","F","M","F"))
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda", "Alice"),
to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice", "Bob"),
same.dept=c(TRUE,FALSE,TRUE,TRUE,FALSE,TRUE, TRUE),
distance=c(3,1,4,5,6,4,3))
g <- graph.data.frame(relations, directed=TRUE, vertices=actors)
get.data.frame(g, what="vertices")
get.data.frame(g, what="edges")
plot(g)
detach("package:igraph")
library(intergraph)
n <- asNetwork(g)
mat <- as.sociomatrix(n, attrname="distance")
isSymmetric(mat)
mat
smat <- symmetrize(mat) # requires package sna
smat
# ERGM
library(ergm)
m01 <- ergm(n ~ edges + mutual + dyadcov(smat))
summary(m01)
m02 <- ergm(n ~ edges + mutual + dyadcov(smat))
summary(m02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment