ejercicio 3.1 analisis multivariante Peña

Author

Jaime Isaac

import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
# Cargar los datos desde el archivo 'accion.txt'
data = pd.read_csv('accion.txt', sep='\t')
print(data.head())
    V1    V2    V3
0  3.4  89.7  30.2
1  5.1  55.7   9.9
2  4.5  52.3  11.5
3  3.5  47.0  11.2
4  5.9  42.7   7.0
# Vector de Medias
means = data.mean()
print("Vector de Medias:\n", means)
Vector de Medias:
 V1     9.420588
V2    69.526471
V3     9.096765
dtype: float64
# Vector de Medianas
medians = data.median()
print("\nVector de Medianas:\n", medians)

Vector de Medianas:
 V1     7.05
V2    61.45
V3     7.35
dtype: float64
# Matriz de Covarianzas
cov_matrix = data.cov()
print("\nMatriz de Covarianzas:\n", cov_matrix)

Matriz de Covarianzas:
             V1          V2         V3
V1   29.095624  100.440651 -15.702810
V2  100.440651  576.229278 -18.546275
V3  -15.702810  -18.546275  22.565992
# Matriz de Correlaciones
corr_matrix = data.corr()
print("\nMatriz de Correlaciones:\n", corr_matrix)

Matriz de Correlaciones:
           V1        V2        V3
V1  1.000000  0.775708 -0.612825
V2  0.775708  1.000000 -0.162642
V3 -0.612825 -0.162642  1.000000
# Visualización de los datos

# Configuración de la figura para múltiples gráficos
plt.figure(figsize=(14, 10))

# Mapa de calor para la Matriz de Correlaciones
plt.subplot(2, 2, 1)
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', vmin=-1, vmax=1)
plt.title("Mapa de Calor de la Matriz de Correlaciones")

# Diagrama de caja para ver la distribución de las variables
plt.subplot(2, 2, 2)
data.boxplot()
plt.title("Diagrama de Caja de las Variables")

# Matriz de dispersión para ver relaciones entre variables
plt.subplot(2, 2, (3, 4))
sns.pairplot(data, kind="scatter", plot_kws={'alpha': 0.5, 's': 30, 'edgecolor': "none"})

plt.suptitle("Matriz de Dispersión")

plt.tight_layout()
plt.show()

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.4.2
Warning: package 'readr' was built under R version 4.4.2
Warning: package 'forcats' was built under R version 4.4.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(MVN)
Warning: package 'MVN' was built under R version 4.4.2
# Leer los datos del archivo 'accion.txt'
data <- read.table("accion.txt", sep="\t", header=TRUE)
head(data)
   V1   V2   V3
1 3.4 89.7 30.2
2 5.1 55.7  9.9
3 4.5 52.3 11.5
4 3.5 47.0 11.2
5 5.9 42.7  7.0
6 5.1 30.6  6.9
# Vector de Medias
means <- colMeans(data)
print("Vector de Medias:")
[1] "Vector de Medias:"
print(means)
       V1        V2        V3 
 9.420588 69.526471  9.096765 
# Vector de Medianas
medians <- apply(data, 2, median)
print("\nVector de Medianas:")
[1] "\nVector de Medianas:"
print(medians)
   V1    V2    V3 
 7.05 61.45  7.35 
# Matriz de Covarianzas
cov_matrix <- cov(data)
# Matriz de Covarianzas
cov_matrix <- cov(data)
print("\nMatriz de Covarianzas:")
[1] "\nMatriz de Covarianzas:"
print(cov_matrix)
          V1        V2        V3
V1  29.09562 100.44065 -15.70281
V2 100.44065 576.22928 -18.54628
V3 -15.70281 -18.54628  22.56599
# Matriz de Correlaciones
corr_matrix <- cor(data)
print("\nMatriz de Correlaciones:")
[1] "\nMatriz de Correlaciones:"
print(corr_matrix)
           V1         V2         V3
V1  1.0000000  0.7757076 -0.6128248
V2  0.7757076  1.0000000 -0.1626417
V3 -0.6128248 -0.1626417  1.0000000
# Asimetría y Kurtosis Multivariante usando el paquete MVN
mvn_result <- mvn(data, mvnTest = "mardia")
print("\nAsimetría Multivariante:")
[1] "\nAsimetría Multivariante:"
print(mvn_result$multivariateNormality)
             Test        Statistic              p value Result
1 Mardia Skewness 103.908270901864 8.97317329453402e-18     NO
2 Mardia Kurtosis 9.67716560797701                    0     NO
3             MVN             <NA>                 <NA>     NO
# Visualización de los datos

# Mapa de calor para la Matriz de Correlaciones
corrplot::corrplot(corr_matrix, method="color", type="upper", order="hclust", 
                   addCoef.col = "black", tl.col="black", tl.srt=45)

# Diagrama de caja para ver la distribución de las variables
boxplot(data, main="Diagrama de Caja de las Variables")

# Matriz de dispersión para ver relaciones entre variables
pairs(data, 
      main = "Matriz de Dispersión",
      pch = 21, bg = adjustcolor("blue", alpha.f = 0.5))

# Gráficos de densidad para cada variable
ggplot(data, aes(x = V1)) + 
  geom_density(fill="lightblue", alpha=0.5) + 
  geom_vline(aes(xintercept=mean(V1)), color="red", linetype="dashed", size=1) +
  labs(title="Gráfico de Densidad de V1", x="V1", y="Densidad") +
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

ggplot(data, aes(x = V2)) + 
  geom_density(fill="lightgreen", alpha=0.5) + 
  geom_vline(aes(xintercept=mean(V2)), color="red", linetype="dashed", size=1) +
  labs(title="Gráfico de Densidad de V2", x="V2", y="Densidad") +
  theme_minimal()

ggplot(data, aes(x = V3)) + 
  geom_density(fill="pink", alpha=0.5) + 
  geom_vline(aes(xintercept=mean(V3)), color="red", linetype="dashed", size=1) +
  labs(title="Gráfico de Densidad de V3", x="V3", y="Densidad") +
  theme_minimal()

library(StatMatch)
Warning: package 'StatMatch' was built under R version 4.4.2
Cargando paquete requerido: proxy
Warning: package 'proxy' was built under R version 4.4.2

Adjuntando el paquete: 'proxy'
The following objects are masked from 'package:stats':

    as.dist, dist
The following object is masked from 'package:base':

    as.matrix
Cargando paquete requerido: survey
Warning: package 'survey' was built under R version 4.4.2
Cargando paquete requerido: grid
Cargando paquete requerido: Matrix

Adjuntando el paquete: 'Matrix'
The following objects are masked from 'package:tidyr':

    expand, pack, unpack
Cargando paquete requerido: survival

Adjuntando el paquete: 'survey'
The following object is masked from 'package:graphics':

    dotchart
Cargando paquete requerido: lpSolve
Warning: package 'lpSolve' was built under R version 4.4.2
# Cargar los datos (asumiendo que están en un archivo 'accion.txt')
data <- read.table("accion.txt", header = TRUE, sep = "\t")

# Calcular la matriz de distancias de Mahalanobis
mahalanobis_distances <- mahalanobis.dist(data)

# Ver la matriz de distancias
print(mahalanobis_distances)
          1         2         3         4         5         6         7
1  0.000000 5.2312186 4.8436222 5.0642219 5.8394140 6.0124310 4.9128363
2  5.231219 0.0000000 0.5264729 0.4828412 1.0509648 1.6852098 0.6944454
3  4.843622 0.5264729 0.0000000 0.2914764 1.1130146 1.5856376 0.9252238
4  5.064222 0.4828412 0.2914764 0.0000000 0.9967267 1.4772803 0.9730540
5  5.839414 1.0509648 1.1130146 0.9967267 0.0000000 0.7076841 1.7453974
6  6.012431 1.6852098 1.5856376 1.4772803 0.7076841 0.0000000 2.3665641
7  4.912836 0.6944454 0.9252238 0.9730540 1.7453974 2.3665641 0.0000000
8  5.288351 0.3084751 0.4537155 0.3557078 0.7800401 1.3836834 0.9843198
9  4.178634 1.1258501 0.7082068 0.8909876 1.7922352 2.1529142 1.0953049
10 4.529466 1.1151661 0.5948599 0.7192756 1.3739088 1.5946589 1.4267690
11 6.241928 1.4092932 1.5291086 1.4009523 0.4198502 0.6843480 2.0959264
12 4.384826 2.0523697 1.5567863 1.6809049 1.8963508 1.7511991 2.4160427
13 4.887614 0.5930170 0.1768763 0.3775730 1.0050462 1.4595049 1.0629937
14 5.587549 0.9760447 0.9251359 0.8484057 0.2627396 0.7336863 1.6580262
15 4.049084 1.5138999 1.0022369 1.2155269 1.8117293 1.9864164 1.6891484
16 5.602526 0.6475861 1.1423814 1.1265260 1.3392807 2.0444220 0.8474181
17 5.525150 0.5152710 0.8256676 0.8145408 0.7661953 1.4528005 1.1230686
18 4.754559 0.5050829 0.4614731 0.5792802 1.4557346 2.0057530 0.4867818
19 4.922227 1.3757312 1.6298841 1.7469582 2.3441171 3.0069975 0.8467692
20 5.227661 2.0944836 2.1525885 2.3627306 2.3096247 2.7580734 2.2253097
21 4.996723 2.3311354 2.3178216 2.5528793 2.5488313 2.9459716 2.4336316
22 5.477622 1.8831470 2.0231299 2.1985082 2.0822282 2.5814823 2.0535217
23 4.954093 2.5740706 2.5019672 2.7435239 2.6935176 3.0099647 2.7202293
24 5.164867 2.1998000 2.1864152 2.4051162 2.2961293 2.6622275 2.3967897
25 5.279144 1.9268349 2.1128311 2.2975260 2.4130602 2.9937887 1.8736500
26 5.387955 1.9822263 2.1664817 2.3472274 2.3891386 2.9517004 1.9862234
27 5.050717 2.1171147 2.1726365 2.3960712 2.4529349 2.9307347 2.1585580
28 5.189090 2.7737477 2.6787921 2.9046431 2.7214869 2.9442738 3.0120160
29 5.255613 2.0799993 2.1919932 2.3953001 2.4093786 2.9161139 2.1307347
30 5.167088 2.1894378 2.1694821 2.3873797 2.2677080 2.6246304 2.3989711
31 5.617795 1.5540727 1.9577776 2.0193596 2.3361019 3.0371072 1.2669259
32 5.848141 0.7336411 1.0737410 0.9822075 0.6302312 1.3333939 1.3565299
33 5.518315 1.7275933 1.8799809 2.0422620 1.8916949 2.3992057 1.9457944
34 6.798220 5.0206769 4.7178646 4.8080255 4.2722966 3.7673117 5.5682975
           8         9        10        11        12        13        14
1  5.2883507 4.1786342 4.5294657 6.2419283 4.3848261 4.8876135 5.5875487
2  0.3084751 1.1258501 1.1151661 1.4092932 2.0523697 0.5930170 0.9760447
3  0.4537155 0.7082068 0.5948599 1.5291086 1.5567863 0.1768763 0.9251359
4  0.3557078 0.8909876 0.7192756 1.4009523 1.6809049 0.3775730 0.8484057
5  0.7800401 1.7922352 1.3739088 0.4198502 1.8963508 1.0050462 0.2627396
6  1.3836834 2.1529142 1.5946589 0.6843480 1.7511991 1.4595049 0.7336863
7  0.9843198 1.0953049 1.4267690 2.0959264 2.4160427 1.0629937 1.6580262
8  0.0000000 1.1515065 0.9705487 1.1677313 1.8436939 0.4470403 0.6791642
9  1.1515065 0.0000000 0.6213925 2.2119841 1.4900442 0.8091584 1.5773432
10 0.9705487 0.6213925 0.0000000 1.7812346 1.0286165 0.5791655 1.1314934
11 1.1677313 2.2119841 1.7812346 0.0000000 2.2069533 1.4223062 0.6586322
12 1.8436939 1.4900442 1.0286165 2.2069533 0.0000000 1.4623035 1.6480452
13 0.4470403 0.8091584 0.5791655 1.4223062 1.4623035 0.0000000 0.7977308
14 0.6791642 1.5773432 1.1314934 0.6586322 1.6480452 0.7977308 0.0000000
15 1.4163213 0.7038070 0.5594268 2.2084230 0.8558395 0.9721707 1.5537777
16 0.8622923 1.6750144 1.7344330 1.5724170 2.6170207 1.1767734 1.3603758
17 0.4633530 1.4987202 1.3421692 1.0599451 2.1043981 0.7719040 0.7527490
18 0.6834135 0.7016459 0.9428653 1.8496661 1.9330316 0.6124886 1.3134654
19 1.6646679 1.7124956 2.1109638 2.6475931 2.9957037 1.7216868 2.2747284
20 2.1365562 2.4294003 2.4422142 2.4802639 2.7544212 2.0658483 2.2290594
21 2.3626122 2.5085395 2.5334562 2.7387667 2.7397104 2.2283193 2.4401673
22 1.9339805 2.3917170 2.3857601 2.2260540 2.7978455 1.9406500 2.0372474
23 2.5698876 2.6671608 2.6420527 2.8726851 2.7013260 2.3966889 2.5714244
24 2.1953287 2.4513143 2.3988231 2.4609159 2.5762166 2.0782381 2.1974053
25 2.0703306 2.3708419 2.5250597 2.6090200 3.0761229 2.0808303 2.3584818
26 2.1041506 2.4580745 2.5713504 2.5629403 3.0840928 2.1209852 2.3425048
27 2.1925329 2.3836194 2.4672904 2.6540685 2.8226475 2.1048483 2.3601178
28 2.7225087 2.8906842 2.7723864 2.8556268 2.6974348 2.5511127 2.6080557
29 2.1659355 2.4563664 2.5339411 2.5878608 2.9425063 2.1274144 2.3405217
30 2.1782659 2.4387202 2.3748280 2.4312061 2.5400231 2.0583334 2.1677455
31 1.8211209 2.2529680 2.5168085 2.5412667 3.3866413 2.0149566 2.3421784
32 0.6391455 1.7717374 1.5576539 0.8229120 2.2837535 1.0207415 0.7354197
33 1.7661679 2.2903394 2.2557651 2.0322786 2.6901261 1.7931672 1.8541341
34 4.7570820 4.9301607 4.4169017 4.2244277 3.5613442 4.5519794 4.1813847
          15        16        17        18        19        20        21
1  4.0490839 5.6025255 5.5251504 4.7545594 4.9222273 5.2276606 4.9967228
2  1.5138999 0.6475861 0.5152710 0.5050829 1.3757312 2.0944836 2.3311354
3  1.0022369 1.1423814 0.8256676 0.4614731 1.6298841 2.1525885 2.3178216
4  1.2155269 1.1265260 0.8145408 0.5792802 1.7469582 2.3627306 2.5528793
5  1.8117293 1.3392807 0.7661953 1.4557346 2.3441171 2.3096247 2.5488313
6  1.9864164 2.0444220 1.4528005 2.0057530 3.0069975 2.7580734 2.9459716
7  1.6891484 0.8474181 1.1230686 0.4867818 0.8467692 2.2253097 2.4336316
8  1.4163213 0.8622923 0.4633530 0.6834135 1.6646679 2.1365562 2.3626122
9  0.7038070 1.6750144 1.4987202 0.7016459 1.7124956 2.4294003 2.5085395
10 0.5594268 1.7344330 1.3421692 0.9428653 2.1109638 2.4422142 2.5334562
11 2.2084230 1.5724170 1.0599451 1.8496661 2.6475931 2.4802639 2.7387667
12 0.8558395 2.6170207 2.1043981 1.9330316 2.9957037 2.7544212 2.7397104
13 0.9721707 1.1767734 0.7719040 0.6124886 1.7216868 2.0658483 2.2283193
14 1.5537777 1.3603758 0.7527490 1.3134654 2.2747284 2.2290594 2.4401673
15 0.0000000 2.0658059 1.7038616 1.2377835 2.2197439 2.3554443 2.3640396
16 2.0658059 0.0000000 0.6316343 0.9896986 1.1396065 1.9092439 2.2130104
17 1.7038616 0.6316343 0.0000000 0.9571854 1.5971930 1.8226648 2.0947825
18 1.2377835 0.9896986 0.9571854 0.0000000 1.2267920 2.1609480 2.3372163
19 2.2197439 1.1396065 1.5971930 1.2267920 0.0000000 1.9688516 2.1714746
20 2.3554443 1.9092439 1.8226648 2.1609480 1.9688516 0.0000000 0.3756732
21 2.3640396 2.2130104 2.0947825 2.3372163 2.1714746 0.3756732 0.0000000
22 2.3887234 1.6196768 1.5691840 2.0235036 1.8227592 0.3871829 0.7623579
23 2.4236167 2.5166751 2.3254106 2.5720443 2.5157869 0.7120844 0.3840808
24 2.2722156 2.1018855 1.9096507 2.2615116 2.2342149 0.3634948 0.3376098
25 2.5093822 1.5866668 1.7535143 1.9717049 1.4013158 0.7395846 0.9961462
26 2.5596839 1.6396872 1.7635559 2.0593455 1.5587412 0.6224997 0.9130283
27 2.3524386 1.9265940 1.9062270 2.1287422 1.8218740 0.2832141 0.3976430
28 2.5638994 2.7476628 2.4727516 2.8169397 2.8896786 1.0196831 0.7913025
29 2.4683536 1.8225877 1.8434176 2.1354436 1.7697042 0.3167623 0.5832539
30 2.2490067 2.1021168 1.8951374 2.2544624 2.2538207 0.4037619 0.3802488
31 2.7031120 1.0221939 1.5912364 1.6387567 0.7321339 1.9187439 2.2084747
32 1.9690088 0.7499770 0.3415074 1.2260567 1.8404488 2.0414557 2.3348560
33 2.2947553 1.4720921 1.3895516 1.9004432 1.7845841 0.5404033 0.9035433
34 4.2854531 5.3314695 4.7291136 5.1374384 5.9508134 4.5568890 4.4522916
          22        23         24        25        26        27        28
1  5.4776224 4.9540926 5.16486700 5.2791438 5.3879553 5.0507166 5.1890900
2  1.8831470 2.5740706 2.19980002 1.9268349 1.9822263 2.1171147 2.7737477
3  2.0231299 2.5019672 2.18641520 2.1128311 2.1664817 2.1726365 2.6787921
4  2.1985082 2.7435239 2.40511621 2.2975260 2.3472274 2.3960712 2.9046431
5  2.0822282 2.6935176 2.29612934 2.4130602 2.3891386 2.4529349 2.7214869
6  2.5814823 3.0099647 2.66222747 2.9937887 2.9517004 2.9307347 2.9442738
7  2.0535217 2.7202293 2.39678969 1.8736500 1.9862234 2.1585580 3.0120160
8  1.9339805 2.5698876 2.19532874 2.0703306 2.1041506 2.1925329 2.7225087
9  2.3917170 2.6671608 2.45131426 2.3708419 2.4580745 2.3836194 2.8906842
10 2.3857601 2.6420527 2.39882311 2.5250597 2.5713504 2.4672904 2.7723864
11 2.2260540 2.8726851 2.46091593 2.6090200 2.5629403 2.6540685 2.8556268
12 2.7978455 2.7013260 2.57621655 3.0761229 3.0840928 2.8226475 2.6974348
13 1.9406500 2.3966889 2.07823808 2.0808303 2.1209852 2.1048483 2.5511127
14 2.0372474 2.5714244 2.19740527 2.3584818 2.3425048 2.3601178 2.6080557
15 2.3887234 2.4236167 2.27221556 2.5093822 2.5596839 2.3524386 2.5638994
16 1.6196768 2.5166751 2.10188552 1.5866668 1.6396872 1.9265940 2.7476628
17 1.5691840 2.3254106 1.90965068 1.7535143 1.7635559 1.9062270 2.4727516
18 2.0235036 2.5720443 2.26151155 1.9717049 2.0593455 2.1287422 2.8169397
19 1.8227592 2.5157869 2.23421486 1.4013158 1.5587412 1.8218740 2.8896786
20 0.3871829 0.7120844 0.36349483 0.7395846 0.6224997 0.2832141 1.0196831
21 0.7623579 0.3840808 0.33760982 0.9961462 0.9130283 0.3976430 0.7913025
22 0.0000000 1.0779390 0.65655916 0.6393982 0.4959627 0.5521636 1.3169785
23 1.0779390 0.0000000 0.46549958 1.3799345 1.2908697 0.7814493 0.4586262
24 0.6565592 0.4654996 0.00000000 1.0951310 0.9842999 0.5692946 0.6893805
25 0.6393982 1.3799345 1.09513101 0.0000000 0.1819090 0.6015763 1.7469498
26 0.4959627 1.2908697 0.98429992 0.1819090 0.0000000 0.5396588 1.6320225
27 0.5521636 0.7814493 0.56929461 0.6015763 0.5396588 0.0000000 1.1730761
28 1.3169785 0.4586262 0.68938047 1.7469498 1.6320225 1.1730761 0.0000000
29 0.4035886 0.9594626 0.67698069 0.4444154 0.3315156 0.2386080 1.3089114
30 0.6778839 0.4761024 0.04978823 1.1321916 1.0215480 0.6131504 0.6714518
31 1.6656107 2.5822440 2.23364595 1.2689112 1.3856584 1.8242383 2.9217040
32 1.7541925 2.5591834 2.12536263 1.9766916 1.9705028 2.1506688 2.6711477
33 0.1954976 1.1962166 0.74688209 0.7414166 0.6208730 0.7105070 1.4011228
34 4.6700279 4.1634118 4.21135985 5.2448269 5.1339661 4.7665907 3.7637084
          29         30        31        32        33       34
1  5.2556132 5.16708840 5.6177951 5.8481407 5.5183151 6.798220
2  2.0799993 2.18943775 1.5540727 0.7336411 1.7275933 5.020677
3  2.1919932 2.16948210 1.9577776 1.0737410 1.8799809 4.717865
4  2.3953001 2.38737971 2.0193596 0.9822075 2.0422620 4.808025
5  2.4093786 2.26770803 2.3361019 0.6302312 1.8916949 4.272297
6  2.9161139 2.62463044 3.0371072 1.3333939 2.3992057 3.767312
7  2.1307347 2.39897112 1.2669259 1.3565299 1.9457944 5.568297
8  2.1659355 2.17826590 1.8211209 0.6391455 1.7661679 4.757082
9  2.4563664 2.43872024 2.2529680 1.7717374 2.2903394 4.930161
10 2.5339411 2.37482799 2.5168085 1.5576539 2.2557651 4.416902
11 2.5878608 2.43120606 2.5412667 0.8229120 2.0322786 4.224428
12 2.9425063 2.54002307 3.3866413 2.2837535 2.6901261 3.561344
13 2.1274144 2.05833338 2.0149566 1.0207415 1.7931672 4.551979
14 2.3405217 2.16774546 2.3421784 0.7354197 1.8541341 4.181385
15 2.4683536 2.24900671 2.7031120 1.9690088 2.2947553 4.285453
16 1.8225877 2.10211681 1.0221939 0.7499770 1.4720921 5.331470
17 1.8434176 1.89513741 1.5912364 0.3415074 1.3895516 4.729114
18 2.1354436 2.25446244 1.6387567 1.2260567 1.9004432 5.137438
19 1.7697042 2.25382067 0.7321339 1.8404488 1.7845841 5.950813
20 0.3167623 0.40376187 1.9187439 2.0414557 0.5404033 4.556889
21 0.5832539 0.38024876 2.2084747 2.3348560 0.9035433 4.452292
22 0.4035886 0.67788393 1.6656107 1.7541925 0.1954976 4.670028
23 0.9594626 0.47610242 2.5822440 2.5591834 1.1962166 4.163412
24 0.6769807 0.04978823 2.2336460 2.1253626 0.7468821 4.211360
25 0.4444154 1.13219159 1.2689112 1.9766916 0.7414166 5.244827
26 0.3315156 1.02154804 1.3856584 1.9705028 0.6208730 5.133966
27 0.2386080 0.61315038 1.8242383 2.1506688 0.7105070 4.766591
28 1.3089114 0.67145178 2.9217040 2.6711477 1.4011228 3.763708
29 0.0000000 0.71875966 1.6826257 2.0650201 0.5804383 4.871288
30 0.7187597 0.00000000 2.2564110 2.1090762 0.7567546 4.164969
31 1.6826257 2.25641098 0.0000000 1.7348675 1.6201247 6.054861
32 2.0650201 2.10907618 1.7348675 0.0000000 1.5650456 4.758010
33 0.5804383 0.75675464 1.6201247 1.5650456 0.0000000 4.612925
34 4.8712878 4.16496910 6.0548611 4.7580102 4.6129247 0.000000
# Cargar los datos
data <- read.table("accion.txt", header = TRUE, sep = "\t")

# Calcular las distancias euclidianas
euclidean_distances <- dist(data, method = "euclidean")

# Mostrar las distancias
print(euclidean_distances)
            1          2          3          4          5          6          7
2  39.6355901                                                                  
3  41.8289374  3.8052595                                                       
4  46.7364954  8.9409172  5.4018515                                            
5  52.4737077 13.3435378 10.6943911  6.4722485                                 
6  63.5499017 25.2786471 22.1903132 17.0296800 12.1268298                      
7  31.3063891  8.9190807 12.1041315 17.4450566 22.2625246 34.1569905           
8  43.8703772  4.7106263  2.3558438  4.5617979  8.7441409 20.5781437 13.5852862
9  38.5535991  5.3235327  4.0422766  8.1914590 14.2642911 25.1175238 10.5057127
10 47.1699057 10.6667708  6.9036222  2.3874673  7.3273460 16.4496201 18.7906892
11 55.8090494 16.5435788 14.0516903  9.7678043  3.3823069  9.5571962 25.4444493
12 52.0923219 15.8773423 12.2004098  7.2076348  7.2732386 11.8667603 24.1756075
13 41.9859500  3.4785054  0.7874008  5.6356011 10.5228323 22.1822001 12.0370262
14 50.9533120 11.9724684  9.1923882  5.0139805  1.5652476 13.3637570 20.8837257
15 40.1583117  5.3768020  2.9444864  6.7149088 12.5880896 23.4380033 11.8878089
16 32.9759003 10.5275828 14.2558760 19.4599589 23.1503780 35.2740698  4.9719212
17 38.9775576  3.8742741  7.4411021 12.2126983 15.4706173 27.5916654  7.9536155
18 36.0839299  3.6290495  6.2297673 11.5702204 16.6703329 28.3890824  5.9110067
19 20.4244951 28.7482173 32.1735917 37.5475698 41.8350332 53.9239279 20.1715146
20 28.1183214 42.4106119 46.0015217 51.3180280 54.7489726 66.8014221 34.5544498
21 28.8190909 45.8983660 49.4592762 54.7959853 58.3092617 70.3628453 37.9311218
22 27.7668868 38.2578097 41.8829321 47.1696937 50.4964355 62.5443043 30.5668121
23 29.1617901 46.0109770 49.5666218 54.8978142 58.3647154 70.4007102 38.1006562
24 27.5515880 39.5789085 43.1681596 48.4721570 51.8414892 63.8769129 31.8411683
25 28.1200996 45.4482123 49.0238717 54.3654302 57.9731835 70.0614730 37.3685697
26 28.9160855 45.5376767 49.1300315 54.4586081 57.9776681 70.0537651 37.5439742
27 28.3326667 45.6725300 49.2355563 54.5782008 58.1490327 70.2200114 37.6405367
28 29.4248195 42.8980186 46.4766608 51.7665915 55.0309913 67.0236525 35.2492553
29 29.0370453 45.7555461 49.3397406 54.6696442 58.1730178 70.2398747 37.7828003
30 27.3850324 38.5963729 42.1872019 47.4870509 50.8418135 62.8748757 30.8925557
31 23.4595396 32.3049532 35.8827256 41.2195342 45.0659517 57.1909084 24.1051862
32 43.2714687  4.3058100  5.6089215  8.7338422 10.9530818 23.0722777 12.2053267
33 27.3790066 33.7489259 37.3891696 42.6550114 45.9292935 57.9760295 26.2137369
34 61.8873986 23.9295654 21.7111976 18.1270544 12.3925825 10.7765533 32.4137641
            8          9         10         11         12         13         14
2                                                                              
3                                                                              
4                                                                              
5                                                                              
6                                                                              
7                                                                              
8                                                                              
9   6.3882705                                                                  
10  6.6037868  8.8306285                                                       
11 12.0341182 17.6462461 10.3561576                                            
12 11.4743192 14.1862610  5.5145263  8.7647019                                 
13  1.9824228  4.6151923  7.2539644 13.8509927 12.4173266                      
14  7.3218850 12.7239931  6.0033324  4.9325450  6.8854920  9.0410176           
15  5.1419841  2.1470911  7.3000000 15.9580701 12.5211821  3.4597688 11.0276924
16 15.0705010 13.9129436 21.1567956 26.0395853 26.3229938 13.9359248 21.9456146
17  7.6720271  8.8707384 14.0872283 18.3842324 18.9915771  6.9130312 14.2720006
18  7.9284299  5.0009999 12.8860390 19.9494361 18.2701943  6.2377881 15.2292482
19 33.4468235 30.4772046 38.9122089 44.7960936 44.2136857 32.0140594 40.5605720
20 46.9490149 44.8546542 52.8321872 57.3972996 57.8989637 45.7014223 53.6171614
21 50.4552277 48.2080906 56.2702408 60.9804067 61.3432148 49.1727567 57.1617005
22 42.7678618 40.8737079 48.7319197 53.1173230 53.7855929 41.5651296 49.3838030
23 50.5499753 48.3440793 56.3685196 61.0209800 61.4115624 49.2711883 57.2217616
24 44.0901350 42.0923984 49.9908992 54.4780690 55.0203599 42.8535879 50.7141992
25 50.0408833 47.7202263 55.8546328 60.6729759 60.9966393 48.7573584 56.8188349
26 50.1097795 47.8967640 55.9690986 60.6459397 61.0885423 48.8497697 56.8388951
27 50.2486816 47.9474713 56.0530106 60.8390500 61.1579104 48.9597794 56.9949121
28 47.3728825 45.4380897 53.2787012 57.6233460 58.2512661 46.1469392 53.9193843
29 50.3195787 48.1103939 56.1707219 60.8373241 61.2707108 49.0551730 57.0335866
30 43.1011601 41.1336845 49.0095909 53.4764434 54.0323052 41.8690817 49.7157923
31 36.9494249 34.5469246 42.7264555 47.8725391 47.9727006 35.6523492 43.8747080
32  4.4011362  8.9409172 10.8729021 13.7771550 15.2823428  4.9030603  9.8620485
33 38.2355855 36.4862988 44.2426265 48.5470905 49.2798133 37.0579276 44.8219812
34 19.8587034 25.1614805 18.1689323  9.9990050 15.0023365 21.3603862 13.4954103
           15         16         17         18         19         20         21
2                                                                              
3                                                                              
4                                                                              
5                                                                              
6                                                                              
7                                                                              
8                                                                              
9                                                                              
10                                                                             
11                                                                             
12                                                                             
13                                                                             
14                                                                             
15                                                                             
16 14.8094564                                                                  
17  8.9297256  7.7006493                                                       
18  6.1497967  8.9230040  5.2306787                                            
19 31.8441517 18.7843020 26.4138221 26.0463049                                 
20 45.9370221 31.9870286 39.4320935 40.1966417 15.5267511                      
21 49.3154134 35.5090129 42.9728984 43.6076828 18.5294360  3.6578682           
22 41.9195658 27.8030574 35.2120718 36.1481673 12.3450395  4.3497126  8.0062476
23 49.4224645 35.6356563 43.0597260 43.7453998 18.8438319  3.8013156  0.8062258
24 43.1270217 29.1749893 36.5611816 37.4197809 13.3869339  3.0083218  6.5566760
25 48.8946827 35.0332699 42.5801597 43.1113674 17.7048016  3.7815341  2.0099751
26 49.0423287 35.1002849 42.6156075 43.2574849 18.0449439  3.4727511  1.6673332
27 49.0869636 35.2761959 42.7809537 43.3503172 18.0914344  3.6193922  0.9055385
28 46.4287626 32.5249135 39.8302649 40.7800196 16.8029759  2.3280893  4.1785165
29 49.2383996 35.3301571 42.8235916 43.4798804 18.3333030  3.5028560  1.0630146
30 42.1572058 28.1955670 35.5686660 36.4539435 12.6546434  4.0024992  7.5564542
31 35.8041897 21.9431083 29.6057427 29.9041803  5.0388491 11.0358507 14.2677959
32  8.1712912 12.2625446  4.6421978  7.7788174 31.0267626 43.8586365 47.4240445
33 37.4923992 23.2937760 30.6623548 31.7190794  9.4578010  8.8820043 12.5175876
34 23.1357753 32.3828983 25.0062012 27.2242190 50.6977919 62.0235931 65.5586920
           22         23         24         25         26         27         28
2                                                                              
3                                                                              
4                                                                              
5                                                                              
6                                                                              
7                                                                              
8                                                                              
9                                                                              
10                                                                             
11                                                                             
12                                                                             
13                                                                             
14                                                                             
15                                                                             
16                                                                             
17                                                                             
18                                                                             
19                                                                             
20                                                                             
21                                                                             
22                                                                             
23  8.1000000                                                                  
24  1.8027756  6.5681047                                                       
25  7.8421936  2.8089144  6.6895441                                            
26  7.6328239  2.3769729  6.4660653  0.9273618                                 
27  7.9082236  1.7058722  6.5612499  1.1401754  1.1224972                      
28  5.0852729  3.8483763  3.5227830  5.2402290  4.6904158  4.6238512           
29  7.7839579  1.7492856  6.5069194  1.3000000  0.6403124  0.8062258  4.4283180
30  1.2884099  7.5637292  1.0049876  7.6459139  7.4458042  7.5485098  4.4090815
31  7.6544105 14.5924638  8.9230040 13.4152898 13.6341483 13.8423264 12.3955637
32 39.6047977 47.4983158 40.9725518 47.0510361 47.0610242 47.2467988 44.2047509
33  4.5705580 12.5928551  6.0448325 12.2837291 12.1536003 12.3971771  9.3653617
34 57.8030285 65.4856633 59.0311621 65.5281474 65.4124155 65.5434520 61.9016971
           29         30         31         32         33
2                                                        
3                                                        
4                                                        
5                                                        
6                                                        
7                                                        
8                                                        
9                                                        
10                                                       
11                                                       
12                                                       
13                                                       
14                                                       
15                                                       
16                                                       
17                                                       
18                                                       
19                                                       
20                                                       
21                                                       
22                                                       
23                                                       
24                                                       
25                                                       
26                                                       
27                                                       
28                                                       
29                                                       
30  7.5026662                                            
31 13.9556440  8.2176639                                 
32 47.2674306 39.9762429 34.1328288                      
33 12.3247718  5.0783856  5.3272882 35.0406906           
34 65.5228060 58.0295451 53.4388445 20.7956269 53.3047850
# Convertir a matriz completa
euclidean_matrix <- as.matrix(euclidean_distances)

# Ver la matriz completa
print(euclidean_matrix)
          1         2          3         4         5         6         7
1   0.00000 39.635590 41.8289374 46.736495 52.473708 63.549902 31.306389
2  39.63559  0.000000  3.8052595  8.940917 13.343538 25.278647  8.919081
3  41.82894  3.805260  0.0000000  5.401852 10.694391 22.190313 12.104132
4  46.73650  8.940917  5.4018515  0.000000  6.472248 17.029680 17.445057
5  52.47371 13.343538 10.6943911  6.472248  0.000000 12.126830 22.262525
6  63.54990 25.278647 22.1903132 17.029680 12.126830  0.000000 34.156990
7  31.30639  8.919081 12.1041315 17.445057 22.262525 34.156990  0.000000
8  43.87038  4.710626  2.3558438  4.561798  8.744141 20.578144 13.585286
9  38.55360  5.323533  4.0422766  8.191459 14.264291 25.117524 10.505713
10 47.16991 10.666771  6.9036222  2.387467  7.327346 16.449620 18.790689
11 55.80905 16.543579 14.0516903  9.767804  3.382307  9.557196 25.444449
12 52.09232 15.877342 12.2004098  7.207635  7.273239 11.866760 24.175608
13 41.98595  3.478505  0.7874008  5.635601 10.522832 22.182200 12.037026
14 50.95331 11.972468  9.1923882  5.013980  1.565248 13.363757 20.883726
15 40.15831  5.376802  2.9444864  6.714909 12.588090 23.438003 11.887809
16 32.97590 10.527583 14.2558760 19.459959 23.150378 35.274070  4.971921
17 38.97756  3.874274  7.4411021 12.212698 15.470617 27.591665  7.953616
18 36.08393  3.629049  6.2297673 11.570220 16.670333 28.389082  5.911007
19 20.42450 28.748217 32.1735917 37.547570 41.835033 53.923928 20.171515
20 28.11832 42.410612 46.0015217 51.318028 54.748973 66.801422 34.554450
21 28.81909 45.898366 49.4592762 54.795985 58.309262 70.362845 37.931122
22 27.76689 38.257810 41.8829321 47.169694 50.496436 62.544304 30.566812
23 29.16179 46.010977 49.5666218 54.897814 58.364715 70.400710 38.100656
24 27.55159 39.578909 43.1681596 48.472157 51.841489 63.876913 31.841168
25 28.12010 45.448212 49.0238717 54.365430 57.973183 70.061473 37.368570
26 28.91609 45.537677 49.1300315 54.458608 57.977668 70.053765 37.543974
27 28.33267 45.672530 49.2355563 54.578201 58.149033 70.220011 37.640537
28 29.42482 42.898019 46.4766608 51.766592 55.030991 67.023653 35.249255
29 29.03705 45.755546 49.3397406 54.669644 58.173018 70.239875 37.782800
30 27.38503 38.596373 42.1872019 47.487051 50.841814 62.874876 30.892556
31 23.45954 32.304953 35.8827256 41.219534 45.065952 57.190908 24.105186
32 43.27147  4.305810  5.6089215  8.733842 10.953082 23.072278 12.205327
33 27.37901 33.748926 37.3891696 42.655011 45.929293 57.976030 26.213737
34 61.88740 23.929565 21.7111976 18.127054 12.392582 10.776553 32.413764
           8         9        10        11        12         13        14
1  43.870377 38.553599 47.169906 55.809049 52.092322 41.9859500 50.953312
2   4.710626  5.323533 10.666771 16.543579 15.877342  3.4785054 11.972468
3   2.355844  4.042277  6.903622 14.051690 12.200410  0.7874008  9.192388
4   4.561798  8.191459  2.387467  9.767804  7.207635  5.6356011  5.013980
5   8.744141 14.264291  7.327346  3.382307  7.273239 10.5228323  1.565248
6  20.578144 25.117524 16.449620  9.557196 11.866760 22.1822001 13.363757
7  13.585286 10.505713 18.790689 25.444449 24.175608 12.0370262 20.883726
8   0.000000  6.388271  6.603787 12.034118 11.474319  1.9824228  7.321885
9   6.388271  0.000000  8.830629 17.646246 14.186261  4.6151923 12.723993
10  6.603787  8.830629  0.000000 10.356158  5.514526  7.2539644  6.003332
11 12.034118 17.646246 10.356158  0.000000  8.764702 13.8509927  4.932545
12 11.474319 14.186261  5.514526  8.764702  0.000000 12.4173266  6.885492
13  1.982423  4.615192  7.253964 13.850993 12.417327  0.0000000  9.041018
14  7.321885 12.723993  6.003332  4.932545  6.885492  9.0410176  0.000000
15  5.141984  2.147091  7.300000 15.958070 12.521182  3.4597688 11.027692
16 15.070501 13.912944 21.156796 26.039585 26.322994 13.9359248 21.945615
17  7.672027  8.870738 14.087228 18.384232 18.991577  6.9130312 14.272001
18  7.928430  5.001000 12.886039 19.949436 18.270194  6.2377881 15.229248
19 33.446823 30.477205 38.912209 44.796094 44.213686 32.0140594 40.560572
20 46.949015 44.854654 52.832187 57.397300 57.898964 45.7014223 53.617161
21 50.455228 48.208091 56.270241 60.980407 61.343215 49.1727567 57.161700
22 42.767862 40.873708 48.731920 53.117323 53.785593 41.5651296 49.383803
23 50.549975 48.344079 56.368520 61.020980 61.411562 49.2711883 57.221762
24 44.090135 42.092398 49.990899 54.478069 55.020360 42.8535879 50.714199
25 50.040883 47.720226 55.854633 60.672976 60.996639 48.7573584 56.818835
26 50.109779 47.896764 55.969099 60.645940 61.088542 48.8497697 56.838895
27 50.248682 47.947471 56.053011 60.839050 61.157910 48.9597794 56.994912
28 47.372883 45.438090 53.278701 57.623346 58.251266 46.1469392 53.919384
29 50.319579 48.110394 56.170722 60.837324 61.270711 49.0551730 57.033587
30 43.101160 41.133684 49.009591 53.476443 54.032305 41.8690817 49.715792
31 36.949425 34.546925 42.726456 47.872539 47.972701 35.6523492 43.874708
32  4.401136  8.940917 10.872902 13.777155 15.282343  4.9030603  9.862048
33 38.235586 36.486299 44.242627 48.547091 49.279813 37.0579276 44.821981
34 19.858703 25.161480 18.168932  9.999005 15.002336 21.3603862 13.495410
          15        16        17        18        19        20         21
1  40.158312 32.975900 38.977558 36.083930 20.424495 28.118321 28.8190909
2   5.376802 10.527583  3.874274  3.629049 28.748217 42.410612 45.8983660
3   2.944486 14.255876  7.441102  6.229767 32.173592 46.001522 49.4592762
4   6.714909 19.459959 12.212698 11.570220 37.547570 51.318028 54.7959853
5  12.588090 23.150378 15.470617 16.670333 41.835033 54.748973 58.3092617
6  23.438003 35.274070 27.591665 28.389082 53.923928 66.801422 70.3628453
7  11.887809  4.971921  7.953616  5.911007 20.171515 34.554450 37.9311218
8   5.141984 15.070501  7.672027  7.928430 33.446823 46.949015 50.4552277
9   2.147091 13.912944  8.870738  5.001000 30.477205 44.854654 48.2080906
10  7.300000 21.156796 14.087228 12.886039 38.912209 52.832187 56.2702408
11 15.958070 26.039585 18.384232 19.949436 44.796094 57.397300 60.9804067
12 12.521182 26.322994 18.991577 18.270194 44.213686 57.898964 61.3432148
13  3.459769 13.935925  6.913031  6.237788 32.014059 45.701422 49.1727567
14 11.027692 21.945615 14.272001 15.229248 40.560572 53.617161 57.1617005
15  0.000000 14.809456  8.929726  6.149797 31.844152 45.937022 49.3154134
16 14.809456  0.000000  7.700649  8.923004 18.784302 31.987029 35.5090129
17  8.929726  7.700649  0.000000  5.230679 26.413822 39.432094 42.9728984
18  6.149797  8.923004  5.230679  0.000000 26.046305 40.196642 43.6076828
19 31.844152 18.784302 26.413822 26.046305  0.000000 15.526751 18.5294360
20 45.937022 31.987029 39.432094 40.196642 15.526751  0.000000  3.6578682
21 49.315413 35.509013 42.972898 43.607683 18.529436  3.657868  0.0000000
22 41.919566 27.803057 35.212072 36.148167 12.345039  4.349713  8.0062476
23 49.422465 35.635656 43.059726 43.745400 18.843832  3.801316  0.8062258
24 43.127022 29.174989 36.561182 37.419781 13.386934  3.008322  6.5566760
25 48.894683 35.033270 42.580160 43.111367 17.704802  3.781534  2.0099751
26 49.042329 35.100285 42.615607 43.257485 18.044944  3.472751  1.6673332
27 49.086964 35.276196 42.780954 43.350317 18.091434  3.619392  0.9055385
28 46.428763 32.524914 39.830265 40.780020 16.802976  2.328089  4.1785165
29 49.238400 35.330157 42.823592 43.479880 18.333303  3.502856  1.0630146
30 42.157206 28.195567 35.568666 36.453944 12.654643  4.002499  7.5564542
31 35.804190 21.943108 29.605743 29.904180  5.038849 11.035851 14.2677959
32  8.171291 12.262545  4.642198  7.778817 31.026763 43.858637 47.4240445
33 37.492399 23.293776 30.662355 31.719079  9.457801  8.882004 12.5175876
34 23.135775 32.382898 25.006201 27.224219 50.697792 62.023593 65.5586920
          22         23        24         25         26         27        28
1  27.766887 29.1617901 27.551588 28.1200996 28.9160855 28.3326667 29.424819
2  38.257810 46.0109770 39.578909 45.4482123 45.5376767 45.6725300 42.898019
3  41.882932 49.5666218 43.168160 49.0238717 49.1300315 49.2355563 46.476661
4  47.169694 54.8978142 48.472157 54.3654302 54.4586081 54.5782008 51.766592
5  50.496436 58.3647154 51.841489 57.9731835 57.9776681 58.1490327 55.030991
6  62.544304 70.4007102 63.876913 70.0614730 70.0537651 70.2200114 67.023653
7  30.566812 38.1006562 31.841168 37.3685697 37.5439742 37.6405367 35.249255
8  42.767862 50.5499753 44.090135 50.0408833 50.1097795 50.2486816 47.372883
9  40.873708 48.3440793 42.092398 47.7202263 47.8967640 47.9474713 45.438090
10 48.731920 56.3685196 49.990899 55.8546328 55.9690986 56.0530106 53.278701
11 53.117323 61.0209800 54.478069 60.6729759 60.6459397 60.8390500 57.623346
12 53.785593 61.4115624 55.020360 60.9966393 61.0885423 61.1579104 58.251266
13 41.565130 49.2711883 42.853588 48.7573584 48.8497697 48.9597794 46.146939
14 49.383803 57.2217616 50.714199 56.8188349 56.8388951 56.9949121 53.919384
15 41.919566 49.4224645 43.127022 48.8946827 49.0423287 49.0869636 46.428763
16 27.803057 35.6356563 29.174989 35.0332699 35.1002849 35.2761959 32.524914
17 35.212072 43.0597260 36.561182 42.5801597 42.6156075 42.7809537 39.830265
18 36.148167 43.7453998 37.419781 43.1113674 43.2574849 43.3503172 40.780020
19 12.345039 18.8438319 13.386934 17.7048016 18.0449439 18.0914344 16.802976
20  4.349713  3.8013156  3.008322  3.7815341  3.4727511  3.6193922  2.328089
21  8.006248  0.8062258  6.556676  2.0099751  1.6673332  0.9055385  4.178516
22  0.000000  8.1000000  1.802776  7.8421936  7.6328239  7.9082236  5.085273
23  8.100000  0.0000000  6.568105  2.8089144  2.3769729  1.7058722  3.848376
24  1.802776  6.5681047  0.000000  6.6895441  6.4660653  6.5612499  3.522783
25  7.842194  2.8089144  6.689544  0.0000000  0.9273618  1.1401754  5.240229
26  7.632824  2.3769729  6.466065  0.9273618  0.0000000  1.1224972  4.690416
27  7.908224  1.7058722  6.561250  1.1401754  1.1224972  0.0000000  4.623851
28  5.085273  3.8483763  3.522783  5.2402290  4.6904158  4.6238512  0.000000
29  7.783958  1.7492856  6.506919  1.3000000  0.6403124  0.8062258  4.428318
30  1.288410  7.5637292  1.004988  7.6459139  7.4458042  7.5485098  4.409082
31  7.654410 14.5924638  8.923004 13.4152898 13.6341483 13.8423264 12.395564
32 39.604798 47.4983158 40.972552 47.0510361 47.0610242 47.2467988 44.204751
33  4.570558 12.5928551  6.044833 12.2837291 12.1536003 12.3971771  9.365362
34 57.803028 65.4856633 59.031162 65.5281474 65.4124155 65.5434520 61.901697
           29        30        31        32        33        34
1  29.0370453 27.385032 23.459540 43.271469 27.379007 61.887399
2  45.7555461 38.596373 32.304953  4.305810 33.748926 23.929565
3  49.3397406 42.187202 35.882726  5.608921 37.389170 21.711198
4  54.6696442 47.487051 41.219534  8.733842 42.655011 18.127054
5  58.1730178 50.841814 45.065952 10.953082 45.929293 12.392582
6  70.2398747 62.874876 57.190908 23.072278 57.976030 10.776553
7  37.7828003 30.892556 24.105186 12.205327 26.213737 32.413764
8  50.3195787 43.101160 36.949425  4.401136 38.235586 19.858703
9  48.1103939 41.133684 34.546925  8.940917 36.486299 25.161480
10 56.1707219 49.009591 42.726456 10.872902 44.242627 18.168932
11 60.8373241 53.476443 47.872539 13.777155 48.547091  9.999005
12 61.2707108 54.032305 47.972701 15.282343 49.279813 15.002336
13 49.0551730 41.869082 35.652349  4.903060 37.057928 21.360386
14 57.0335866 49.715792 43.874708  9.862048 44.821981 13.495410
15 49.2383996 42.157206 35.804190  8.171291 37.492399 23.135775
16 35.3301571 28.195567 21.943108 12.262545 23.293776 32.382898
17 42.8235916 35.568666 29.605743  4.642198 30.662355 25.006201
18 43.4798804 36.453944 29.904180  7.778817 31.719079 27.224219
19 18.3333030 12.654643  5.038849 31.026763  9.457801 50.697792
20  3.5028560  4.002499 11.035851 43.858637  8.882004 62.023593
21  1.0630146  7.556454 14.267796 47.424045 12.517588 65.558692
22  7.7839579  1.288410  7.654410 39.604798  4.570558 57.803028
23  1.7492856  7.563729 14.592464 47.498316 12.592855 65.485663
24  6.5069194  1.004988  8.923004 40.972552  6.044833 59.031162
25  1.3000000  7.645914 13.415290 47.051036 12.283729 65.528147
26  0.6403124  7.445804 13.634148 47.061024 12.153600 65.412415
27  0.8062258  7.548510 13.842326 47.246799 12.397177 65.543452
28  4.4283180  4.409082 12.395564 44.204751  9.365362 61.901697
29  0.0000000  7.502666 13.955644 47.267431 12.324772 65.522806
30  7.5026662  0.000000  8.217664 39.976243  5.078386 58.029545
31 13.9556440  8.217664  0.000000 34.132829  5.327288 53.438844
32 47.2674306 39.976243 34.132829  0.000000 35.040691 20.795627
33 12.3247718  5.078386  5.327288 35.040691  0.000000 53.304785
34 65.5228060 58.029545 53.438844 20.795627 53.304785  0.000000
#install.packages("proxy")
library(proxy)

# Calcular distancias euclidianas con proxy
euclidean_distances_proxy <- dist(data, method = "Euclidean", diag = TRUE, upper = TRUE)

# Mostrar las distancias
print(euclidean_distances_proxy)
            1          2          3          4          5          6          7
1   0.0000000 39.6355901 41.8289374 46.7364954 52.4737077 63.5499017 31.3063891
2  39.6355901  0.0000000  3.8052595  8.9409172 13.3435378 25.2786471  8.9190807
3  41.8289374  3.8052595  0.0000000  5.4018515 10.6943911 22.1903132 12.1041315
4  46.7364954  8.9409172  5.4018515  0.0000000  6.4722485 17.0296800 17.4450566
5  52.4737077 13.3435378 10.6943911  6.4722485  0.0000000 12.1268298 22.2625246
6  63.5499017 25.2786471 22.1903132 17.0296800 12.1268298  0.0000000 34.1569905
7  31.3063891  8.9190807 12.1041315 17.4450566 22.2625246 34.1569905  0.0000000
8  43.8703772  4.7106263  2.3558438  4.5617979  8.7441409 20.5781437 13.5852862
9  38.5535991  5.3235327  4.0422766  8.1914590 14.2642911 25.1175238 10.5057127
10 47.1699057 10.6667708  6.9036222  2.3874673  7.3273460 16.4496201 18.7906892
11 55.8090494 16.5435788 14.0516903  9.7678043  3.3823069  9.5571962 25.4444493
12 52.0923219 15.8773423 12.2004098  7.2076348  7.2732386 11.8667603 24.1756075
13 41.9859500  3.4785054  0.7874008  5.6356011 10.5228323 22.1822001 12.0370262
14 50.9533120 11.9724684  9.1923882  5.0139805  1.5652476 13.3637570 20.8837257
15 40.1583117  5.3768020  2.9444864  6.7149088 12.5880896 23.4380033 11.8878089
16 32.9759003 10.5275828 14.2558760 19.4599589 23.1503780 35.2740698  4.9719212
17 38.9775576  3.8742741  7.4411021 12.2126983 15.4706173 27.5916654  7.9536155
18 36.0839299  3.6290495  6.2297673 11.5702204 16.6703329 28.3890824  5.9110067
19 20.4244951 28.7482173 32.1735917 37.5475698 41.8350332 53.9239279 20.1715146
20 28.1183214 42.4106119 46.0015217 51.3180280 54.7489726 66.8014221 34.5544498
21 28.8190909 45.8983660 49.4592762 54.7959853 58.3092617 70.3628453 37.9311218
22 27.7668868 38.2578097 41.8829321 47.1696937 50.4964355 62.5443043 30.5668121
23 29.1617901 46.0109770 49.5666218 54.8978142 58.3647154 70.4007102 38.1006562
24 27.5515880 39.5789085 43.1681596 48.4721570 51.8414892 63.8769129 31.8411683
25 28.1200996 45.4482123 49.0238717 54.3654302 57.9731835 70.0614730 37.3685697
26 28.9160855 45.5376767 49.1300315 54.4586081 57.9776681 70.0537651 37.5439742
27 28.3326667 45.6725300 49.2355563 54.5782008 58.1490327 70.2200114 37.6405367
28 29.4248195 42.8980186 46.4766608 51.7665915 55.0309913 67.0236525 35.2492553
29 29.0370453 45.7555461 49.3397406 54.6696442 58.1730178 70.2398747 37.7828003
30 27.3850324 38.5963729 42.1872019 47.4870509 50.8418135 62.8748757 30.8925557
31 23.4595396 32.3049532 35.8827256 41.2195342 45.0659517 57.1909084 24.1051862
32 43.2714687  4.3058100  5.6089215  8.7338422 10.9530818 23.0722777 12.2053267
33 27.3790066 33.7489259 37.3891696 42.6550114 45.9292935 57.9760295 26.2137369
34 61.8873986 23.9295654 21.7111976 18.1270544 12.3925825 10.7765533 32.4137641
            8          9         10         11         12         13         14
1  43.8703772 38.5535991 47.1699057 55.8090494 52.0923219 41.9859500 50.9533120
2   4.7106263  5.3235327 10.6667708 16.5435788 15.8773423  3.4785054 11.9724684
3   2.3558438  4.0422766  6.9036222 14.0516903 12.2004098  0.7874008  9.1923882
4   4.5617979  8.1914590  2.3874673  9.7678043  7.2076348  5.6356011  5.0139805
5   8.7441409 14.2642911  7.3273460  3.3823069  7.2732386 10.5228323  1.5652476
6  20.5781437 25.1175238 16.4496201  9.5571962 11.8667603 22.1822001 13.3637570
7  13.5852862 10.5057127 18.7906892 25.4444493 24.1756075 12.0370262 20.8837257
8   0.0000000  6.3882705  6.6037868 12.0341182 11.4743192  1.9824228  7.3218850
9   6.3882705  0.0000000  8.8306285 17.6462461 14.1862610  4.6151923 12.7239931
10  6.6037868  8.8306285  0.0000000 10.3561576  5.5145263  7.2539644  6.0033324
11 12.0341182 17.6462461 10.3561576  0.0000000  8.7647019 13.8509927  4.9325450
12 11.4743192 14.1862610  5.5145263  8.7647019  0.0000000 12.4173266  6.8854920
13  1.9824228  4.6151923  7.2539644 13.8509927 12.4173266  0.0000000  9.0410176
14  7.3218850 12.7239931  6.0033324  4.9325450  6.8854920  9.0410176  0.0000000
15  5.1419841  2.1470911  7.3000000 15.9580701 12.5211821  3.4597688 11.0276924
16 15.0705010 13.9129436 21.1567956 26.0395853 26.3229938 13.9359248 21.9456146
17  7.6720271  8.8707384 14.0872283 18.3842324 18.9915771  6.9130312 14.2720006
18  7.9284299  5.0009999 12.8860390 19.9494361 18.2701943  6.2377881 15.2292482
19 33.4468235 30.4772046 38.9122089 44.7960936 44.2136857 32.0140594 40.5605720
20 46.9490149 44.8546542 52.8321872 57.3972996 57.8989637 45.7014223 53.6171614
21 50.4552277 48.2080906 56.2702408 60.9804067 61.3432148 49.1727567 57.1617005
22 42.7678618 40.8737079 48.7319197 53.1173230 53.7855929 41.5651296 49.3838030
23 50.5499753 48.3440793 56.3685196 61.0209800 61.4115624 49.2711883 57.2217616
24 44.0901350 42.0923984 49.9908992 54.4780690 55.0203599 42.8535879 50.7141992
25 50.0408833 47.7202263 55.8546328 60.6729759 60.9966393 48.7573584 56.8188349
26 50.1097795 47.8967640 55.9690986 60.6459397 61.0885423 48.8497697 56.8388951
27 50.2486816 47.9474713 56.0530106 60.8390500 61.1579104 48.9597794 56.9949121
28 47.3728825 45.4380897 53.2787012 57.6233460 58.2512661 46.1469392 53.9193843
29 50.3195787 48.1103939 56.1707219 60.8373241 61.2707108 49.0551730 57.0335866
30 43.1011601 41.1336845 49.0095909 53.4764434 54.0323052 41.8690817 49.7157923
31 36.9494249 34.5469246 42.7264555 47.8725391 47.9727006 35.6523492 43.8747080
32  4.4011362  8.9409172 10.8729021 13.7771550 15.2823428  4.9030603  9.8620485
33 38.2355855 36.4862988 44.2426265 48.5470905 49.2798133 37.0579276 44.8219812
34 19.8587034 25.1614805 18.1689323  9.9990050 15.0023365 21.3603862 13.4954103
           15         16         17         18         19         20         21
1  40.1583117 32.9759003 38.9775576 36.0839299 20.4244951 28.1183214 28.8190909
2   5.3768020 10.5275828  3.8742741  3.6290495 28.7482173 42.4106119 45.8983660
3   2.9444864 14.2558760  7.4411021  6.2297673 32.1735917 46.0015217 49.4592762
4   6.7149088 19.4599589 12.2126983 11.5702204 37.5475698 51.3180280 54.7959853
5  12.5880896 23.1503780 15.4706173 16.6703329 41.8350332 54.7489726 58.3092617
6  23.4380033 35.2740698 27.5916654 28.3890824 53.9239279 66.8014221 70.3628453
7  11.8878089  4.9719212  7.9536155  5.9110067 20.1715146 34.5544498 37.9311218
8   5.1419841 15.0705010  7.6720271  7.9284299 33.4468235 46.9490149 50.4552277
9   2.1470911 13.9129436  8.8707384  5.0009999 30.4772046 44.8546542 48.2080906
10  7.3000000 21.1567956 14.0872283 12.8860390 38.9122089 52.8321872 56.2702408
11 15.9580701 26.0395853 18.3842324 19.9494361 44.7960936 57.3972996 60.9804067
12 12.5211821 26.3229938 18.9915771 18.2701943 44.2136857 57.8989637 61.3432148
13  3.4597688 13.9359248  6.9130312  6.2377881 32.0140594 45.7014223 49.1727567
14 11.0276924 21.9456146 14.2720006 15.2292482 40.5605720 53.6171614 57.1617005
15  0.0000000 14.8094564  8.9297256  6.1497967 31.8441517 45.9370221 49.3154134
16 14.8094564  0.0000000  7.7006493  8.9230040 18.7843020 31.9870286 35.5090129
17  8.9297256  7.7006493  0.0000000  5.2306787 26.4138221 39.4320935 42.9728984
18  6.1497967  8.9230040  5.2306787  0.0000000 26.0463049 40.1966417 43.6076828
19 31.8441517 18.7843020 26.4138221 26.0463049  0.0000000 15.5267511 18.5294360
20 45.9370221 31.9870286 39.4320935 40.1966417 15.5267511  0.0000000  3.6578682
21 49.3154134 35.5090129 42.9728984 43.6076828 18.5294360  3.6578682  0.0000000
22 41.9195658 27.8030574 35.2120718 36.1481673 12.3450395  4.3497126  8.0062476
23 49.4224645 35.6356563 43.0597260 43.7453998 18.8438319  3.8013156  0.8062258
24 43.1270217 29.1749893 36.5611816 37.4197809 13.3869339  3.0083218  6.5566760
25 48.8946827 35.0332699 42.5801597 43.1113674 17.7048016  3.7815341  2.0099751
26 49.0423287 35.1002849 42.6156075 43.2574849 18.0449439  3.4727511  1.6673332
27 49.0869636 35.2761959 42.7809537 43.3503172 18.0914344  3.6193922  0.9055385
28 46.4287626 32.5249135 39.8302649 40.7800196 16.8029759  2.3280893  4.1785165
29 49.2383996 35.3301571 42.8235916 43.4798804 18.3333030  3.5028560  1.0630146
30 42.1572058 28.1955670 35.5686660 36.4539435 12.6546434  4.0024992  7.5564542
31 35.8041897 21.9431083 29.6057427 29.9041803  5.0388491 11.0358507 14.2677959
32  8.1712912 12.2625446  4.6421978  7.7788174 31.0267626 43.8586365 47.4240445
33 37.4923992 23.2937760 30.6623548 31.7190794  9.4578010  8.8820043 12.5175876
34 23.1357753 32.3828983 25.0062012 27.2242190 50.6977919 62.0235931 65.5586920
           22         23         24         25         26         27         28
1  27.7668868 29.1617901 27.5515880 28.1200996 28.9160855 28.3326667 29.4248195
2  38.2578097 46.0109770 39.5789085 45.4482123 45.5376767 45.6725300 42.8980186
3  41.8829321 49.5666218 43.1681596 49.0238717 49.1300315 49.2355563 46.4766608
4  47.1696937 54.8978142 48.4721570 54.3654302 54.4586081 54.5782008 51.7665915
5  50.4964355 58.3647154 51.8414892 57.9731835 57.9776681 58.1490327 55.0309913
6  62.5443043 70.4007102 63.8769129 70.0614730 70.0537651 70.2200114 67.0236525
7  30.5668121 38.1006562 31.8411683 37.3685697 37.5439742 37.6405367 35.2492553
8  42.7678618 50.5499753 44.0901350 50.0408833 50.1097795 50.2486816 47.3728825
9  40.8737079 48.3440793 42.0923984 47.7202263 47.8967640 47.9474713 45.4380897
10 48.7319197 56.3685196 49.9908992 55.8546328 55.9690986 56.0530106 53.2787012
11 53.1173230 61.0209800 54.4780690 60.6729759 60.6459397 60.8390500 57.6233460
12 53.7855929 61.4115624 55.0203599 60.9966393 61.0885423 61.1579104 58.2512661
13 41.5651296 49.2711883 42.8535879 48.7573584 48.8497697 48.9597794 46.1469392
14 49.3838030 57.2217616 50.7141992 56.8188349 56.8388951 56.9949121 53.9193843
15 41.9195658 49.4224645 43.1270217 48.8946827 49.0423287 49.0869636 46.4287626
16 27.8030574 35.6356563 29.1749893 35.0332699 35.1002849 35.2761959 32.5249135
17 35.2120718 43.0597260 36.5611816 42.5801597 42.6156075 42.7809537 39.8302649
18 36.1481673 43.7453998 37.4197809 43.1113674 43.2574849 43.3503172 40.7800196
19 12.3450395 18.8438319 13.3869339 17.7048016 18.0449439 18.0914344 16.8029759
20  4.3497126  3.8013156  3.0083218  3.7815341  3.4727511  3.6193922  2.3280893
21  8.0062476  0.8062258  6.5566760  2.0099751  1.6673332  0.9055385  4.1785165
22  0.0000000  8.1000000  1.8027756  7.8421936  7.6328239  7.9082236  5.0852729
23  8.1000000  0.0000000  6.5681047  2.8089144  2.3769729  1.7058722  3.8483763
24  1.8027756  6.5681047  0.0000000  6.6895441  6.4660653  6.5612499  3.5227830
25  7.8421936  2.8089144  6.6895441  0.0000000  0.9273618  1.1401754  5.2402290
26  7.6328239  2.3769729  6.4660653  0.9273618  0.0000000  1.1224972  4.6904158
27  7.9082236  1.7058722  6.5612499  1.1401754  1.1224972  0.0000000  4.6238512
28  5.0852729  3.8483763  3.5227830  5.2402290  4.6904158  4.6238512  0.0000000
29  7.7839579  1.7492856  6.5069194  1.3000000  0.6403124  0.8062258  4.4283180
30  1.2884099  7.5637292  1.0049876  7.6459139  7.4458042  7.5485098  4.4090815
31  7.6544105 14.5924638  8.9230040 13.4152898 13.6341483 13.8423264 12.3955637
32 39.6047977 47.4983158 40.9725518 47.0510361 47.0610242 47.2467988 44.2047509
33  4.5705580 12.5928551  6.0448325 12.2837291 12.1536003 12.3971771  9.3653617
34 57.8030285 65.4856633 59.0311621 65.5281474 65.4124155 65.5434520 61.9016971
           29         30         31         32         33         34
1  29.0370453 27.3850324 23.4595396 43.2714687 27.3790066 61.8873986
2  45.7555461 38.5963729 32.3049532  4.3058100 33.7489259 23.9295654
3  49.3397406 42.1872019 35.8827256  5.6089215 37.3891696 21.7111976
4  54.6696442 47.4870509 41.2195342  8.7338422 42.6550114 18.1270544
5  58.1730178 50.8418135 45.0659517 10.9530818 45.9292935 12.3925825
6  70.2398747 62.8748757 57.1909084 23.0722777 57.9760295 10.7765533
7  37.7828003 30.8925557 24.1051862 12.2053267 26.2137369 32.4137641
8  50.3195787 43.1011601 36.9494249  4.4011362 38.2355855 19.8587034
9  48.1103939 41.1336845 34.5469246  8.9409172 36.4862988 25.1614805
10 56.1707219 49.0095909 42.7264555 10.8729021 44.2426265 18.1689323
11 60.8373241 53.4764434 47.8725391 13.7771550 48.5470905  9.9990050
12 61.2707108 54.0323052 47.9727006 15.2823428 49.2798133 15.0023365
13 49.0551730 41.8690817 35.6523492  4.9030603 37.0579276 21.3603862
14 57.0335866 49.7157923 43.8747080  9.8620485 44.8219812 13.4954103
15 49.2383996 42.1572058 35.8041897  8.1712912 37.4923992 23.1357753
16 35.3301571 28.1955670 21.9431083 12.2625446 23.2937760 32.3828983
17 42.8235916 35.5686660 29.6057427  4.6421978 30.6623548 25.0062012
18 43.4798804 36.4539435 29.9041803  7.7788174 31.7190794 27.2242190
19 18.3333030 12.6546434  5.0388491 31.0267626  9.4578010 50.6977919
20  3.5028560  4.0024992 11.0358507 43.8586365  8.8820043 62.0235931
21  1.0630146  7.5564542 14.2677959 47.4240445 12.5175876 65.5586920
22  7.7839579  1.2884099  7.6544105 39.6047977  4.5705580 57.8030285
23  1.7492856  7.5637292 14.5924638 47.4983158 12.5928551 65.4856633
24  6.5069194  1.0049876  8.9230040 40.9725518  6.0448325 59.0311621
25  1.3000000  7.6459139 13.4152898 47.0510361 12.2837291 65.5281474
26  0.6403124  7.4458042 13.6341483 47.0610242 12.1536003 65.4124155
27  0.8062258  7.5485098 13.8423264 47.2467988 12.3971771 65.5434520
28  4.4283180  4.4090815 12.3955637 44.2047509  9.3653617 61.9016971
29  0.0000000  7.5026662 13.9556440 47.2674306 12.3247718 65.5228060
30  7.5026662  0.0000000  8.2176639 39.9762429  5.0783856 58.0295451
31 13.9556440  8.2176639  0.0000000 34.1328288  5.3272882 53.4388445
32 47.2674306 39.9762429 34.1328288  0.0000000 35.0406906 20.7956269
33 12.3247718  5.0783856  5.3272882 35.0406906  0.0000000 53.3047850
34 65.5228060 58.0295451 53.4388445 20.7956269 53.3047850  0.0000000
import pandas as pd
import numpy as np
from scipy.spatial import distance

# Cargar los datos
data = pd.read_csv('accion.txt', sep='\t')

# Calcular la matriz de covarianzas
cov_matrix = np.cov(data.T)

# Calcular la inversa de la matriz de covarianzas
inv_cov_matrix = np.linalg.inv(cov_matrix)

# Calcular la media de cada variable
mean_data = data.mean().values

# Calcular la matriz de distancias de Mahalanobis
mahalanobis_matrix = distance.cdist(data, data, 'mahalanobis', VI=inv_cov_matrix)

print("Matriz de distancias de Mahalanobis:")
Matriz de distancias de Mahalanobis:
print(mahalanobis_matrix)
[[0.         5.23121856 4.84362218 ... 5.8481407  5.51831508 6.79821955]
 [5.23121856 0.         0.52647286 ... 0.73364113 1.72759331 5.02067693]
 [4.84362218 0.52647286 0.         ... 1.07374101 1.87998086 4.7178646 ]
 ...
 [5.8481407  0.73364113 1.07374101 ... 0.         1.56504562 4.75801024]
 [5.51831508 1.72759331 1.87998086 ... 1.56504562 0.         4.61292473]
 [6.79821955 5.02067693 4.7178646  ... 4.75801024 4.61292473 0.        ]]
import pandas as pd
from scipy.spatial import distance

# Cargar los datos (asumiendo que ya está cargado como 'data')

# Calcular la matriz de distancias euclidianas
euclidean_matrix = distance.cdist(data, data, 'euclidean')

print("Matriz de distancias euclidianas:")
Matriz de distancias euclidianas:
print(euclidean_matrix)
[[ 0.         39.63559007 41.82893735 ... 43.27146866 27.37900656
  61.88739856]
 [39.63559007  0.          3.80525952 ...  4.30581003 33.74892591
  23.9295654 ]
 [41.82893735  3.80525952  0.         ...  5.60892146 37.38916955
  21.71119757]
 ...
 [43.27146866  4.30581003  5.60892146 ...  0.         35.04069063
  20.79562694]
 [27.37900656 33.74892591 37.38916955 ... 35.04069063  0.
  53.30478496]
 [61.88739856 23.9295654  21.71119757 ... 20.79562694 53.30478496
   0.        ]]