Network analysis of livestock movement data
network-analysis.Rmdmovenet uses the Statnet suite of packages (e.g. networkDynamic and tsna) for (temporal) social network analysis. We are currently working on the functions in this section - e.g. creation of a pdf report with network measures of particular relevance to disease transmission.
library(movenet)
# Load example movenet-format movement and holding tibbles into the global environment:
movement_data <- head(example_movement_data, 100)
holding_data <- example_holding_dataGenerating a temporal network representation
We can generate a temporal network (networkDynamic) representation of movement data and optional holding data, as follows:
# Create a networkDynamic from our data
network <- movedata2networkDynamic(movement_data, holding_data,
incl_nonactive_holdings = FALSE)
network
#> NetworkDynamic properties:
#> distinct change times: 85
#> maximal time range: 17897 until 18254
#>
#> Dynamic (TEA) attributes:
#> Edge TEAs: movement_reference.active
#> qty_pigs.active
#>
#> Includes optional net.obs.period attribute:
#> Network observation period info:
#> Number of observation spells: 1
#> Maximal time range observed: 17897 until 18254
#> Temporal mode: continuous
#> Time unit: unknown
#> Suggested time increment: NA
#>
#> Network attributes:
#> vertices = 170
#> directed = TRUE
#> hyper = FALSE
#> loops = FALSE
#> multiple = FALSE
#> bipartite = FALSE
#> net.obs.period: (not shown)
#> weight = qty_pigs
#> vertex.pid = true_id
#> total edges= 100
#> missing edges= 0
#> non-missing edges= 100
#>
#> Vertex attribute names:
#> active coordinates herd_size holding_type true_id vertex.names
#>
#> Edge attribute names:
#> active movement_reference.active qty_pigs.activeCalculate summary statistics for selected temporal network measures
This networkDynamic representation can then be used to calculate various network summary measures, such as finding the maximum reachability in the network:
max_reachability <-
parallel_summarise_temporal_node_properties(list(network),
n_threads = 1,
node_property = "forward reachability",
statistics = list(max = max),
identify_nodes = TRUE)
unlist(max_reachability)
#> summary_statistics.max node_pid_with_max_value
#> "5" "29/530/4214"Create a temporal social network analysis report
The movenet package provides a function to create a network analysis report, with analyses of monthly network snapshots:
create_temporal_network_analysis_report(
network,
output_file = file.path(tempdir(),"network_report.html"),
incl_reachability_analysis = FALSE,
n_threads = 1,
whole_months = TRUE,
time_unit = "month")This creates an html document that can be opened in a browser, and contains a full report as shown below: