Learn R Programming

netdiffuseR (version 1.16.2)

egonet_attrs: Retrieve alter's attributes (network effects)

Description

For a given set of vertices V, retrieves each vertex's alter's attributes. This function enables users to calculate exposure on variables other than the attribute that is diffusing. Further, it enables the specification of alternative functions to use to characterize ego's personal network including calculating the mean, maximum, minimum, median, or sum of the alters' attributes. These measures may be static or dynamic over the interval of diffusion and they may be binary or valued.

Usage

egonet_attrs(graph, attrs, V = NULL, direction = "outgoing",
  fun = function(x) x, as.df = FALSE, self = getOption("diffnet.self"),
  valued = getOption("diffnet.valued"))

Arguments

graph
Any class of accepted graph format (see netdiffuseR-graphs).
attrs
If graph is static, Numeric matrix with $n$ rows, otherwise a list of numeric matrices with $n$ rows.
V
Integer vector. Set of vertices from which the attributes will be retrieved.
direction
Character scalar. Either "outgoing", "incomming".
fun
Function. Applied to each
as.df
Logical scalar. When TRUE returns a data.frame instead of a list (see details).
self
Logical scalar. When FALSE ignores ego's own attributes.
valued
Logical scalar. When TRUE stores the value of the edge, otherwise includes a one.

Value

  • A list with ego alters's attributes. By default, if the graph is static, the output is a list of length length(V) with matrices having the following columns:
  • valueEither the corresponding value of the tie.
  • idAlter's id
  • ...Further attributes contained in attrs
  • On the other hand, if graph is dynamic, the output is list of length $T$ of lists of length length(V) with matrices having the following columns:
  • valueEither the corresponding value of the diagonal matrix or a one.
  • idAlter's id
  • perTime id
  • ...Further attributes contained in attrs

Details

By indexing inner/outer edges, this function retrieves ego network attributes for all $v \in V$, which by default is the complete set of vertices in the graph.

When as.df=TRUE the function returns a data.frame of size $(|V|\times T)\times k$ where $T$ is the number of time periods and $k$ is the number of columns generated by the function.

The function can be used to create network effects as those in the RSiena package. The difference here is that the definition of the statistic directly relies on the user. For example, in the RSiena package, the dyadic covariate effect 37. covariate (centered) main effect (X)

$$s_{i37}(x) = \sum_j x_{ij}(w_{ij}-\bar w)$$

Which, having a diffnet object with attributes named x and w, can be calculated as

egonet_attrs(diffnet, as.df=TRUE, fun=function(dat) { sum(dat[, "x"]*(dat[, "w"] - mean(dat[, "w"]))) })

Furthermore, we could use the median centered instead, for example

egonet_attrs(diffnet, as.df=TRUE, fun=function(dat) { sum(dat[, "x"]*(dat[, "w"] - median(dat[, "w"]))) })

Where for each $i$, dat will be a matrix with as many rows as individuals in his egonetwork. Such matrix holds the column names of the attributes in the network.

Examples

Run this code
# Creating a random graph
set.seed(1001)
diffnet <- rdiffnet(150, 20, seed.graph="small-world")

# Adding attributes
indeg <- dgr(diffnet, cmode="indegree")
diffnet.attrs(diffnet, "vertex", "dyn") <-
 lapply(1:20, function(x) cbind(indeg=indeg[,x]))

# Retrieving egonet's attributes (vertices 1 and 20)
egonet_attrs(diffnet, V=c(1,20))

Run the code above in your browser using DataLab