Create a sampler object that allows you simulating streams of small networks fast.
new_rergmito(model, theta, ...) # S3 method for ergmito_sampler [(x, i, ...)
model | A formula. |
---|---|
theta | Named vector. Model parameters. |
... | Further arguments passed to |
x | An object of class |
i |
|
An environment with the following objects:
calc_prob
A function to calculate each graph's probability under the
specified model.
call
A language object with the call.
counts
A list with 3 elements: stats
the sufficient statistics of each network,
weights
and statmat
the overall matrices of sufficient statistics used to
compute the likelihood.
network
The baseline network used to either fit the model or obtain
attributes.
networks
A list with the actual sample space of networks.
probabilities
A numeric vector with each graph's probability.
sample
A function to draw samples. n
specifies the number of samples to
draw and theta
the parameter to use to calculate the likelihoods.
theta
Named numeric vector with the current values of the model parameters.
The indexing method [.ergmito_sampler
returns a list of networks
While the ergm package is very efficient, it was not built to do some of the computations required in the ergmito package. This translates in having some of the functions of the package (ergm) with poor speed performance. This led us to "reinvent the wheel" in some cases to speed things up, this includes calculating observed statistics in a list of networks.
The indexing method, [.ergmito_sampler
, allows extracting networks
directly by passing indexes. i
indicates the index of the networks to draw,
which go from 1 through 2^(n*(n-1))
if directed and 2^(n*(n-1)/2)
if
undirected .
# We can generate a sampler from a random graph set.seed(7131) ans <- new_rergmito(rbernoulli(4) ~ edges, theta = -.5) # Five samples ans$sample(5)#> [[1]] #> [,1] [,2] [,3] [,4] #> [1,] 0 1 0 0 #> [2,] 1 0 0 0 #> [3,] 0 0 0 1 #> [4,] 0 1 0 0 #> #> [[2]] #> [,1] [,2] [,3] [,4] #> [1,] 0 1 0 0 #> [2,] 0 0 0 0 #> [3,] 0 1 0 1 #> [4,] 0 1 1 0 #> #> [[3]] #> [,1] [,2] [,3] [,4] #> [1,] 0 0 0 1 #> [2,] 0 0 1 0 #> [3,] 0 1 0 0 #> [4,] 1 0 1 0 #> #> [[4]] #> [,1] [,2] [,3] [,4] #> [1,] 0 0 0 0 #> [2,] 0 0 1 0 #> [3,] 0 0 0 1 #> [4,] 0 1 0 0 #> #> [[5]] #> [,1] [,2] [,3] [,4] #> [1,] 0 0 1 0 #> [2,] 0 0 1 0 #> [3,] 0 0 0 0 #> [4,] 0 0 1 0 #># or we can use some nodal data: data(fivenets) ans <- new_rergmito( fivenets[[3]] ~ edges + nodematch("female"), theta = c(-1, 1) ) # Five samples ans$sample(5) # All these networks have a "female" vertex attr#> [[1]] #> Network attributes: #> vertices = 4 #> directed = TRUE #> hyper = FALSE #> loops = FALSE #> multiple = FALSE #> bipartite = FALSE #> total edges= 5 #> missing edges= 0 #> non-missing edges= 5 #> #> Vertex attribute names: #> female vertex.names #> #> No edge attributes #> #> [[2]] #> Network attributes: #> vertices = 4 #> directed = TRUE #> hyper = FALSE #> loops = FALSE #> multiple = FALSE #> bipartite = FALSE #> total edges= 3 #> missing edges= 0 #> non-missing edges= 3 #> #> Vertex attribute names: #> female vertex.names #> #> No edge attributes #> #> [[3]] #> Network attributes: #> vertices = 4 #> directed = TRUE #> hyper = FALSE #> loops = FALSE #> multiple = FALSE #> bipartite = FALSE #> total edges= 6 #> missing edges= 0 #> non-missing edges= 6 #> #> Vertex attribute names: #> female vertex.names #> #> No edge attributes #> #> [[4]] #> Network attributes: #> vertices = 4 #> directed = TRUE #> hyper = FALSE #> loops = FALSE #> multiple = FALSE #> bipartite = FALSE #> total edges= 4 #> missing edges= 0 #> non-missing edges= 4 #> #> Vertex attribute names: #> female vertex.names #> #> No edge attributes #> #> [[5]] #> Network attributes: #> vertices = 4 #> directed = TRUE #> hyper = FALSE #> loops = FALSE #> multiple = FALSE #> bipartite = FALSE #> total edges= 6 #> missing edges= 0 #> non-missing edges= 6 #> #> Vertex attribute names: #> female vertex.names #> #> No edge attributes #>