mediate_MEMS | R Documentation |
mediate_MEMS
implements parametric and nonparametric routines to compare MEMS
estimate between models. Largely a wrapper for compare_MEMS
, the sole novel functionality of mediate_MEMS
is provided when a user specifies the model_comparison
argument to be TRUE
. When model_comparison
is set to TRUE
, mediate_MEMS
compares the direct, indirect, and total MEMS
estimates to those obtained from partial_model2
and full_model2
. This can be used as a sensitivity test to researchers' choice of model. It can also provide the basis for testing differences in direct, total, and indirect effect sizes within the same model by setting partial_model2
to equal partial_model
and full_model2
to equal full_model
and provide a second explanatory micro process to the micro_process2
argument. In these cases, the difference between "models" captures the differences effect size of the direct, indirect, and total MEMS
estimates for two distinct explanatory micro processes. See Wertsching and Duxbury (2025) for details.
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.
mediate_MEMS(partial_model,
full_model,
micro_process,
macro_function,
model_comparison=FALSE,
partial_model2=NULL,
full_model2=NULL,
micro_process2=NULL,
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 with a distinct functional form 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 in the case of sensitivity tests. Currently accepts |
micro_process |
a character string containing the name of the micro process of interest. The character string should exactly match coefficient names in |
macro_function |
a |
model_comparison |
returns sensitivity tests evaluating robustness of partial, full, and indirect MEMS estimates to distinct model choices when set to |
partial_model2 |
a second model identitical to the specification of |
full_model2 |
a second model identitical to the specification of |
micro_process2 |
the character string identifying the micro_process to compare in sensitivity analysis. Required if |
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.
If a single pair of models are compared, mediate_MEMS
results will be identical to compare_MEMS
results. However, if model_comparison
is set to TRUE
and a second pair of models are provided using a different set of control variables or a distinct functional form, mediate_MEMS
will also return sensitivity tests evaluating whether the partial, full, and indirect MEMS estimates are significantly different between the two sets of models. This functionality can also be used to formally test differences in partial, full, and indirect effect sizes by setting partial_model2
to be the same as partial model
and full_model2
to be the same as full_model
and setting micro_process2
to be a different variable than micro_process
.
mediate_MEMS
functionality inherits directly from the compare_MEMS
and MEMS
commands. See the compare_MEMS
and MEMS
pages for more details.
If full_output=FALSE
and model_comparison=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
and model_comparison=FALSE
, 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. |
If full_output=FALSE
and model_comparison=TRUE
, then a list is returned with the following elements.
model_set1 |
is the table of summary output testing the partial, full, and indirect MEMS using |
model_set2 |
is the table of summary output testing the partial, full, and indirect MEMS using |
model_comparison |
is the table of output testing the difference in estimates between |
If full_output=TRUE
and model_comparison=TRUE
, then a list is returned with the following three elements.
summary_results |
is the list of summary output provided as described above when |
sample_results |
is a list containing the simulation draws used to calculate point estimates, variance estimates, and sensitivity tests for the partial MEMS, full MEMS, and indirect MEMS. |
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
compare_MEMS
##############
# Not run
###############
library(statnet)
library(igraph)
data("faux.mesa.high")
#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 results from compare_MEMS and mediate_MEMS
compare_MEMS(partial_model=model,
full_model=model2,
micro_process="nodematch.Race",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
mediate_MEMS(partial_model=model,
full_model=model2,
micro_process="nodematch.Race",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
###test sensitivity to MPLE versus MCMC MLE estimation
modela<-ergmMPLE(faux.mesa.high~edges+nodecov("Grade")+nodefactor("Race")+
nodefactor("Sex")+nodematch("Race")+nodematch("Sex")+absdiff("Grade"),
output="fit")
model2a<-ergmMPLE(faux.mesa.high~edges+nodecov("Grade")+nodefactor("Race")+
nodefactor("Sex")+nodematch("Race")+nodematch("Sex")+absdiff("Grade")+
gwesp(.5,fixed=TRUE),
output="fit")
mediate_MEMS(partial_model=model,
full_model=model2,
micro_process="nodematch.Race",
model_comparison = TRUE,
partial_model2=modela,
full_model2=model2a,
micro_process2="nodematch.Race",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
##compare direct, total, and indirect effect sizes
mediate_MEMS(partial_model=model,
full_model=model2,
micro_process="nodematch.Race",
model_comparison = TRUE,
partial_model2=model,
full_model2=model2,
micro_process2="absdiff.Grade",
macro_function=transitivity,
object_type = "igraph",
silent=FALSE,
algorithm="parametric")
#####################################################
# More complicated sensitivty test using macro function 2
#####################################################
#are the direct, total, and indirect MEMS of
#network selection on similar smoking behavior on
#students' shared smoking robust to distinct
#model choices?
###Compare between SAOM and TERGM treating behavioral
#(smoking) autocorrelation as outcome, smoking homophily
#as treatment, and triadic closure as mediator
########################################
# Co-evolution SAOM
#######################################
library(RSiena)
network_array<-list(s501,s502,s503)
smoking<-as.data.frame(s50s)
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
##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")
###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 WITHOUT transitive ties
create.model<-sienaAlgorithmCreate(projname="Co-evolution_output",
seed=21093,
nsub=4,
n3=1000)
TLSmodel_notrans<-siena07(create.model,
data=SAOM.Data,
effects=SAOM.terms,
verbose=TRUE,
returnDeps=TRUE)
#include transTies
SAOM.terms<-includeEffects(SAOM.terms,transTies,inPop)
TLSmodel<-siena07(create.model,
data=SAOM.Data,
effects=SAOM.terms,
verbose=TRUE,
returnDeps=TRUE)
#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_nogwesp<-tergm(net_list~Form(
~edges+
mutual+
gwidegree(.5,fixed=TRUE)+
nodeicov("smoking")+
nodeocov("smoking")+
nodematch("smoking")+
nodeicov("alcohol")+
nodeocov("alcohol")+
absdiff("alcohol")),
estimate="CMLE"
)
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 direct, total, and indirect
#MEMS estimates
mediate_MEMS(partial_model=TLSmodel_notrans,
full_model=TLSmodel,
micro_process="same Behavior",
macro_function =Moran_dv,
model_comparison = TRUE,
partial_model2=TERGM_1_nogwesp,
full_model2=TERGM_1,
micro_process2="Form~nodematch.smoking",
macro_function2=Moran_tergm,
object_type = "network",
SAOM_data = SAOM.Data,
silent=FALSE,
nsim=100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.