heavystats 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
heavystats/__init__.py ADDED
@@ -0,0 +1,114 @@
1
+ __version__ = "0.3.1"
2
+
3
+ from heavystats.validation import ValidationReport, validate_data
4
+ from heavystats.comparation import (
5
+ ComparationReport,
6
+ compare_groups,
7
+ )
8
+ from heavystats.cleaning import (
9
+ VariableTypeReport,
10
+ VariablesTableReport,
11
+ columns_type,
12
+ categorical_columns,
13
+ numerical_columns,
14
+ variables_table,
15
+ get_analytical_sample,
16
+ select_metal,
17
+ load_data,
18
+ standardize_boolean_columns,
19
+ desaggregate_multiple_responses,
20
+ encode_dietary_frequencies,
21
+ create_composite_indicators,
22
+ )
23
+ from heavystats.univariate import (
24
+ UnivariateTables,
25
+ UnivariatePlots,
26
+ DEFAULT_LABELS_MAP,
27
+ DEFAULT_CUSTOM_PARAMS,
28
+ DEFAULT_PERMISSIBLE_LIMITS,
29
+ CDC_BMI_REFERENCE,
30
+ get_label,
31
+ )
32
+ from heavystats.bivariate import (
33
+ BivariateTables,
34
+ BivariateTableReport,
35
+ BivariatePlots,
36
+ mann_whitney_test,
37
+ kruskal_wallis_test,
38
+ dunn_posthoc_test,
39
+ jonckheere_terpstra_test,
40
+ spearman_correlation,
41
+ spearman_matrix,
42
+ fisher_chi2_test,
43
+ adjust_pvalues,
44
+ hodges_lehmann_2sample,
45
+ bootstrap_ci_diff_medians,
46
+ rank_bivariate_associations,
47
+ collinearity_matrix,
48
+ DEFAULT_METAL_LIMITS,
49
+ DEFAULT_METAL_LODS,
50
+ DEFAULT_METAL_CUTOFFS,
51
+ DEFAULT_METAL_PAIRS,
52
+ )
53
+ from heavystats.version_checker import check_for_updates
54
+
55
+ __all__ = [
56
+ "__version__",
57
+ "ValidationReport",
58
+ "validate_data",
59
+ "ComparationReport",
60
+ "compare_groups",
61
+ "VariableTypeReport",
62
+ "VariablesTableReport",
63
+ "columns_type",
64
+ "categorical_columns",
65
+ "numerical_columns",
66
+ "variables_table",
67
+ "get_analytical_sample",
68
+ "select_metal",
69
+ "load_data",
70
+ "standardize_boolean_columns",
71
+ "desaggregate_multiple_responses",
72
+ "encode_dietary_frequencies",
73
+ "create_composite_indicators",
74
+ "UnivariateTables",
75
+ "UnivariatePlots",
76
+ "BivariateTables",
77
+ "BivariateTableReport",
78
+ "BivariatePlots",
79
+ "mann_whitney_test",
80
+ "kruskal_wallis_test",
81
+ "dunn_posthoc_test",
82
+ "jonckheere_terpstra_test",
83
+ "spearman_correlation",
84
+ "spearman_matrix",
85
+ "fisher_chi2_test",
86
+ "adjust_pvalues",
87
+ "hodges_lehmann_2sample",
88
+ "bootstrap_ci_diff_medians",
89
+ "rank_bivariate_associations",
90
+ "collinearity_matrix",
91
+ "DEFAULT_LABELS_MAP",
92
+ "DEFAULT_CUSTOM_PARAMS",
93
+ "DEFAULT_PERMISSIBLE_LIMITS",
94
+ "DEFAULT_METAL_LIMITS",
95
+ "DEFAULT_METAL_LODS",
96
+ "DEFAULT_METAL_CUTOFFS",
97
+ "DEFAULT_METAL_PAIRS",
98
+ "CDC_BMI_REFERENCE",
99
+ "get_label",
100
+ "check_for_updates",
101
+ ]
102
+
103
+ # Verificación de versiones no bloqueante en segundo plano al importar
104
+ try:
105
+ check_for_updates(__version__, async_check=True)
106
+ except Exception:
107
+ pass
108
+
109
+
110
+ def __getattr__(name: str):
111
+ if name == "df":
112
+ from heavystats.cleaning import df
113
+ return df
114
+ raise AttributeError(f"module {__name__} has no attribute {name}")
@@ -0,0 +1,68 @@
1
+ """
2
+ Módulo de Análisis Bivariante de HeavyStats (`heavystats.bivariate`).
3
+ Implementa el protocolo de análisis estadístico bivariante bioestadístico y toxicológico.
4
+ """
5
+
6
+ from heavystats.bivariate.tests import (
7
+ mann_whitney_test,
8
+ kruskal_wallis_test,
9
+ dunn_posthoc_test,
10
+ jonckheere_terpstra_test,
11
+ spearman_correlation,
12
+ spearman_matrix,
13
+ fisher_chi2_test,
14
+ adjust_pvalues,
15
+ hodges_lehmann_2sample,
16
+ bootstrap_ci_diff_medians,
17
+ rank_bivariate_associations,
18
+ collinearity_matrix,
19
+ )
20
+ from heavystats.bivariate.tables import (
21
+ BivariateTables,
22
+ BivariateTableReport,
23
+ )
24
+ from heavystats.bivariate.plots import (
25
+ BivariatePlots,
26
+ )
27
+ from heavystats.bivariate.constants import (
28
+ DEFAULT_PRIMARY_METALS,
29
+ DEFAULT_METAL_LIMITS,
30
+ DEFAULT_METAL_LODS,
31
+ DEFAULT_METAL_CUTOFFS,
32
+ DEFAULT_METAL_PAIRS,
33
+ DEFAULT_BIVARIATE_GROUPS,
34
+ CDC_LEAD_REFERENCE_VALUE,
35
+ EPA_MERCURY_REFERENCE_VALUE,
36
+ OMS_CADMIUM_REFERENCE_VALUE,
37
+ DIET_ORDINAL_MAP,
38
+ DIET_ORDINAL_LABELS,
39
+ )
40
+
41
+ __all__ = [
42
+ "BivariateTables",
43
+ "BivariateTableReport",
44
+ "BivariatePlots",
45
+ "mann_whitney_test",
46
+ "kruskal_wallis_test",
47
+ "dunn_posthoc_test",
48
+ "jonckheere_terpstra_test",
49
+ "spearman_correlation",
50
+ "spearman_matrix",
51
+ "fisher_chi2_test",
52
+ "adjust_pvalues",
53
+ "hodges_lehmann_2sample",
54
+ "bootstrap_ci_diff_medians",
55
+ "rank_bivariate_associations",
56
+ "collinearity_matrix",
57
+ "DEFAULT_PRIMARY_METALS",
58
+ "DEFAULT_METAL_LIMITS",
59
+ "DEFAULT_METAL_LODS",
60
+ "DEFAULT_METAL_CUTOFFS",
61
+ "DEFAULT_METAL_PAIRS",
62
+ "DEFAULT_BIVARIATE_GROUPS",
63
+ "CDC_LEAD_REFERENCE_VALUE",
64
+ "EPA_MERCURY_REFERENCE_VALUE",
65
+ "OMS_CADMIUM_REFERENCE_VALUE",
66
+ "DIET_ORDINAL_MAP",
67
+ "DIET_ORDINAL_LABELS",
68
+ ]
@@ -0,0 +1,183 @@
1
+ """
2
+ Constantes, mapas de etiquetas, límites permisibles y configuraciones del modulo bivariante.
3
+ """
4
+
5
+ from typing import Dict, List, Tuple, Any, Optional
6
+ from heavystats.univariate.constants import (
7
+ DEFAULT_LABELS_MAP,
8
+ DEFAULT_CUSTOM_PARAMS,
9
+ DEFAULT_PERMISSIBLE_LIMITS,
10
+ get_label,
11
+ )
12
+
13
+ # Metales principales analizados
14
+ DEFAULT_PRIMARY_METALS: List[str] = [
15
+ "Plomo_ug_dL",
16
+ "Mercurio_ug_L",
17
+ "Cadmio_ug_L",
18
+ ]
19
+
20
+ # Límites de referencia toxicológicos y normativos internacionales
21
+ CDC_LEAD_REFERENCE_VALUE: float = 3.5 # µg/dL (CDC 2021 BLRV para niños)
22
+ EPA_MERCURY_REFERENCE_VALUE: float = 5.0 # µg/L (EPA / OMS)
23
+ OMS_CADMIUM_REFERENCE_VALUE: float = 1.0 # µg/L (OMS / ATSDR)
24
+
25
+ DEFAULT_METAL_LIMITS: Dict[str, float] = {
26
+ "Plomo_ug_dL": CDC_LEAD_REFERENCE_VALUE,
27
+ "Mercurio_ug_L": EPA_MERCURY_REFERENCE_VALUE,
28
+ "Cadmio_ug_L": OMS_CADMIUM_REFERENCE_VALUE,
29
+ "Plomo": CDC_LEAD_REFERENCE_VALUE,
30
+ "Mercurio": EPA_MERCURY_REFERENCE_VALUE,
31
+ "Cadmio": OMS_CADMIUM_REFERENCE_VALUE,
32
+ "pb": CDC_LEAD_REFERENCE_VALUE,
33
+ "hg": EPA_MERCURY_REFERENCE_VALUE,
34
+ "cd": OMS_CADMIUM_REFERENCE_VALUE,
35
+ }
36
+
37
+ # Límites de detección analíticos (LOD) por defecto
38
+ DEFAULT_METAL_LODS: Dict[str, float] = {
39
+ "Plomo_ug_dL": 0.10, # µg/dL
40
+ "Mercurio_ug_L": 0.10, # µg/L
41
+ "Cadmio_ug_L": 0.05, # µg/L
42
+ "Plomo": 0.10,
43
+ "Mercurio": 0.10,
44
+ "Cadmio": 0.05,
45
+ "pb": 0.10,
46
+ "hg": 0.10,
47
+ "cd": 0.05,
48
+ }
49
+
50
+ # Puntos de corte para clasificación toxicológica Bajo / Medio / Alto (Etapa 12)
51
+ # Formato: (corte_bajo_medio, corte_medio_alto)
52
+ # Plomo: Bajo (<1.0 µg/dL), Medio (1.0 a <3.5 µg/dL), Alto (≥3.5 µg/dL - CDC BLRV)
53
+ # Mercurio: Bajo (<1.0 µg/L), Medio (1.0 a <5.0 µg/L), Alto (≥5.0 µg/L - EPA/OMS)
54
+ # Cadmio: Bajo (<0.2 µg/L), Medio (0.2 a <1.0 µg/L), Alto (≥1.0 µg/L - OMS)
55
+ DEFAULT_METAL_CUTOFFS: Dict[str, Tuple[float, float]] = {
56
+ "Plomo_ug_dL": (1.0, CDC_LEAD_REFERENCE_VALUE),
57
+ "Mercurio_ug_L": (1.0, EPA_MERCURY_REFERENCE_VALUE),
58
+ "Cadmio_ug_L": (0.2, OMS_CADMIUM_REFERENCE_VALUE),
59
+ "Plomo": (1.0, CDC_LEAD_REFERENCE_VALUE),
60
+ "Mercurio": (1.0, EPA_MERCURY_REFERENCE_VALUE),
61
+ "Cadmio": (0.2, OMS_CADMIUM_REFERENCE_VALUE),
62
+ "pb": (1.0, CDC_LEAD_REFERENCE_VALUE),
63
+ "hg": (1.0, EPA_MERCURY_REFERENCE_VALUE),
64
+ "cd": (0.2, OMS_CADMIUM_REFERENCE_VALUE),
65
+ }
66
+
67
+ # Pares de Co-Exposición Metal-Metal (Etapa 11)
68
+ DEFAULT_METAL_PAIRS: List[Tuple[str, str]] = [
69
+ ("Plomo_ug_dL", "Mercurio_ug_L"),
70
+ ("Plomo_ug_dL", "Cadmio_ug_L"),
71
+ ("Mercurio_ug_L", "Cadmio_ug_L"),
72
+ ]
73
+
74
+ # Codificación ordinal de frecuencias de consumo alimenticio (Etapa 7)
75
+ DIET_ORDINAL_MAP: Dict[str, int] = {
76
+ "nunca": 0,
77
+ "rara vez": 1,
78
+ "a veces": 2,
79
+ "frecuentemente": 3,
80
+ "diario": 4,
81
+ }
82
+
83
+ DIET_ORDINAL_LABELS: Dict[int, str] = {
84
+ 0: "Nunca",
85
+ 1: "Rara vez",
86
+ 2: "A veces",
87
+ 3: "Frecuentemente",
88
+ 4: "Diario",
89
+ }
90
+
91
+ # Diccionario de grupos conceptuales de variables para análisis bivariante y tamizaje
92
+ DEFAULT_BIVARIATE_GROUPS: Dict[str, List[str]] = {
93
+ "Variables Sociodemográficas y Antropométricas": [
94
+ "Edad", "Sexo", "Sector", "Institucion", "Peso_kg", "Altura_cm", "IMC"
95
+ ],
96
+ "Factores de Exposición Ambiental y Talleres": [
97
+ "Es_Expuesto",
98
+ "Exposicion_Talleres_carpinteria",
99
+ "Exposicion_Talleres_latoneria",
100
+ "Exposicion_Talleres_mecanico",
101
+ "Exposicion_Industrias_fabrica_metales",
102
+ "Exposicion_Industrias_fabrica_productos_quimicos",
103
+ "Exposicion_Lugares_canale",
104
+ "Exposicion_Lugares_canales",
105
+ "Exposicion_Lugares_estacion_gasolina",
106
+ "Exposicion_Lugares_llenadora_gas_natural",
107
+ "Exposicion_Lugares_rectificadora_motores",
108
+ "Exposicion_Lugares_rios",
109
+ "Exposicion_Cualquier_Taller",
110
+ "Exposicion_Cualquier_Industria",
111
+ "Exposicion_Cualquier_Lugar_Riesgo",
112
+ ],
113
+ "Hábitos de Salud y Fuentes de Agua": [
114
+ "Salud_Agua_filtrada",
115
+ "Salud_Agua_mineral_embotellada",
116
+ "Salud_Agua_pozo_profundo",
117
+ "Salud_Fuma",
118
+ "Salud_Actividad",
119
+ "Salud_Bombillos",
120
+ "Salud_Techo",
121
+ "Salud_Joyeria",
122
+ "Salud_Transporte_caminar",
123
+ "Salud_Transporte_publico",
124
+ "Salud_Transporte_vehiculo",
125
+ "Salud_Suplementos_multivitaminico",
126
+ "Salud_Suplementos_proteico",
127
+ ],
128
+ "Frecuencia de Consumo Dietario (Ordinal 0-4)": [
129
+ "Alim_Pescados",
130
+ "Alim_Carnes",
131
+ "Alim_Tuberculos",
132
+ "Alim_Leguminosas",
133
+ "Alim_Cereales",
134
+ "Alim_Vegetales",
135
+ "Alim_Frutas",
136
+ "Alim_Lacteos",
137
+ "Alim_Huevos",
138
+ "Alim_Bebidas",
139
+ "Alim_Azucar",
140
+ "Alim_Grasas",
141
+ "Alim_Chocolate",
142
+ ],
143
+ "Indicadores y Score del Algoritmo de Riesgo": [
144
+ "Score_Riesgo",
145
+ "Riesgo_Pb",
146
+ "Riesgo_Hg",
147
+ "Riesgo_Cd",
148
+ ],
149
+ }
150
+
151
+ # Etiquetas extendidas bivariantes para presentación
152
+ EXTENDED_BIVARIATE_LABELS: Dict[str, str] = {
153
+ "Exposicion_Cualquier_Taller": "Cualquier Taller en Entorno",
154
+ "Exposicion_Cualquier_Industria": "Cualquier Industria en Entorno",
155
+ "Exposicion_Cualquier_Lugar_Riesgo": "Cualquier Punto Crítico Ambiental",
156
+ "Salud_Cualquier_Agua_Riesgo": "Fuente de Agua no Tratada / Pozo",
157
+ "Score_Riesgo": "Score de Riesgo",
158
+ "Nivel_Riesgo": "Nivel Categórico de Riesgo",
159
+ "Riesgo_Pb": "Riesgo Plomo (Pb)",
160
+ "Riesgo_Hg": "Riesgo Mercurio (Hg)",
161
+ "Riesgo_Cd": "Riesgo Cadmio (Cd)",
162
+ "IMC": "Índice de Masa Corporal (IMC)",
163
+ }
164
+
165
+ DEFAULT_LABELS_MAP.update(EXTENDED_BIVARIATE_LABELS)
166
+
167
+ __all__ = [
168
+ "DEFAULT_PRIMARY_METALS",
169
+ "CDC_LEAD_REFERENCE_VALUE",
170
+ "EPA_MERCURY_REFERENCE_VALUE",
171
+ "OMS_CADMIUM_REFERENCE_VALUE",
172
+ "DEFAULT_METAL_LIMITS",
173
+ "DEFAULT_METAL_LODS",
174
+ "DEFAULT_METAL_CUTOFFS",
175
+ "DEFAULT_METAL_PAIRS",
176
+ "DIET_ORDINAL_MAP",
177
+ "DIET_ORDINAL_LABELS",
178
+ "DEFAULT_BIVARIATE_GROUPS",
179
+ "DEFAULT_LABELS_MAP",
180
+ "DEFAULT_CUSTOM_PARAMS",
181
+ "DEFAULT_PERMISSIBLE_LIMITS",
182
+ "get_label",
183
+ ]