Learn R Programming

CDatanet (version 2.2.1)

peer.avg: Computing Peer Averages

Description

The peer.avg function computes peer average values using network data (provided as a list of adjacency matrices) and observable characteristics.

Usage

peer.avg(Glist, V, export.as.list = FALSE)

Value

The matrix product diag(Glist[[1]], Glist[[2]], ...) %*% V, where diag() represents the block diagonal operator.

Arguments

Glist

An adjacency matrix or a list of sub-adjacency matrices representing the network structure.

V

A vector or matrix of observable characteristics.

export.as.list

(optional) A boolean indicating whether the output should be a list of matrices (TRUE) or a single matrix (FALSE).

See Also

simnetwork, vec.to.mat

Examples

Run this code
# Generate a list of adjacency matrices
## Sub-network sizes
N <- c(250, 370, 120)  
## Rate of friendship
p <- c(0.2, 0.15, 0.18)   
## Network data
u <- unlist(lapply(1:3, function(x) rbinom(N[x] * (N[x] - 1), 1, p[x])))
G <- vec.to.mat(u, N, normalise = TRUE)

# Generate a vector y
y <- rnorm(sum(N))

# Compute G %*% y
Gy <- peer.avg(Glist = G, V = y)

Run the code above in your browser using DataLab