Learn R Programming

EpiModel (version 0.95)

set.nodematch.attributes: Set Nodematch Values from Proportions

Description

This function sets the values of static vertex attributes present in the formation formula as nodematch terms.

Usage

set.nodematch.attributes(nw, nm.attr, new.nodes)

Arguments

nw
an object of class network or networkDynamic.
nm.attr
object output from get.nodematch.attributes.
new.nodes
vector of new nodes with missing (that is, NA) attribute values.

Details

Incoming nodes in a dynamic network simulation require values for any attributes that are used in the formation formula through nodematch network terms. This function sets the values of those attributes based on the proportional distribution of the existing node attributes. The distribution must first be obtained from get.nodematch.attributes.

See Also

get.nodematch.attributes

Examples

Run this code
# Set network with two vertex attributes and check distribution
nw <- network.initialize(100)
nw %v% "race" <- rep(0:1, each=50)
nw %v% "sex" <- c(rep("M", 10), rep("F", 90))
prop.table(table(nw %v% "race"))
prop.table(table(nw %v% "sex"))

# Formation formula uses both attributes
formation <- ~ edges + nodematch("race") + nodematch("sex")

# Need to get existing proportions of those two terms first
nm.attr <- get.nodematch.attributes(nw, formation)

# Now add 50 more nodes, and set the new attributes in proportion
add.vertices(nw, nv=50)
nw <- set.nodematch.attributes(nw, nm.attr, new.nodes=101:150)

# Some random variation due to sampling new node values
prop.table(table(nw %v% "race"))
prop.table(table(nw %v% "sex"))

Run the code above in your browser using DataLab