community.sampler: Sampling Community Matrices

View source: R/Community.R

community.samplerR Documentation

Sampling Community Matrices

Description

Construct functions to generate random community matrices

Usage

community.sampler(edges, required.groups = c(0))

Arguments

edges

an edge list

required.groups

a vector of integers specifying which groups of edges must always occur in the community matrix.

Details

Given an edge list that specifies a directed graph, this function constructs a list of functions that can be use to generate random community matrices corresponding to that directed graph.

Edges in the edge list that do not fall in a required group are considered uncertain, and may or may not be represented in the community matrix.

Random community matrices are generated in two stages, the first stage determines which of the uncertain edges will be included or excluded in subsequent simulations, while the second stage generates random matrices corresponding to the selected. The select function is a function of a single argument p that determines which of the uncertain edge pairs will be included in matrices generated by subsequent calls to community. This function always selects either neither or both edges of a pair and every uncertain pair has likelihood p of being selected. The community function is a function of no arguments that generates a random community matrix. The weights function is a function of a single argument W that returns those entries of the community matrix W that correspond to edges in the edge list.

Value

Returns a list with elements

community()

a function to generate a random community matrix

select(p)

a function that randomly selects which uncertain edges will be retained

weights(W)

a function that returns the (non-zero) weights as a vector

edge.labels

the labels of the edges

uncertain.labels

the labels of the uncertain edges

Examples

set.seed(32)
## Sample model
edges <- parse.digraph(c(
  "E *-> D",
  "D *-> C",
  "C -> E",
  "E *-> B",
  "B *-> A",
  "A -> E",
  "D --> B"))
edges <- enforce.limitation(edges)
s <- community.sampler(edges)
## Force D --> B edge out
s$select(0)
## Generate community matrices
s$community()
s$community()
## Force D --> B edge in
s$select(1)
## Generate community matrices
s$community()
s$community()
## Select the uncertain D --> B edge with prob 0.6
s$select(0.6)
## Generate community matrices
s$community()
s$community()

SWotherspoon/QPress documentation built on Sept. 26, 2022, 2:27 a.m.