diffnet_index: Indexing diffnet objects (on development)

diffnet_indexR Documentation

Indexing diffnet objects (on development)

Description

Access and assign (replace) elements from the adjacency matrices or the vertex attributes data frames.

Usage

## S3 method for class 'diffnet'
x[[name, as.df = FALSE]]

## S3 replacement method for class 'diffnet'
x[[i, j]] <- value

## S3 method for class 'diffnet'
x[i, j, k, drop = FALSE]

## S3 replacement method for class 'diffnet'
x[i, j, k] <- value

Arguments

x

A diffnet class object.

name

String vector. Names of the vertices attributes.

as.df

Logical scalar. When TRUE returns a data frame, otherwise a list of length T.

i

Index of the i-th row of the adjacency matrix (see details).

j

Index of the j-th column of the adjacency matrix (see details)

value

Value to assign (see details)

k

Index of the k-th slice of the adjacency matrix (see details).

drop

Logical scalar. When TRUE returns an adjacency matrix, otherwise a filtered diffnet object.

Details

The [[.diffnet methods provides access to the diffnet attributes data frames, static and dynamic. By providing the name of the corresponding attribute, depending on whether it is static or dynamic the function will return either a data frame–static attributes–or a list of these–dynamic attributes. For the assigning method, ⁠[[<-.diffnet⁠, the function will infer what kind of attribute is by analyzing the dimensions of value, in particular we have the following possible cases:

Class Dimension Inferred
matrix n\times T Dynamic
matrix n\times 1 Static
matrix (n\times T)\times 1 Dynamic
data.frame n\times T Dynamic
data.frame n\times 1 Static
data.frame (n\times T)\times 1 Dynamic
vector n Static
vector n\times T Dynamic
list* T data.frames/matrices/vectors Dynamic

*: With n\times 1 data.frame/matrix or n length vector.

Other cases will return with error.

In the case of the slices index k, either an integer vector with the positions, a character vector with the labels of the time periods or a logical vector of length T can be used to specify which slices to retrieve. Likewise, indexing vertices works in the same way with the only difference that, instead of time period labels and a logical vector of length T, vertices ids labels and a logical vector of length n should be provided.

When subsetting slices, the function 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 k=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, k have no gaps, and it should be within the graph time period range.

Value

In the case of the assigning methods, a diffnet object. Otherwise, for [[.diffnet a vector extracted from one of the attributes data frames, and for [.diffnet a list of length length(k) with the corresponding [i,j] elements from the adjacency matrix.

Author(s)

George G. Vega Yon

See Also

Other diffnet methods: %*%(), as.array.diffnet(), c.diffnet(), diffnet-arithmetic, diffnet-class, plot.diffnet(), summary.diffnet()

Examples


# Creating a random diffusion network ---------------------------------------
set.seed(111)
graph <- rdiffnet(50,4)

# Accessing to a static attribute
graph[["real_threshold"]]

# Accessing to subsets of the adjacency matrix
graph[1,,1:3, drop=TRUE]
graph[,,1:3, drop=TRUE][[1]]

# ... Now, as diffnet objects (the default)
graph[1,,1:3, drop=FALSE]
graph[,,1:3, drop=FALSE]

# Changing values in the adjacency matrix
graph[1, , , drop=TRUE]
graph[1,,] <- -5
graph[1, , , drop=TRUE]

# Adding attributes (dynamic) -----------------------------------------------
# Preparing the data
set.seed(1122)
x <- rdiffnet(30, 4, seed.p.adopt=.15)

# Calculating exposure, and storing it diffe
expoM <- exposure(x)
expoL <- lapply(seq_len(x$meta$nper), function(x) expoM[,x,drop=FALSE])
expoD <- do.call(rbind, expoL)

# Adding data (all these are equivalent)
x[["expoM"]] <- expoM
x[["expoL"]] <- expoL
x[["expoD"]] <- expoD

# Lets compare
identical(x[["expoM"]], x[["expoL"]]) # TRUE
identical(x[["expoM"]], x[["expoD"]]) # TRUE

srdyal/diffusiontest documentation built on Oct. 2, 2024, 5:18 a.m.