diffnet
class objectdiffnet
objects contain difussion of innovation networks. With adjacency
matrices and time of adoption (toa) vector as its main components, most of the
package's functions have methods for this class of objects.as_diffnet(graph, toa, t0 = min(toa, na.rm = TRUE), t1 = max(toa, na.rm =
TRUE), vertex.dyn.attrs = NULL, vertex.static.attrs = NULL,
graph.attrs = NULL, undirected = getOption("diffnet.undirected"),
self = getOption("diffnet.self"),
multiple = getOption("diffnet.multiple"))diffnet.subset.slices(graph, slices)
diffnet.attrs(graph, element = c("vertex", "graph"), attr.class = c("dyn",
"static"), as.df = FALSE)
diffnet.attrs(graph, element = "vertex", attr.class = "static") <- value
diffnet.toa(graph)
diffnet.toa(graph, i) <- value
## S3 method for class 'diffnet':
plot(x, y = NULL, t = 1, displaylabels = FALSE,
vertex.col = c("blue", "grey"), gmode = ifelse(x$meta$undirected, "graph",
"digraph"), vertex.cex = "degree", edge.col = "gray",
mode = "fruchtermanreingold", layout.par = NULL,
main = "Diffusion network in time %d", ...)
## S3 method for class 'diffnet':
print(x, ...)
## S3 method for class 'diffnet':
summary(object, slices = NULL, no.print = FALSE,
skip.moran = FALSE, valued = getOption("diffnet.valued", FALSE), ...)
## S3 method for class 'diffnet':
[(x, i, j, drop = FALSE)
netdiffuseR-graphs
).toa_mat
.toa_mat
."dyn"
),
or static ("static"
).diffnet.toa
, replacement, otherwise see below.Extract
.diffnet
object.plot
shows vertex labels.gplot.
plot
, further arguments passed to gplot
, otherwise
is ignored.diffnet
object.diffnet
with the following elements:dgCMatrix
.toa_mat
.type
: Character scalar equal to"dynamic"
.class
: Character scalar equal to"list"
.ids
: Character vector of size$n$with vertices' labels.pers
: Integer vector of size$T$.nper
: Integer scalar equal to$T$.n
: Integer scalar equal to$n$.self
: Logical scalar.undirected
: Logical scalar.multiple
: Logical scalar.diffnet.subset.slices
retrieves a subsection, in terms of time periods,
of the graph. When doing so, it modifies the toa
vector as well as the
adopt
and cumadopt
matrices collapsing network tinmming. For example,
if a network goes from time 1 to 20 and we set slices=3:10
, all individuals
who adopted prior to time 3 will be set as adopters at time 3, and all individuals
who adopted after time 10 will be set as adopters at time 10, changing the
adoption and cumulative adoption matrices. Importantly, slice
must be an
integer range without gaps.diffnet.attrs
Allows retriving network attributes. In particular, by default
returns a list of length $T$ with matrices with the following columns:
per
Indicating the time period to which the observation corresponds.toa
Indicating the time of adoption of the vertex.Each vertex static attributes' are repeated $T$ times in total so that these
can be binded (rbind
) to dynamic attributes.
When as.df=TRUE
, this convenience function is useful as it can be used
to create event history (panel data) datasets used for model fitting.
Conversely, the replacement method allows including new vertex or graph attributes either dynamic or static (see examples below).
diffnet.toa(graph)
works as an alias of graph$toa
.
The replacement method, diffnet.toa<-
used as diffnet.toa(graph)<-...
,
is the right way of modifying times of adoption as when doing so it
performs several checks on the time ranges, and
recalculates adoption and cumulative adoption matrices using toa_mat
.
gplot
,
and its layout via gplot.layout
, both from
the (vertex.cex
can either be a numeric scalar, a numeric vector or a character
scalar taking any of the following values "degree"
, "indegree"
, or
"outdegree"
. The later will be passed to dgr
to calculate
degree of the selected slice and will be normalized as
$$vertex.cex = d/[max(d) - min(d)]\times 2 + .5$$
where d=sqrt(dgr(graph))
.
In the case of the summary
method, Moran's I is calculated over the
cumulative adoption matrix using as weighting matrix the inverse of the geodesic
distance matrix. All this via moran
. For each time period t
,
this is calculated as:
m = moran(C[,t], G^(-1))
Where C[,t]
is the t-th column of the cumulative adoption matrix,
G^(-1)
is the element-wise inverse of the geodesic matrix at time t
,
and moran
is skip.moran=TRUE
Moran's I is not reported. This can be useful when the graph is particuarly
large (tens of thousands of vertices) as when doing so geodesic distances are
not calculated, which avoids allocating a square matrix of size $n$ on
the memory. As a difference from the adjacency matrices, the matrix with the
geodesic distances can't be stored as a sparse matrix (saving space).
netdiffuseR-options
# Creating a random graph
set.seed(123)
graph <- rgraph_ba(t=9)
graph <- lapply(1:5, function(x) graph)
# Pretty TOA
names(graph) <- 2001L:2005L
toa <- sample(c(2001L:2005L,NA), 10, TRUE)
# Creating diffnet object
diffnet <- as_diffnet(graph, toa)
diffnet
summary(diffnet)
# ATTRIBUTES ----------------------------------------------------------------
# Adding new attributes to the network
diffnet.attrs(diffnet, "vertex", "static") <- cbind(posnum=1:diffnet$meta$n)
diffnet.attrs(diffnet, "vertex", "dyn") <-
lapply(1:diffnet$meta$nper, function(x) cbind(rand=runif(diffnet$meta$n)))
# Retrieving attributes
diffnet.attrs(diffnet, "vertex", "static")
# Now as a data.frame (only static)
diffnet.attrs(diffnet, "vertex", "static", as.df = TRUE)
# Now as a data.frame (all of them)
diffnet.attrs(diffnet, as.df = TRUE)
Run the code above in your browser using DataLab