netstats_om_nwalks: Compute the Number of Walks of Length K in a One-Mode Network

View source: R/nwalksom.R

netstats_om_nwalksR Documentation

Compute the Number of Walks of Length K in a One-Mode Network

Description

[Stable]

This function calculates the number of walks of length k between any two vertices in an unweighted one-mode network.

Usage

netstats_om_nwalks(net, k)

Arguments

net

An unweighted one-mode network adjacency matrix.

k

A numerical value that corresponds to the length of the paths to be computed.

Details

A nice result from graph theory is that the number of walks of length k between vertices i and j can be found by:

A_{ij}^k

This function assumes that there are no self-loops (i.e., the diagonal of the matrix is 0).

Value

An n x n matrix of counts of paths.

Author(s)

Kevin A. Carson kacarson@arizona.edu, Diego F. Leal dflc@arizona.edu

Examples


# For this example, we generate a random one-mode graph with the sna package.
#creating the random network with 10 actors
set.seed(9999)
rnet <- matrix(sample(c(0,1), 10*10, replace = TRUE, prob = c(0.8,0.2)),
               nrow = 10, ncol = 10, byrow = TRUE)
diag(rnet) <- 0 #setting self ties to 0
#counting the walks of length 2
netstats_om_nwalks(rnet, k = 2)
#counting the walks of length 5
netstats_om_nwalks(rnet, k = 5)

dream documentation built on Jan. 21, 2026, 1:06 a.m.