Title: | Generalized Path Analysis for Social Networks |
---|---|
Description: | The social network literature features numerous methods for assigning value to paths as a function of their ties. 'gretel' systemizes these approaches, casting them as instances of a generalized path value function indexed by a penalty parameter. The package also calculates probabilistic path value and identifies optimal paths in either value framework. Finally, proximity matrices can be generated in these frameworks that capture high-order connections overlooked in primitive adjacency sociomatrices. Novel methods are described in Buch (2019) <https://davidbuch.github.io/analyzing-networks-with-gretel.html>. More traditional methods are also implemented, as described in Yang, Knoke (2001) <doi:10.1016/S0378-8733(01)00043-0>. |
Authors: | David Buch [aut, cre] |
Maintainer: | David Buch <[email protected]> |
License: | GPL-3 |
Version: | 0.0.1.9000 |
Built: | 2024-11-06 04:26:31 UTC |
Source: | https://github.com/davidbuch/gretel |
Identify the path of optimal generalized path value from every source
to every target in sociomatrix
.
all_opt_gpv(sociomatrix, p = Inf, node_costs = NULL)
all_opt_gpv(sociomatrix, p = Inf, node_costs = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
p |
a nonnegative real number that sets the 'p-norm' parameter for generalized path value calculation. |
node_costs |
a list of costs, in order, of all nodes represented in the sociomatrix, all are assumed 0 if unspecified |
All optimal paths from source to target nodes in sociomatrix
. To
minimize memory usage, paths are returned as a list of trees in Dijkstra's
format. Specific paths can be unpacked with unpack
as described in the
example below.
gpv
to calculate the value of a user-specified path,
opt_gpv
to identify the optimal path from a single source
node to a single target node
Identify the path of optimal probabilistic path value from every source
to every target in sociomatrix
.
all_opt_ppv(sociomatrix, odds_scale = 1, odds_scale_by_node = NULL)
all_opt_ppv(sociomatrix, odds_scale = 1, odds_scale_by_node = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
odds_scale |
a nonnegative real number indicating the observed tie strength value that corresponds to 1-1 transmission odds |
odds_scale_by_node |
sets a transfer odds scale for each node in a probabilistic path value calculation. |
All optimal paths from source to target nodes in sociomatrix
. To
minimize memory usage, paths are returned as a list of trees in Dijkstra's
format. Specific paths can be unpacked with unpack
as described in the
example below.
ppv
to calculate the value of a user-specified path,
opt_ppv
to identify the optimal path from a single source
node to a single target node
Calculates the binary distance of a user-specified network path through a network,
if all edges exist. Otherwise, returns Inf
to signify infinite distance.
binary_distance(sociomatrix, path)
binary_distance(sociomatrix, path)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
## Calculate binary distance along a path in a sociomatrix binary_distance(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist binary_distance(YangKnoke01, path = c(1,2,4,5))
## Calculate binary distance along a path in a sociomatrix binary_distance(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist binary_distance(YangKnoke01, path = c(1,2,4,5))
A sociomatrix encoding tie strengths among five nodes
BuchDarrah19
BuchDarrah19
a numeric matrix with 5 rows and 5 columns
<DOI:10.1016/j.socnet.2010.03.006>
Find the shortest L-Inf norm paths to other vertices
dijkstra_inf(dist, src)
dijkstra_inf(dist, src)
dist |
A matrix of distances between nodes |
src |
An integer vertex ID |
A numeric vector, entry i of which is the vertex immediately preceeding vertex i in the shortest path leading to i. Full paths must be constructed recursively.
Find the shortest paths to other vertices
dijkstra_nodes(dist, src, node_costs)
dijkstra_nodes(dist, src, node_costs)
dist |
A matrix of distances between nodes |
src |
An integer vertex ID |
node_costs |
a list of costs, in order, of all nodes represented in the sociomatrix, all are assumed 0 if unspecified |
A numeric vector, entry i of which is the vertex immediately preceeding vertex i in the shortest path leading to i. Full paths must be constructed recursively.
Calculates 'APL' (Average Path Length) as defined in Yang, Knoke (2001).
Called flament_average_path_length
in homage to A.C. Flament, who defined
path length in 1963.
flament_average_path_length(sociomatrix, path)
flament_average_path_length(sociomatrix, path)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
## Calculate 'APL' of a path in a sociomatrix flament_average_path_length(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist flament_average_path_length(YangKnoke01, path = c(1,2,4,5))
## Calculate 'APL' of a path in a sociomatrix flament_average_path_length(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist flament_average_path_length(YangKnoke01, path = c(1,2,4,5))
Calculates path length as defined in Flament (1963). That is, sums the
values of each edge in the path, if all edges exist. Otherwise, returns NA
.
flament_path_length(sociomatrix, path)
flament_path_length(sociomatrix, path)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
## Calculate Flament's Path Length along a path in a sociomatrix flament_path_length(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist flament_path_length(YangKnoke01, path = c(1,2,4,5))
## Calculate Flament's Path Length along a path in a sociomatrix flament_path_length(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist flament_path_length(YangKnoke01, path = c(1,2,4,5))
Generates a proximity matrix in one of three modes:
'ogpv'
Optimal Generalized Path Value. Entry i,j
of the
proximity matrix will equal the optimal 'gpv' among all paths connecting node
i
to node j
.
'oppv'
Optimal Probabilistic Path Value. Entry i,j
of the
proximity matrix will equal the optimal 'ppv' among all paths connecting node
i
to node j
.
'sconductivity'
Social Conductivity (Random Walk Probability). If
each tie strength recorded in sociomatrix
is taken to be analogous to the
conductivity of an electrical component, i,j
of the proximity matrix
will equal total conductivity of all paths from node i
to node j
.
generate_proximities(sociomatrix, mode = c("ogpv", "oppv", "sconductivity"), p = Inf, node_costs = NULL, odds_scale = 1, odds_scale_by_node = NULL)
generate_proximities(sociomatrix, mode = c("ogpv", "oppv", "sconductivity"), p = Inf, node_costs = NULL, odds_scale = 1, odds_scale_by_node = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
mode |
a selection of |
p |
if |
node_costs |
if |
odds_scale |
if |
odds_scale_by_node |
if |
## Generate a proximity matrix in each mode ## Optimal Generalized Path Value generate_proximities(YangKnoke01, mode = "ogpv", p = Inf, node_costs = c(1,3,3,2,1)) ## Optimal Probabilistic Path Value generate_proximities(YangKnoke01, mode = "oppv", odds_scale = 2) ## Sconductivity generate_proximities(YangKnoke01, mode = "sconductivity")
## Generate a proximity matrix in each mode ## Optimal Generalized Path Value generate_proximities(YangKnoke01, mode = "ogpv", p = Inf, node_costs = c(1,3,3,2,1)) ## Optimal Probabilistic Path Value generate_proximities(YangKnoke01, mode = "oppv", odds_scale = 2) ## Sconductivity generate_proximities(YangKnoke01, mode = "sconductivity")
Calculates the generalized path value of a user-specified path through
sociomatrix
. Parameter p
sets the p-norm used in calculation.
gpv(sociomatrix, path, p = Inf, node_costs = NULL)
gpv(sociomatrix, path, p = Inf, node_costs = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
p |
a nonnegative real number that sets the 'p-norm' parameter for generalized path value calculation. |
node_costs |
a list of costs, in order, of all nodes represented in the sociomatrix, all are assumed 0 if unspecified |
As a rule of thumb, p close to 0 will downweight the impact of particular
tie strengths and upweight the impact of binary path length. p equal to
infinity will recapitulate the traditional path value measure of Peay (1980)
and is therefore the default. In other words, the value of a path under
p = Inf
will be the value of the weakest tie. The value of the same
path under p = 0
will be the inverse of its binary length.
opt_gpv
to identify the path of optimal 'gpv' between two nodes
and all_opt_gpv
to identify the optimal paths between all pairs of
nodes. Calling generate_proximities
with mode = 'gpv'
returns a matrix 'gpv' values for the optimal paths between all pairs of
nodes.
## Calculate gpv along a path in a sociomatrix gpv(YangKnoke01, path = c(1,2,5), p = 1) ## The same calculation, with nonzero node costs gpv(YangKnoke01, path = c(1,2,5), p = 1, node_costs = c(1,3,3,2,1)) ## This path doesn't exist gpv(YangKnoke01, path = c(1,2,4,5), p = 0)
## Calculate gpv along a path in a sociomatrix gpv(YangKnoke01, path = c(1,2,5), p = 1) ## The same calculation, with nonzero node costs gpv(YangKnoke01, path = c(1,2,5), p = 1, node_costs = c(1,3,3,2,1)) ## This path doesn't exist gpv(YangKnoke01, path = c(1,2,4,5), p = 0)
This package contains two categories of functions. The first category is concerned with assigning values to user specified paths, while the second identifies paths of optimal value.
Key functions in the path value calculation category are
- gpv
, which calculates Generalized Path Value
- ppv
, which calculates Probabilistic Path Value
- binary_distance
, peay_path_value
, flament_path_length
,
peay_average_path_value
, and flament_average_path_length
, which
calculate path value measures described in Yang, Knoke (2001).
- generate_proximities
, which generates a matrix of values representing the
measures of optimal paths from each source node (row index) to each target node
(column index).
Key functions in the optimal path identification category are
- opt_gpv
, which identifies the path of optimal Generalized Path Value from
a particular source node to a particular target node
- opt_ppv
, which identifies the path of optimal Probabilistic Path Value from
a particular source node to a particular target node
- all_opt_gpv
, which identifies the 'gpv'-optimal paths from every source node
to every target node
- all_opt_ppv
, which identifies the 'ppv'-optimal paths from every source node
to every target node
- unpack
, which unpacks the Dijkstra-format encoded shortest paths returned by
all_opt_gpv
and all_opt_ppv
. See their help pages for details.
A sociomatrix encoding tie strengths among five nodes, used for examples in Opsahl, Agneessens, Skvoretz (2010) Social Networks 32(2010):245-251
OpsahlEtAl10
OpsahlEtAl10
a numeric matrix with 5 rows and 5 columns
<DOI:10.1016/j.socnet.2010.03.006>
Identify the path of optimal generalized path value from a source node to a target node.
opt_gpv(sociomatrix, source, target, p = Inf, node_costs = NULL)
opt_gpv(sociomatrix, source, target, p = Inf, node_costs = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
source |
an integer index corresponding to a node in |
target |
an integer index corresponding to a node in |
p |
a nonnegative real number that sets the 'p-norm' parameter for generalized path value calculation. |
node_costs |
a list of costs, in order, of all nodes represented in the sociomatrix, all are assumed 0 if unspecified |
gpv
to calculate the value of a user-specified path,
all_opt_gpv
to simultaneously identify the optimal paths
from any source node to any target node.
Identify the path of optimal probabilistic path value from a source node to a target node.
opt_ppv(sociomatrix, source, target, odds_scale = 1, odds_scale_by_node = NULL)
opt_ppv(sociomatrix, source, target, odds_scale = 1, odds_scale_by_node = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
source |
an integer index corresponding to a node in |
target |
an integer index corresponding to a node in |
odds_scale |
a nonnegative real number indicating the observed tie strength value that corresponds to 1-1 transmission odds |
odds_scale_by_node |
sets a transfer odds scale for each node in a probabilistic path value calculation. |
ppv
to calculate the value of a user-specified path,
all_opt_ppv
to simultaneously identify the optimal paths
from any source node to any target node.
Calculates 'APV' (Average Path Value) as defined in Yang, Knoke (2001)
Called peay_average_path_value
in homage to E.R. Peay, who defined
path length in 1980.
peay_average_path_value(sociomatrix, path)
peay_average_path_value(sociomatrix, path)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
## Calculate 'APV' of a path in a sociomatrix peay_average_path_value(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist peay_average_path_value(YangKnoke01, path = c(1,2,4,5))
## Calculate 'APV' of a path in a sociomatrix peay_average_path_value(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist peay_average_path_value(YangKnoke01, path = c(1,2,4,5))
Calculates path value as defined in Peay (1980). That is, returns the value of the weakest connection in the path, if all edges exist. Otherwise, returns 0.
peay_path_value(sociomatrix, path)
peay_path_value(sociomatrix, path)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
## Calculate Peay's Path Value along a path in a sociomatrix peay_path_value(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist peay_path_value(YangKnoke01, path = c(1,2,4,5))
## Calculate Peay's Path Value along a path in a sociomatrix peay_path_value(YangKnoke01, path = c(1,2,5)) ## This path doesn't exist peay_path_value(YangKnoke01, path = c(1,2,4,5))
Given a real valued sociomatrix, a path, and an optional odds_scale
, ppv
calculates the transmission odds for the path and returns the transmission odds
times odds_scale
so the result can be directly compared with observed
tie strenghts.
ppv(sociomatrix, path, odds_scale = 1, odds_scale_by_node = NULL)
ppv(sociomatrix, path, odds_scale = 1, odds_scale_by_node = NULL)
sociomatrix |
a nonnegative, real valued sociomatrix. |
path |
an integer vector of node indices from |
odds_scale |
a nonnegative real number indicating the observed tie strength value that corresponds to 1-1 transmission odds |
odds_scale_by_node |
sets a transfer odds scale for each node in a probabilistic path value calculation. |
We assume that observed tie strengths in sociomatrix
are linearly
proportional to transmission odds. That is, if the transmission odds for
a strength 1 tie are 1 to 1, the transmission odds for a strength 5 tie are
1 to 5.
opt_ppv
to identify the path of optimal 'ppv' between two nodes
and all_opt_ppv
to identify the optimal paths between all pairs of
nodes. Calling generate_proximities
with mode = 'ppv'
returns a matrix 'ppv' values for the optimal paths between all pairs of
nodes.
## Calculate ppv along a path in a sociomatrix ppv(YangKnoke01, path = c(1,2,5), odds_scale = 3) ## This path doesn't exist gpv(YangKnoke01, path = c(1,2,4,5))
## Calculate ppv along a path in a sociomatrix ppv(YangKnoke01, path = c(1,2,5), odds_scale = 3) ## This path doesn't exist gpv(YangKnoke01, path = c(1,2,4,5))
Used with all_opt_gpv
and all_opt_ppv
to
unpack individual paths from the Dijkstra-format trees that
those functions return.
unpack(tree, source, target)
unpack(tree, source, target)
tree |
a Dijkstra-format tree returned by |
source |
an integer index corresponding to a node in |
target |
an integer index corresponding to a node in |
Returns NA
if a path does not exist
A sociomatrix encoding tie strengths among five nodes, used for examples in Yang, S., Knoke, D. (2001) Social Networks 23(4):285-295
YangKnoke01
YangKnoke01
a numeric matrix with 5 rows and 5 columns
<DOI: 10.1016/S0378-8733(01)00043-0>