Skip to contents

transforms netify network objects into statnet's network objects (also available as netify_to_network, to_statnet, and to_network), providing access to the extensive statistical modeling capabilities of the statnet suite, including ergms (exponential random graph models), descriptive statistics, and network visualization tools.

Usage

netify_to_statnet(netlet, add_nodal_attribs = TRUE, add_dyad_attribs = TRUE)

netify_to_network(netlet, add_nodal_attribs = TRUE, add_dyad_attribs = TRUE)

to_statnet(netlet, add_nodal_attribs = TRUE, add_dyad_attribs = TRUE)

to_network(netlet, add_nodal_attribs = TRUE, add_dyad_attribs = TRUE)

Arguments

netlet

a netify object containing network data. cross-sectional, longitudinal, and multilayer netlets are all supported; multilayer inputs are dispatched layer-by-layer and the layer results are returned in a named list keyed by layer.

add_nodal_attribs

logical. if TRUE (default), includes nodal attributes from the netify object as vertex attributes in the network object. set to FALSE to create a network with structure only.

add_dyad_attribs

logical. if TRUE (default), includes dyadic attributes from the netify object as edge attributes in the network object. each dyad variable is attached in two places on the resulting network: as a network-level attribute under its original name (the full \(n\times n\) matrix) and as a per-edge attribute under <var>_e. the trailing _e disambiguates the per-edge edgelist from the network-level matrix. for ergm::edgecov() pass the original (matrix) name, not the _e alias, since edgecov() reads a network-level matrix attribute. the _e per-edge attribute is exposed for descriptive use (e.g. coloring edges in network::plot.network).

Value

a network object or list of network objects:

cross-sectional networks

returns a single network object

longitudinal networks

returns a named list of network objects with class c("network.list", "list"), names corresponding to time periods. the network.list class is the format that tergm cmle (tergm(nl ~ form(.) + persist(.), estimate = "cmle", times = seq_along(nl))) and stergm expect directly, so the output is plug-and-play for longitudinal ergms.

multilayer networks

returns a named list of (per-time) network objects keyed by layer name

the resulting network object(s) will have:

  • vertices named according to actors in the netify object

  • edge weights from the netify weight variable stored as "weight" attribute

  • vertex attributes for each nodal variable (if add_nodal_attribs = TRUE)

  • edge attributes for each dyadic variable (if add_dyad_attribs = TRUE); per-edge attributes carry the _e suffix, network-level attributes keep the original name

  • proper directedness based on the symmetric parameter of the netify object

  • a netify_na_cols attribute (character vector) listing nodal columns that carry nas; pass this directly to drop_na_actors() to drop the offending actors before fitting ergm formulas that reference those columns

Details

the conversion process handles different netify structures:

  • cross-sectional: direct conversion to a single network object

  • longitudinal arrays: internally converted to list format, then each time slice becomes a separate network object

  • longitudinal lists: each time period converted to separate network object

the statnet network format stores networks as an edgelist with attributes, making it memory-efficient for sparse networks. all nodal and dyadic attributes from the netify object are preserved and can be used in subsequent ergm modeling or network analysis.

for longitudinal data, each time period results in an independent network object. this format is suitable for discrete-time network analysis or pooled ergm estimation across time periods.

Note

this function requires the network package (part of statnet) to be installed.

for ergm modeling, the ergm package (also part of statnet) should be loaded after creating the network objects.

Author

ha eun choi, cassy dorff, colin henry, shahryar minhas

cassy dorff, shahryar minhas

Examples

data(classroom_edges)
data(classroom_nodes)

net <- netify(
    classroom_edges,
    actor1 = "from", actor2 = "to",
    symmetric = TRUE,
    nodal_data = classroom_nodes,
    missing_to_zero = TRUE
)

ntwk <- netify_to_statnet(net)

# examine the result
ntwk
#>  Network attributes:
#>   vertices = 30 
#>   directed = FALSE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = FALSE 
#>   total edges= 51 
#>     missing edges= 0 
#>     non-missing edges= 51 
#> 
#>  Vertex attribute names: 
#>     gender gpa grade vertex.names 
#> 
#> No edge attributes
network::network.size(ntwk) # number of vertices
#> [1] 30
network::network.edgecount(ntwk) # number of edges
#> [1] 51
network::list.vertex.attributes(ntwk) # nodal attributes
#> [1] "gender"       "gpa"          "grade"        "na"           "vertex.names"
network::get.vertex.attribute(ntwk, "gender") # gender by student
#>  [1] "F" "F" "M" "M" "F" "M" "M" "F" "M" "F" "M" "F" "M" "F" "M" "M" "F" "M" "M"
#> [20] "M" "M" "M" "M" "M" "M" "M" "M" "M" "M" "F"

# check network properties
network::is.directed(ntwk)
#> [1] FALSE
network::has.loops(ntwk)
#> [1] FALSE

# longitudinal example
classroom_panel <- rbind(
    transform(classroom_edges[1:12, ], wave = 1),
    transform(classroom_edges[13:24, ], wave = 2)
)

longit_net <- netify(
    classroom_panel,
    actor1 = "from", actor2 = "to", time = "wave",
    symmetric = TRUE,
    missing_to_zero = TRUE
)

ntwk_list <- netify_to_statnet(longit_net)

# examine structure
length(ntwk_list) # number of time periods
#> [1] 2
names(ntwk_list) # time period labels
#> [1] "1" "2"

# \donttest{
# use with ergm for modeling (requires ergm package)
library(ergm)
#> Loading required package: network
#> 
#> ‘network’ 1.20.0 (2026-02-06), part of the Statnet Project
#> * ‘news(package="network")’ for changes since last version
#> * ‘citation("network")’ for citation information
#> * ‘https://statnet.org’ for help, support, and other information
#> 
#> Attaching package: ‘network’
#> The following objects are masked from ‘package:igraph’:
#> 
#>     %c%, %s%, add.edges, add.vertices, delete.edges, delete.vertices,
#>     get.edge.attribute, get.edges, get.vertex.attribute, is.bipartite,
#>     is.directed, list.edge.attributes, list.vertex.attributes,
#>     set.edge.attribute, set.vertex.attribute
#> 
#> ‘ergm’ 4.12.0 (2026-02-17), part of the Statnet Project
#> * ‘news(package="ergm")’ for changes since last version
#> * ‘citation("ergm")’ for citation information
#> * ‘https://statnet.org’ for help, support, and other information
#> ‘ergm’ 4 is a major update that introduces some backwards-incompatible
#> changes. Please type ‘news(package="ergm")’ for a list of major
#> changes.
model <- ergm(ntwk ~ edges + nodematch("gender"))
#> Starting maximum pseudolikelihood estimation (MPLE):
#> Obtaining the responsible dyads.
#> Evaluating the predictor and response matrix.
#> Maximizing the pseudolikelihood.
#> Finished MPLE.
#> Evaluating log-likelihood at the estimate. 
#> 
# }