-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHypothesisTesting.js
More file actions
72 lines (61 loc) · 2.55 KB
/
HypothesisTesting.js
File metadata and controls
72 lines (61 loc) · 2.55 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
function performHypothesisTest() {
event.preventDefault(); // Prevent form submission
// Get input values
var sampleMeanInput = document.getElementById('sampleMean');
var populationMeanInput = document.getElementById('populationMean');
var sampleStdDevInput = document.getElementById('sampleStdDev');
var sampleSizeInput = document.getElementById('sampleSize');
var significanceLevelInput = document.getElementById('significanceLevel');
var sampleMean = parseFloat(sampleMeanInput.value);
var populationMean = parseFloat(populationMeanInput.value);
var sampleStdDev = parseFloat(sampleStdDevInput.value);
var sampleSize = parseFloat(sampleSizeInput.value);
var significanceLevel = parseFloat(significanceLevelInput.value);
// Perform hypothesis test
var testStatistic = calculateTestStatistic(sampleMean, populationMean, sampleStdDev, sampleSize);
var criticalValue = calculateCriticalValue(significanceLevel, sampleSize);
var result = performComparison(testStatistic, criticalValue);
// Display result
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = 'Hypothesis Test Result: ' + result;
}
function calculateTestStatistic(sampleMean, populationMean, sampleStdDev, sampleSize) {
// Calculate test statistic (z-score)
var testStatistic = (sampleMean - populationMean) / (sampleStdDev / Math.sqrt(sampleSize));
return testStatistic;
}
function calculateCriticalValue(significanceLevel, sampleSize) {
// Calculate critical value based on significance level
var criticalValue;
if (significanceLevel === 0.01) {
criticalValue = 2.326;
} else if (significanceLevel === 0.05) {
criticalValue = 1.645;
} else if (significanceLevel === 0.10) {
criticalValue = 1.282;
} else {
alert('Invalid significance level.');
return;
}
// Adjust critical value for two-tailed test
criticalValue = Math.abs(criticalValue);
return criticalValue;
}
function performComparison(testStatistic, criticalValue) {
// Compare test statistic with critical value
if (testStatistic > criticalValue) {
return 'Reject the null hypothesis';
}
else {
return 'Fail to reject null hypothesis';
}
}
// FORMULA
function showPopup() {
var popup = document.getElementById('popup');
popup.style.display = 'block';
}
function closePopup() {
var popup = document.getElementById('popup');
popup.style.display = 'none';
}