Learn R Programming

ergm (version 3.9.4)

node-attr: Specifying nodal attributes and their levels

Description

This document describes the ways in which to specify nodal attribute or functions and which levels for categorical factors to include. For the helper functions to facilitate this, see node-attr-api.

Arguments

Details

Term nodal attribute arguments, typically called attrs, attrname, by, on, etc. are interpreted as follows:

a single character string

Extract the vertex attribute with this name.

a character vector of length > 1

Extract the vertex attributes and paste them together, separated by dots.

a function

The function is called on the LHS network, expected to return a vector of appropriate length. (Shorter vectors will be recycled as needed.)

a formula

The expression on the RHS of the formula is evaluated in an environment of the vertex attributes of the network, expected to return a vector of appropriate length. (Shorter vectors will be recycled as needed.) Within this expression, the network itself accessible as either . or .nw. For example, nodecov(~abs(Grade-mean(Grade))/network.size(.)) would return the absolute difference of each actor's "Grade" attribute from its network-wide mean, divided by the network size.

For categorical attributes, to select which levels are of interest and their ordering, use the argument levels. It is interpreted as follows:

an expression wrapped in I()

Use the given list of levels as is.

a numeric or logical vector

Used for indexing of the default set of levels (typically, unique values of the attribute) in default older (typically lexicographic), i.e., sort(unique(attr))[levels]. Negative values exclude. To specify numeric or logical levels literally, wrap in I().

a character vector

Use as is.

a function

The function is called on the list of unique values of the attribute, the values of the attribute themselves, and the network itself, depending on its arity. Its return value is interpreted as above.

a formula

The expression on the RHS of the formula is evaluated in an environment in which the network itself is accessible as .nw, the list of unique values of the attribute as . or as .levels, and the attribute vector itself as .attr. Its return value is interpreted as above.

Note that levels often has a default that is sensible for the term in question.

Examples

Run this code
# NOT RUN {
data(faux.mesa.high)
# Mixing between lower and upper grades:
summary(faux.mesa.high~mm(~Grade>=10))
# Mixing between grades 7 and 8 only:
summary(faux.mesa.high~mm("Grade", levels=I(c(7,8))))
# or
summary(faux.mesa.high~mm("Grade", levels=1:2))
# or using levels2 (see ? mm) to filter the combinations of levels,
summary(faux.mesa.high~mm("Grade",
        levels2=~sapply(.levels,
                        function(l)
                          l[[1]]%in%c(7,8) && l[[2]]%in%c(7,8))))
# }

Run the code above in your browser using DataLab