diffnet-class | R Documentation |
diffnet
class objectdiffnet
objects contain diffusion networks. With adjacency
matrices and time of adoption (toa) vector (or matrix, for multiple behavior diffusion),
as its main components, most of the package's functions have methods for this class of objects.
as_diffnet(graph, ...)
## Default S3 method:
as_diffnet(graph, ...)
## S3 method for class 'networkDynamic'
as_diffnet(graph, toavar, ...)
new_diffnet(
graph,
toa,
t0 = min(toa, na.rm = TRUE),
t1 = max(toa, na.rm = TRUE),
vertex.dyn.attrs = NULL,
vertex.static.attrs = NULL,
id.and.per.vars = NULL,
graph.attrs = NULL,
undirected = getOption("diffnet.undirected"),
self = getOption("diffnet.self"),
multiple = getOption("diffnet.multiple"),
name = "Diffusion Network",
behavior = "Unspecified"
)
## S3 method for class 'diffnet'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
attr.class = c("dyn", "static"),
...
)
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'
print(x, ...)
nodes(graph)
diffnetLapply(graph, FUN, ...)
## S3 method for class 'diffnet'
str(object, ...)
## S3 method for class 'diffnet'
dimnames(x)
## S3 method for class 'diffnet'
t(x)
## S3 method for class 'diffnet'
dim(x)
is_undirected(x)
## S3 method for class 'diffnet'
is_undirected(x)
## Default S3 method:
is_undirected(x)
is_self(x)
## S3 method for class 'diffnet'
is_self(x)
## Default S3 method:
is_self(x)
is_multiple(x)
## S3 method for class 'diffnet'
is_multiple(x)
## Default S3 method:
is_multiple(x)
is_valued(x)
## S3 method for class 'diffnet'
is_valued(x)
## Default S3 method:
is_valued(x)
graph |
A dynamic graph (see |
... |
Further arguments passed to the jmethod. |
toavar |
Character scalar. Name of the variable that holds the time of adoption. |
toa |
Numeric vector of size |
t0 |
Integer scalar. Passed to |
t1 |
Integer scalar. Passed to |
vertex.dyn.attrs |
Vertices dynamic attributes (see details). |
vertex.static.attrs |
Vertices static attributes (see details). |
id.and.per.vars |
A character vector of length 2. Optionally specified to check the order of the rows in the attribute data. |
graph.attrs |
Graph dynamic attributes (not supported yet). |
undirected |
Logical scalar. When |
self |
Logical scalar. When |
multiple |
Logical scalar. When |
name |
Character scalar. Name of the diffusion network (descriptive). |
behavior |
Character scalar. Name of the behavior been analyzed (innovation). |
x |
A |
row.names |
Ignored. |
optional |
Ignored. |
attr.class |
Character vector/scalar. Indicates the class of the attribute, either dynamic ( |
element |
Character vector/scalar. Indicates what to retrieve/alter. |
as.df |
Logical scalar. When TRUE returns a data.frame. |
value |
In the case of |
i |
Indices specifying elements to replace. See |
FUN |
a function to be passed to lapply |
object |
A |
diffnet
objects hold both, static and dynamic vertex attributes. When
creating diffnet
objects, these can be specified using the arguments
vertex.static.attrs
and vertex.dyn.attrs
; depending on whether
the attributes to specify are static or dynamic, netdiffuseR currently
supports the following objects:
Class | Dimension | Check sorting |
Static attributes | ||
matrix | with n rows | id |
data.frame | with n rows | id |
vector | of length n | - |
Dynamic attributes | ||
matrix | with n\times T rows | id , per |
data.frame | with n\times T rows | id , per |
vector | of length n\times T | - |
list | of length T with matrices or data.frames of n rows | id , per |
The last column, Check sorting, lists the variables that
the user should specify if he wants the function to check the order of the rows
of the attributes (notice that this is not possible for the case of vectors).
By providing the name of the vertex id variable, id
, and the time period
id variable, per
, the function makes sure that the attribute data is
presented in the right order. See the example below. If the user does not
provide the names of the vertex id and time period variables then the function
does not check the way the rows are sorted, further it assumes that the data
is in the correct order.
The function 'is_undirected' returns TRUE if the network is marked as undirected. In the case of 'diffnet' objects, this information is stored in the 'meta' element as 'undirected'. The default method is to try to find an attribute called 'undirected', i.e., 'attr(x, "undirected")', if no attribute is found, then the function returns 'FALSE'.
The functions 'is_self', 'is_valued', and 'is_multiple' work exactly the same as 'is_undirected'. 'diffnet' networks are not valued.
A list of class diffnet
with the following elements:
graph |
A list of length |
toa |
An integer vector of length |
.
adopt , cumadopt |
Numeric matrices of size |
vertex.static.attrs |
If not NULL, a data frame with |
vertex.dyn.attrs |
A list of length |
graph.attrs |
A data frame with |
meta |
A list of length 9 with the following elements:
|
diffnet.attrs
Allows retriving network attributes. In particular, by default
returns a list of length T
with data frames with the following columns:
per
Indicating the time period to which the observation corresponds.
toa
Indicating the time of adoption of the vertex.
Further columns depending on the vertex and graph attributes.
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
.
nodes(graph)
is an alias for graph$meta$ids
.
George G. Vega Yon & AnĂbal Olivera M.
Default options are listed at netdiffuseR-options
Other diffnet methods:
%*%()
,
as.array.diffnet()
,
c.diffnet()
,
diffnet-arithmetic
,
diffnet_index
,
plot.diffnet()
,
summary.diffnet()
Other data management functions:
edgelist_to_adjmat()
,
egonet_attrs()
,
isolated()
,
survey_to_diffnet()
# Creating a diffnet object from TOA (time of adoption) ---------------------
# 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 <- new_diffnet(graph, toa)
diffnet
summary(diffnet)
# Plotting slice 4
plot(diffnet, t=4)
# A diffnet object from TOA of multiple behaviors ---------------------------
# TOA for two behaviors
toa_matrix <- matrix(sample(c(2001L:2005L,NA), 20, TRUE), ncol = 2)
# Creating diffnet object
diffnet_multi <- new_diffnet(graph, toa_matrix)
diffnet_multi
summary(diffnet_multi)
# ATTRIBUTES ----------------------------------------------------------------
# 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)
as.data.frame(diffnet) # This is a wrapper
# Unsorted data -------------------------------------------------------------
# Loading example data
data(fakesurveyDyn)
# Creating a diffnet object
fs_diffnet <- survey_to_diffnet(
fakesurveyDyn, "id", c("net1", "net2", "net3"), "toa", "group",
timevar = "time", keep.isolates=TRUE, warn.coercion=FALSE)
# Now, we extract the graph data and create a diffnet object from scratch
graph <- fs_diffnet$graph
ids <- fs_diffnet$meta$ids
graph <- Map(function(g) {
dimnames(g) <- list(ids,ids)
g
}, g=graph)
attrs <- diffnet.attrs(fs_diffnet, as.df=TRUE)
toa <- diffnet.toa(fs_diffnet)
# Lets apply a different sorting to the data to see if it works
n <- nrow(attrs)
attrs <- attrs[order(runif(n)),]
# Now, recreating the old diffnet object (notice -id.and.per.vars- arg)
fs_diffnet_new <- new_diffnet(graph, toa=toa, vertex.dyn.attrs=attrs,
id.and.per.vars = c("id", "per"))
# Now, retrieving attributes. The 'new one' will have more (repeated)
attrs_new <- diffnet.attrs(fs_diffnet_new, as.df=TRUE)
attrs_old <- diffnet.attrs(fs_diffnet, as.df=TRUE)
# Comparing elements!
tocompare <- intersect(colnames(attrs_new), colnames(attrs_old))
all(attrs_new[,tocompare] == attrs_old[,tocompare], na.rm = TRUE) # TRUE!
# diffnetLapply -------------------------------------------------------------
data(medInnovationsDiffNet)
diffnetLapply(medInnovationsDiffNet, function(x, cumadopt, ...) {sum(cumadopt)})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.