`;
};
// --- PDF DOWNLOAD ---
downloadPdfBtn.addEventListener('click', () => {
if (!lastResults.type) {
alert("Please run a test before downloading results.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(22);
doc.text('Hypothesis Test Results', 105, 20, { align: 'center' });
doc.setFontSize(16);
doc.text(lastResults.type, 105, 28, { align: 'center' });
if (lastResults.type === 'T-Test') {
const { tStatistic, df, criticalT, isSignificant, mean1, mean2, n1, n2 } = lastResults.data;
doc.autoTable({
startY: 40,
head: [['Metric', 'Value']],
body: [
['Test Type', 'Independent Samples T-Test'],
['Group 1 Sample Size (n1)', n1],
['Group 1 Mean', mean1.toFixed(3)],
['Group 2 Sample Size (n2)', n2],
['Group 2 Mean', mean2.toFixed(3)],
['T-Statistic', tStatistic.toFixed(3)],
['Degrees of Freedom', df],
['Conclusion', `Statistically ${isSignificant ? 'Significant' : 'Not Significant'} (p < 0.05)`]
]
});
} else if (lastResults.type === 'Chi-Squared Test') {
const { chiSquared, df, criticalChi, isSignificant } = lastResults.data;
doc.autoTable({
startY: 40,
head: [['Metric', 'Value']],
body: [
['Test Type', 'Chi-Squared Test of Independence'],
['Chi-Squared (χ²) Value', chiSquared.toFixed(3)],
['Degrees of Freedom', df],
['Conclusion', `Statistically ${isSignificant ? 'Significant' : 'Not Significant'} (p < 0.05)`]
]
});
}
doc.save('statistical-test-results.pdf');
});
});
