egonet_attrs(graph, attrs, V = NULL, direction = "outgoing", fun = function(x) x, as.df = FALSE, self = getOption("diffnet.self"), self.attrs = FALSE, valued = getOption("diffnet.valued"))netdiffuseR-graphs).graph is static, Numeric matrix with $n$ rows, otherwise a list of numeric matrices with $n$ rows."outgoing", "incomming".TRUE ego's attributes are included in the output
as the first row.length(V) with matrices having the following
columns:attrsgraph is dynamic, the output is list of length
$T$ of lists of length length(V) with data frames having the following
columns:attrsWhen as.df=TRUE the function returns a data.frame of size
$(|V| * T)*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.
# Creating a random graph
set.seed(1001)
diffnet <- rdiffnet(150, 20, seed.graph="small-world")
# Adding attributes
indeg <- dgr(diffnet, cmode="indegree")
head(indeg)
diffnet[["indegree"]] <- indeg
# Retrieving egonet's attributes (vertices 1 and 20)
egonet_attrs(diffnet, V=c(1,20))
Run the code above in your browser using DataLab