-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
543 lines (502 loc) · 25.3 KB
/
index.html
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
<html>
<head>
<title>Normal Probability Distribution Graph Interactive</title>
<meta name="description"
content="You can explore how the normal curve and the z-table are related in this JSXGraph applet.">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=AM_HTMLorMML" id=""></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<link rel="stylesheet" href="./css/app.css" type="text/css">
<body>
<div class="contain">
<div
style="visibility: hidden; overflow: hidden; position: absolute; top: 0px; height: 1px; width: auto; padding: 0px; border: 0px; margin: 0px; text-align: left; text-indent: 0px; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal;">
<div id="MathJax_Hidden"></div>
</div>
<div id="MathJax_Message" style="display: none;"></div>
<h1>Normal Probability Distribution Graph Interactive</h1>
<div class="interactive">
<form id="options">
<!-- svg gets built here -->
<div id="jxgbox1" class="explanation" style="overflow: hidden; position: relative;">
</div>
<!-- controls under graph -->
<div id="output">
<p class="options"><input type="checkbox" name="checkboxname" value="sncurve" id="sncurve"> <label
for="sncurve">Show standard normal curve</label>
<input type="checkbox" name="checkboxname" value="sdgraph" id="sdgraph" checked="checked"> <label
for="sdgraph">Show standard deviations</label></p>
<p id="musig"><span id="muOutput" class="intmath">
μ = mean = <input id='muX_box' type='number' value=4.0000 step="0.1"> σ = standard deviation = <input id='sig_box' type='number' value=1.5000 step="0.1">
</span> <span id="sigmaOutput" class="intmath"></span></p>
<p class="check2"><input type="checkbox" name="checkboxname" value="zscorecalc" id="zscorecalc"> <label
for="zscorecalc">Show <span class="MathJax_Preview"
style="color: inherit; display: none;"></span><span class="MathJax"
id="MathJax-Element-1-Frame" tabindex="0"
data-mathml="<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mi>z</mi></mstyle></math>"
role="presentation" style="position: relative;">
<nobr aria-hidden="true"><span class="math" id="MathJax-Span-1"
style="width: 0.471em; display: inline-block;"><span
style="display: inline-block; position: relative; width: 0.404em; height: 0px; font-size: 104%;"><span
style="position: absolute; clip: rect(1.94em, 1000.4em, 2.808em, -999.997em); top: -2.534em; left: 0em;"><span
class="mrow" id="MathJax-Span-2"><span class="mstyle"
id="MathJax-Span-3"><span class="mrow" id="MathJax-Span-4"><span
class="mi" id="MathJax-Span-5"
style="font-family: STIXGeneral-Italic;">z</span></span></span></span><span
style="display: inline-block; width: 0px; height: 2.541em;"></span></span></span><span
style="display: inline-block; overflow: hidden; vertical-align: -0.135em; border-left: 0px solid; width: 0px; height: 0.698em;"></span></span>
</nobr><span class="MJX_Assistive_MathML" role="presentation"><math
xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mi>z</mi>
</mstyle>
</math></span>
</span>
<script type="math/asciimath" id="MathJax-Element-1">z</script>-score calculations
</label></p>
<p id="zscores" style="display: none;"><span id="z1ScoreCalc"></span> <span id="z2ScoreCalc"></span></p>
<p class="check2"><input type="checkbox" name="checkboxname" value="probcalc" id="probcalc"> <label
for="probcalc">Show probability calculation</label></p>
<p><span id="probOutput" class="intmath" style="display: none;"></span></p>
</div>
</form>
</div>
</div>
<script type="text/javascript" src="./js/jsxgraphcore.js"></script>
<script type="text/javascript">
$(function () {
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
var a, bell, chk, segArr = [],
ptArr = [],
bellArr = [];
var mu = 4,
sigma = 1.5;
var bell = function (x) {
return 1 / (sigma * Math.sqrt(2 * Math.PI)) * Math.exp(-1 * Math.pow((x - mu), 2) / (2 *
Math.pow(sigma, 2)));
};
var bellStand = function (x) {
return 1 / (Math.sqrt(2 * Math.PI)) * Math.exp(-1 * Math.pow((x), 2) / (2));
};
var graphStart, graphEnd;
var graphWidth = Math.abs(graphStart) + Math.abs(graphEnd);
var glid_mu;
var showSNcurve = 1,
bellCurveStand, areaS;
var muOut, sigmaOut, z1Score, z2Score;
plot = function () {
JXG.Options.curve.highlight = false;
graphStart = mu - 3.5 * sigma;
graphEnd = mu + 3.5 * sigma;
board = JXG.JSXGraph.initBoard("jxgbox1", {
showNavigation: false,
showCopyright: false,
boundingbox: [-3, 0.82, graphEnd, -0.15],
axis: false
});
var axs = board.create("line", [
[0, 0],
[1, 0]
], {
strokecolor: "#102535",
strokeWidth: 2,
highlight: false,
fixed: true
});
var xticks = Math.pow(10, (Math.ceil(Math.log(sigma / 5) / Math.log(10))));
board.createElement("ticks", [axs, xticks], {
highlight: false,
drawLabels: true,
label: {
offset: [-2, -14]
},
needsRegularUpdate: false
});
var yaxs = board.create("segment", [
[0, 0],
[0, 10]
], {
strokecolor: "#102535",
highlight: false,
strokeWidth: 2,
fixed: true
});
var yticks;
if (1 / (sigma * Math.sqrt(2 * Math.PI)) > 0.1) {
yticks = 0.1;
} else {
yticks = 0.01;
}
board.createElement("ticks", [yaxs, yticks], {
drawLabels: true,
label: {
offset: [-30, 0]
},
needsRegularUpdate: false
});
// LRD4 – Change these values for the bell curve style. Can add/change attributes like strokeWidth; strokeColor; etc.
var bellCurve = board.create("functiongraph", [bell, -20, 20], {
strokeWidth: 3,
strokeColor: "#529CEE",
highlight: false,
dash: 0
});
for (i = -3; i < 4; i++) {
ptArr[i] = board.create("point", [i * sigma + mu, 0], {
visible: false,
name: ''
});
// LRD3 - Change these values to alter the styling of the bell curve points
bellArr[i] = board.create("point", [i * sigma + mu, bell(i * sigma + mu)], {
visible: false,
name: '',
fillColor: "#005A9C",
strokeColor: "#005A9C"
});
// LRD1 – Change these values to style the dashed vertical lines under the bell curve
segArr[i] = board.create("segment", [ptArr[i], bellArr[i]], {
strokeWidth: 2,
dash: 2,
color: "#529CEE",
fixed: true
});
}
// LRD5 - Bottom slider styling
var line0 = board.create('line', [
[0, -0.1],
[1, -0.1]
], {
strokeWidth: 2,
strokeOpacity: 1,
strokeColor: '#000',
highlight: false,
fixed: true
});
//left slider handle
var glid_x1 = board.create('glider', [3, -0.1, line0], {
name: '<i>x</i><sub>1</sub>',
showInfobox: false,
fillColor: "#005A9C",
strokeColor: "white",
strokeWidth: 5,
size: 6,
});
//right slider handle
var glid_x2 = board.create('glider', [5.5, -0.1, line0], {
name: '<i>x</i><sub>2</sub>',
showInfobox: false,
fillColor: "#005A9C",
strokeColor: "white",
strokeWidth: 5,
size: 6,
});
showProbs = function () {
//board.suspendUpdate();
var ints = 10;
a1 = Math.abs(JXG.Math.Numerics.NewtonCotes([glid_x1.X(), mu], bell, {
number_of_nodes: ints,
integration_type: "simpson"
}));
a2 = Math.abs(JXG.Math.Numerics.NewtonCotes([mu, glid_x2.X()], bell, {
number_of_nodes: ints,
integration_type: "simpson"
}));
if (glid_x1.X() < mu && glid_x2.X() > mu) {
$("#probOutput").html(
"Probability = P(<i>z</i><sub>1</sub>) + P(<i>z</i><sub>2</sub>) = " +
a1.toFixed(4) + " + " + a2.toFixed(4) + " = " + ((a1 + a2).toFixed(4)));
} else if (glid_x1.X() == mu || glid_x2.X() == mu) {
$("#probOutput").text("Probability = " + ((a1 + a2).toFixed(4)));
} else if (glid_x1.X() < mu && glid_x2.X() < mu) {
$("#probOutput").html(
"Probability = P(<i>z</i><sub>1</sub>) − P(<i>z</i><sub>2</sub>)=" +
a1.toFixed(4) + " − " + a2.toFixed(4) + " = " + ((a1 - a2)
.toFixed(4)));
} else {
$("#probOutput").html(
"Probability = P(<i>z</i><sub>2</sub>) − P(<i>z</i><sub>1</sub>) = " +
a2.toFixed(4) + " − " + a1.toFixed(4) + " = " + ((a2 - a1)
.toFixed(4)));
}
//board.unsuspendUpdate();
}
var line1 = board.create('line', [
[0, 0.5],
[1, 0.5]
], {
//LRD6 - Change these values to alter the styling of the line the red dots are on at the top of the graph
strokeWidth: 1,
strokeOpacity: .2,
strokeColor: '#000',
highlight: false,
fixed: true
});
var glid_mu = board.create('glider', [mu, 0.5, line1], {
name: 'μ',
showInfobox: false
});
var glid_sig = board.create('glider', [glid_mu.X() + sigma, 0.5, line1], {
name: 'σ',
showInfobox: false
});
muOut = $("#muOutput");
sigmaOut = $("#sigmaOutput");
z1Score = ("#z1ScoreCalc");
z2Score = ("#z1ScoreCalc");
var muBox = $("#muX_box");
var sigmaBox = $("#sig_box");
updateGlider = function(type, val) {
if (type == "mu") {
mu = val;
glid_mu.moveTo([mu, 0]);
glid_sig.moveTo([val + sigma, 0], 0);
for (var i = -3; i < 4; i++) {
ptArr[i].moveTo([i * sigma + mu, 0]);
bellArr[i].moveTo([i * sigma + mu, bell(i * sigma + mu)]);
}
showMuSig();
showZscoreCalc();
showProbs();
} else {
glid_sig.moveTo([mu + val, 0], 0);
if (glid_sig.X() - glid_mu.X() > 0.2) {
sigma = Math.abs(glid_sig.X() - glid_mu.X());
for (var i = -3; i < 4; i++) {
ptArr[i].moveTo([i * sigma + mu, 0]);
bellArr[i].moveTo([i * sigma + mu, bell(i * sigma + mu)]);
}
showMuSig();
showZscoreCalc();
showProbs();
} else {
glid_sig.setGliderPosition(glid_mu.X() + 0.2);
sigma = 0.2;
}
}
}
showMuSig = function () {
muBox.val((glid_mu.X()).toFixed(4));
sigmaBox.val(Math.abs(glid_mu.X() - glid_sig.X()).toFixed(4));
}
showMuSig();
//add listeners to mu_box and sig_box
muBox.change(function () {
updateGlider("mu", parseFloat(muBox.val()));
});
sigmaBox.change(function () {
updateGlider("sigma", parseFloat(sigmaBox.val()));
});
showZscoreCalc = function () {
//board.suspendUpdate();
$("#z1ScoreCalc").html("`z_1=(x_1 - mu)/sigma = (" + glid_x1.X().toFixed(2) + "-" +
glid_mu.X().toFixed(2) + ")/" + (glid_sig.X() - glid_mu.X()).toFixed(2) +
"=" + ((glid_x1.X() - glid_mu.X()) / (glid_sig.X() - glid_mu.X())).toFixed(
4) + "`" +
" `z_2=(x_2 - mu)/sigma = (" + glid_x2.X().toFixed(2) + "-" + glid_mu.X()
.toFixed(2) + ")/" + (glid_sig.X() - glid_mu.X()).toFixed(2) + "=" + ((
glid_x2.X() - glid_mu.X()) / (glid_sig.X() - glid_mu.X())).toFixed(4) +
"`");
//$("#z2ScoreCalc").html("`z_2=(x_2 - mu)/sigma = ("+glid_x2.X().toFixed(2)+"-"+glid_mu.X().toFixed(2)+")/"+(glid_sig.X()-glid_mu.X()).toFixed(2)+"="+( (glid_x2.X() - glid_mu.X())/ (glid_sig.X()-glid_mu.X()) ).toFixed(4)+"`" );
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
//board.unsuspendUpdate();
}
glid_x1.on('drag', function () {
//board.suspendUpdate();
glid_x2.moveTo([Math.max(glid_x1.X() + 0.15, glid_x2.X()), 0], 0);
showMuSig();
showZscoreCalc();
showProbs();
//board.unsuspendUpdate();
});
glid_x2.on('drag', function () {
//board.suspendUpdate();
glid_x1.moveTo([Math.min(glid_x1.X(), glid_x2.X() - 0.15), 0], 0);
showMuSig();
showZscoreCalc();
showProbs();
//board.unsuspendUpdate();
});
glid_mu.on('drag', function () {
//board.suspendUpdate();
mu = glid_mu.X();
glid_sig.moveTo([glid_mu.X() + sigma, 0], 0);
for (i = -3; i < 4; i++) {
ptArr[i].moveTo([i * sigma + mu, 0]);
bellArr[i].moveTo([i * sigma + mu, bell(i * sigma + mu)]);
}
showMuSig();
showZscoreCalc();
showProbs();
//board.unsuspendUpdate();
});
board.addHook(function () {
if (glid_sig.X() - glid_mu.X() < 0.2) {
glid_sig.setGliderPosition(glid_mu.X() + 0.2);
}
}, 'update');
glid_sig.on('drag', function () {
//board.suspendUpdate();
if (glid_sig.X() - glid_mu.X() > 0.2) {
sigma = Math.abs(glid_sig.X() - glid_mu.X());
for (i = -3; i < 4; i++) {
ptArr[i].moveTo([i * sigma + mu, 0]);
bellArr[i].moveTo([i * sigma + mu, bell(i * sigma + mu)]);
}
showMuSig();
showZscoreCalc();
showProbs();
} else {
glid_sig.setGliderPosition(glid_mu.X() + 0.2);
sigma = 0.2;
}
//board.unsuspendUpdate();
});
x1txt = board.create("text", [function () {
return glid_x1.X();
}, 0.05, function () {
return "<p><i>x</i><sub>1</sub> = " + glid_x1.X().toFixed(2) + "</p>";
}], {
highlight: false
});
x2txt = board.create("text", [function () {
return glid_x2.X();
}, 0.1, function () {
return "<p><i>x</i><sub>2</sub> = " + glid_x2.X().toFixed(2) + "</p>";
}], {
highlight: false
});
var xData, yData;
// LRD2 – LRD NOTE: Change these values to change the colour of the highlighted area under the curve!
var area = board.create('curve', [
[],
[]
], {
color: '#22B0E1',
strokeWidth: 2,
opacity: 0.3,
highlightStrokeColorOpacity: 0.3
});
area.updateDataArray = function () {
//board.suspendUpdate();
xData = [glid_x1.X()];
yData = [bellCurve.Y(glid_x1.X())];
for (j = 0; j < bellCurve
.numberPoints; j++) { // cannot be "i" because interferes with sigma segments
if ((glid_x1.X() <= bellCurve.points[j].usrCoords[1]) && (bellCurve.points[j]
.usrCoords[1] <= glid_x2.X())) {
xData.push(bellCurve.points[j].usrCoords[1]);
yData.push(bellCurve.points[j].usrCoords[2]);
}
}
xData.push(glid_x2.X());
yData.push(bellCurve.Y(glid_x2.X()));
xData.push(glid_x2.X());
yData.push(0);
xData.push(glid_x1.X());
yData.push(0);
// close the curve
xData.push(glid_x1.X());
yData.push(bellCurve.Y(glid_x1.X()));
this.dataX = xData;
this.dataY = yData;
//board.unsuspendUpdate();
};
/////////////////////////////////////////////////////////////////////////////////////
showSNcurve = function () {
bellCurveStand = board.create("functiongraph", [bellStand, -20, 20], {
strokeWidth: 1,
strokecolor: "#ccc",
highlight: false,
dash: 0
});
var xDataS, yDataS;
areaS = board.create('curve', [
[],
[]
], {
color: '#aaa',
opacity: 0.2
});
areaS.updateDataArray = function () {
//board.suspendUpdate();
xDataS = [(glid_x1.X() - mu) / sigma];
yDataS = [bellCurveStand.Y((glid_x1.X() - mu) / sigma)];
for (k = 0; k < bellCurveStand.numberPoints; k++) { // cannot be "i" or "j"
if (((glid_x1.X() - mu) / sigma <= bellCurveStand.points[k].usrCoords[
1]) && (bellCurveStand.points[k].usrCoords[1] <= (glid_x2.X() -
mu) / sigma)) {
xDataS.push(bellCurveStand.points[k].usrCoords[1]);
yDataS.push(bellCurveStand.points[k].usrCoords[2]);
}
}
xDataS.push((glid_x2.X() - mu) / sigma);
yDataS.push(bellCurveStand.Y((glid_x2.X() - mu) / sigma));
xDataS.push((glid_x2.X() - mu) / sigma);
yDataS.push(0);
xDataS.push((glid_x1.X() - mu) / sigma);
yDataS.push(0);
xDataS.push((glid_x1.X() - mu) / sigma);
yDataS.push(bellCurveStand.Y((glid_x1.X() - mu) / sigma));
this.dataX = xDataS;
this.dataY = yDataS;
//board.unsuspendUpdate();
};
}
}
plot();
getChk = function () {
board.suspendUpdate();
$("input:checkbox").each(function () {
var thisChk = $(this);
var thisId = thisChk.attr("id");
if (thisId == "sdgraph") {
if (thisChk.is(":checked")) {
for (i = -3; i < 4; i++) {
segArr[i].setProperty('visible:true');
}
} else {
for (i = -3; i < 4; i++) {
segArr[i].setProperty('visible:false');
}
}
} else if (thisId == "sncurve") {
if (thisChk.is(":checked")) {
board.removeObject(bellCurveStand);
board.removeObject(areaS);
showSNcurve();
} else {
board.removeObject(bellCurveStand);
board.removeObject(areaS);
}
} else if (thisId == "zscorecalc") {
if (thisChk.is(":checked")) {
showZscoreCalc();
$("#zscores").css("display", "block");
} else {
$("#z1ScoreCalc").html("");
$("#z2ScoreCalc").html("");
$("#zscores").css("display", "none");
}
} else {
if (thisChk.is(":checked")) {
$("#probOutput").css("display", "block");
showProbs();
} else {
$("#probOutput").html("");
$("#probOutput").css("display", "none");
}
}
})
board.unsuspendUpdate();
}
getChk();
$("#options").change(getChk);
})
</script>
<div style="position: absolute; width: 0px; height: 0px; overflow: hidden; padding: 0px; border: 0px; margin: 0px;">
<div id="MathJax_Font_Test"
style="position: absolute; visibility: hidden; top: 0px; left: 0px; width: auto; padding: 0px; border: 0px; margin: 0px; white-space: nowrap; text-align: left; text-indent: 0px; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; font-size: 40px; font-weight: normal; font-style: normal; font-family: STIXSizeOneSym, sans-serif;">
</div>
</div>
</body>
</html>