Last active
August 29, 2015 14:05
-
-
Save sdaza/7794e824c5f90e381414 to your computer and use it in GitHub Desktop.
Example ERGM (dyadic cov)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########### | |
# 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