R-CMD-check Codecov test coverage License: MIT

ts2net is an R package to transform one or multiple time series into networks. This transformation is useful to model and study complex systems, which are commonly represented by a set of time series extracted from the small parts that compose the system. In this case, the network represents time series by nodes that are linked if their respective time series are similar or associated. Network models can also be used for time series data mining. Single or multiple time series can transformed into a networks and analyzed using network science and graph mining tools.

THIS IS A BETA VERSION - Please report bugs HERE


The development version can be installed from GitHub using the function install_github() from either devtools or remotes packages:

install.packages("remotes") # if `remotes` package is not installed


The ts2net package provides two modelling approaches: one or a set of time series as a network.

A set of time series as a network

The first modeling approach consists on transforming a set of time series into a network. This transformation typically involves the distance calculation for every pair of time series, represented by the distance matrix D. Then, D is transformed into a network using strategies such as k nearest neighbors, ε neighborhood, or complete weighted graph. The following example shows how to calculate all pairs of distances (D) and construct a k nearest neighbor network (k-NN) using a toy data set composed by five sines and five cosines series (with noise):

# Generating a toy data set
ts_dataset = dataset_sincos_generate(num_sin_series = 10, num_cos_series = 10,
                                     ts_length = 100, jitter_amount = 0.25)
# Pairwise distance calculation
D = ts_dist(ts_dataset) 
# epsilon-NN network construction
ennet = net_enn(D, epsilon = 0.5)
# k-NN network construction
knnet = net_knn(D, k = 2)
# weighted network construction
wnet = net_weighted(D)

Time series to networkTime series to network Fig. 1: Transforming a time series data set into a network. (a) A toy data set composed by 10 sine and 10 cosine time series. A small white noise was added to each series. (b) Positive correlation distance calculated for the sin-cos data set. (c) The ε-NN network using ε = 0.5. (d) The k-NN network using k = 2. (e) The weighted network with edges thickness proportional to the weight. Node colors represent the two classes (sine and cosines).

Functions to calculate the distance matrix:

Distance functions available:

Multiple time series into a network:

A single time series as a network

The second approach consists on transform a single time series into a network. The most straightforward method to perform this transformation consists on breaking the time series into time windows and use the same approach described for multiple time series. Other methods, such as visibility graphs or recurrence networks, can also be used. The following example show how to transform a single time series X into a visibility graph:

X = c(10, 5, 2.1, 4.1, 1, 7, 10)
net_vg = tsnet_vg(X)

Visibility graphsVisibility graphs Fig. 2: Visibility graph construction. (a and c) The example time series X with values represented by the bars and points. Gray lines connect ``visible’’ values as defined in the (a) natural (red) and (c) horizontal (blue) visibility graphs. The resulting natural (b) and horizontal (d) visibility graphs.).

One time series into a network:


ts2net is distributed under the MIT license.


Found an issue :bomb: or a bug :bug: ? Please report it Here.


Do you have suggestions of improvements or new features? Please add them here.


Leonardo N. Ferreira