R/NetworkBuilding.R
matrix_from_edgelist.Rd
Compute the adjacency matrix of a network from its edgelist
matrix_from_edgelist(
edgelist,
origin_name = "origin",
target_name = "target",
count,
format_long = FALSE
)
(data.table) A table containing the edges (or links) of the network, i.e. representing the movements of subjects between facilities. Either in long format with at least two columns (origin and target facilities of a link), each row corresponding to a single movement, or aggregated by unique pairs of origin/target, therefore with an additional variable for movements count (default). See details.
(character) Column of the origin facilities of the links.
(character) Column of the target facilities of the links.
(character) Column of the counts of movements by unique pair of facilities.
(logical) Whether the edgelist is in long format, with each row corresponding to a single movement. If TRUE, the edgelist will be aggregated by unique pairs of facilities to compute the matrix.
A square numeric matrix, the adjacency matrix of the network.
The edgelist contains the information on the connections between nodes of the network, that is the movements of subjects between facilities. The edgelist can be in two different formats: long or aggregated. In long format, each row corresponds to a single movement between two facilities, therefore only two columns are needed, one containing the origin facilities of a movement, the other containing the target facilities. In aggregated format, the edgelist is aggregated by unique pairs of origin-target facilities. Thus, each row corresponds to a unique connection between two facilities, and the table contains an additional variable which is the count of the number of movements recorded for the pair. If the edgelist is provided in long format, it will be aggregated to compute the matrix.
mydb <- create_fake_subjectDB(n_subjects = 100, n_facilities = 10)
myBase <- checkBase(mydb)
#> Checking for missing values...
#> Checking for duplicated records...
#> Removed 0 duplicates
#> Done.
hospinet <- hospinet_from_subject_database(myBase)
matrix_from_edgelist(hospinet$edgelist, count = "N")
#> f01 f02 f03 f04 f05 f06 f07 f08 f09 f10
#> f01 0 1 2 4 1 0 6 2 2 0
#> f02 1 0 3 3 0 0 1 0 0 1
#> f03 0 3 0 2 2 2 1 3 0 5
#> f04 2 2 1 0 3 0 2 1 1 1
#> f05 1 3 2 3 0 2 2 3 1 1
#> f06 1 0 2 1 2 0 2 1 1 0
#> f07 5 1 1 1 2 1 0 3 4 2
#> f08 1 1 2 2 1 0 1 0 1 0
#> f09 2 2 3 2 1 3 1 1 0 2
#> f10 0 0 1 1 2 1 1 2 2 0