# Comparison with R’s ‘energy’#

The ‘energy’ package for R provides an implementation of the E-statistics in this package programmed by the original authors of these statistics.

This package is inspired by ‘energy’, and tries to bring the same functionality to a Python audience.

In this section, both packages are compared, to give an overview of the differences, and to make porting code between R and Python easier.

## Table of energy-dcor equivalents#

energy (R)

dcor (Python)

Notes

```dx <- dist(x)
DX <- as.matrix(dx)
```
```DX = dcor.distances.pairwise_distances(x)
```

Not really part of ‘energy’, but the ‘stats’ package.

In Python it returns a numpy array, while in R it returns a matrix object

```D_center(DX)
```
```dcor.double_centered(DX)
```
```U_center(DX)
```
```dcor.u_centered(DX)
```
```
```
```dcor.mean_product(U, V)
```

Provided for symmetry with `dcor.u_product`, although the implementation is very simple

```U_product(U, V)
```
```dcor.u_product(U, V)
```
```
```
```dcor.u_projection(U)
```
```
```
```dcor.u_complementary_projection(U)
```
```dcov(x, y)
```
```dcor.distance_covariance(x, y)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```dcov(x, y, index = 0.5)
```
```dcor.distance_covariance(
x,
y,
exponent = 0.5,
)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```dcor(x, y)
```
```dcor.distance_correlation(x, y)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```dcor(x, y, index = 0.5)
```
```dcor.distance_correlation(
x,
y,
exponent = 0.5,
)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```DCOR(x, y)
```
```dcor.distance_stats(x, y)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```DCOR(x, y, index = 0.5)
```
```dcor.distance_stats(
x,
y,
exponent = 0.5,
)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```dcovU(x, y)
```
```dcor.u_distance_covariance_sqr(x, y)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```
```
```dcor.u_distance_covariance_sqr(
x,
y,
exponent = 0.5,
)
```
```bcdcor(x, y)
```
```dcor.u_distance_correlation_sqr(x, y)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```
```
```dcor.u_distance_correlation_sqr(
x,
y,
exponent = 0.5,
)
```
```dx <- dist(x)
dy <- dist(y)

DX <- as.matrix(dx)
DY <- as.matrix(dy)

dcovU_stats(DX, DY)
```
```dcor.u_distance_stats_sqr(x, y)
```
```
```
```dcor.u_distance_stats_sqr(
x,
y,
exponent = 0.5,
)
```
```
```
```dcor.distance_correlation_af_inv(x, y)
```
```pdcov(x, y, z)
```
```dcor.partial_distance_covariance(x, y, z)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```pdcor(x, y, z)
```
```dcor.partial_distance_correlation(x, y, z)
```

In ‘energy’, the distance matrix can be computed beforehand. That is not currently possible in ‘dcor’

```edist(
rbind(x, y),
c(nrow(x), nrow(y))
)
```
```dcor.homogeneity.energy_test_statistic(
x,
y,
)
```

In spite of its name, ‘energy’ function ‘edist’ is not the energy distance, but a test statistic.

The ‘energy’ version computes all pairwise estimations between clusters. The ‘dcor’ version computes only the statistic between two random variables.

The only method supported in ‘dcor’ is ‘cluster’.

```edist(
rbind(x, y),
c(nrow(x), nrow(y)),
alpha = 0.5,
method="cluster"
)
```
```dcor.homogeneity.energy_test_statistic(
x,
y,
exponent=0.5,
)
```

In spite of its name, ‘energy’ function ‘edist’ is not the energy distance, but a test statistic.

The ‘energy’ version computes all pairwise estimations between clusters. The ‘dcor’ version computes only the statistic between two random variables.

The only method supported in ‘dcor’ is ‘cluster’.

```
```
```dcor.energy_distance(x, y)
```
```eqdist.etest(
rbind(x, y, z),
c(nrow(x), nrow(y), nrow(z)),
R=10
)
```
```dcor.homogeneity.energy_test(
x,
y,
z,
num_resamples=10,
)
```

Only the default method is implemented

```dcov.test(
x,
y,
index = 0.5,
R = 10
)
```
```dcor.independence.distance_covariance_test(
x,
y,
exponent=0.5,
num_resamples=10,
)
```
```dcor.t(x, y)
```
```dcor.independence.distance_correlation_t_statistic(
x,
y,
)
```
```dcor.ttest(x, y)
```
```dcor.independence.distance_correlation_t_test(
x,
y,
)
```