# \dontshow{
require(ergm)
set.seed(21093)
a1<-network::as.network(matrix(c(rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3),
rbinom(10, 1,.3)),
nrow=10,ncol=10))
network::set.vertex.attribute(a1,"var.1",rbinom(10,1,.3))
a<-ergm(a1~edges+nodeifactor("var.1"))
ab<-ergm(a1~edges+nodeifactor("var.1")+nodeofactor("var.1"))
ergm.msma(a,ab,
direct_substructural_effect="nodeifactor.var.1.1",
mediator="nodeofactor.var.1.1")
# }
# \donttest{
library(ergm)
data("faux.mesa.high")
faux.mesa.high
#does sociality explain triadic effects?
#model without sociality effects
my.ergm1<-ergm(faux.mesa.high~edges+
nodematch("Grade")+
nodematch("Sex")+
nodematch("Race")+
gwesp(.5,fixed=TRUE),
control = control.ergm(MCMLE.termination="Hummel",
MCMLE.effectiveSize = NULL,
MCMC.samplesize = 5000,
MCMLE.maxit=120))
#model with sociality effects
my.ergm2<-ergm(faux.mesa.high~edges+
nodecov("Grade")+
nodefactor("Race")+
nodefactor("Sex")+
nodematch("Grade")+
nodematch("Sex")+
nodematch("Race")+
gwesp(.5,fixed=TRUE),
control = control.ergm(MCMLE.termination="Hummel",
MCMLE.effectiveSize = NULL,
MCMC.samplesize = 5000,
MCMLE.maxit=120))
###sociality effects as mediators
ergm.msma(my.ergm1,
my.ergm2,
direct_substructural_effect="gwesp.fixed.0.5",
mediator=c("nodecov.Grade","nodefactor.Sex.M","nodefactor.Race.White",
"nodefactor.Race.Other","nodefactor.Race.Hisp","nodefactor.Race.NatAm"),
estimate="aMSE")
# }
Run the code above in your browser using DataLab