#Just have a look at the network, to see
plot(s_friends,vertex.col="WHITE")
plot(s_friends,vertex.col="S3")
#some example models for the workshop.
#This script assumes that the libraries and data have already been loaded
#Start w. a model that is just density, reciprocity, and matching on
#grade and race
m1<-ergm(s_friends~edges+mutual+nodematch("S3")+nodematch("WHITE"));
summary(m1);
#now add number of common clubs
m2<-ergm(s_friends~edges+mutual+nodematch("S3")+
nodematch("WHITE")+edgecov(s_clubs,"ovlpec"));
summary(m2)
#now let the grade effect vary by grade
m3<-ergm(s_friends~edges+mutual+nodematch("S3",diff=TRUE)+
nodematch("WHITE")+edgecov(s_clubs,"ovlpec"));
summary(m3)
#now let the race effect vary
m4<-ergm(s_friends~edges+mutual+nodematch("S3")+
nodematch("WHITE",diff=TRUE)+edgecov(s_clubs,"ovlpec"));
summary(m4)
#add a transitivity effect
m5<-ergm(s_friends~edges+mutual+ttriad+nodematch("S3")+
nodematch("WHITE")+edgecov(s_clubs,"ovlpec"));
summary(m5)
#now add node level send & recieve effects
#these take forever, so commented out!
#m6<-ergm(s_friends~edges+mutual+sender+receiver+nodematch("S3")+
nodematch("WHITE")+edgecov(s_clubs,"ovlpec"));
#summary(m6)
#now we want to do some goodness of fit tests. The idea is to simulate
#a network from the fit model, and compare higher-order
#statistics to the observed network. Let's start by simulating from
#one of the models.
#run the simulation
m5.sim<-simulate(m5,nsim=2);
#look at the resulting elements
names(m5.sim);
#summarize one of them (default listing)
#summary(m5.sim[[1]])
#plot one of the networks
plot(m5.sim$networks[[1]],vertex.col="WHITE")
#the built in goodness-of-fit routine is also very useful.
#look at the function
help(gof);
m5.gof <- gof(m5~idegree);
plot(m5.gof);