peer.avg: Computing Peer Averages

View source: R/auxfunc.R

peer.avgR Documentation

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)

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).

Value

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

See Also

simnetwork, vec.to.mat

Examples

# 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)

CDatanet documentation built on April 3, 2025, 11:07 p.m.