-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
1077 lines (887 loc) · 42.1 KB
/
app.js
File metadata and controls
1077 lines (887 loc) · 42.1 KB
1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ========================================
// APP PRINCIPAL - COORDINADOR DE INTERFAZ
// ========================================
// ========================================
// NAVEGACIÓN
// ========================================
document.addEventListener('DOMContentLoaded', function () {
inicializarApp();
});
function inicializarApp() {
configurarNavegacion();
configurarGenerador();
configurarAnalizador();
}
function configurarNavegacion() {
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
// Actualizar navegación activa
navLinks.forEach(l => l.classList.remove('active'));
this.classList.add('active');
// Mostrar sección correspondiente
document.querySelectorAll('.section').forEach(section => {
section.classList.remove('active');
});
document.getElementById(targetId).classList.add('active');
});
});
}
// ========================================
// CONFIGURACIÓN DEL GENERADOR
// ========================================
function configurarGenerador() {
// Botón agregar prueba
document.getElementById('btnAgregarPrueba').addEventListener('click', agregarFilaPrueba);
// Botón agregar sociodemográfico
document.getElementById('btnAgregarSocio').addEventListener('click', agregarFilaSocio);
// Botón generar base de datos
document.getElementById('btnGenerar').addEventListener('click', generarBaseDatos);
// Botón descargar CSV
document.getElementById('btnDescargarCSV').addEventListener('click', descargarCSV);
// Botones importar/exportar pruebas
document.getElementById('btnImportarPruebas').addEventListener('click', () => {
document.getElementById('importPruebasInput').click();
});
document.getElementById('btnExportarPruebas').addEventListener('click', exportarConfigPruebas);
document.getElementById('importPruebasInput').addEventListener('change', importarConfigPruebas);
// Botones importar/exportar sociodemográficos
document.getElementById('btnImportarSocio').addEventListener('click', () => {
document.getElementById('importSocioInput').click();
});
document.getElementById('btnExportarSocio').addEventListener('click', exportarConfigSocio);
document.getElementById('importSocioInput').addEventListener('change', importarConfigSocio);
// Delegación de eventos para botones de eliminar
document.getElementById('bodyPruebas').addEventListener('click', function (e) {
if (e.target.closest('.btn-delete')) {
eliminarFilaPrueba(e.target.closest('tr'));
}
});
document.getElementById('bodySocio').addEventListener('click', function (e) {
if (e.target.closest('.btn-delete')) {
eliminarFilaSocio(e.target.closest('tr'));
}
});
}
function agregarFilaPrueba() {
const tbody = document.getElementById('bodyPruebas');
const nuevaFila = tbody.querySelector('.fila-prueba').cloneNode(true);
// Limpiar valores
nuevaFila.querySelectorAll('input').forEach(input => {
input.value = '';
});
tbody.appendChild(nuevaFila);
mostrarToast('Fila agregada', 'success');
}
function eliminarFilaPrueba(fila) {
const tbody = document.getElementById('bodyPruebas');
const filas = tbody.querySelectorAll('.fila-prueba');
if (filas.length <= 1) {
mostrarToast('Debe haber al menos una prueba', 'warning');
return;
}
fila.remove();
mostrarToast('Fila eliminada', 'success');
}
function agregarFilaSocio() {
const tbody = document.getElementById('bodySocio');
const nuevaFila = tbody.querySelector('.fila-socio').cloneNode(true);
// Limpiar valores
nuevaFila.querySelectorAll('input').forEach(input => {
input.value = '';
});
tbody.appendChild(nuevaFila);
mostrarToast('Variable agregada', 'success');
}
function eliminarFilaSocio(fila) {
const tbody = document.getElementById('bodySocio');
const filas = tbody.querySelectorAll('.fila-socio');
if (filas.length <= 1) {
mostrarToast('Debe haber al menos una variable sociodemográfica', 'warning');
return;
}
fila.remove();
mostrarToast('Variable eliminada', 'success');
}
function generarBaseDatos() {
try {
// Recolectar configuración
generadorDatos.recolectarConfiguracion();
// Validar
const validacion = generadorDatos.validarConfiguracion();
if (validacion.errores.length > 0) {
mostrarToast('Error: ' + validacion.errores[0], 'error');
return;
}
if (validacion.advertencias.length > 0) {
console.warn('Advertencias:', validacion.advertencias);
}
// Generar datos
mostrarToast('Generando base de datos...', 'success');
setTimeout(() => {
const datos = generadorDatos.generarBaseDatos();
mostrarPreview(datos);
habilitarDescargaCSV();
habilitarUsarGenerados();
mostrarToast('¡Base de datos generada exitosamente!', 'success');
}, 300);
} catch (error) {
mostrarToast(error.message, 'error');
console.error(error);
}
}
function mostrarPreview(datos) {
const container = document.getElementById('previewContainer');
const config = generadorDatos.obtenerConfiguracion();
// Actualizar estadísticas
document.getElementById('statParticipantes').textContent = datos.length;
document.getElementById('statVariables').textContent = Object.keys(datos[0]).length;
document.getElementById('statPruebas').textContent = config.pruebas.length;
// Crear tabla preview (solo primeras 10 filas)
const thead = document.getElementById('previewHead');
const tbody = document.getElementById('previewBody');
// Limpiar
thead.innerHTML = '';
tbody.innerHTML = '';
// Encabezados
const columnas = Object.keys(datos[0]);
const filaEncabezados = document.createElement('tr');
columnas.forEach(col => {
const th = document.createElement('th');
th.textContent = col;
filaEncabezados.appendChild(th);
});
thead.appendChild(filaEncabezados);
// Datos (máximo 10 filas)
const maxFilas = Math.min(10, datos.length);
for (let i = 0; i < maxFilas; i++) {
const fila = document.createElement('tr');
columnas.forEach(col => {
const td = document.createElement('td');
const valor = datos[i][col];
td.textContent = typeof valor === 'number' ? valor.toFixed(2) : valor;
fila.appendChild(td);
});
tbody.appendChild(fila);
}
// Mostrar container
container.style.display = 'block';
// Scroll suave hacia el preview
container.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
function habilitarDescargaCSV() {
const btn = document.getElementById('btnDescargarCSV');
btn.disabled = false;
}
function descargarCSV() {
try {
generadorDatos.descargarCSV();
mostrarToast('CSV descargado exitosamente', 'success');
} catch (error) {
mostrarToast(error.message, 'error');
}
}
function habilitarUsarGenerados() {
const btn = document.getElementById('btnUsarGenerados');
btn.disabled = false;
}
// ========================================
// CONFIGURACIÓN DEL ANALIZADOR
// ========================================
function configurarAnalizador() {
// Botón usar datos generados
document.getElementById('btnUsarGenerados').addEventListener('click', cargarDatosGenerados);
// Input file CSV
document.getElementById('fileInput').addEventListener('change', cargarArchivoCSV);
// Botón analizar
document.getElementById('btnAnalizar').addEventListener('click', ejecutarAnalisis);
// Botón descargar resultados
document.getElementById('btnDescargarResultados').addEventListener('click', descargarResultados);
}
function cargarDatosGenerados() {
try {
// Verificar que AnalizadorEstadistico esté disponible
//if (typeof AnalizadorEstadistico === 'undefined') {
// mostrarToast('Error: El analizador estadístico no está cargado. Recarga la página.', 'error');
// return;
//}
const datos = generadorDatos.obtenerDatosGenerados();
if (!datos || datos.length === 0) {
mostrarToast('No hay datos generados. Genera una base de datos primero.', 'warning');
return;
}
if (typeof window.AnalizadorEstadistico === 'undefined') {
mostrarToast('Error: AnalizadorEstadistico indefinido', 'error');
return;
}
window.AnalizadorEstadistico.cargarDatos(datos);
mostrarDatosCargados(datos);
mostrarToast('Datos cargados exitosamente', 'success');
} catch (error) {
mostrarToast(error.message, 'error');
}
}
function cargarArchivoCSV(e) {
const file = e.target.files[0];
if (!file) return;
if (!file.name.endsWith('.csv')) {
mostrarToast('Por favor selecciona un archivo CSV', 'error');
return;
}
const reader = new FileReader();
reader.onload = function (event) {
try {
const csvText = event.target.result;
AnalizadorEstadistico.cargarDesdeCSV(csvText);
mostrarDatosCargados(AnalizadorEstadistico.obtenerDatos());
mostrarToast('Archivo CSV cargado exitosamente', 'success');
} catch (error) {
mostrarToast(error.message, 'error');
}
};
reader.readAsText(file);
}
function mostrarDatosCargados(datos) {
const container = document.getElementById('datosContainer');
const seleccionContainer = document.getElementById('seleccionContainer');
// Actualizar estadísticas
document.getElementById('analisisN').textContent = datos.length;
document.getElementById('analisisVars').textContent = Object.keys(datos[0]).length;
// Crear tabla (primeras 10 filas)
const thead = document.getElementById('analisisHead');
const tbody = document.getElementById('analisisBody');
thead.innerHTML = '';
tbody.innerHTML = '';
const columnas = Object.keys(datos[0]);
// Encabezados
const filaEncabezados = document.createElement('tr');
columnas.forEach(col => {
const th = document.createElement('th');
th.textContent = col;
filaEncabezados.appendChild(th);
});
thead.appendChild(filaEncabezados);
// Datos
const maxFilas = Math.min(10, datos.length);
for (let i = 0; i < maxFilas; i++) {
const fila = document.createElement('tr');
columnas.forEach(col => {
const td = document.createElement('td');
const valor = datos[i][col];
td.textContent = typeof valor === 'number' ? valor.toFixed(2) : valor;
fila.appendChild(td);
});
tbody.appendChild(fila);
}
// Poblar selectores de variables (solo columnas numéricas)
const columnasNumericas = columnas.filter(col => {
return typeof datos[0][col] === 'number' || !isNaN(parseFloat(datos[0][col]));
});
const select1 = document.getElementById('variable1');
const select2 = document.getElementById('variable2');
select1.innerHTML = '<option value="">Seleccionar variable...</option>';
select2.innerHTML = '<option value="">Seleccionar variable...</option>';
columnasNumericas.forEach(col => {
if (typeof col !== "string") {
mostrarToast('Las columnas deben ser de tipo string', 'error');
return;
}
const option1 = document.createElement('option');
option1.value = col.trim();
option1.textContent = col.trim();
select1.appendChild(option1);
const option2 = document.createElement('option');
option2.value = col.trim();
option2.textContent = col.trim();
select2.appendChild(option2);
});
// Mostrar containers
container.style.display = 'block';
seleccionContainer.style.display = 'block';
// Scroll
container.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
function ejecutarAnalisis() {
try {
const var1 = document.getElementById('variable1').value;
const var2 = document.getElementById('variable2').value;
const tipoPrueba = document.querySelector('input[name="tipoPrueba"]:checked').value;
if (!var1 || !var2) {
mostrarToast('Por favor selecciona ambas variables', 'warning');
return;
}
if (var1 === var2) {
mostrarToast('Las variables deben ser diferentes', 'warning');
return;
}
mostrarToast('Ejecutando análisis...', 'success');
setTimeout(() => {
// Contexto de investigación
const unidadAnalisis = document.getElementById('unidadAnalisis').value;
const lugarContexto = document.getElementById('lugarContexto').value;
console.log("Unidad (texto):", unidadAnalisis);
console.log("Contexto (texto):", lugarContexto);
// Marco metodológico
const marco = AnalizadorEstadistico.generarMarcoMetodologico(var1, var2, unidadAnalisis, lugarContexto);
// Calcular correlación
const resultado = AnalizadorEstadistico.calcularCorrelacion(var1, var2, tipoPrueba);
// Generar todas las secciones dinámicamente
mostrarMarcoMetodologico(marco);
mostrarPruebasNormalidad(var1, var2, resultado);
mostrarCorrelacion(var1, var2, resultado);
mostrarDecision(var1, var2, resultado);
mostrarDiscusion(var1, var2, resultado);
// Mostrar referencias bibliográficas
mostrarReferencias(var1, var2, resultado);
mostrarToast('Análisis completado exitosamente', 'success');
}, 300);
} catch (error) {
mostrarToast(error.message, 'error');
console.error(error);
}
}
function mostrarMarcoMetodologico(marco) {
const container = document.getElementById('marcoMetodologicoContainer');
if (!container) {
console.warn('No existe elemento #marcoMetodologicoContainer en el HTML');
return;
}
let html = `
<div class="result-section">
<h3 class="section-title">📋 Marco Metodológico</h3>
<div class="result-box">
<h4 class="result-subtitle">❓ Pregunta de Investigación</h4>
<p class="marco-text">${marco.preguntaInvestigacion}</p>
</div>
<div class="result-box">
<h4 class="result-subtitle">🎯 Objetivo General</h4>
<p class="marco-text">${marco.objetivoGeneral}</p>
</div>
<div class="result-box">
<h4 class="result-subtitle">📋 Objetivos Específicos</h4>
<ol class="marco-list">
${marco.objetivosEspecificos.map(obj => `<li>${obj}</li>`).join('')}
</ol>
</div>
<div class="result-box">
<h4 class="result-subtitle">💡 Hipótesis de Investigación (H₁)</h4>
<p class="marco-text">${marco.hipotesis.hipotesisInvestigador}</p>
</div>
<div class="result-box">
<h4 class="result-subtitle">❌ Hipótesis Nula (H₀)</h4>
<p class="marco-text">${marco.hipotesis.hipotesisNula}</p>
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function mostrarPruebasNormalidad(var1, var2, resultado) {
const container = document.getElementById('pruebasNormalidadContainer');
if (!container) {
console.warn('No existe elemento #pruebasNormalidadContainer en el HTML');
return;
}
const html = `
<div class="result-section">
<h3 class="section-title">Pruebas de normalidad</h3>
<p class="result-subtitle">Hernández-Sampieri & Mendoza (2023) establecen que el tamaño muestral es el criterio decisivo para elegir la prueba de normalidad adecuada, porque cada una tiene sensibilidad diferente según el volumen de datos. Por un lado, Shapiro-Wilk es la prueba más potente parar muestras pequeñas (menor a 50 datos). Por otro lado, Kolmogorov-Smirnov es recomendable aplicarla con muestras mayores a 50. Es decir, el criterio metodológico en la selección de la prueba depende del cumplimiento del supuesto muestral.</p>
<div class="result-box" style="margin-bottom: 1rem;">
<h5 style="margin-bottom: 0.5rem; font-weight: 600;">Variable: ${var1}</h5>
<table class="result-table">
<tr>
<td>Prueba utilizada:</td>
<td><strong>${resultado.normalidad1.prueba}</strong> (${resultado.normalidad1.razon})</td>
</tr>
<tr>
<td>Estadístico:</td>
<td>${resultado.normalidad1.estadistico.toFixed(4)}</td>
</tr>
<tr>
<td>p-valor:</td>
<td>${resultado.normalidad1.pValor.toFixed(4)}</td>
</tr>
<tr>
<td>Decisión:</td>
<td><strong>${resultado.normalidad1.decision}</strong></td>
</tr>
</table>
</div>
<div class="result-box">
<h5 style="margin-bottom: 0.5rem; font-weight: 600;">Variable: ${var2}</h5>
<table class="result-table">
<tr>
<td>Prueba utilizada:</td>
<td><strong>${resultado.normalidad2.prueba}</strong> (${resultado.normalidad2.razon})</td>
</tr>
<tr>
<td>Estadístico:</td>
<td>${resultado.normalidad2.estadistico.toFixed(4)}</td>
</tr>
<tr>
<td>p-valor:</td>
<td>${resultado.normalidad2.pValor.toFixed(4)}</td>
</tr>
<tr>
<td>Decisión:</td>
<td><strong>${resultado.normalidad2.decision}</strong></td>
</tr>
</table>
</div>
<!-- Interpretación de Normalidad -->
<div class="result-box interpretation-box" style="background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border-left: 4px solid #3b82f6; padding: 1.5rem; margin-top: 1rem;">
<h5 style="margin-bottom: 0.75rem; color: #1e40af; font-weight: 600; display: flex; align-items: center;">
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor" style="margin-right: 0.5rem;">
<path d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"/>
</svg>
Interpretación Estadística
</h5>
<p style="margin: 0; line-height: 1.8; text-align: justify; color: #1e293b;">
${InterpretacionesEstadisticas.generarInterpretacionNormalidad(var1, var2, resultado)}
</p>
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function mostrarCorrelacion(var1, var2, resultado) {
const container = document.getElementById('resultadosCorrelacion');
if (!container) return;
const html = `
<div class="result-section">
<h3 class="section-title">Análisis de Correlación</h3>
<p class="result-subtitle">El análisis de correlación permite medir la fuerza y dirección de la relación entre dos variables cuantitativas. Según Hernández, Fernández & Baptista (2010), el coeficiente de correlación de Pearson es adecuado cuando ambas variables siguen una distribución normal, mientras que el coeficiente de correlación de Spearman es preferible cuando al menos una variable no cumple con la normalidad. Es decir, la elección del coeficiente no es arbitraria, depende estrictamente del cumplimiento del supuesto de normalidad previamente validado. La interpretación del coeficiente varía desde -1 (correlación negativa perfecta) hasta +1 (correlación positiva perfecta), siendo 0 indicativo de ausencia de correlación.</p>
<div class="result-box">
<table class="result-table">
<tr>
<td>Variables:</td>
<td><strong>${var1} - ${var2}</strong></td>
</tr>
<tr>
<td>N:</td>
<td>${resultado.n}</td>
</tr>
<tr>
<td>Coeficiente utilizado:</td>
<td><strong>${resultado.tipoCorrelacion}</strong></td>
</tr>
<tr>
<td>Razón:</td>
<td>${resultado.normalidad1.normal && resultado.normalidad2.normal ?
'Ambas variables siguen una distribución normal' :
'Al menos una variable no sigue una distribución normal'}</td>
</tr>
<tr>
<td>Coeficiente (${resultado.tipoCorrelacion === 'Pearson' ? 'r' : 'ρ'}):</td>
<td><strong style="font-size: 1.1em;">${resultado.coeficiente.toFixed(4)}</strong></td>
</tr>
<tr>
<td>p-valor (${resultado.tipoPrueba}):</td>
<td><strong>${resultado.pValor.toFixed(4)}</strong></td>
</tr>
<tr>
<td>Interpretación:</td>
<td><strong>${resultado.interpretacion.texto}</strong></td>
</tr>
</table>
</div>
<!-- Interpretación de Correlación -->
<div class="result-box interpretation-box" style="background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); border-left: 4px solid #22c55e; padding: 1.5rem; margin-top: 1rem;">
<h5 style="margin-bottom: 0.75rem; color: #15803d; font-weight: 600; display: flex; align-items: center;">
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor" style="margin-right: 0.5rem;">
<path d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"/>
</svg>
Interpretación Estadística
</h5>
<p style="margin: 0; line-height: 1.8; text-align: justify; color: #1e293b;">
${InterpretacionesEstadisticas.generarInterpretacionCorrelacion(var1, var2, resultado)}
</p>
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function mostrarDecision(var1, var2, resultado) {
const container = document.getElementById('resultadosDecision');
if (!container) return;
const prueba = AnalizadorEstadistico.pruebaHipotesis(resultado);
const html = `
<div class="result-section">
<h3 class="section-title">Prueba de Hipótesis</h3>
<p class="result-subtitle">Según Taherdoost (2022), la prueba de hipótesis es un procedimiento estadístico que permite evaluar afirmaciones sobre parámetros poblacionales basándose en datos muestrales. El proceso implica formular una hipótesis nula (H₀) y una hipótesis alternativa (H₁), seleccionar un nivel de significancia (α), calcular un estadístico de prueba y determinar el p-valor asociado. La decisión de rechazar o no rechazar H₀ se basa en la comparación del p-valor con α, proporcionando así una base objetiva para la inferencia estadística.</p>
<div class="result-box">
<table class="result-table">
<tr>
<td>Nivel de significancia (α):</td>
<td><strong>${prueba.alpha}</strong></td>
</tr>
<tr>
<td>p-valor:</td>
<td><strong>${resultado.pValor.toFixed(4)}</strong></td>
</tr>
<tr>
<td>Comparación:</td>
<td>${resultado.pValor.toFixed(4)} ${prueba.decision === 'rechazar' ? '<' : '≥'} ${prueba.alpha}</td>
</tr>
<tr>
<td>Decisión sobre H₀:</td>
<td class="${prueba.decision === 'rechazar' ? 'decision-reject' : 'decision-accept'}">
<strong>${prueba.decision === 'rechazar' ? 'SE RECHAZA H₀' : 'NO SE RECHAZA H₀'}</strong>
</td>
</tr>
<tr>
<td>Conclusión:</td>
<td><strong>${prueba.conclusionH1}</strong></td>
</tr>
</table>
<div style="margin-top: 1rem; padding: 1rem; background-color: #f9f9f9; border-radius: 6px;">
<p style="margin: 0; font-size: 0.9rem; line-height: 1.6;">
${prueba.conclusionH0}
</p>
</div>
</div>
<!-- Interpretación de Prueba de Hipótesis -->
<div class="result-box interpretation-box" style="background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); border-left: 4px solid #f59e0b; padding: 1.5rem; margin-top: 1rem;">
<h5 style="margin-bottom: 0.75rem; color: #b45309; font-weight: 600; display: flex; align-items: center;">
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor" style="margin-right: 0.5rem;">
<path d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z"/>
</svg>
Interpretación Estadística
</h5>
<p style="margin: 0; line-height: 1.8; text-align: justify; color: #1e293b;">
${InterpretacionesEstadisticas.generarInterpretacionHipotesis(var1, var2, resultado, prueba)}
</p>
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function mostrarDiscusion(var1, var2, resultado) {
const container = document.getElementById('resultadosDiscusion');
if (!container) return;
const discusion = AnalizadorEstadistico.generarDiscusion(var1, var2, resultado);
const html = `
<div class="result-section">
<h3 class="section-title">Discusión (Plantilla)</h3>
<div class="discussion-box">
${discusion.replace(/\[(.*?)\]/g, '<span class="highlight">[$1]</span>')}
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function mostrarReferencias(var1, var2, resultado) {
// ✅ DECLARA EL CONTENEDOR PRINCIPAL
const container = document.getElementById('resultadosContainer');
if (!container) {
console.error("No se encontró el contenedor #resultadosContainer");
return;
}
const html = `
<div class="references-container">
<h4 class="result-title">Referencias bibliográficas</h4>
<div class="reference-card">
<p class="reference-text">1. Hernández-Sampieri, R., & Mendoza, C. (2023). Metodología de la investigación: las rutas cuantitativa, cualitativa y mixta. <a href="https://apiperiodico.jalisco.gob.mx/api/sites/periodicooficial.jalisco.gob.mx/files/metodologia_de_la_investigacion_-_roberto_hernandez_sampieri.pdf" target="_blank">https://apiperiodico.jalisco.gob.mx/api/sites/periodicooficial.jalisco.gob.mx/files/metodologia_de_la_investigacion_-_roberto_hernandez_sampieri.pdf</a></p>
</div>
<div class="reference-card">
<p class="reference-text">2. Hernández, D., Fernández, C., & Baptista, M. D. P. (2010). Metodologia de la investigacion 5ta Edicion Sampieri. <a href="https://www.academia.edu/download/46694261/Metodologia_de_la_investigacion_5ta_Edicion_Sampieri___Dulce_Hernandez_-_Academia.edu.pdf" target="_blank">https://www.academia.edu/download/46694261/Metodologia_de_la_investigacion_5ta_Edicion_Sampieri___Dulce_Hernandez_-_Academia.edu.pdf</a></p>
</div>
<div class="reference-card">
<p class="reference-text">3. Taherdoost, H. (2022). What are different research approaches? Comprehensive review of qualitative, quantitative, and mixed method research, their applications, types, and limitations. Journal of Management Science & Engineering Research, 5(1), 53-63. <a href="https://hal.science/hal-03741840/document" target="_blank">https://hal.science/hal-03741840/document</a></p>
</div>
<div class="reference-card">
<p class="reference-text">4. Cohen, J. (2013). Statistical power analysis for the behavioral sciences. routledge. <a href="https://www.taylorfrancis.com/books/mono/10.4324/9780203771587/statistical-power-analysis-behavioral-sciences-jacob-cohen" target="_blank">https://www.taylorfrancis.com/books/mono/10.4324/9780203771587/statistical-power-analysis-behavioral-sciences-jacob-cohen</a></p>
</div>
</div>
`;
container.innerHTML = html;
container.style.display = 'block';
}
function descargarResultados() {
// Obtener el contenido de resultados
const normalidad = document.getElementById('resultadosNormalidad').innerText;
const correlacion = document.getElementById('resultadosCorrelacion').innerText;
const decision = document.getElementById('resultadosDecision').innerText;
const discusion = document.getElementById('resultadosDiscusion').innerText;
const contenido = `
RESULTADOS DEL ANÁLISIS ESTADÍSTICO
====================================
1. PRUEBA DE NORMALIDAD
${normalidad}
2. ANÁLISIS DE CORRELACIÓN
${correlacion}
3. PRUEBA DE HIPÓTESIS
${decision}
4. DISCUSIÓN (PLANTILLA)
${discusion}
----
Generado por StatSim Pro
Fecha: ${new Date().toLocaleDateString()}
`;
const blob = new Blob([contenido], { type: 'text/plain;charset=utf-8;' });
const link = document.createElement('a');
if (link.download !== undefined) {
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', 'resultados_analisis.txt');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
mostrarToast('Resultados descargados', 'success');
}
// ========================================
// UTILIDADES
// ========================================
function mostrarToast(mensaje, tipo = 'success') {
const toast = document.getElementById('toast');
toast.textContent = mensaje;
toast.className = `toast ${tipo}`;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
// ========================================
// FORMATEO DE NÚMEROS
// ========================================
function formatearNumero(numero, decimales = 2) {
return Number(numero).toFixed(decimales);
}
function formatearPValor(p) {
if (p < 0.001) return '< .001';
if (p < 0.01) return p.toFixed(3);
return p.toFixed(4);
}
// ========================================
// IMPORTAR/EXPORTAR CONFIGURACIONES
// ========================================
// PRUEBAS APLICADAS
function exportarConfigPruebas() {
try {
const filas = document.querySelectorAll('#bodyPruebas .fila-prueba');
if (filas.length === 0) {
mostrarToast('No hay pruebas para exportar', 'warning');
return;
}
// Crear CSV con encabezados
let csv = 'Nombre,NumItems,Media,DE,MinItem,MaxItem\n';
filas.forEach(fila => {
const inputs = fila.querySelectorAll('input');
const nombre = inputs[0].value.trim() || '';
const numItems = inputs[1].value || '';
const media = inputs[2].value || '';
const de = inputs[3].value || '';
const min = inputs[4].value || '';
const max = inputs[5].value || '';
// Escapar valores con comas
const nombreEscapado = nombre.includes(',') ? `"${nombre}"` : nombre;
csv += `${nombreEscapado},${numItems},${media},${de},${min},${max}\n`;
});
// Descargar archivo
descargarArchivo(csv, 'configuracion_pruebas.csv', 'text/csv');
mostrarToast('Configuración de pruebas exportada exitosamente', 'success');
} catch (error) {
mostrarToast('Error al exportar: ' + error.message, 'error');
}
}
function importarConfigPruebas(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (event) {
try {
const csv = event.target.result;
const lineas = csv.trim().split('\n');
if (lineas.length < 2) {
mostrarToast('El archivo CSV está vacío o no tiene datos', 'error');
return;
}
// Verificar encabezados
const encabezados = lineas[0].toLowerCase();
if (!encabezados.includes('nombre') || !encabezados.includes('numitems')) {
mostrarToast('El archivo CSV no tiene el formato correcto. Encabezados esperados: Nombre,NumItems,Media,DE,MinItem,MaxItem', 'error');
return;
}
// Limpiar tabla actual
const tbody = document.getElementById('bodyPruebas');
tbody.innerHTML = '';
// Procesar cada línea (saltar encabezados)
for (let i = 1; i < lineas.length; i++) {
const linea = lineas[i].trim();
if (!linea) continue;
const valores = parsearLineaCSV(linea);
if (valores.length >= 4) {
agregarFilaPruebaConDatos({
nombre: valores[0] || '',
numItems: valores[1] || '',
media: valores[2] || '',
de: valores[3] || '',
min: valores[4] || '',
max: valores[5] || ''
});
}
}
mostrarToast(`Configuración importada: ${lineas.length - 1} pruebas`, 'success');
} catch (error) {
mostrarToast('Error al importar: ' + error.message, 'error');
}
};
reader.readAsText(file);
e.target.value = ''; // Limpiar input
}
function agregarFilaPruebaConDatos(datos) {
const tbody = document.getElementById('bodyPruebas');
const nuevaFila = document.createElement('tr');
nuevaFila.className = 'fila-prueba';
nuevaFila.innerHTML = `
<td><input type="text" class="input input-sm" placeholder="Ej: WAIS-IV" maxlength="100" value="${datos.nombre}"></td>
<td><input type="number" class="input input-sm" placeholder="Ej: 60" min="1" value="${datos.numItems}"></td>
<td><input type="number" class="input input-sm" placeholder="Ej: 100" step="0.01" value="${datos.media}"></td>
<td><input type="number" class="input input-sm" placeholder="Ej: 15" step="0.01" min="0.01" value="${datos.de}"></td>
<td><input type="number" class="input input-sm" placeholder="Ej: 0" step="1" value="${datos.min}"></td>
<td><input type="number" class="input input-sm" placeholder="Ej: 5" step="1" value="${datos.max}"></td>
<td>
<button class="btn-icon btn-delete" title="Eliminar">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<path d="M3 4H13M5 4V3C5 2.44772 5.44772 2 6 2H10C10.5523 2 11 2.44772 11 3V4M6 7V11M10 7V11M4 4H12L11.5 13C11.5 13.5523 11.0523 14 10.5 14H5.5C4.94772 14 4.5 13.5523 4.5 13L4 4Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
</svg>
</button>
</td>
`;
tbody.appendChild(nuevaFila);
}
// SOCIODEMOGRÁFICOS
function exportarConfigSocio() {
try {
const filas = document.querySelectorAll('#bodySocio .fila-socio');
if (filas.length === 0) {
mostrarToast('No hay variables sociodemográficas para exportar', 'warning');
return;
}
// Crear CSV con encabezados
let csv = 'Categoria,Promedio,DE,Minimo,Maximo,Decimales\n';
filas.forEach(fila => {
const inputs = fila.querySelectorAll('input');
const categoria = inputs[0].value.trim() || '';
const promedio = inputs[1].value || '';
const de = inputs[2].value || '';
const min = inputs[3].value || '';
const max = inputs[4].value || '';
const decimales = inputs[5].value || '';
// Escapar valores con comas
const categoriaEscapada = categoria.includes(',') ? `"${categoria}"` : categoria;
csv += `${categoriaEscapada},${promedio},${de},${min},${max},${decimales}\n`;
});
// Descargar archivo
descargarArchivo(csv, 'configuracion_sociodemograficos.csv', 'text/csv');
mostrarToast('Configuración de sociodemográficos exportada exitosamente', 'success');
} catch (error) {
mostrarToast('Error al exportar: ' + error.message, 'error');
}
}
function importarConfigSocio(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (event) {
try {
const csv = event.target.result;
const lineas = csv.trim().split('\n');
if (lineas.length < 2) {
mostrarToast('El archivo CSV está vacío o no tiene datos', 'error');
return;
}
// Verificar encabezados
const encabezados = lineas[0].toLowerCase();
if (!encabezados.includes('categoria') || !encabezados.includes('promedio')) {
mostrarToast('El archivo CSV no tiene el formato correcto. Encabezados esperados: Categoria,Promedio,DE,Minimo,Maximo,Decimales', 'error');
return;
}
// Limpiar tabla actual
const tbody = document.getElementById('bodySocio');
tbody.innerHTML = '';
// Procesar cada línea (saltar encabezados)
for (let i = 1; i < lineas.length; i++) {
const linea = lineas[i].trim();
if (!linea) continue;
const valores = parsearLineaCSV(linea);
if (valores.length >= 3) {
agregarFilaSocioConDatos({
categoria: valores[0] || '',
promedio: valores[1] || '',
de: valores[2] || '',
min: valores[3] || '',
max: valores[4] || '',