Title: | Dynamic Mixed-Membership Network Regression Model |
---|---|
Description: | Stochastic collapsed variational inference on mixed-membership stochastic blockmodel for networks, incorporating node-level predictors of mixed-membership vectors, as well as dyad-level predictors. For networks observed over time, the model defines a hidden Markov process that allows the effects of node-level predictors to evolve in discrete, historical periods. In addition, the package offers a variety of utilities for exploring results of estimation, including tools for conducting posterior predictive checks of goodness-of-fit and several plotting functions. The package implements methods described in Olivella, Pratt and Imai (2019) 'Dynamic Stochastic Blockmodel Regression for Social Networks: Application to International Conflicts', available at <https://www.santiagoolivella.info/pdfs/socnet.pdf>. |
Authors: | Santiago Olivella [aut, cre], Adeline Lo [aut, cre], Tyler Pratt [aut, cre], Kosuke Imai [aut, cre] |
Maintainer: | Santiago Olivella <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.0.2 |
Built: | 2024-10-24 05:15:02 UTC |
Source: | https://github.com/solivella/netmix |
mmsbm
packageThese are various utilities and generic methods used by the main package function.
approxB(y, d_id, pi_mat, directed = TRUE) getZ(pi_mat) alphaLBound(par, tot_nodes, c_t, x_t, s_mat, t_id, var_beta, mu_beta) alphaGrad(par, tot_nodes, c_t, x_t, s_mat, t_id, var_beta, mu_beta) .cbind.fill(...) .scaleVars(x, keep_const = TRUE) .transf_muvar(orig, is_var, is_array, des.mat, nblock = NULL, nstate = NULL) .bar.legend(colPalette, range) .mpower(mat, p) .findPerm(block_list, target_mat = NULL, use_perms = TRUE) .transf(mat) .compute.alpha(X, beta) .vcovBeta( all_phi, beta_coef, n.sim, n.blk, n.hmm, n.nodes, n.periods, mu.beta, var.beta, est_kappa, t_id_n, X ) .e.pi(alpha_list, kappa, C_mat = NULL) .initPi( soc_mats, dyads, edges, nodes_pp, dyads_pp, n.blocks, periods, directed, ctrl )
approxB(y, d_id, pi_mat, directed = TRUE) getZ(pi_mat) alphaLBound(par, tot_nodes, c_t, x_t, s_mat, t_id, var_beta, mu_beta) alphaGrad(par, tot_nodes, c_t, x_t, s_mat, t_id, var_beta, mu_beta) .cbind.fill(...) .scaleVars(x, keep_const = TRUE) .transf_muvar(orig, is_var, is_array, des.mat, nblock = NULL, nstate = NULL) .bar.legend(colPalette, range) .mpower(mat, p) .findPerm(block_list, target_mat = NULL, use_perms = TRUE) .transf(mat) .compute.alpha(X, beta) .vcovBeta( all_phi, beta_coef, n.sim, n.blk, n.hmm, n.nodes, n.periods, mu.beta, var.beta, est_kappa, t_id_n, X ) .e.pi(alpha_list, kappa, C_mat = NULL) .initPi( soc_mats, dyads, edges, nodes_pp, dyads_pp, n.blocks, periods, directed, ctrl )
y , d_id , pi_mat , directed
|
Internal arguments for blockmodel approximation. |
par |
Vector of parameter values. |
tot_nodes |
Integer vector; total number of nodes each node interacts with. |
c_t |
Integer matrix; samples from Poisson-Binomial counts of a node instantiating a group. |
x_t |
Numeric matrix; transposed monadic design matrices. |
s_mat |
Integer matrix; Samples of HMM states by time period. |
t_id |
Integer vector; for each node, what time-period is it observed in? zero-indexed. |
mu_beta , var_beta
|
Numeric arrays; prior mean and variances of monadic coefficients. |
... |
Numeric vectors; vectors of potentially different length to be cbind-ed. |
x , keep_const
|
Internal arguments for matrix scaling. |
orig |
Object to be transformed. |
is_var |
Boolean. Is the object to be transformed a variance term? |
is_array |
Boolean. Is the object to be transformed an array? |
des.mat |
Numeric matrix. Design matrix corresponding to transformed object. |
nblock |
Number of groups in model, defaults to |
nstate |
Number of hidden Markov states in model, defaults to |
colPalette |
A function produced by |
range |
The range of values to label the legend. |
mat |
Numeric matrix. |
p |
Numeric scalar; power to raise matrix to. |
block_list |
List of matrices; each element is a square, numeric matrix that defines a blockmodel, |
target_mat |
Numeric matrix; reference blockmodel that those in block_list should
be aligned to. Optional, defaults to |
use_perms |
Boolean; should all row/column permutations be explored when
realigning matrices? defaults to |
X |
Numeric matrix; design matrix of monadic predictors. |
beta |
Numeric array; array of coefficients associated with monadic predictors. It of dimensions Nr. Predictors by Nr. of Blocks by Nr. of HMM states. |
all_phi , beta_coef , n.sim , n.blk , n.hmm , n.nodes , n.periods , mu.beta , var.beta , est_kappa , t_id_n
|
Additional internal arguments for covariance estimation. |
alpha_list |
List of mixed-membership parameter matrices. |
kappa |
Numeric matrix; matrix of marginal HMM state probabilities. |
C_mat |
Numeric matrix; matrix of posterior counts of block instantiations per node. |
soc_mats , dyads , edges , nodes_pp , dyads_pp , n.blocks , periods , ctrl
|
Internal arguments for MM computation. |
These functions are meant for internal use only.
See individual return section for each function:
Matrix of cbind
'ed elements in ...
, with missing values in each vector filled with NA
.
Matrix; the result of raising mat
to the p
power.
List of permuted blockmodel matrices.
Matrix with transformed mixed-membership vectors along its rows, s.t. no element is equal to 0.0 or 1.0.
List of predicted alpha matrices, one element per HMM state.
Matrix of predicted mixed-membership vectors along its rows, with expectation computed over marginal distribution over HMM states for each time period.
Transformed data.frame with missing values list-wise deleted, or expanded with missing indicator variables.
List of sociomatrices.
List of bootstrapped sociomatrices.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
mmsbm
ObjectExtract Regression Coefficients for a Fitted mmsbm
Object
## S3 method for class 'mmsbm' coef(object, param = "All", ...)
## S3 method for class 'mmsbm' coef(object, param = "All", ...)
object |
An object of class |
param |
Character string, which set of parameters should the vcov be extracted for? One
of |
... |
Currently ignored |
For param="DyadCoef"
, a numeric vector. For param="MonadCoef"
, an array
with HMM states along the third dimension. For param="All"
, named list of individual return components.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) coef(lazega_mmsbm, "MonadCoef")
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) coef(lazega_mmsbm, "MonadCoef")
The function estimates the effect of a shift in monadic covariate values on the probability of edge formation in the network.
covFX(fm, cov, shift, max.val = FALSE)
covFX(fm, cov, shift, max.val = FALSE)
fm |
An object of class |
cov |
Character string identifying the monadic covariate to be shifted. |
shift |
Numeric value specifying the desired increase or decrease in the monadic covariate. The monadic predictor will be shifted by this value for all nodes and time periods. |
max.val |
An optional numeric value specifying the maximum possible value for the monadic covariate. |
List with named components:
Overall average effect of the covariate shift on the predicted probability of edge formation.
Vector of average effects of the covariate shift on the predicted probability of edge formation for each time period.
Vector of average effects of the covariate shift on the predicted probability of edge formation for each node.
Vector of average effects of the covariate shift on the predicted probability of edge formation for each node dyad.
Vector of estimated effects of the covariate shift on the predicted probability of edge formation for each node dyad-time unit.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ Age, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Compute effect of decreasing every lawyers' age by 10 years fx_list <- covFX(lazega_mmsbm, cov = "Age", shift = -10) fx_list[["Overall Avg. Effect of Age"]]
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ Age, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Compute effect of decreasing every lawyers' age by 10 years fx_list <- covFX(lazega_mmsbm, cov = "Age", shift = -10) fx_list[["Overall Avg. Effect of Age"]]
The function generates a variety of plots that serve as posterior predictive checks on the goodness of fit of a fitted mmsbm
object.
gof(x, ...) ## S3 method for class 'mmsbm' gof( x, gof_stat = c("Geodesics", "Degree"), level = 0.95, samples = 50, new.data.dyad = NULL, new.data.monad = NULL, seed = NULL, ... )
gof(x, ...) ## S3 method for class 'mmsbm' gof( x, gof_stat = c("Geodesics", "Degree"), level = 0.95, samples = 50, new.data.dyad = NULL, new.data.monad = NULL, seed = NULL, ... )
x |
An object of class |
... |
Currently ignored. |
gof_stat |
Character vector. Accepts any subset from "Geodesics","Degree", "Indegree", "Outdegree", "3-Motifs", "Dyad Shared Partners", "Edge Shared Partners", and "Incoming K-stars". See details. |
level |
Double. Level of credible interval for posterior predictive distribution around structural quantities of interest. |
samples |
Integer. Number of sampled networks from model's posterior predictive using |
new.data.dyad |
See |
new.data.monad |
See |
seed |
See |
Goodness of fit of network models has typically been established by evaluating how the structural characteristics of predicted networks
compare to those of the observed network. When estimated in a Bayesian framework, this approach is equivalent to
conducting posterior preditive checks on these structural quantities of interest. When new.data.dyad
and/or new.data.monad
are
passed that are different from those used in estimation, this is equivalent to conducting posterior predictive checks out-of-sample.
The set of structural features used to determine goodness of fit is somewhat arbitrary, and chosen mostly to incorporate various first order, second order, and (to the extent possible) third-order characteristics of the network. "Geodesics" focuses on the distribution over observed and predicted geodesic distances between nodes; "Indegree" and "Outdegree" focuses on the distribution over incoming and outgoing connections per node; "3-motifs" focus on a distribution over possible connectivity patterns between triads (i.e. the triadic census); "Dyad Shared Partners" focuses on the distribution over the number of shared partners between any two dayds; "Edge Shared Partners" is similarly defined, but w.r.t. edges, rather than dyads; and finally "Incoming K-stars" focuses on a frequency distribution over stars with k=1,... spokes.
Obtaining samples of the last three structural features can be very computationally expensive, and is discouraged on networks with more than 50 nodes.
A ggplot
object.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Plot observed (red) and simulated (gray) distributions over ## indegrees ## (typically a larger number of samples would be taken) ## (strictly requires ggplot2) gof(lazega_mmsbm, gof_stat = "Indegree", samples = 2)
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Plot observed (red) and simulated (gray) distributions over ## indegrees ## (typically a larger number of samples would be taken) ## (strictly requires ggplot2) gof(lazega_mmsbm, gof_stat = "Indegree", samples = 2)
The function lists the nodes (optionally, node-time periods) that most frequently instantiate membership in each latent group.
## S3 method for class 'mmsbm' head(x, n = 6, t = NULL, node = TRUE, t.correct = FALSE, ...)
## S3 method for class 'mmsbm' head(x, n = 6, t = NULL, node = TRUE, t.correct = FALSE, ...)
x |
An object of class |
n |
Numeric or integer; specifies how many units will be identified for each group. |
t |
Optional vector of time periods to be used for assessing latent group membership. |
node |
Logical; indicates whether latent group memberships should be averaged at the node level. If FALSE, the function returns the node-time period units with highest estimated membership in each latent group. |
t.correct |
Logical; indicates whether latent group memberships should be corrected for temporal trends. If TRUE, the function returns the node-time period units with highest estimated membership in each latent group. |
... |
Currently ignored |
List of length n.blocks
. Each entry contains a sorted vector of average latent membership probabilities of length n
.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups set.seed(123) lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Show top 6 lawyers in each estimated latent block head(lazega_mmsbm)
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups set.seed(123) lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Show top 6 lawyers in each estimated latent block head(lazega_mmsbm)
A dataset containing edges and dyad-level predictors in the network of friendships among lawyers in a New England law firm. More details are available in Lazega (2001).
data(lazega_dyadic)
data(lazega_dyadic)
A data frame with 5041 rows and 4 variables:
lawyer ID, corresponding to identifiers common
to those in lazega_monadic
; numeric
value of edge in network; binary
are the corresponding lawyers in the same office? boolean
https://github.com/Z-co/networkdata/blob/master/networkdata/data/lazega.rda
Emmanuel Lazega, The Collegial Phenomenon: The Social Mechanisms of Cooperation Among Peers in a Corporate Law Partnership, Oxford University Press (2001).
A dataset containing vertex-level predictors in the network of sought-after advise among lawyers in a New England law firm. More details are available in Lazega (2001).
data(lazega_monadic)
data(lazega_monadic)
A data frame with 71 rows and 7 variables:
lawyer ID,corresponding to identifiers common
to those in lazega_dyadic
; numeric
age, in years; numeric
1=man; 2=woman; factor
1=harvard, yale; 2=ucon; 3= other; factor
1=litigation; 2=corporate; factor
time in the firm, in years; numeric
1=partner; 2=associate; factor
Emmanuel Lazega, The Collegial Phenomenon: The Social Mechanisms of Cooperation Among Peers in a Corporate Law Partnership, Oxford University Press (2001).
https://github.com/Z-co/networkdata/blob/master/networkdata/data/lazega.rda
The function estimates a dynamic mixed-membership stochastic blockmodel that incorporates covariates.
mmsbm( formula.dyad, formula.monad = ~1, senderID, receiverID, nodeID = NULL, timeID = NULL, data.dyad, data.monad = NULL, n.blocks, n.hmmstates = 1, directed = TRUE, mmsbm.control = list() )
mmsbm( formula.dyad, formula.monad = ~1, senderID, receiverID, nodeID = NULL, timeID = NULL, data.dyad, data.monad = NULL, n.blocks, n.hmmstates = 1, directed = TRUE, mmsbm.control = list() )
formula.dyad |
A |
formula.monad |
An optional |
senderID |
Character string. Quoted name of the variable in |
receiverID |
Character string. Quoted name of the variable in |
nodeID |
Character string. Quoted name of the variable in |
timeID |
Character string. Quoted name of the variable in both |
data.dyad |
Data frame. Sociomatrix in “long” (i.e. dyadic) format. Must contain at least three variables: the sender identifier (or identifier of the first node in an undirected networks dyad), the receiver identifier (or identifier of the second node in an undirected network dyad), and the value of the edge between them. Currently, only edges between zero and one (inclusive) are supported. |
data.monad |
Data frame. Nodal atributes. Must contain a node identifier matching the names of nodes
used in the |
n.blocks |
Integer value. How many latent groups should be used to estimate the model? |
n.hmmstates |
Integer value. How many hidden Markov state should be used in the HMM? Defaults to 1 (i.e. no HMM). |
directed |
Boolean. Is the network directed? Defaults to |
mmsbm.control |
A named list of optional algorithm control parameters.
|
Object of class mmsbm
. List with named components:
Matrix of variational posterior of mean of mixed-membership vectors. nodes
by
n.blocks
.
n.blocks
by n.blocks
matrix of estimated tie log-odds between members
of corresponding latent groups. The blockmodel.
If hessian=TRUE
, variance-covariance matrix of parameters in blockmodel, ordered in column-major order.
Array of estimated coefficient values for monadic covariates. Has n.blocks
columns,
and n.hmmstates
slices.
If hessian=TRUE
, variance-covariance matrix of monadic coefficients.
Vector estimated coefficient values for dyadic covariates.
If hessian=TRUE
, variance-covariance matrix of dyadic coefficients.
Matrix of estimated HMM transition probabilities.
Matrix of marginal probabilities of being in an HMM state at any given point in time.
n.hmmstates
by years (or whatever time interval networks are observed at).
Final LB value
Vector of all LB across iterations, useful to check early convergence issues.
Final number of VI iterations.
Convergence indicator; zero indicates failure to converge.
Order in which nodes are stored in all return objects.
Model frames used during estimation (stripped of attributes).
Values of selected formal arguments used by other methods.
The value of RNG seed used during estimation.
Original (unevaluated) function call.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups ## Setting to `hessian=TRUE` increases computation time ## but is needed if standard errors are to be computed. lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE))
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups ## Setting to `hessian=TRUE` increases computation time ## but is needed if standard errors are to be computed. lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE))
This is the interface to the C++ fitter for the dynamic mixed-membership stochastic blockmodel for network regression.
z_t |
Numeric matrix; transpose of monadic design matrix. Should not include intercept row. |
x_t |
Numeric matrix; transpose of dyadic design matrix. |
y |
Numeric vector; vector of edge values. Must have same number of elements as |
time_id_dyad |
Integer vector; zero-based time-period identifier for each node. |
nodes_per_period |
Integer vector; total number of unique nodes observed in each time period. |
node_id_dyad |
Integer matrix; zero-based sender and receiver identifier per dyad. |
mu_b |
Numeric matrix; matrix of prior means for elements in blockmodel matrix. |
var_b |
Numeric matrix; matrix of prior variances for elements in blockmodel matrix. |
pi_init |
Numeric matrix; matrix of initial mixed-memberships. Nodes along columns. |
kappa_init_t |
Numeric matrix; matrix of initial marginal HMM state probabilities. Time-periods along columns. |
b_init_t |
Numeric matrix; square matrix of initial values of blockmodel. |
beta_init |
Numeric vector; flat array (column-major order) of initial values of monadic coefficients. |
gamma_init |
Numeric vector; vector of initial values of dyadic coefficients |
control |
List; see the |
Unclassed list with named components; see Value
of mmsbm
This function is for internal use only. End-users should always resort to mmsbm
.
In particular, that interface post-processes the return value of this internal in important ways.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
The function provides a variety of plotting options for a fitted mmsbm
object.
## S3 method for class 'mmsbm' plot(x, type = "groups", FX = NULL, node = NULL, ...)
## S3 method for class 'mmsbm' plot(x, type = "groups", FX = NULL, node = NULL, ...)
x |
An object of class |
type |
character string denoting the type of plot. The default, " |
FX |
with |
node |
with |
... |
Currently ignored |
The requested plot object.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Plot blockmodel as network plot(lazega_mmsbm)
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Plot blockmodel as network plot(lazega_mmsbm)
The function produces expected posterior edges based on estimated parameters and (optionally new) predictor data
## S3 method for class 'mmsbm' predict( object, new.data.dyad = NULL, new.data.monad = NULL, forecast = FALSE, type = c("link", "response", "mm"), ... )
## S3 method for class 'mmsbm' predict( object, new.data.dyad = NULL, new.data.monad = NULL, forecast = FALSE, type = c("link", "response", "mm"), ... )
object |
Object of class |
new.data.dyad |
An optional |
new.data.monad |
An optional |
forecast |
Boolean. Should prediction forcast one step into the future? Defaults to FALSE. |
type |
Character string. The default is to use the linear predictor of edges. The alternative "response" returns predicted probabilities. The alternative "mm" returns predicted mixed-membership vectors. |
... |
Currently ignored |
If new.data.dyad = NULL
, vector of length nrow(object$dyadic.data)
. Else, vector of length nrow(new.data.dyad)
.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Get in-sample predicted edge probabilities lazega_preds <- predict(lazega_mmsbm, type = "response")
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Get in-sample predicted edge probabilities lazega_preds <- predict(lazega_mmsbm, type = "response")
mmsbm
objectThe function generates one sample network from the posterior predictive of the model represented by a fitted mmsbm
object.
## S3 method for class 'mmsbm' simulate( object, nsim = 1, seed = NULL, new.data.dyad = NULL, new.data.monad = NULL, ... )
## S3 method for class 'mmsbm' simulate( object, nsim = 1, seed = NULL, new.data.dyad = NULL, new.data.monad = NULL, ... )
object |
An object of class |
nsim |
Number of networks to simulate |
seed |
RNG seed. |
new.data.dyad |
An optional |
new.data.monad |
An optional |
... |
Currently ignored |
List of length nsim
of simulated networks.
If new.data.dyad = NULL
, each element is a vector of length nrow(object$dyadic.data)
.
Else, vector of length nrow(new.data.dyad)
. If seed
is not NULL, return object
includes its value as attribute "seed".
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Simulate 5 new networks lazega_sim <- simulate(lazega_mmsbm, nsim = 5, seed = 123)
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = FALSE)) ## Simulate 5 new networks lazega_sim <- simulate(lazega_mmsbm, nsim = 5, seed = 123)
The function summarizes the output of a dynMMSBM model object
## S3 method for class 'mmsbm' summary(object, ...)
## S3 method for class 'mmsbm' summary(object, ...)
object |
An object of class |
... |
Currently ignored |
List with named components:
Total number of dyad-time period observations.
Number of latent groups included in the dynMMSBM model.
Average membership in each latent group, across all node-time periods.
n.groups
by n.groups
matrix of estimated edge formation probabilities between latent groups.
Vector of estimated coefficient values for dyadic covariates.
Array of estimated coefficient values for monadic covariates. Has n.groups
columns,
and n.hmmstates
slices.
Average HMM state probabilities across all time periods.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = TRUE)) ## Summarize estimated model summary(lazega_mmsbm)
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, hessian = TRUE)) ## Summarize estimated model summary(lazega_mmsbm)
mmsbm
ObjectExtract Variance-Covariance Matrix for a Fitted mmsbm
Object
## S3 method for class 'mmsbm' vcov(object, param = "All", ...)
## S3 method for class 'mmsbm' vcov(object, param = "All", ...)
object |
An object of class |
param |
Character string, which set of parameters should the vcov be extracted for? One
of |
... |
Currently ignored |
For param="All"
, named list of individual return components. For all other values of param
,
a numeric covariance matrix.
Santiago Olivella ([email protected]), Adeline Lo ([email protected]), Tyler Pratt ([email protected]), Kosuke Imai ([email protected])
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, se_sim = 2)) # Usually requires more samples. vcov(lazega_mmsbm, "MonadCoef")
library(NetMix) ## Load datasets data("lazega_dyadic") data("lazega_monadic") ## Estimate model with 2 groups lazega_mmsbm <- mmsbm(SocializeWith ~ Coworkers, ~ School + Practice + Status, senderID = "Lawyer1", receiverID = "Lawyer2", nodeID = "Lawyer", data.dyad = lazega_dyadic, data.monad = lazega_monadic, n.blocks = 2, mmsbm.control = list(seed = 123, conv_tol = 1e-2, se_sim = 2)) # Usually requires more samples. vcov(lazega_mmsbm, "MonadCoef")