Title: | Analytical Methods for Stream DAGs |
---|---|
Description: | Provides indices and tools for directed acyclic graphs (DAGs), particularly DAG representations of intermittent streams. A detailed introduction to the package can be found in the publication: "Non-perennial stream networks as directed acyclic graphs: The R-package streamDAG" (Aho et al., 2023) <doi:10.1016/j.envsoft.2023.105775>, and in the introductory package vignette. |
Authors: | Ken Aho [aut, cre], Arya Legg [dtc, ctb], Rob Ramos [dtc], Maggi Kraft [dtc], Charles T. Bond [dtc], Rebecca L. Hale [dtc] |
Maintainer: | Ken Aho <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.5-9 |
Built: | 2025-02-02 05:28:29 UTC |
Source: | https://github.com/moondog1969/streamdag |
This function and its documentation have been lifted from the igraph function E
with arguments according to DAG conventions. An arc sequence is a vector containing numeric arc ids, with a special class attribute that allows custom operations: selecting subsets of arcs based on attributes, or graph structure, creating the intersection, union of arcs, etc.
A(G, P, path)
A(G, P, path)
G |
Graph object of class |
P |
A list of node to select arcs via pairs of nodes. The first and second nodes select the first arc, the third and fourth node select the second arc, etc. |
path |
A list of nodes, to select arcs along a path. Note that this only works reliably for simple graphs. If the graph has multiple arcs, one of them will be chosen arbitrarily to be included in the arc sequence. |
Arc sequences are usually used as function arguments that refer to arcs of a graph.
An arc sequence is tied to the graph it refers to: it really denoted the specific arcs of that graph, and cannot be used together with another graph.
An arc sequence is most often created by the A()
function. The result includes arcs in increasing arc id order by default (if none of the P
and path
arguments are used). An arc sequence can be indexed by a numeric vector, just like a regular R vector.
An arc sequence of the graph.
Gabor Csardi
See E
G <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) A(G)
G <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) A(G)
When applying the definition of matrix multiplication to an adjacency matrix
, the
entry in
will give the number of paths in the graph from node
to node
of length
.
A.mult(G, power, text.summary = TRUE)
A.mult(G, power, text.summary = TRUE)
G |
Graph object of class |
power |
The power to rise the adjacency matrix to. |
text.summary |
Logical. If |
Returns either a character vector of paths of a specified length or, if text.summary = TRUE
, the adjacency matrix raised to a specified power.
Ken Aho
kon_full <- streamDAGs("konza_full") A.mult(kon_full, power = 6)
kon_full <- streamDAGs("konza_full") A.mult(kon_full, power = 6)
Contains spatial coordinates for graph nodes for stream networks in the Aquatic Intermittency effects on Microbiomes in Streams (AIMS) project
data("AIMS.node.coords")
data("AIMS.node.coords")
A data frame with 307 observations on the following 7 variables.
Object.ID
Nodal identifier
lat
Latitude
long
Longitude
site
Stream network name, currently includes: "KZ"
= Konza Prairie, "TD"
= Talladega, "WH"
= Weyerhauser, "PR"
= Painted Rock, "JD"
= Johnson Draw, "DC"
= Dry Creek, and "GJ"
= Johnson Draw.
piezo
Logical, indicating whether the location contains a peizometer.
microbial_seasonal_network
Logical, whether the location was sampled as part of AIMS seasonal microbial sampling.
STIC_inferred_PA
Logical, whether surface water presence/absence data were obtained from STIC (Stream Temperature, Intermittency, and Conductivity) sensors at the location.
New_in_2023
Logical, referring to sites at Johnson Draw added in 2023.
Given nodal water presence absence data for a graph, G, the function calculates arc water presence probabilities using particular rules (see approaches in Details).
arc.pa.from.nodes(G, node.pa, approach = "aho", na.rm = TRUE)
arc.pa.from.nodes(G, node.pa, approach = "aho", na.rm = TRUE)
G |
Graph object of class |
node.pa |
A data frame or matrix of nodal presence absence data with column names corresponding to node names in |
approach |
One of |
na.rm |
For |
The approach
argument currently supports three alternatives "aho"
, "dstream"
and "ustream"
. Let represent the
th arc with bounding nodes
and
.
Under approach = "aho"
there are three possibilities:
if both
and
are wet,
if both
and
are dry, and
if only one of
or
is wet.
Under approach = "dstream"
, if
is wet, and
if
is dry.
Conversely, if approach = "ustream"
, if u is wet, and
if u is dry.
Returns a matrix whose entries are estimated probabilities of success (e.g. surface water presence) based on the rules given in Aho et al. (2023). Matrix columns specify arcs and rows typically represent time series observations.
Ken Aho
Aho, K., Derryberry, D., Godsey, S. E., Ramos, R., Warix, S., Zipper, S. (2023) The communication distance of non-perennial streams. EarthArXiv https://eartharxiv.org/repository/view/4907/
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452 --+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) data(mur_node_pres_abs) pa <- mur_node_pres_abs[400:405,][,-1] arc.pa.from.nodes(murphy_spring, pa) arc.pa.from.nodes(murphy_spring, pa, "dstream")
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452 --+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) data(mur_node_pres_abs) pa <- mur_node_pres_abs[400:405,][,-1] arc.pa.from.nodes(murphy_spring, pa) arc.pa.from.nodes(murphy_spring, pa, "dstream")
Calculates graph assortativity
assort(G, mode = "in.out")
assort(G, mode = "in.out")
G |
Graph object of class |
mode |
One of |
The definitive measure of graph assortativity is the Pearson correlation coefficient of the degree of pairs of adjacent nodes (Newman, 2002). Let define nodes and directionality of the ith arc,
, let
index the degree type:
, and let
, be the
and
degree of the ith arc. Then, the general form of assortativity index is:
where and
are the arithmetic means of the
s and
s, and
and
are the population standard deviations of the
s and
s. Under this framework, there are four possible forms to
(Foster et al., 2010). These are:
, and
.
Assortativity coefficeint outcome(s)
Ken Aho, Gabor Csardi wrote degree
Newman, M. E. (2002). Assortative mixing in networks. Physical Review Letters, 89(20), 208701.
Foster, J. G., Foster, D. V., Grassberger, P., & Paczuski, M. (2010). Edge direction and the structure of networks. Proceedings of the National Academy of Sciences, 107(24), 10815-10820.
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) assort(network_a)
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) assort(network_a)
A simple function for calculating the dot product of a vector of stream arc lengths and a corresponding vector of either binary (stream presence or absence) outcomes, probabilities of stream presence or inverse probabilites of stream presence.
bern.length(lengths, pa, mode = "local")
bern.length(lengths, pa, mode = "local")
lengths |
A numeric vector of stream arc lengths |
pa |
A numeric vector of either binary (stream presence or absence) outcomes, probabilities of stream presence or inverse probabilites of stream presence. A vector outcome in |
mode |
One of |
When pa
is a vector of binary (stream presence or absence) data, the function provides a measure of instantaneous stream length (in the units used in lengths
). When pa
is a vector of probabilities of stream presence, the function provides average stream length (in units used in lengths
). When pa
is a vector of inverse probabilites of stream presence, the function provides average communication distance (in units used in lengths
).
Ken Aho
Botter, G., & Durighetto, N. (2020). The stream length duration curve: A tool for characterizing the time variability of the flowing stream length. Water Resources Research, 56(8), e2020WR027282.
lengths <- rexp(10, 10) pa <- rbinom(10, 11, 0.4) bern.length(lengths, pa)
lengths <- rexp(10, 10) pa <- rbinom(10, 11, 0.4) bern.length(lengths, pa)
Calculates summaries for beta and inverse-beta posteriors given prior probabilities for success, binary data and prior weight specification. Summaries include beta and inverse beta posterior means and variances and stream length and communication distance summaries given that stream length
is provided for intermittent stream segments.
beta.posterior(p.prior, dat, length = NULL, w = 0.5)
beta.posterior(p.prior, dat, length = NULL, w = 0.5)
p.prior |
Prior probability for success for the beta prior. The beta prior for the probability of success (e.g., stream presence) for kth outcome (e.g., stream segment) is defined as: |
dat |
An |
length |
An optional |
w |
Weight for the prior distribution compared to the actual data (generally a proportion). |
As our Bayesian framework we assume a conjugate beta prior and binomial likelihood
resulting in the posterior
.
Returns a list with components:
alpha |
The |
beta |
The |
mean |
The means of the beta posteriors. |
var |
The variances of the beta posteriors. |
mean.inv |
The means of the inverse-beta posteriors. |
var.inv |
The variances of the inverse-beta posteriors. |
Com.dist |
If |
Length |
If |
x |
The observed number of Bernoulli successes over n trials observed in |
Ken Aho
Densities (probabilities) of a bivariate Bernoulli distribution, .
biv.bern(p11, p10, p01, p00, y1, y2)
biv.bern(p11, p10, p01, p00, y1, y2)
p11 |
The probability that |
p10 |
The probability that |
p01 |
The probability that |
p00 |
The probability that |
y1 |
Outcome for |
y2 |
Outcome for |
Densities (probability) of the joint Bernoulli distribution.
Ken Aho
biv.bern(0.25,0.25,0.25,0.25,1,0) biv.bern(0.1,0.4,0.3,0.2,1,0)
biv.bern(0.25,0.25,0.25,0.25,1,0) biv.bern(0.1,0.4,0.3,0.2,1,0)
Stream segment presence absence data for Dry Cr. Idaho (outlet coordinates: 43.71839N, 116.13747
W). Arc outcomes determined from STIC (Stream Temperature, Intermittency, and Conductivity) sensors at bounding nodes.
data("dc_arc_pres_abs")
data("dc_arc_pres_abs")
A data frame with 46187 observations on the following 29 variables.
datetime
a POSIXlt
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
Maggie Kraft
Lengths of stream (arc) segments from Dry Creek Idaho (outlet coordinates: 43.71839N, 116.13747
W).
data("dc_lengths")
data("dc_lengths")
A data frame with 28 observations on the following 2 variables.
Arcs
Arc names, arrows directionally connect nodes.
Lengths
Stream segment (arc) length in kilometers.
Maggie Kraft
Stream node surface water presence absence at Dry Creek ID (outlet coordinates: 43.71839N, 116.13747
W). Outcomes based on STIC (Stream Temperature, Intermittency, and Conductivity) sensor and piezometer responses, resulting in binary observations for 36 nodes at 15 minutes intervals, over four years.
data("dc_node_pres_abs")
data("dc_node_pres_abs")
A data frame with 86958 observations on the following 37 variables.
datetime
a POSIXlt object
DC10
a numeric vector
C1
a numeric vector
DC11
a numeric vector
DPZ07
a numeric vector
DPZ06
a numeric vector
DC12
a numeric vector
C2
a numeric vector
DC13
a numeric vector
DC15
a numeric vector
C3
a numeric vector
DC14
a numeric vector
DC16
a numeric vector
DPZ05
a numeric vector
C4
a numeric vector
DC17
a numeric vector
C5
a numeric vector
DC18
a numeric vector
DC19
a numeric vector
C6
a numeric vector
DC20
a numeric vector
DC4
a numeric vector
C7
a numeric vector
DC1
a numeric vector
DC2
a numeric vector
DC3
a numeric vector
DC5
a numeric vector
DPZ02
a numeric vector
C8
a numeric vector
DPZ04
a numeric vector
DPZ03
a numeric vector
DC9
a numeric vector
C9
a numeric vector
DC8
a numeric vector
DC7
a numeric vector
DC6
a numeric vector
DSS01
a numeric vector
Maggie Kraft
Calculates degree distribution probability density. By default calculates an uncorrelated (random) density for a given degree.
degree.dists(d, exp.lambda = 3/2, normalize = TRUE)
degree.dists(d, exp.lambda = 3/2, normalize = TRUE)
d |
degree |
exp.lambda |
if not NULL, allows specification of chaotic |
normalize |
ensures that sum of demsities = 1 |
In general where
is the degree. For random degree distributions,
.
Returns a density plot for a degree.
Ken Aho
degree.distribution
, plot_degree.dist
.
Create a new graph after deleting stream graph arcs based on presence/absence data, e.g., data based on outcomes from STIC (Stream Temperature, Intermittency, and Conductivity) loggers.
delete.arcs.pa(G, pa)
delete.arcs.pa(G, pa)
G |
A graph object of class "igraph", see |
pa |
A vector of binary = 0,1 values indicating the absence or presence of arcs from |
Returns a igraph graph object missing the arcs indicated with 0 in pa
.
Ken Aho, Gabor Csardi wrote delete.edges
G <- graph_from_literal(a--+b--+c--+d--+e) delete.arcs.pa(G, c(0,0,1,1))
G <- graph_from_literal(a--+b--+c--+d--+e) delete.arcs.pa(G, c(0,0,1,1))
Create a new graph after deleting stream graph nodes based on presence/absence data, e.g., data based on outcomes from STIC (Stream Temperature, Intermittency, and Conductivity) loggers.
delete.nodes.pa(G, pa, na.response = "none")
delete.nodes.pa(G, pa, na.response = "none")
G |
A graph object of class "igraph", see |
pa |
A vector of binary = 0,1 values indicating the absence or presence of nodes from |
na.response |
One of |
A perennial problem with STIC (Stream Temperature, Intermittency, and Conductivity) sensors is the presence of missing data. If na.response = "none"
and NAs exist then the waring message "NAs in data need to be addressed. NAs converted 0."
is printed. One can also choose na.response = "treat.as.0"
or na.response = "treat.as.1"
which converts NAs to zeroes or ones. Clearly, none of these draconian approaches is optimal. Thus, if NAs occur, an attribute is added to the output graph object returned by the function, which lists the nodes with missing data. This attribute can be obtained with out$NA.vertices
where out <- delete.nodes.pa(...)
, see Examples below. An alternative is to use a classification algorithm for imputation e.g., STIC.RFimpute
, which uses missForest::missForest
.
Returns a igraph graph object, missing the nodes indicated with 0 in pa
.
Ken Aho, Gabor Csardi wrote delete.vertices
G <- graph_from_literal(a--+b--+c--+d--+e) delete.nodes.pa(G, c(0,0,1,1,1)) # delete.nodes.pa(G, c(0,0,NA,1,1)) # gives warning and converts NA to 0 d <- delete.nodes.pa(G, c(0,0,NA,1,1), "treat.as.0") d d$NA.vertices
G <- graph_from_literal(a--+b--+c--+d--+e) delete.nodes.pa(G, c(0,0,1,1,1)) # delete.nodes.pa(G, c(0,0,NA,1,1)) # gives warning and converts NA to 0 d <- delete.nodes.pa(G, c(0,0,NA,1,1), "treat.as.0") d d$NA.vertices
Calculates density (dinvbeta
), lower-tailed probability (pinvbeta
) and obtains random outcomes (rinvbeta
) for an inverse beta distribution
dinvbeta(x, alpha, beta) pinvbeta(x, alpha, beta) rinvbeta(n, alpha, beta)
dinvbeta(x, alpha, beta) pinvbeta(x, alpha, beta) rinvbeta(n, alpha, beta)
x |
Quantile vector or scalar at which to evaluate density or probability. |
alpha |
Alpha parameter |
beta |
Beta parameter |
n |
Number of random outcomes to be generated. |
Returns density, probability, and random outcomes for an inverse beta distribution.
Ken Aho and Dwayne Derryberry
See Also dbeta
.
dinvbeta(1,1,1) pinvbeta(1,1,1) rinvbeta(1,1,1)
dinvbeta(1,1,1) pinvbeta(1,1,1) rinvbeta(1,1,1)
Efficiency is the reciprocal of internodal distance. Thus, the efficiency beween nodes i and j is defined as where
denotes the distance between nodes i and j for all
.
efficiency.matrix(G, mode = "in") avg.efficiency(G, mode = "in") global.efficiency(G, mode = "in")
efficiency.matrix(G, mode = "in") avg.efficiency(G, mode = "in") global.efficiency(G, mode = "in")
G |
Graph object of class "igraph". See |
mode |
One of |
The function efficiency.matrix
calculates an efficiency matrix whose elements correspond to elements in the graph distance matrix. The function avg.efficiency
calculates average efficiencies of nodes to all other nodes, thus providing a local measure of graph connectedness. The function global.efficiency
calculates the mean of the of all pairwise efficiencies, thus providing a global measure of graph connectedness. For all three functions, reciprocals of infinite distances are taken to be zero.
The function efficiency.matrix
returns a reciprocal distance matrix for nodes in G
. The function avg.efficiency
treats efficiency as a local measure, and thus returns a vector whose entries are average efficiencies for each node. The function global.efficiency
returns a scalar (the mean of the reciprocal distance matrix).
Ken Aho. Gabor Csardi wrote the function distances
in igraph.
Ek, B., VerSchneider, C., & Narayan, D. A. (2015). Global efficiency of graphs. AKCE International Journal of Graphs and Combinatorics, 12(1), 1-13.
kon_full <- streamDAGs("konza_full") efficiency.matrix(kon_full) avg.efficiency(kon_full) global.efficiency(kon_full)
kon_full <- streamDAGs("konza_full") efficiency.matrix(kon_full) avg.efficiency(kon_full) global.efficiency(kon_full)
The function creates a list of associated dataframes for particular AIMS graph objects. Currently these include one of more of $coords
$arc.length
$node.pa
.
get.AIMS.data(graph = "mur_full", supress.message = FALSE)
get.AIMS.data(graph = "mur_full", supress.message = FALSE)
graph |
A character string defining one of the AIMS graphs codified in |
supress.message |
Logical. Supress message detailing objects created by function. |
The function radically simplifies code gymnastics required to obtain datasets associated AIMS graphs (see, for instance, Detaails in streamDAGs
).
Returns a list containg up to three dataframes:
coords |
Spatial coordinates and other information from |
arc.length |
Lengths of network, generally in km. |
node.pa |
Presence(1)/absence(0) of surface water at the node. |
Ken Aho
jd <- get.AIMS.data("jd_full", TRUE) head(jd$coords) head(jd$arc.length) head(jd$node.pa)
jd <- get.AIMS.data("jd_full", TRUE) head(jd$coords) head(jd$arc.length) head(jd$node.pa)
Latitudes and Longitudes of nodes established at Gibson Jack in 2016. Datum: WGS 84.
data("gj_coords16")
data("gj_coords16")
A data frame with 124 observations on the following 3 variables.
Object.ID
Node name
lat
Latitude
long
Longitude
Lengths of stream (arc) segments from the Gibson Jack watershed in southeast Idaho (outlet coordinates: 42.767180N, 112.480240
W). The dataframe
gj_lengths
contains arc lengths for a network including STICs, but excluding piezometers. The dataframe gj_lengths_piezo_full
contains arc lengths for a network that includes both STICs and piezometers.
data("gj_lengths")
data("gj_lengths")
A data frame with 28 observations jd_lengths
or 35 observations jd_lengths_piezo_full
on the following 2 variables.
Arcs
Arc names, arrows directionally connect nodes.
Lengths
Stream segment (arc) length in kilometers.
Maggie Kraft
Stream node surface water presence absence data from Gibson Jack, Idaho (outlet coordinates: 42.767180N, 112.480240
W). Outcomes based on STIC (Stream Temperature, Intermittency, and Conductivity) sensors, resulting in binary observations for 29 nodes at 15 minutes intervals over three years.
data("gj_node_pres_abs")
data("gj_node_pres_abs")
A data frame with 55109 observations on the following 36 variables.
datetime
a POSIXlt vector
GJ16
a numeric vector
GJ14
a numeric vector
C2
a numeric vector
C3
a numeric vector
C4
a numeric vector
GJ11
a numeric vector
GJ13
a numeric vector
GJ12
a numeric vector
GJ19
a numeric vector
GJ20
a numeric vector
GJ18
a numeric vector
GJ17
a numeric vector
C5
a numeric vector
GJ10
a numeric vector
GJ9
a numeric vector
C6
a numeric vector
GJ23
a numeric vector
GJ22
a numeric vector
C1
a numeric vector
C7
a numeric vector
GJ25
a numeric vector
GJ21
a numeric vector
GJ8
a numeric vector
GJ7
a numeric vector
GJ3
a numeric vector
C8
a numeric vector
GJ6
a numeric vector
GJ5
a numeric vector
GJ4
a numeric vector
GPZ02
a numeric vector
GPZ03
a numeric vector
GPZ04
a numeric vector
GPZ05
a numeric vector
GPZ06
a numeric vector
GPZ07
a numeric vector
GSS01
a numeric vector
Maggie Kraft
Streamflow presence and absence data for each node location collected by manual observation November 6, 2016, May 6, 2017, and August 14, 2017. Note, a longer dataset 2021-2023, gathered by the AIMS team at fewer points, is available for Gibson Jack under the name gj_node_pres_abs
.
data("gj_node_pres_abs16")
data("gj_node_pres_abs16")
A data frame with 3 observations on the following 125 variables.
Date
a character vector
GJ_ST1_0600
a numeric vector
GJ_ST1_0400
a numeric vector
GJ_ST1_0200
a numeric vector
GJ_ST1_0000
a numeric vector
GJ_SF_2800
a numeric vector
GJ_SF_2600
a numeric vector
GJ_SF_2400
a numeric vector
GJ_SF_2200
a numeric vector
GJ_SF_2000
a numeric vector
GJ_SF_1800
a numeric vector
GJ_SF_1600
a numeric vector
GJ_SF_1400
a numeric vector
GJ_SF_1200
a numeric vector
GJ_SF_1000
a numeric vector
GJ_SF_0800
a numeric vector
GJ_SF_0600
a numeric vector
GJ_SF_0400
a numeric vector
GJ_SF_0200
a numeric vector
GJ_SF_0000
a numeric vector
GJ_NT1_WF_FH
a numeric vector
GJ_NT1_WF_000
a numeric vector
GJ_NT1_0800
a numeric vector
GJ_NT1_0600
a numeric vector
GJ_NT1_0400
a numeric vector
GJ_NT1_0200
a numeric vector
GJ_NT1_0000
a numeric vector
GJ_NT2_1600
a numeric vector
GJ_NT2_1400
a numeric vector
GJ_NT2_1200
a numeric vector
GJ_NT2_1000
a numeric vector
GJ_NT2_0800
a numeric vector
GJ_NT2_0600
a numeric vector
GJ_NT2_0400
a numeric vector
GJ_NT2_0200
a numeric vector
GJ_NT2_0000
a numeric vector
GJ_NT3_0200
a numeric vector
GJ_NT3_0000
a numeric vector
GJ_NT4_0600
a numeric vector
GJ_NT4_0400
a numeric vector
GJ_NT4_0200
a numeric vector
GJ_NT4_0000
a numeric vector
GJ_NF_3800
a numeric vector
GJ_NF_3750
a numeric vector
GJ_NF_3600
a numeric vector
GJ_NF_3400
a numeric vector
GJ_NF_3200
a numeric vector
GJ_NF_3000_CU
a numeric vector
GJ_NF_3000_CD
a numeric vector
GJ_NF_2800_CU
a numeric vector
GJ_NF_2800_CD
a numeric vector
GJ_NF_2600
a numeric vector
GJ_NF_2400_CU
a numeric vector
GJ_NF_2400_CD
a numeric vector
GJ_NF_2200
a numeric vector
GJ_NF_2000
a numeric vector
GJ_NF_1800
a numeric vector
GJ_NF_1600
a numeric vector
GJ_NF_1400
a numeric vector
GJ_NF_1200
a numeric vector
GJ_NF_1060_CU
a numeric vector
GJ_NF_1060_CD
a numeric vector
GJ_NF_1000
a numeric vector
GJ_NF_0800
a numeric vector
GJ_NF_0600
a numeric vector
GJ_NF_0400
a numeric vector
GJ_NF_0200
a numeric vector
GJ_NF_0000
a numeric vector
GJ_MT2_0900
a numeric vector
GJ_MT2_0800
a numeric vector
GJ_MT2_0600
a numeric vector
GJ_MT2_0400
a numeric vector
GJ_MT2_0200
a numeric vector
GJ_MT2_0000
a numeric vector
GJ_MT1_1650
a numeric vector
GJ_MT1_1600
a numeric vector
GJ_MT1_1550
a numeric vector
GJ_MT1_1500
a numeric vector
GJ_MT1_1450
a numeric vector
GJ_MT1_1400
a numeric vector
GJ_MT1_1350
a numeric vector
GJ_MT1_1300
a numeric vector
GJ_MT1_1250
a numeric vector
GJ_MT1_1200
a numeric vector
GJ_MT1_1150
a numeric vector
GJ_MT1_1100
a numeric vector
GJ_MT1_1050
a numeric vector
GJ_MT1_1000
a numeric vector
GJ_MT1_0950
a numeric vector
GJ_MT1_0900
a numeric vector
GJ_MT1_0850
a numeric vector
GJ_MT1_0800
a numeric vector
GJ_MT1_0750
a numeric vector
GJ_MT1_0700
a numeric vector
GJ_MT1_0650
a numeric vector
GJ_MT1_0600
a numeric vector
GJ_MT1_0550
a numeric vector
GJ_MT1_0500
a numeric vector
GJ_MT1_0450
a numeric vector
GJ_MT1_0400
a numeric vector
GJ_MT1_0350
a numeric vector
GJ_MT1_0300
a numeric vector
GJ_MT1_0250
a numeric vector
GJ_MT1_0200
a numeric vector
GJ_MT1_0150
a numeric vector
GJ_MT1_0100
a numeric vector
GJ_MT1_0050
a numeric vector
GJ_MT1_0000
a numeric vector
GJ_MS_3000
a numeric vector
GJ_MS_2800
a numeric vector
GJ_MS_2600
a numeric vector
GJ_MS_2400
a numeric vector
GJ_MS_2200
a numeric vector
GJ_MS_2000
a numeric vector
GJ_MS_1800_CU
a numeric vector
GJ_MS_1800_CD
a numeric vector
GJ_MS_1600
a numeric vector
GJ_MS_1400
a numeric vector
GJ_MS_1200
a numeric vector
GJ_MS_1000
a numeric vector
GJ_MS_0800
a numeric vector
GJ_MS_0600
a numeric vector
GJ_MS_0400
a numeric vector
GJ_MS_0200
a numeric vector
GJ_MS_0000
a numeric vector
This function calculates useful DAG global summaries including size, diameter, number of paths to sink, mean path length, mean alpha centrality, mean PageRank centrality, graph centralization, Strahler order, Shreve order, the Randic index, the first Zagreb Index, the second Zagreb index, atom-bond connectivity, the geometric-arithmatic index, the harmonic index, the Harary index, global efficiency, the assortativity correlation (+, -), and the assortativity correlation (+, +).
global.summary(G, which = "all", sink, mode = "in", inf.paths = FALSE)
global.summary(G, which = "all", sink, mode = "in", inf.paths = FALSE)
G |
graph object of class "igraph". See |
which |
Which metric to use. Currently one of |
sink |
sink node from graph object |
mode |
Type of degree used. One of |
inf.paths |
logical, consider infinite paths? |
Simple global graph measures of complexivity and/or connectivity of a stream DAG include size, diameter, and number of paths to a sink. The size is equal to the number of arcs in the stream network. The diameter equals the length of the longest path, i.e., the height of the sink, and in eccentricity of the sink. The number of paths to the sink is equivalent to the number of nodes from which the sink node is reachable, which will be for a fully active stream. For more information on
metrics see
I.D
. Links describing other metrics are provided below.
Returns a vector of global graph measures for G
.
Ken Aho, Gabor Csardi wrote alpha_centrality
and other underlying functions.
Kunkler, S. J., LaMar, M. D., Kincaid, R. K., & Phillips, D. (2013). Algorithm and complexity for a network assortativity measure. arXiv Preprint arXiv:1307.0905.
Das, K. C., Gutman, I., & Furtula, B. (2011). On atom-bond connectivity index. Chemical Physics Letters, 511(4-6), 452-454.
Li, X., & Shi, Y. (2008). A survey on the randic index. MATCH Commun. Math. Comput. Chem, 59(1), 127-156.
alpha_centrality
,
I.D
, spath.lengths
, n.sources
, stream.order
, harary
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) global.summary(network_a, sink ="o")
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) global.summary(network_a, sink ="o")
Computes the Harary global metric for a stream DAG.
harary(G)
harary(G)
G |
Graph object of class |
The Harary index is computed as:
where is the reciprocal of the
th element of the graph distance matrix. Reciprocals of infinite values in the distance matrix are taken to be zero. Users should be aware that the graph object
G
is assumed to be DAG, and that distances are based on in-paths.
Returns a scalar: the global Harary index.
Ken Aho, Gabor Csardi wote distances
Plavsic, D., Nikolic, S., Trinajstic, N., & Mihalic, Z. (1993). On the Harary index for the characterization of chemical graphs. Journal of Mathematical Chemistry, 12(1), 235-250.
harary(streamDAGs("konza_full"))
harary(streamDAGs("konza_full"))
Calculates global generalized topopological indices for a digraph
I.D(G, mode = "gen.rand", alpha = -1/2, mult = FALSE, degrees = "out.in")
I.D(G, mode = "gen.rand", alpha = -1/2, mult = FALSE, degrees = "out.in")
G |
Graph object of class. See |
mode |
One of |
alpha |
Exponent value for forms of omega with alpha exponent. |
mult |
Logical if |
degrees |
Degree designations for the arc |
For an arc ,
, we denote the out degree of
as
, and the in degree of
as
. Now let
represent a generalized topopological index for a digraph,
(cf. Deng et al., 2021) that depends on
and
:
Six basic configurations for can be recognized:
1. If , for
, then
is the general directed Randic index (Kincaid et al., 2016) for
. Specific variants include the Randic index
, the second Zagreb index
and the second modified Zagreb index
(Anthony & Marr, 2021).
2. If , then
is the general sum-connectivity index for D (Deng et al., 2021). Further, if
, then
is the sum connectivity (Zhou & Trinajstic, 2009), and the directed first Zagreb index (Anthony & Marr, 2021) for
and
, respectively .
3. If , then
is the atom bond connectivity of D (Estrada et al., 1998).
4. If , then
is the geometric-arithmetic index for
(Vukicevic & Furtula, 2009).
5. If , then
is the harmonic index of
(Favaron et al., 1993).
6. If , then
is the augmented Randic index of
(Furtula et al. 2010). This index is not reccomended for stream DAGs as it will contained undefined terms for any network with unbranched paths.
More options are possible under the generalization of Kincaid (1996). Specifically, for an arc , let
index the degree type:
. Then, four combinations of
can occur, resulting in four different versions of each
metric described above. These combinations are:
(as shown above),
,
, and
. The default
is strongly reccomended for stream DAGs over other variants.
Index values for a DAG
Ken Aho, Gabor Csardi wrote degree
Anthony, B. M., & Marr, A. M. (2021). Directed zagreb indices. Graphs and Combinatorial Optimization: From Theory to Applications: CTW 2020 Proceedings, 181-193.
Deng, H., Yang, J., Tang, Z., Yang, J., & You, M. (2021). On the vertex-degree based invariants of digraphs. arXiv Preprint arXiv:2104.14742.
Estrada, E., Torres, L., Rodriguez, L., & Gutman, I. (1998). An atom-bond connectivity index: Modelling the enthalpy of formation of alkanes. NISCAIR-CSIR, India.
Favaron, O., Maheo, M., & Sacle, J.-F. (1993). Some eigenvalue properties in graphs (conjectures of graffitii). Discrete Mathematics, 111(1-3), 197-220.
Furtula, B., Graovac, A., & Vukicevic, D. (2010). Augmented Zagreb index. Journal of Mathematical Chemistry, 48(2), 370-380.
Kincaid, R. K., Kunkler, S. J., Lamar, M. D., & Phillips, D. J. (2016). Algorithms and complexity results for finding graphs with extremal Randic index. Networks, 67(4), 338-347.
Vukicevic, D., & Furtula, B. (2009). Topological index based on the ratios of geometrical and arithmetical means of end-vertex degrees of edges. Journal of Mathematical Chemistry, 46(4), 1369-1376.
Zhou, B., & Trinajstic, N. (2009). On a novel connectivity index. Journal of Mathematical Chemistry, 46(4), 1252-1270.
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) I.D(network_a)
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) I.D(network_a)
Integral connectivity scale lengths (ICSL, Western et al. 2013) is the average distance between wet locations using either (1) Euclidean distance or (2) topographically-defined hydrologic distance, e.g., instream hydrologic distance, subsurface distance (Ali and Roy 2009) and outlet distance, in which connected saturated paths must reach the catchment outlet.
ICSL(G, coords = NULL, names = NULL, lengths = NULL, dist.matrix = NULL, show.dist = FALSE)
ICSL(G, coords = NULL, names = NULL, lengths = NULL, dist.matrix = NULL, show.dist = FALSE)
G |
A graph object of class "igraph", see |
coords |
Spatial coordinates to allow computation of nodal Euclidean distances |
names |
Nodal names |
lengths |
Stream arc lengths or hydrologic arc lengths |
show.dist |
Logical. Show distance matrix? |
dist.matrix |
An optional distance matrix, potentially providing non-Euclidean node distances (e.g., node subsurface distance, etc.). Distance matrix |
Computes either:
1) the average Euclidean distance of connected nodal locations as defined in G
, if coords
are provided, 2) if dist.matrix
is provided, the average nodal distances of a distance matrix provided in dist.matrix
for nodes that remain in G
, or 3) the instream distances of connected nodal locations if stream lenghts are provided in lengths
. For 3), the length
vector will need to be trimmed as arcs disappear within intermittent streams (see Examples).
Returns a global distance scalar. See Details.
Ken Aho, Gabor Csardi wrote underlying functions distances
and E
Ali, G. A., & Roy, A. G. (2010). Shopping for hydrologically representative connectivity metrics in a humid temperate forested catchment. Water Resources Research, 46(12).
Western, A. W., Bloschl, G., & Grayson, R. B. (2001). Toward capturing hydrologically significant connectivity in spatial patterns. Water Resources Research, 37(1), 83-97.
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452 --+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) #---- ICSL based on nodal Euclidean distances ----# data(mur_coords) ICSL(murphy_spring, coords = mur_coords[,2:3], names = mur_coords[,1]) #---- ICSL based on in-stream length data ----# data(mur_lengths) ICSL(murphy_spring, lengths = mur_lengths[,2], names = mur_coords[,1]) # or, simply ms <- murphy_spring E(ms)$weight <- mur_lengths[,2] ICSL(ms) # Arcs 1 and 3 dry B <- graph_from_literal(IN_N, M1984, IN_S --+ M1993 --+ M1951 --+ M1909, M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452 --+ M1377 --+ M1254, M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823 --+ M759 --+ M716, M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153 --+ M91 --+ OUT) ICSL(B, lengths = mur_lengths[,2][-c(1,3)], show.dist = TRUE)
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452 --+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) #---- ICSL based on nodal Euclidean distances ----# data(mur_coords) ICSL(murphy_spring, coords = mur_coords[,2:3], names = mur_coords[,1]) #---- ICSL based on in-stream length data ----# data(mur_lengths) ICSL(murphy_spring, lengths = mur_lengths[,2], names = mur_coords[,1]) # or, simply ms <- murphy_spring E(ms)$weight <- mur_lengths[,2] ICSL(ms) # Arcs 1 and 3 dry B <- graph_from_literal(IN_N, M1984, IN_S --+ M1993 --+ M1951 --+ M1909, M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452 --+ M1377 --+ M1254, M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823 --+ M759 --+ M716, M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153 --+ M91 --+ OUT) ICSL(B, lengths = mur_lengths[,2][-c(1,3)], show.dist = TRUE)
Calculates improved closeness centrality of individual nodes in a DAG.
imp.closeness(G)
imp.closeness(G)
G |
Graph object of class "igraph", see See |
Improved closeness centrality (Beauchamp, 1965) was developed for weakly connected or disconnected digraphs. The measure is based on the reciprocal of nodal shortest path distances from the jth node to the kth node, . For the jth node this is:
where, for disconnected nodes, the reciprocal distance is taken to be zero.
Improved closeness centrality of a node
Ken Aho, Gabor Csardi wrote distances
Beauchamp, M. A. (1965). An improved index of centrality. Behavioral Science, 10(2), 161-163.
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) imp.closeness(network_a)
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) imp.closeness(network_a)
The function was written primarilly to recognize DAG islands to allow correct implementation of the function stream.order
and is still early in its development.
isle(G)
isle(G)
G |
Graph object of class |
The function currently allows detection of simple island structures (those that don't contain sub-islands). One of the output objects from the function is a new graph object with island nodes into a single node(s).
Output consists of the following:
test |
Logical indicating whether or not |
island |
List of islands with their nodal components |
input.id |
Neighboring node(s) directly upstream from island(s). |
output.id |
Neighboring node(s) directly downstream from island(s). |
new.graph |
New graph object created from |
island.names |
Names of island nodes created in new output graph (that combines nodes constituing islands into a single node). Follows the naming system |
splits |
The number of islands detected. |
Ken Aho
stream.order
, delete.vertices
, add.vertices
, add.edges
G <- graph_from_literal(a --+ c --+ e, b --+ d --+ e --+ f --+ p, g --+ i --+ j --+ m, i --+ k --+ m, m --+ n --+ o --+ p, h --+ l --+ n, p --+ q --+ r) plot(G) isle(G)
G <- graph_from_literal(a --+ c --+ e, b --+ d --+ e --+ f --+ p, g --+ i --+ j --+ m, i --+ k --+ m, m --+ n --+ o --+ p, h --+ l --+ n, p --+ q --+ r) plot(G) isle(G)
Lengths of stream (arc) segments from Johnson Draw in southwest Idaho (outlet coordinates: 43.12256N, 116.77630
W). The dataframe
jd_lengths
contains segment lengths in the absence of piezos [nodes are currently defined by STIC (Stream Temperature, Intermittency, and Conductivity) locations only] and thus correspond to the network in streamDAGs("jd_full")
. The dataframe jd_lengths_full
contains segment lengths for node designated by both STICs and piezos. A corresponding network that includes piezos is depicted by streamDAGs("jd_piezo_full")
. The dataframe jd_lengths_2023
contains segment lengths for node designated by both STICs, piezos and additional STC sites established in 2023. A correspding network can be obtained with streamDAGs("jd_piezo_full_2023")
.
data("jd_lengths")
data("jd_lengths")
A data frame with observations on the following 2 variables.
Arcs
Arc names, arrows directionally connect nodes.
Lengths
Lengths in in km.
Arya Legg, Maggie Kraft
Stream node surface water presence absence data from 2022-2023 for the Johnson Draw watershed in southwest Idaho (outlet coordinates: 43.12256N, 116.77630
W). Outcomes are based on STIC sensors and piezometers, resulting in binary observations for 35 nodes (28 STICs and 7 piezometers) at 15 minutes intervals over three years. JD21, JD22, JD23, JD25, JD26, JD27, JD28 were added in 2023 for the AIMS experiment.
data("jd_node_pres_abs")
data("jd_node_pres_abs")
A data frame with 51653 observations on the following 36 variables.
datetime
a POSIXlt
JD5
a numeric vector
JD6
a numeric vector
JD7
a numeric vector
C1
a numeric vector
JD10
a numeric vector
JD9
a numeric vector
JD8
a numeric vector
JD11
a numeric vector
JD12
a numeric vector
JD13
a numeric vector
C2
a numeric vector
JD16
a numeric vector
JD17
a numeric vector
JD18
a numeric vector
JD19
a numeric vector
JD20
a numeric vector
JD4
a numeric vector
JD3
a numeric vector
JD2
a numeric vector
JD1
a numeric vector
JD15
a numeric vector
JD14
a numeric vector
JSS01
a numeric vector
JPZ02
a numeric vector
JPZ03
a numeric vector
JPZ04
a numeric vector
JPZ05
a numeric vector
JPZ06
a numeric vector
JPZ07
a numeric vector
JD21
a numeric vector
JD22
a numeric vector
JD23
a numeric vector
JD25
a numeric vector
JD26
a numeric vector
JD27
a numeric vector
JD28
a numeric vector
Maggie Kraft
Coordinates (in Lat/Long) of nodes established at the Konza Prairie stream network.
data("kon_coords")
data("kon_coords")
A data frame with 46 observations on the following 3 variables.
Object.ID
Node name
lat
Latitude
long
Longitude
Lengths of Murphy Cr. stream (arc) segments
data("kon_lengths")
data("kon_lengths")
A data frame with 45 observations on the following 2 variables.
Arcs
Arc names, arrows directionally connect nodes.
Lengths
Lengths in meters
Rob Ramos
Obtains local (nodal) summaries from a DAG
local.summary(G, metric = "all", mode = "in")
local.summary(G, metric = "all", mode = "in")
G |
Graph of class "igraph". See |
metric |
One of |
mode |
One of |
Nodes are returned with values measuring the indegree, alpha centrality, PageRank centrality, improved closeness centrality, betweenness centrality, upstream network length, and upstream in-path length mean, variance, max (i.e., in-eccentricity), skew, kurtosis, and mean efficiency.
Ken Aho, Gabor Csardi wrote degree
, page_rank
and alpha_centrality
functions.
degree
, alpha_centrality
, page_rank
, betweenness
,
imp.closeness
,
skew
, kurt
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) local.summary(network_a)
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) local.summary(network_a)
Simulated multivariate Benroulli outcomes for 27 stream segments, based on their observed marginal probabilities for steam presence and covariance structures. "M"-labelling for nodes indicates "meters above outlet".
data("mur_arc_pres_abs")
data("mur_arc_pres_abs")
A data frame with 1000 observations on the following 27 variables.
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
UTM coordinates (Zone 11T) and Latitudes and Longitudes of nodes established at Murphy Cr. Idaho. Datum: WGS 84.
data("mur_coords")
data("mur_coords")
A data frame with 28 observations on the following 5 variables.
Object.ID
Node name
E
UTM Easting
N
UTM Northing
lat
Latitude
long
Longitude
Lengths of Murphy Cr. stream (arc) segments
data("mur_lengths")
data("mur_lengths")
A data frame with 27 observations on the following 2 variables.
Arcs
Arc names, arrows directionally connect nodes.
Lengths
Stream segment (arc) length in meters.
Warix, S. R., Godsey, S. E., Lohse, K. A., & Hale, R. L. (2021). Influence of groundwater and topography on stream drying in semi-arid headwater streams. Hydrological Processes, 35(5), e14185.
A subset of stream node presence absence data from Warix et al. (2019) resulting in binary observations for 28 nodes at 2.5 hr intervals.
data("mur_node_pres_abs")
data("mur_node_pres_abs")
A data frame with 1163 observations on the following 29 variables.
Datetime
a character vector
IN_N
a numeric vector
M1984
a numeric vector
M1909
a numeric vector
IN_S
a numeric vector
M1993
a numeric vector
M1951
a numeric vector
M1799
a numeric vector
M1719
a numeric vector
M1653
a numeric vector
M1572
a numeric vector
M1452
a numeric vector
M1377
a numeric vector
M1254
a numeric vector
M1166
a numeric vector
M1121
a numeric vector
M1036
a numeric vector
M918
a numeric vector
M823
a numeric vector
M759
a numeric vector
M716
a numeric vector
M624
a numeric vector
M523
a numeric vector
M454
a numeric vector
M380
a numeric vector
M233
a numeric vector
M153
a numeric vector
M91
a numeric vector
OUT
a numeric vector
Warix, S. R., Godsey, S. E., Lohse, K. A., & Hale, R. L. (2021). Influence of groundwater and topography on stream drying in semi-arid headwater streams. Hydrological Processes, 35(5), e14185.
A data frame with one hundred multivariate Bernoulli simulated outcomes representing spring, summer and fall.
data("mur_seasons_arc_pa")
data("mur_seasons_arc_pa")
A data frame with 300 observations on the following 28 variables.
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
Season
A categorical variable with three levels: "spring"
(6/3/2019 - 7/13/2019), "summer"
(7/13/2019 - 8/23/2019) and "fall"
(8/23/2019 - 10/2/2019)
Identify the number of sources and the source nodes. Sources are assumed to be linked to the sink.
n.sources(G, sink = NULL) sources(G, sink = NULL)
n.sources(G, sink = NULL) sources(G, sink = NULL)
G |
A graph object of class "igraph", see |
sink |
The name of the sink node. |
Returns a character vector listing streamDAG source nodes (those linked to the sink with indegree 0).
Ken Aho, Gabor Csardi wrote degree
sources(streamDAGs("konza_full"), sink = "SFM01_1")
sources(streamDAGs("konza_full"), sink = "SFM01_1")
Obtains all shortest in paths to a sink
path.lengths.sink(G, sink = NULL, inf.paths = TRUE)
path.lengths.sink(G, sink = NULL, inf.paths = TRUE)
G |
Graph object of class "igraph", see: |
sink |
sink node from |
inf.paths |
Logical, consider infinite paths? |
Length of path to a sink
Ken Aho, Gabor Csardi wrote distances
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452--+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) path.lengths.sink(murphy_spring, sink = "OUT") # with stream lengths as weights data(mur_lengths) E(murphy_spring)$weights <- mur_lengths[,2] path.lengths.sink(murphy_spring, "OUT")
murphy_spring <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452--+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) path.lengths.sink(murphy_spring, sink = "OUT") # with stream lengths as weights data(mur_lengths) E(murphy_spring)$weights <- mur_lengths[,2] path.lengths.sink(murphy_spring, "OUT")
Functions detect and summarize visibilities of path nodes from one or several source nodes to an sink. Specifically, the function The function path.visibility
determines path visibilities from single source node to a single sink. multi.path.visibility
Generates tables of path visibilities and visibility summaries for multiple source nodes to a single sink.
Ordering of nodes, vitally important to the calculation of visibility is currently obtained by identifying paths from each source node to the sink. The sum of node distances in each path are then sorted decreasingly to define an initial order for calculating visibilities. It is currently assumed that the user will manually handle disconnected paths via the source
argument of visibility functions. Use of source nodes disconnected to the sink will result in the message: "only use source nodes connected to sink"
. Because of this situation disconnected graphs will be handled by a function in development single.node.visibility
.
path.visibility(G, degree = "in", source = NULL, sink = NULL, weights = NULL) multi.path.visibility(G, degree = "in", source = NULL, sink = NULL, weights = NULL, autoprint = TRUE)
path.visibility(G, degree = "in", source = NULL, sink = NULL, weights = NULL) multi.path.visibility(G, degree = "in", source = NULL, sink = NULL, weights = NULL, autoprint = TRUE)
G |
Graph of class "igraph". See |
degree |
One of |
source |
A starting node for a path. The function |
sink |
An ending node for a path. |
weights |
If |
autoprint |
Logical. Should table summary of nodal visibilities be automatically printed or made ? |
Following Lacasa et al. (2008), let represent the occurrance number of the
th node in a time series or stream path, and let
represent a data outcome from the
th node. Nodes
and
will have visibility if all other data,
, between
and
fufill:
The function path.visibility
returns a symmetric matrix whose upper triangle denotes nodal co-visibilities. The lower triangle is left empty for efficiency. Reading down a column in the upper triangle shows upstream visibilites to and from a node, while reading across rows shows downstream visibilities.
The function multi.path.visibility
returns a list containing the three objects. The first is printed and the latter two are invisible
by default.
visibility.summary |
The printed result is a matrix of path visibity counts for a node, with respect to upstream (to), downstream (from), and combined directions (both). |
complete.matrix |
Analogous, to |
all.matrices |
A list containing |
Output is summarized based on a deduced ordering of nodes from sources to sin. The ordering is based on nodal path lengths.
Ken Aho, Gabor Csardi wrote degree
and shortest_paths
.
Lacasa, L., Luque, B., Ballesteros, F., Luque, J., & Nuno, J. C. (2008). From time series to complex networks: The visibility graph. Proceedings of the National Academy of Sciences, 105(13), 4972-4975.
A <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) path.visibility(A, source = "a", sink = "o") multi.path.visibility(A, source = c("a","c","f","h"), sink = "o") # From Lacasa et al. (2008) B <- graph_from_literal(a --+ b --+ c --+ d --+ e --+ f --+ g) weights <- data.frame(matrix(nrow = 1, data = c(0.87, 0.49, 0.36, 0.83, 0.87, 0.49, 0.36))) names(weights) = letters[1:7] path.visibility(B, source = "a", sink = "g", weights = weights)
A <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) path.visibility(A, source = "a", sink = "o") multi.path.visibility(A, source = c("a","c","f","h"), sink = "o") # From Lacasa et al. (2008) B <- graph_from_literal(a --+ b --+ c --+ d --+ e --+ f --+ g) weights <- data.frame(matrix(nrow = 1, data = c(0.87, 0.49, 0.36, 0.83, 0.87, 0.49, 0.36))) names(weights) = letters[1:7] path.visibility(B, source = "a", sink = "g", weights = weights)
Plots bserved degree distribution against models for uncorrelated random, chaotic and correlated random processes.
plot_degree.dist(G, mode = "all", exp.lambda = c(1.1, 3/2, 2), leg.loc = "topright")
plot_degree.dist(G, mode = "all", exp.lambda = c(1.1, 3/2, 2), leg.loc = "topright")
G |
Graph object of class "igraph". See |
mode |
Character string, one of |
exp.lambda |
log.lamda = if not NULL, allows specification of chaotic |
leg.loc |
placement of |
Plots processes for observed versus distributions under random or chaotic degrees.
Ken Aho
degree.dists
, degree.distribution
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) plot_degree.dist(network_a)
network_a <- graph_from_literal(a --+ b, c --+ d, d --+ e, b --+ e, e --+ j, j --+ m, f --+ g, g --+ i, h --+ i, i --+ k, k --+ l, l --+ m, m --+ n, n --+ o) plot_degree.dist(network_a)
Replaces impossible correlations (values too small or too large) with minimum and maximum correlations, respectively.
min_r(p1, p2) max_r(p1, p2) R.bounds(p, R, pad = 0.001)
min_r(p1, p2) max_r(p1, p2) R.bounds(p, R, pad = 0.001)
p1 |
Probability of success for first random variable |
p2 |
Probability of success for second random variable |
p |
Vector of marginal probabilities for multivariate Bernoulli random variables, for |
R |
Raw correlation matrix for random variables |
pad |
Padding (in correlation units) to adjust the returned correlation matrix with respect extremal values. |
The functions r.min
and r.max
define minimum and maximimum possible correlations. The function R.bounds
replaces impossibly large or small values with maximally large or small values repectively.
Functions return a scalar defining minimum or maximimum possible correlations. See Aho et al. (2023).
Ken Aho
Aho, K., Derryberry, D., Godsey, S. E., Ramos, R., Warix, S., Zipper, S. (2023) The communication distance of non-perennial streams. EarthArXiv https://eartharxiv.org/repository/view/4907/
min_r(0.6, 0.9) max_r(0.1, 0.2) x1 <- rep(c(1,0),5) x2 <- c(rep(1,7), rep(0,3)) x3 <- c(rep(1,3), rep(0,7)) R <- cor(cbind(x1, x2, x3)) R.bounds(c(0.5, 0.7, 1), R)
min_r(0.6, 0.9) max_r(0.1, 0.2) x1 <- rep(c(1,0),5) x2 <- c(rep(1,7), rep(0,3)) x3 <- c(rep(1,3), rep(0,7)) R <- cor(cbind(x1, x2, x3)) R.bounds(c(0.5, 0.7, 1), R)
The function measures the “size” of the intact network or sub-network (either number of upstream nodes, or user defined defined length, e.g., m, km) with respect to network arcs.
size.intact.to.arc(G, arc.node = "in")
size.intact.to.arc(G, arc.node = "in")
G |
Graph object of class "igraph", see: |
arc.node |
One of |
For an unweighted graph, the upstream network “size” equates to the number of nodes in the intact network or sub-network upstream of an arc. For a graph whose arcs are weighted with actual stream segment lengths (see Examples), this will be the length (in measured units of length given in the weights) of the intact network or sub-network upstream of the arc. The argument arc.node
allows upstream network size to be calculated with respect to either the upstream ("in"
) nodes of arcs or the downstream ("out"
) nodes of arcs. This designation will be applied to define the end (outlet) of the network or sub-network. Thus, option "out"
may produce unexpectedly large results when these downstream "out"
nodes of arcs occur at confluences.
Output is a numeric vector whose length will be equal to the number of arcs in G
.
Ken Aho, Gabor Csardi wrote distances
mur <- streamDAGs("mur_full") data(mur_lengths) E(mur)$weight <- mur_lengths[,2] size.intact.to.arc(mur) # upstream network sizes are in meters
mur <- streamDAGs("mur_full") data(mur_lengths) E(mur)$weight <- mur_lengths[,2] size.intact.to.arc(mur) # upstream network sizes are in meters
The length of the subgraph network that ends (feeds into) a particular node, e.g., the sink. For a weighted graph, the sum of the weights of the subgraph are given. Thus, if weights are stream lengths the function will give the stream length of the portion of the intact stream network that feeds into a particular node.
size.intact.to.sink(G, sink = NULL) size.intact.to.node(G, node = NULL)
size.intact.to.sink(G, sink = NULL) size.intact.to.node(G, node = NULL)
G |
A graph object of class "igraph", see |
sink |
The sink node of |
node |
A node of interest. If |
Returns the size of the graph or subgraph whose downstream end (outlet) is a node
of interest.
Ken Aho, Gabor Csardi wrote several important function components including subgraph
.
# Murphy Cr. disconnected network, no arc from M1799 to M1719! G <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993 --+ M1951, M1951 --+ M1909 --+ M1799, M1719 --+ M1653 --+ M1572 --+ M1452 --+ M1377, M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823 --+ M759, M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153 --+ M91, M91 --+ OUT) data(mur_coords) # coordinate data spatial.plot(G, mur_coords[,2], mur_coords[,3], names = mur_coords[,1]) data(mur_lengths) # segment length data lengths_new <- mur_lengths[-7,] # Drop M1799 -> M1719 arc length E(G)$weight <- lengths_new[,2] # units are in meters size.intact.to.node(G, node = "all") size.intact.to.sink(G, sink = "OUT") # same as output below: size.intact.to.node(G, node = "OUT")
# Murphy Cr. disconnected network, no arc from M1799 to M1719! G <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993 --+ M1951, M1951 --+ M1909 --+ M1799, M1719 --+ M1653 --+ M1572 --+ M1452 --+ M1377, M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823 --+ M759, M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153 --+ M91, M91 --+ OUT) data(mur_coords) # coordinate data spatial.plot(G, mur_coords[,2], mur_coords[,3], names = mur_coords[,1]) data(mur_lengths) # segment length data lengths_new <- mur_lengths[-7,] # Drop M1799 -> M1719 arc length E(G)$weight <- lengths_new[,2] # units are in meters size.intact.to.node(G, node = "all") size.intact.to.sink(G, sink = "OUT") # same as output below: size.intact.to.node(G, node = "OUT")
The function spath.lengths
calculates path lengths from all possible nodes to or from a designated node, i.e., the shortest in-paths and out-paths repsectively. Weighted path length are possible, including weighted path lengths based on field-observed instream arc lengths (see Examples). This results in "actual" path lengths in observed units. The function n.tot.paths
calculates the total number of paths beginning or ending at all nodes in a graph, based on exponention of the the adjacency matrix.
spath.lengths(G, node = NULL, mode = "in", ignore.inf = TRUE) n.tot.paths(G, mode = "in", sink = NULL)
spath.lengths(G, node = NULL, mode = "in", ignore.inf = TRUE) n.tot.paths(G, mode = "in", sink = NULL)
G |
Graph of class "igraph". See |
node |
Designated node. |
mode |
One of |
ignore.inf |
Logical. Whether infinite distances are to be ignored. By default |
sink |
Name of sink node. |
Lengths of paths to a node of interest.
Ken Aho , Gabor Csardi wrote distances
data(mur_lengths) mur <- streamDAGs("mur_full") n.tot.paths(mur) spath.lengths(mur, "M1653") E(mur)$weight <- mur_lengths[,2] # weighted (actual in-stream lengths in meters) spath.lengths(mur, "M1653")
data(mur_lengths) mur <- streamDAGs("mur_full") n.tot.paths(mur) spath.lengths(mur, "M1653") E(mur)$weight <- mur_lengths[,2] # weighted (actual in-stream lengths in meters) spath.lengths(mur, "M1653")
Makes a spatial plot of a igraph object or stream shapefile, given nodal coordinates and node IDs.
spatial.plot(G, x, y, names = NULL, plot = TRUE, col = "lightblue", cex.text = .4, cex = 1, arrow.col = "lightblue", arrow.lwd = 1, plot.bg = "white", pch = 21, pt.bg = "orange", grid.lwd = 2, plot.dry = FALSE, col.dry = gray(.7), cex.dry = 1, pch.dry = 19, arrow.col.dry = gray(.7), arrow.lwd.dry = 1, cnw = NULL, xlim = NULL, ylim = NULL, arrow.warn = TRUE, ...) spatial.plot.sf(x, y, names, shapefile = NULL, cex = 1, arrow.col = "lightblue", arrow.lwd = 1, pch = 21, pt.bg = "orange")
spatial.plot(G, x, y, names = NULL, plot = TRUE, col = "lightblue", cex.text = .4, cex = 1, arrow.col = "lightblue", arrow.lwd = 1, plot.bg = "white", pch = 21, pt.bg = "orange", grid.lwd = 2, plot.dry = FALSE, col.dry = gray(.7), cex.dry = 1, pch.dry = 19, arrow.col.dry = gray(.7), arrow.lwd.dry = 1, cnw = NULL, xlim = NULL, ylim = NULL, arrow.warn = TRUE, ...) spatial.plot.sf(x, y, names, shapefile = NULL, cex = 1, arrow.col = "lightblue", arrow.lwd = 1, pch = 21, pt.bg = "orange")
G |
Graph object, see |
x |
X-coordinates of nodes. |
y |
Y-coordinates of nodes. |
names |
Names of nodes, must use the same names as |
plot |
Logical. Create plot? |
shapefile |
Shapefile object brought in using library sf |
col |
point symbol color. |
cex.text |
Character expansion for node labels in plot; |
cex |
Chahracter expnansion of point symbols. |
arrow.col |
Color of plot arrows. |
arrow.lwd |
Arrow line width. |
plot.bg |
Background color of plot. |
pch |
Plotting character. |
pt.bg |
Background color for plotting character. |
grid.lwd |
Grid line width; |
plot.dry |
Logical. Should “dry” nodes, i.e., nodes in |
col.dry |
Color of “dry” nodes in plot. |
cex.dry |
Symbol sizer of “dry” nodes in plot. |
pch.dry |
Plotting character (symbol) of “dry” nodes in plot. |
arrow.col.dry |
Arrow color for "dry" arcs. Dry arrow rendering requires |
arrow.lwd.dry |
Arrow line width for "dry" arcs. Dry arrow rendering requires |
cnw |
Complete network |
xlim |
A numeric vector of length 2, giving the lower and upper y-axis limits. |
ylim |
A numeric vector of length 2, giving the lower and upper x-axis limits. |
arrow.warn |
Logical. The function |
... |
Other arguments to |
The function spatial.plot
makes a plot of a stream DAG, showing arc flow directions to and from spatial node locations. The function can also be used to identify node and arc arrow coordinates for plotting (see Examples). The function spatial.plot.sf
can create a spatially explicit graph from a stream shapefile with the stream outlay under a ggplot framework (see Examples). The function spatial.plot
can be used to distinguish dry and wet nodes and arcs) (see Examples).
A plot and an invisible
list containing the x
and y
coordinates of nodes: the objects $x
and $y
, respectively, and the x
and y
coordinates of start and end points of arc arrows:the objects $x0
, $y0
, $x1
, and $y1
, respectively.
Ken Aho
G <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452--+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) data(mur_coords) x <- mur_coords[,2] y <- mur_coords[,3] names <- mur_coords[,1] spatial.plot(G, x, y, names) # using shapefiles library(ggplot2); library(sf); library(ggrepel) mur_sf <- st_read(system.file("shape/Murphy_Creek.shp", package="streamDAG")) g1 <- spatial.plot.sf(x, y, names, shapefile = mur_sf) # modify ggplot g1 + theme_classic() #-- Distinguishing wet and dry arcs and nodes --# data(mur_node_pres_abs) # STIC H2O presence/absence npa <- mur_node_pres_abs[650,][,-1] # STC data from 8/9/2019 22:30 G1 <- delete.nodes.pa(G, npa) # delete nodes based STIC data # Example 1 (only show wet nodes and arcs with associated wet nodes) spatial.plot(G1, x, y, names) # Example 2 (show wet nodes and arcs with associated wet nodes, and dry nodes) spatial.plot(G1, x, y, names, plot.dry = TRUE) # Example 3 (show wet nodes and arcs wet node arcs, and underlying network) entire <- spatial.plot(G, x, y, names, plot = FALSE) spatial.plot(G1, x, y, names, plot.dry = TRUE, cnw = entire) #-- Animation: drying of Johnson Draw drainage --# jd_graph <- streamDAGs("jd_full") data(AIMS.node.coords) jd_coords <- AIMS.node.coords[AIMS.node.coords$site == "JD",] jd_coords <- jd_coords[jd_coords$STIC_inferred_PA,] data(jd_node_pres_abs) # Drop 2023 sites jd_pa <- jd_node_pres_abs[,-c( 22, 23, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 36, 37)] pb = txtProgressBar(min = 1, max = 250, initial = 1, style = 3) times <- round(seq(1,50322, length = 250),0) for(i in 1:250){ dev.flush() jd_sub <- delete.nodes.pa(jd_graph, jd_pa[times[i],][-1], na.response = "treat.as.1") spatial.plot(jd_sub, x = jd_coords[,3], y = jd_coords[,2], names = jd_coords[,1], ylim = c(43.122, 43.129), xlim = c(-116.8, -116.775), plot.dry = TRUE, main = jd_node_pres_abs[,1][times[i]], xlab = "Longitude", ylab = "Latitude") dev.hold() Sys.sleep(.05) setTxtProgressBar(pb, i) }
G <- graph_from_literal(IN_N --+ M1984 --+ M1909, IN_S --+ M1993, M1993 --+ M1951 --+ M1909 --+ M1799 --+ M1719 --+ M1653 --+ M1572 --+ M1452, M1452--+ M1377 --+ M1254 --+ M1166 --+ M1121 --+ M1036 --+ M918 --+ M823, M823 --+ M759 --+ M716 --+ M624 --+ M523 --+ M454 --+ M380 --+ M233 --+ M153, M153 --+ M91 --+ OUT) data(mur_coords) x <- mur_coords[,2] y <- mur_coords[,3] names <- mur_coords[,1] spatial.plot(G, x, y, names) # using shapefiles library(ggplot2); library(sf); library(ggrepel) mur_sf <- st_read(system.file("shape/Murphy_Creek.shp", package="streamDAG")) g1 <- spatial.plot.sf(x, y, names, shapefile = mur_sf) # modify ggplot g1 + theme_classic() #-- Distinguishing wet and dry arcs and nodes --# data(mur_node_pres_abs) # STIC H2O presence/absence npa <- mur_node_pres_abs[650,][,-1] # STC data from 8/9/2019 22:30 G1 <- delete.nodes.pa(G, npa) # delete nodes based STIC data # Example 1 (only show wet nodes and arcs with associated wet nodes) spatial.plot(G1, x, y, names) # Example 2 (show wet nodes and arcs with associated wet nodes, and dry nodes) spatial.plot(G1, x, y, names, plot.dry = TRUE) # Example 3 (show wet nodes and arcs wet node arcs, and underlying network) entire <- spatial.plot(G, x, y, names, plot = FALSE) spatial.plot(G1, x, y, names, plot.dry = TRUE, cnw = entire) #-- Animation: drying of Johnson Draw drainage --# jd_graph <- streamDAGs("jd_full") data(AIMS.node.coords) jd_coords <- AIMS.node.coords[AIMS.node.coords$site == "JD",] jd_coords <- jd_coords[jd_coords$STIC_inferred_PA,] data(jd_node_pres_abs) # Drop 2023 sites jd_pa <- jd_node_pres_abs[,-c( 22, 23, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 36, 37)] pb = txtProgressBar(min = 1, max = 250, initial = 1, style = 3) times <- round(seq(1,50322, length = 250),0) for(i in 1:250){ dev.flush() jd_sub <- delete.nodes.pa(jd_graph, jd_pa[times[i],][-1], na.response = "treat.as.1") spatial.plot(jd_sub, x = jd_coords[,3], y = jd_coords[,2], names = jd_coords[,1], ylim = c(43.122, 43.129), xlim = c(-116.8, -116.775), plot.dry = TRUE, main = jd_node_pres_abs[,1][times[i]], xlab = "Longitude", ylab = "Latitude") dev.hold() Sys.sleep(.05) setTxtProgressBar(pb, i) }
A simple wrapper for the missForest
random forest imputation algorithm. STIC.RFimpute
first converts STIC (Stream Temperature, Intermittency, and Conductivity) presence/absence data to categorical outcomes to avoid regression fitting. One should consult missForest
for specifics on the underlying algorithm.
STIC.RFimpute(p.a, ...)
STIC.RFimpute(p.a, ...)
p.a |
Optimally, a dataframe containing presence absence data at sites (columns) over time (rows). |
... |
Additional arguments from |
Provides the conventional unaltered missForest
output.
Daniel J. Stekhoven, <[email protected]>
Stekhoven, D.J. and Buehlmann, P. (2012), 'MissForest - nonparametric missing value imputation for mixed-type data', Bioinformatics, 28(1) 2012, 112-118, doi: 10.1093/bioinformatics/btr597
arc.pa <- data.frame(matrix(ncol = 3, data = c(1,1,1, 0,1,1, 1,1,1, 0,NA,1), byrow = TRUE)) names(arc.pa) <- c("n1 --> n2", "n2 --> n3", "n3 --> n4") STIC.RFimpute(arc.pa)
arc.pa <- data.frame(matrix(ncol = 3, data = c(1,1,1, 0,1,1, 1,1,1, 0,NA,1), byrow = TRUE)) names(arc.pa) <- c("n1 --> n2", "n2 --> n3", "n3 --> n4") STIC.RFimpute(arc.pa)
The function stream.order
calculates Strahler or Shreve number for each each in a stream DAG. The function sink.G
is a utility algorithm that subsets the graph if the sink node is part of a sub-graph that is disconnected from other nodes.
sink.G(G, sink = NULL) stream.order(G, sink = NULL, method = "strahler")
sink.G(G, sink = NULL) stream.order(G, sink = NULL, method = "strahler")
G |
Graph object of class "igraph", see: See |
sink |
Sink node from |
method |
One of |
Strahler stream order (Strahler 1957) is a "top down" system in which first order stream sections occur at the outermost tributaries. A stream section resulting from the merging of tributaries of the same order will have a Strahler number one unit greater than the order of those tributaries. A stream section resulting from the merging of tributaries of different order will have the Strahler stream order of the tributary with the larger Strahler number. Under Shreve stream order, (Shreve 1966) a stream section resulting from the merging of tributaries will have an order that is the sum of the order of those tributaries.
The function can currently only handle graphs with confluences (which, as noted above, serve to define the stream order) and simple islands (those without sub-islands and those whose downstream endpoint does not occur at a join). Under the current version, islands will not change the order of a reach.
Returns Stahler or Shreve numbers for each stream DAG node.
May be slow for extremely large and complex streams due to a reliance on loops.
Ken Aho
Shreve, R. L. (1966). Statistical law of stream numbers. The Journal of Geology, 74(1), 17-37.
Strahler, A. N. (1952). Hypsometric (area-altitude) analysis of erosional topology. Geological Society of America Bulletin, 63 (11): 1117-1142
stream.order(G = streamDAGs("konza_full"), sink = "SFM01_1", method = "strahler") stream.order(G = streamDAGs("konza_full"), sink = "SFM01_1", method = "shreve")
stream.order(G = streamDAGs("konza_full"), sink = "SFM01_1", method = "strahler") stream.order(G = streamDAGs("konza_full"), sink = "SFM01_1", method = "shreve")
The function contains a number of stream direct acyclic graph datasets written in igraph format. See: graph_from_literal
. Many of the graphs were based on sampling regimes for the National Science Foundation Aquatic Intermittency Effects on Microbiomes in Streams (AIMS) project.
streamDAGs(graph = c("dc_piezo_full", "dc_full", "gj_full16", "gj_synoptic_2023", "gj_full", "gj_piezo_full", "jd_piezo_full", "jd_piezo_full_2023","jd_full", "konza_full", "KD0521", "KD0528", "KD0604", "mur_full", "td_full", "wh_full", "pr_full"))
streamDAGs(graph = c("dc_piezo_full", "dc_full", "gj_full16", "gj_synoptic_2023", "gj_full", "gj_piezo_full", "jd_piezo_full", "jd_piezo_full_2023","jd_full", "konza_full", "KD0521", "KD0528", "KD0604", "mur_full", "td_full", "wh_full", "pr_full"))
graph |
Currently, one of |
Currently, the following graph
options exist. Note that many of the graphs have associated datasets. Obtaining these datasets is now greatly simplified through the use of get.AIMS.data
(code steps shown below are unnecessary).
"dc_piezo_full"
codifies the Dry Creek stream network in southwestern Idaho for STIC (Stream Temperature, Intermittency, and Conductivity) sensors, confluences, and piezometer locations (outlet coordinates: 43.71839N, 116.13747
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "DC"
.
Nodal surface water presence/absence data for this graph can be obtained directly from dc_node_pres_abs
.
Arc lengths for this graph can be obtained directly from dc_lengths
.
"dc_full"
codifies the Dry Creek stream network in southwestern Idaho but only for STICs and confluences, not piezometer locations (outlet coordinates: 43.71839N, 116.13747
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "DC" & AIMS.node.coords$STIC_inferred_PA
.
Nodal surface water presence/absence data for this graph can be obtained using dc <- streamDAGs("dc_full")
followed by dc_node_pres_abs[attributes(V(dc))$names]
.
"gj_full16"
codifies nodes established at the Gibson Jack drainage in southeast Idaho, as defined in 2016 (outlet coordinates: 42.767180N, 112.480240
W).
"gj_full"
codifies nodes established at the Gibson Jack drainage in southeast Idaho for STIC sensors in 2022-2023, along with confluence locations. Piezometer locations not included (outlet coordinates: 42.767180N, 112.480240
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "GJ" & AIMS.node.coords$STIC_inferred_PA
.
Nodal surface water presence/absence data for this graph can be obtained from: gj_node_pres_abs
using gj <- streamDAGs("gj_full"); vnames <- attributes(V(gj))$names; w <- which(names(gj_node_pres_abs)[-1] %in% vnames) + 1; node.pa <- gj_node_pres_abs[,c(1,w)]
.
Arc lengths for this graph can be obtained from gj_lengths_piezo_full
using gj <- streamDAGs("gj_full"); anames <- attributes(E(gj))$vnames; enames <- gsub("\|", " -> ", anames); m <- match(enames, gj_lengths_piezo_full[,1])
gj_lengths_piezo_full[m,]
.
"gj_piezo_full"
codifies nodes established at the Gibson Jack drainage in southeast Idaho, by the the AIMS team which include longterm STICs and piezometers, along with confluence locations (outlet coordinates: 42.767180N, 112.480240
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "GJ" & (AIMS.node.coords$STIC_inferred_PA | AIMS.node.coords$piezo)
.
Nodal surface water presence/absence data for this graph can be obtained using gj <- streamDAGs("gj_piezo_full")
followed by gj_node_pres_abs[attributes(V(gj))$names]
.
Arc lengths for this graph can be obtained from gj_lengths_piezo_full
using gj <- streamDAGs("gj_piezo_full"); anames <- attributes(E(gj))$vnames; enames <- gsub("\|", " -> ", anames); m <- match(enames, gj_lengths_piezo_full[,1]); gj_lengths_piezo_full[m,]
.
"gj_synoptic_2023"
codifies nodes established at the Gibson Jack drainage in southeast Idaho by the AIMS team during synoptic sampling in 2023, includes piezometers and additional sites to those sampled in "gj_full"
(outlet coordinates: 42.767180N, 112.480240
W).
"jd_piezo_full"
codifies the Johnson Draw stream network in southwestern Idaho for both STIC and and piezometer locations (outlet coordinates: 43.12256N, 116.77630
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "JD" & AIMS.node.coords$New_in_2023 == FALSE
.
Nodal surface water presence/absence data for this graph can be obtained from jd_node_pres_abs
using jd <- streamDAGs("jd_piezo_full")
followed by jd_node_pres_abs[attributes(V(jd))$names]
.
Arc lengths can be subset from jd_lengths_2023
using something like: jd <- streamDAGs("jd_piezo_full"); anames <- attributes(E(jd))$vnames; nnames <- gsub("\\|", " -> ", anames); jd_lengths_2023[which(jd_lengths_2023[,1] %in% nnames ),]
.
"jd_piezo_full_2023"
codifies the Johnson Draw stream network in southwestern Idaho for both STIC and and piezometer locations, along with new STIC locations added in 2023 (outlet coordinates: 43.12256N, 116.77630
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "JD"
.
Nodal surface water presence/absence data for this graph can be obtained from jd_node_pres_abs
using jd <- streamDAGs("jd_piezo_full_2023")
followed by jd_node_pres_abs[attributes(V(jd))$names]
.
Arc lengths can be subset from jd_lengths_2023
using something like: jd <- streamDAGs("jd_piezo_full_2023"); anames <- attributes(E(jd))$vnames; nnames <- gsub("\\|", " -> ", anames); jd_lengths_2023[which(jd_lengths_2023[,1] %in% nnames ),]
.
"jd_full"
codifies the Johnson Draw stream network in southwestern Idaho, but only for STICs, not piezometers (outlet coordinates: 43.12256N, 116.77630
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "JD" & AIMS.node.coords$STIC_inferred_PA
.
Nodal surface water presence/absence data for this graph can be obtained using jd <- streamDAGs("jd_full")
followed by jd_node_pres_abs[attributes(V(jd))$names]
.
Arc lengths can be obtained from jd_lengths
.
"konza_full"
provides codification of a complete intermittent stream network of Konza Prairie in the northern Flint Hills region of Kansas (outlet coordinates: 39.11394N, 96.61153
W).
Network spatial coordinates for this graph can be obtained directly from kon_coords
Arc lengths can be obtained from kon_lengths
.
Options "KD0521"
,"KD0528"
, and "KD0604"
provide networks for Konza Prairie at 05/21/2021 (before spring snow melt), 05/28/2021 (during spring snow melt) and 06/04/2021 (drying following snow melt), respectively.
"mur_full"
is an igraph codification of the complete Murphy Creek dataset from the Owyhee Mountains in SW Idaho (outlet coordinates: 43.256N, 116.817
W) established in 2019 by Warix et al. (2021), also see Aho et al. (2023).
Network spatial coordinates for the graph can be obtained directly from mur_coords
Nodal surface water presence/absence data for this graph can be obtained from mur_node_pres_abs
Arc lengths can be obrtained from mur_lengths
.
"pr_full"
codifies the Painted Rock stream network in northern Alabama (outlet coordinates: 34.96867N, 86.16544
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "PR"
.
"td_full"
codifies the Talladega stream network in central Alabama (outlet coordinates: 33.76218N, 85.59552
W).
Network spatial coordinates for this graph can be subset from AIMS.node.coords
using: AIMS.node.coords$site == "TD"
.
"wh_full"
codifies the Weyerhauser stream network in western Alabama (outlet coordinates: 32.98463N, 88.01227
W).
Network spatial coordinates for this graph can be obtained from AIMS.node.coords
using: AIMS.node.coords$site == "WH"
.
Returns a graph object of class igraph.
Ken Aho, Maggie Kraft, Rob Ramos, Rebecca L. Hale, Charles T. Bond, Arya Legg
Aho, K., Derryberry, D., Godsey, S. E., Ramos, R., Warix, S., & Zipper, S. (2023). The communication distance of non-perennial streams. EarthArvix doi: 10.31223/X5Q367
Warix, S. R., Godsey, S. E., Lohse, K. A., & Hale, R. L. (2021), Influence of groundwater and topography on stream drying in semi-arid headwater streams. Hydrological Processes, 35(5), e14185.
streamDAGs("mur_full")
streamDAGs("mur_full")
The function vector_segments
and assign_pa_to_segments
were written to facilitate the generation of plots (including ggplots) that overlay user defined digraphs (based on arc designations) on GIS shapefiles or other tightly packed cartesian coordinate structures.
vector_segments(sf.coords, node.coords, realign = TRUE, arcs, arc.symbol = " --> ", nneighbors = 40, remove.duplicates = FALSE) assign_pa_to_segments(input, n, arc.pa, datetime = NULL)
vector_segments(sf.coords, node.coords, realign = TRUE, arcs, arc.symbol = " --> ", nneighbors = 40, remove.duplicates = FALSE) assign_pa_to_segments(input, n, arc.pa, datetime = NULL)
sf.coords |
A two column dataframe containing shapefile Cartesian coordinates (or other tightly packed Cartesian coordinates, see Examples). The first column should define |
node.coords |
A two column dataframe containing network node Cartesian coordinates, with the first column defining |
realign |
Logical. If |
arcs |
A character vector of arc names in the network. In particular, designations of nodes which serve arcs bounds, seperated by a user-defined |
arc.symbol |
A symbol indicating the directional arc connecting two nodes. For example, to designate the arc |
nneighbors |
Number of nearest neighbor points to potentially consider as the next point in an evolving arc path. |
remove.duplicates |
Logical. For duplicate coordinates, should the second point be removed? |
input |
The first argument for |
n |
The number of repeated presence/absence timeframe observations for surface water contained in |
arc.pa |
An |
datetime |
Optional |
The function vector_segments
assigns network arc designations (from the argument arcs
) to shape
file coordinates. The function assign_pa_to_segments
presence/absence surface water designations to these arcs based on information from arc.pa
.
The function vector_segments
creates an object of class network_to_sf
. It also returns a list with two components, with only the first being visible
.
df |
Is a dataframe with four columns: 1) |
node.coords |
Is dataframe with the |
The function assign_pa_to_segments
returns a dataframe that adds a stream/presence absence column to the to the df
dataframe output from vector_segments
, based on the argument arc.pa
The assign_pa_to_segments
function will return a warning
(but will try to run anyway) if input
is not the output from vector_segments
.
Ken Aho
# Data sfx <- c(-3,0,1.5,2,2.9,4,5,6) sfy <- c(5,2,1.7,1.6,1.5,1.4,1.2,1) sf.coords <- data.frame(x = sfx, y = sfy) node.coords <- data.frame(x = c(-2.1,2,4,6), y = c(3.75,1.6,1.4,1)) row.names(node.coords) <- c("n1","n2","n3","n4") # must be consistent with arc names arc.pa <- data.frame(matrix(ncol = 3, data = c(1,1,1, 0,1,1, 1,1,1, 0,0,1), byrow = TRUE)) names(arc.pa) <- c("n1 --> n2", "n2 --> n3", "n3 --> n4") # Use of vector_segments vs <- vector_segments(sf.coords, node.coords, realign = TRUE, names(arc.pa)) vs # Plotting example plot(sf.coords, pch = 19, col = c(rep(1,4),rep(2,2),rep(3,2))) vsd <- vs$df fal <- as.factor(vsd$arc.label) lvls <- levels(fal) for(i in 1:nlevels(fal)){ temp <- vsd[fal == lvls[i],] lines(temp$x, temp$y, col = i) } vs4 <- assign_pa_to_segments(vs, 4, arc.pa) head(vs4)
# Data sfx <- c(-3,0,1.5,2,2.9,4,5,6) sfy <- c(5,2,1.7,1.6,1.5,1.4,1.2,1) sf.coords <- data.frame(x = sfx, y = sfy) node.coords <- data.frame(x = c(-2.1,2,4,6), y = c(3.75,1.6,1.4,1)) row.names(node.coords) <- c("n1","n2","n3","n4") # must be consistent with arc names arc.pa <- data.frame(matrix(ncol = 3, data = c(1,1,1, 0,1,1, 1,1,1, 0,0,1), byrow = TRUE)) names(arc.pa) <- c("n1 --> n2", "n2 --> n3", "n3 --> n4") # Use of vector_segments vs <- vector_segments(sf.coords, node.coords, realign = TRUE, names(arc.pa)) vs # Plotting example plot(sf.coords, pch = 19, col = c(rep(1,4),rep(2,2),rep(3,2))) vsd <- vs$df fal <- as.factor(vsd$arc.label) lvls <- levels(fal) for(i in 1:nlevels(fal)){ temp <- vsd[fal == lvls[i],] lines(temp$x, temp$y, col = i) } vs4 <- assign_pa_to_segments(vs, 4, arc.pa) head(vs4)