rAdj {SpatGC}R Documentation

Generate a Random Adjacency Matrix

Description

This function generates a random adjacency matrix for a given number of regions. The matrix is symmetric, and the upper triangular part (excluding the diagonal) is randomly generated using the rbinom function with a specified probability. The lower triangular part is filled in by reflecting the upper triangular part to ensure the matrix is symmetric.

Usage

rAdj(n, prob = 0.2)

Arguments

n

Integer. The number of regions, which determines the dimensions of the adjacency matrix. Must be a positive integer.

prob

Numeric. The probability of an edge (connection) between two regions, used as the probability for the binomial distribution. Default value is 0.2. Should be between 0 and 1 (inclusive).

Value

A symmetric numeric matrix of dimensions n x n representing the adjacency matrix. The values in the matrix are either 0 or 1, where 1 indicates an edge (connection) between two regions.

Examples


# Generate a random adjacency matrix for 5 regions with a probability of 0.3
random_adj_matrix <- rAdj(5, prob = 0.3)
print(random_adj_matrix)

# Check if the matrix is symmetric
all(random_adj_matrix == t(random_adj_matrix))



[Package SpatGC version 0.1.0 Index]