This document outlines the steps necessary to install and estimate the SFRM-ERGM as described in the article Modeling Heterogeneous Peer Assortment Effects using Finite Mixture Exponential Random Graph Models. This model uses the ERGM framework implemented within the statnet
R package, a set of user defined ERGM terms, as well as a custom set of functions. Contained in this Supplementary Materials archive, there should be a tar.gz titled SRFM.ERGMuserterms_3.10.0.tar.gz
, a R file titled SRFM_ERGM.R
, two CSV files, one titled Example_Covariates.csv
and the other titled Example_Network.csv
. Unfortunately, this install only works under a 32 bit R, so if you get errors attempting to install the userterms package, make sure your R version is 32 bit.
To install the ERGM terms for network simulation OR to fit the final set of estimates using MLE ERGM, have statnet
already installed, and use the following commands. Simply running the LCERGM function does not require the SRFM.ERGMuserterms function.
install.packages("SRFM.ERGMuserterms_3.10.0.tar.gz", repos = NULL, type = "source", INSTALL_opts = "--no-multiarch")
library(statnet)
library(SRFM.ERGMuserterms)
library(clues)
source("SRFM_ERGM.R")
covariates <- read.csv("Example_Covariates.csv", stringsAsFactors = F)
net <- as.matrix(read.csv("Example_Network.csv", stringsAsFactors = F))
net <- network(net, directed = T)
net%v%"Age" <- covariates[,"Age_yr"]
net%v%"Gender" <- covariates[,"Gender"]
net%v%"Ethnicity" <- covariates[,"Ethnicity"]
net%v%"Alcohol_Use" <- covariates[,"HRB1_2y"]
net%v%"MJ_Use" <- covariates[,"HRB1_6y"]
net%v%"Tob_Use" <- covariates[,"HRB1_3y"]
net%v%"YSR" <- covariates[,"YSR"]
net%v%"latclass" <- covariates[,"latClass"]
fixedeffects <- . ~ . + gwesp(fixed = T, decay = .1) + mutual() + nodematch("Gender") + nodematch("Ethnicity")+
nodeicov("Alcohol_Use") + nodeocov("Tob_Use") + nodeocov("YSR") + nodeocov("MJ_Use")+
nodeicov("Tob_Use") + absdiff("Tob_Use") + absdiff("MJ_Use") + nodeicov("MJ_Use")+ nodeicov("YSR") + absdiff("YSR") + absdiff("Alcohol_Use")
mod2 <- LCERGM(fixedeffects, net ~ nodeocov("Alcohol_Use") + edges(), net, 2, type = "sender")
The LCERGM
function takes as its arguments a formula of fixed effects, and an additional formula of latent class effects. Any ERGM term can be used as a latent class effect, at least theoretically. The LCERGM function returns a GLM object representing the MPLE estimates from the best fitting (by AIC) converged solution. The second object in the list is a vector of modal class assignments, and the third object is a matrix of class membership probabilities.
===================== Full Simulation Study =====================
The full simulation study contained in the manuscript is based on bootstrap samples of an empirical data collected from adolescents. Additionally, the simulation study itself was written to be performed on a high performance cluster computer, and is not easily deployable on other systems. Due to this, if you are interested in the full simulation code, please contact the lead author of this manuscript, and they would be happy to work with you to get the simulation running locally.