Learn R Programming

intensitynet

The intensitynet package provides tools to analyze point patterns in space over planar network structures derived from graph-related intensity measures for undirected, directed, and mixed networks. This package is based on the research done by Eckardt, M., Mateu, J. presented in the following papers: Eckardt, M., Mateu, J. Point Patterns Occurring on Complex Structures in Space and Space-Time: An Alternative Network Approach. Journal of Computational and Graphical Statistics 27. 312-322 (2017). 10.1080/10618600.2017.1391695 Eckardt, M., Mateu, J. Second-order and local characteristics of network intensity functions. TEST 30, 318-340 (2021). 10.1007/s11749-020-00720-4

Installation

You can install the released version of intensitynet from CRAN with:

install.packages("intensitynet")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("LlagosteraPol/intensitynet")

Example

This is an example that shows you how to set up intensitynet and calculate and plot the Geary-c correlation:

library(intensitynet)
library(spatstat)
#> Loading required package: spatstat.data
#> Loading required package: spatstat.geom
#> spatstat.geom 2.3-1
#> Loading required package: spatstat.core
#> Loading required package: nlme
#> Loading required package: rpart
#> spatstat.core 2.3-2
#> Loading required package: spatstat.linnet
#> spatstat.linnet 2.3-1
#> 
#> spatstat 2.3-0       (nickname: 'That's not important right now') 
#> For an introduction to spatstat, type 'beginner'
data(chicago)


chicago_df <- as.data.frame(chicago[["data"]]) # Get as dataframe the data from Chicago

# Get the adjacency matrix. One way is to create an igraph object from the edge coordinates.
edges <- cbind(chicago[["domain"]][["from"]], chicago[["domain"]][["to"]])
chicago_net <- igraph::graph_from_edgelist(edges)

# And then use the igraph function 'as_adjacency_matrix'
chicago_adj_mtx <- as.matrix(igraph::as_adjacency_matrix(chicago_net))
chicago_node_coords <- data.frame(xcoord = chicago[["domain"]][["vertices"]][["x"]], 
                                  ycoord = chicago[["domain"]][["vertices"]][["y"]])
                                   
# Create the intensitynet object, in this case will be undirected 
intnet_chicago <- intensitynet(chicago_adj_mtx, 
                               node_coords = chicago_node_coords, 
                               event_data = chicago_df)

intnet_chicago <- RelateEventsToNetwork(intnet_chicago)
#> Calculating edge intensities...
#> ================================================================================
#> Calculating node intensities...
#> ================================================================================

data_geary <- NodeLocalCorrelation(intnet_chicago, dep_type = 'geary', intensity = igraph::vertex_attr(intnet_chicago$graph)$intensity)
geary_c <- data_geary$correlation
intnet_chicago <- data_geary$intnet

PlotHeatmap(intnet_chicago, heattype='geary')

Copy Link

Version

Install

install.packages('intensitynet')

Monthly Downloads

588

Version

1.3.1

License

GPL-3

Maintainer

Pol Llagostera

Last Published

September 26th, 2022

Functions in intensitynet (1.3.1)

PlotNeighborhood.intensitynet

Plot the net and the events in the neighborhood area of the given node
PlotNeighborhood

Plot the net and the events in the neighborhood area of the given node
PlotHeatmap.intensitynet

Plot the network correlations or intensities.
NodeLocalCorrelation

Gives the node local Moran-I, Getis-Gstar or Geary-c correlations
PointToLine.netTools

Return the distance between an event and the line (not segment) formed by two nodes.
NodeLocalCorrelation.intensitynet

Gives the node local Moran-I, Getis-Gstar or Geary-c correlations
PlotHeatmap

Plot the network correlations or intensities.
PointToSegment.netTools

Return the shortest distance between an event and a set of segments.
PathTotalWeight

Calculates the total weight of the given path
PathTotalWeight.intensitynet

Calculates the total weight of the given path
SetEdgeIntensity.netTools

Sets the given intensities as an edge attribute to the given igraph network
RelateEventsToNetwork

Calculates edgewise and mean nodewise intensities for the given intensitynet object and, for each edge, the proportions of all event covariates.
RelateEventsToNetwork.intensitynetMix

Calculates edgewise and mean nodewise intensities for Mixed networks and, for each edge, the proportions of all event covariates.
ShortestNodeDistance.intensitynet

Calculates the shortest distance path between two nodes (based on the minimum amount of edges). The function also returns the total weight of the path, if the weight is not available, returns the number of edges.
PointToSegment_deprecated.netTools

Return the shortest distance between an event and the segment formed by two nodes.
ShortestPath

Calculates the shortest path between two vertices (based on the minimum amount of edges) and calculates its total weight
SetNetworkAttribute.intensitynet

Set attributes to the network edges or nodes
SetNodeIntensity.netTools

Sets the given intensities as a node attribute to the given igraph network
RelateEventsToNetwork.intensitynetDir

Calculates edgewise and mean nodewise intensities for Directed networks and, for each edge, the proportions of all event covariates.
RelateEventsToNetwork.intensitynetUnd

Calculates edgewise and mean nodewise intensities for for Undirected networks and, for each edge, the proportions of all event covariates.
ShortestPath.intensitynet

Calculates the shortest path between two vertices (based on the minimum amount of edges) and calculates its total weight
mix_intnet_chicago

This data is an intensitynet object containing an mixed network. The base data used is from Chicago, extracted from the spatstat package.
Undirected2RandomDirectedAdjMtx.netTools

Creates a directed adjacency matrix from an Undirected one with random directions (in-out edges) but with the same connections between nodes.
nodeIntensity.intensitynetDir

Given a node, calculates its mean intensities regarding in and out edges associated with the node.
nodeIntensity.intensitynetUnd

Calculates the mean intensity of the given node (intensity of all the edges of the node/number of edges of the node)
nodeIntensity.intensitynetMix

Given a node, calculates its mean intensities depending on the edges associated with the node, those intensities are: in, out (for directed edges), undirected and total intensity.
dir_intnet_chicago

This data is an intensitynet object containing a directed network. The base data used is from Chicago, extracted from the spatstat package.
intensitynet

Constructor of the class intensitynet. In order to create an intensitynet object, it is needed; an adjacency matrix, the coordinates of the nodes and the coordinates of the events.
plot.intensitynetDir

Plot intensitynet object
und_intnet_chicago

This data is an intensitynet object containing an undirected network. The base data used is from Chicago, extracted from the spatstat package.
plot.intensitynetUnd

Plot intensitynet object
plot.intensitynetMix

Plot intensitynet object
GeoreferencedPlot.netTools

Plot the given network using its node coordinates
InitGraph.netTools

Creates an igraph network with the given data
ApplyWindow

Get the intensitynet object delimited by the given window
EdgeIntensity.intensitynet

If not calculated, calculates the intensity of the edge with nodes; node_id1, node_id2. If the edge already contains an intensity, give it directly.
GeoreferencedGgplot2.netTools

This function uses 'ggplot' to plot heatmaps of a network
ApplyWindow.intensitynet

Get the intensitynet object delimited by the given window
NodeGeneralCorrelation

It allows to compute different dependence statistics on the network for the given vector and for neighborhoods of distinct order. Such statistics are; correlation, covariance, Moran’s I and Geary’s C.
NodeGeneralCorrelation.intensitynet

It allows to compute different dependence statistics on the network for the given vector and for neighborhoods of distinct order. Such statistics are; correlation, covariance, Moran’s I and Geary’s C.
EdgeIntensitiesAndProportions.intensitynet

Calculate all the edge intensities of the graph. It's more fast than using iteratively the function EdgeIntensity for all edges.
CalculateDistancesMtx.netTools

Calculates the distances between all pairs of nodes from the given network