compare_MEMS | R Documentation |
compare_MEMS
implements parametric and nonparametric routines to compare MEMS
estimate between models. When compared between nested models, compare_MEMS
results can be interpreted as the portion of a MEMS explained by a mediating or confounding variable. When compared between models with distinct functional forms and the same specification, compare_MEMS
results can be interpreted as the sensitivity of MEMS
results to decision about model functional form as described by Wertsching and Duxbury (2025).
compare_MEMS
can also be used as a test of the difference between two MEMS
estimates within the same model. This is useful when researchers watn to formally evaluate whether the MEMS
for one explanatory micro mechanism is significantly larger or smaller than a second explanatory micro mecahnism.
The difference in MEMS is the change in MEMS after one or more micro-processes are included into a model or, in the case of sensitivity tests, when the functional form is changed. Let MEMS_p
represent the MEMS obtained from a model that omits one or more intervening variables and MEMS_f
be the MMES obtained from a model that includes the intervening variable(s). The change in MEMS is given
\Delta MEMS=MEMS_p-MEMS_f
. MEMS_p
and MEMS_f
may also be have the same specification but use distinct functional forms or other modeling decisions in the case of sensitivity tests. Tuning parameters can be assigned to toggle the strength of \theta
in model-implied estimates of MEMS
. MEMS
currently accepts glm
, glmer
, ergm
, btergm
, sienaFit
, rem.dyad
, and netlogit
objects and implements both parametric and nonparametric estimation. Pooled estimation for multiple network models is also implemented for ergm
and sienaFit
objects.
compare_MEMS(partial_model,
full_model,
micro_process,
micro_process2=NULL,
macro_function,
macro_function2=NULL,
object_type=NULL,
interval=c(0,1),
nsim=500,
algorithm="parametric",
silent=FALSE,
full_output=FALSE,
sensitivity_ev=TRUE,
SAOM_data=NULL,
SAOM_var=NULL,
time_interval=NULL,
covar_list=NULL,
edgelist=NULL,
net_logit_y=NULL,
net_logit_x=NULL,
group_id=NULL,
node_numbers=NULL,
mediator=NULL,
link_id=NULL,
controls=NULL,
control_functions=NULL)
partial_model |
the micro-model excluding one or more intervening or confounding variables of interest. May also be a fully specified model in the case of sensitivity tests. Currently accepts |
full_model |
the micro-model including one or more intervening or confounding variables of interest. May also be a fully specified model with a distinct functional form from |
micro_process |
a character string containing the name of the micro process of interest. The character string should exactly match coefficient names in |
micro_process2 |
an optional character string containing the name of the micro process for comparison. Used when |
macro_function |
a |
macro_function2 |
an optional function that calculates the macro statistic of interest. When provided, |
object_type |
A character string that tells netmediate the type of object to apply the
|
interval |
The value of tuning parameters to assign to |
nsim |
The number of simulations or bootstrap samples to use during estimation. |
algorithm |
The estimation algorithm to be used. Currently accepts |
silent |
logical parameter. Whether to provide updates on the progress of the simulation or not. |
full_output |
logical parameter. If set to |
sensitivity_ev |
optional parameter. If set to |
SAOM_data |
required when the model is a |
SAOM_var |
optional parameter when the model is a |
time_interval |
an optional parameter to be used with |
covar_list |
an optional list of sender/receiver covariates used in |
edgelist |
an optional three column edgelist providing the sender, receiver, and time of event occurrence when using rem. |
net_logit_y |
the dependent variable for |
net_logit_x |
the matrix of independent variables for |
group_id |
optional vector of group identifiers to use when estimating a |
node_numbers |
a numeric vector containing the number of nodes in each group_id when using |
mediator |
a character string detailing the mediator of interest. Intended for internal use with the |
link_id |
a vector or list of vectors corresponding to unique identifiers. Intended for internal use with the |
controls |
a vector of character strings listing the controls to be calculated when using |
control_functions |
a list of functions to calculate the macro control variables provided in controls. Intended for internal use with the |
Compares MEMS estimates between two models. If one or more confounding or intervening variables are excluded or included between models, the change in MEMS can be interpreted as the portion of the MEMS explained by one or more confounding or intervening variable. If two models are provided with the same specification but a distinct functional form, the change in MEMS is a sensitivty test of how much the MEMS estimate changes because of a model decision. This can be useful, for example, when comparing TERGM and SAOM estimates as each models make distinct assumptions about sources of network change and the temporal ordering of tie changes.
compare_MEMS
functionality inherits directly from the MEMS
command. See the MEMS
page for more details.
If full_output=FALSE
, then a table is returned with the change MEMS, its standard error, confidence interval, and p-value, and the same results for the partial and complete MEMS.
If full_output=TRUE
, then a list is returned with the following three elements.
diff_MEMS_results |
is the table of summary output containing the MEMS, its standard error, confidence interval, and p-value, and a list of the simulated values of the change in MEMS. |
p_MEMS_results |
contains the summary statistics for the partial MEMS along with all simulated statistics. |
f_MEMS_results |
contains the summary statistics for the full MEMS along with all simulated statistics. |
Duxbury, Scott W. Associate Professor, University of North Carolina–Chapel Hill, Department of Sociology.
Duxbury, Scott W. 2024. "Micro Effects on Macro Structure in Social Networks." Sociological Methodology.
Wertsching, Jenna, and Scott W. Duxbury. Working paper. "Micro Effects on Macro Structure: Identification, Comparison between Nested Models, and Sensitivity Tests for Functional Form."
Duxbury, Scott W., and Xin Zhao. Working paper. "Sensitivity Tests for Micro-Macro Network Analysis."
AMME
MEMS
ergm.mma
mediate
mediate_MEMS
##############
# Not run
###############
library(statnet)
library(igraph)
data("faux.mesa.high")
####################
###mediation analysis
####################
#how much of the effect of racial homophily on transitivity
#is explained by triadic closure effects?
model<-ergm(faux.mesa.high~edges+nodecov("Grade")+nodefactor("Race")+
nodefactor("Sex")+nodematch("Race")+nodematch("Sex")+absdiff("Grade"))
model2<-ergm(faux.mesa.high~edges+nodecov("Grade")+nodefactor("Race")+
nodefactor("Sex")+nodematch("Race")+nodematch("Sex")+absdiff("Grade")+
gwesp(.5,fixed=TRUE))
compare_MEMS(partial_model=model,
full_model=model2,
micro_process="nodematch.Race",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
########################
# Effect size comparison
########################
#Is the effect of racial homophily on transitivity larger or smaller
#than the effect of grade homophily?
compare_MEMS(partial_model=model2,
full_model=model2,
micro_process="nodematch.Race",
micro_process2="absdiff.Grade",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
###################
# Robustness check
##################
#Are MEMS estimates derived from ERGM robust to alternative MPLE estimation strategies?
model_MPLE<-ergmMPLE(faux.mesa.high~edges+nodecov("Grade")+nodefactor("Race")+
nodefactor("Sex")+nodematch("Race")+nodematch("Sex")+absdiff("Grade")+
gwesp(.5,fixed=TRUE),
output="fit")
compare_MEMS(partial_model=model2,
full_model=model_MPLE,
micro_process="gwesp.fixed.0.5",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric",
sensitivity_ev=FALSE)
###Compare between SAOM and TERGM
#treating behavioral (smoking) autocorrelation
#as outcome
library(RSiena)
##we'll load RSiena since we're using data from here.
###create a list of adjacency matrices
network_array<-list(s501,s502,s503)
smoking<-as.data.frame(s50s) ##load smoking data
##for our analysis, we'll look at binary smoking behavior
for(i in 1:ncol(smoking)){
smoking[,i][smoking[,i]>1]<-2
}
alcohol<-as.data.frame(s50a) ##we'll use alcohol consumption as a covariate as well
########################################
# Co-evolution model
#######################################
##create "sienaDependent" object,
TLSnet<-sienaDependent(array(c(network_array[[1]],
network_array[[2]],
network_array[[3]]),
dim=c(50,50,3)))
TLSbeh<-sienaDependent(as.matrix(smoking),type="behavior")
#set covariates
Alcohol<-varCovar(as.matrix(alcohol))
###create dataset, but specify network AND behavior
SAOM.Data<-sienaDataCreate(Network=TLSnet,
Behavior=TLSbeh,
Alcohol)
###Create the effects object
SAOM.terms<-getEffects(SAOM.Data)
###We'll start by specifying the NETWORK function
SAOM.terms<-includeEffects(SAOM.terms,egoX,altX,absDiffX,interaction1="Alcohol")
SAOM.terms<-includeEffects(SAOM.terms,egoX,altX,sameX,interaction1="Behavior")
SAOM.terms<-includeEffects(SAOM.terms,transTies,inPop)
###Now let's specify the BEHAVIOR function
SAOM.terms<-includeEffects(SAOM.terms,effFrom,name="Behavior",
interaction1="Alcohol")
SAOM.terms<-includeEffects(SAOM.terms,totSim,name="Behavior",
interaction1="Network")
SAOM.terms<-includeEffects(SAOM.terms,isolate,
name="Behavior",interaction1="Network")
#estimate the model
create.model<-sienaAlgorithmCreate(projname="Co-evolution_output",
seed=21093,
nsub=4,
n3=1000)
TLSmodel<-siena07(create.model,
data=SAOM.Data,
effects=SAOM.terms,
verbose=TRUE,
returnDeps=TRUE)
TLSmodel
#now fit the TERGM
library(statnet)
net_list<-list(as.network(s501),as.network(s502),as.network(s503))
net_list[[1]]<-network::set.vertex.attribute(net_list[[1]],"smoking",s50s[,1])
net_list[[2]]<-network::set.vertex.attribute(net_list[[2]],"smoking",s50s[,2])
net_list[[3]]<-network::set.vertex.attribute(net_list[[3]],"smoking",s50s[,3])
net_list[[1]]<-network::set.vertex.attribute(net_list[[1]],"alcohol",s50a[,1])
net_list[[2]]<-network::set.vertex.attribute(net_list[[2]],"alcohol",s50a[,2])
net_list[[3]]<-network::set.vertex.attribute(net_list[[3]],"alcohol",s50a[,3])
TERGM_1<-tergm(net_list~Form(
~edges+
mutual+
gwesp(.5,fixed=TRUE)+
gwidegree(.5,fixed=TRUE)+
nodeicov("smoking")+
nodeocov("smoking")+
nodematch("smoking")+
nodeicov("alcohol")+
nodeocov("alcohol")+
absdiff("alcohol")),
estimate="CMLE"
)
#create network autocorrelation function for TERGM
Moran_tergm<-function(x){
y<-network::get.vertex.attribute(x,"smoking")
return(nacf(x,y,type="moran",lag=1)[2])
}
#test difference in TERGM and SAOM estimates of the MEMS for
#network selection on same smoking behavior for
#smoking similarity at the aggregate level
compare_MEMS(partial_model=TLSmodel,
full_model=TERGM_1,
micro_process="same Behavior",
macro_function =Moran_dv,
micro_process2="Form~nodematch.smoking",
macro_function2=Moran_tergm,
object_type = "network",
SAOM_data = SAOM.Data,
silent=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.