This repository has been archived by the owner on May 11, 2021. It is now read-only.
/
mean_median_and_mode.html
182 lines (153 loc) · 7.46 KB
/
mean_median_and_mode.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
<!DOCTYPE html>
<html data-require="math math-format stat graphie graphie-helpers">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mean median and mode</title>
<script src="../khan-exercise.js"></script>
<style type="text/css">
.number-list {
text-align: center
}
</style>
</head>
<body>
<div class="exercise">
<script type="text/javascript">
function GenerateIntegers() {
var len, integers;
do {
// generate random list of numbers
len = KhanUtil.randRange( 5, 10 );
integers = [];
for (var i = 0; i < len; i++) {
integers[i] = KhanUtil.randRange( 1, 10 );
}
} while ( !KhanUtil.mode(integers) );
return integers;
}
function DisplayMedian( sortedInts ) {
var si = sortedInts.slice(0),
center = Math.floor( si.length / 2 ),
prepend = "\\boldsymbol{",
append = "}";
if ( si.length % 2 == 0 ) {
si[center] = prepend + si[center] + append;
si[center - 1] = prepend + si[center - 1] + append;
} else {
si[center] = prepend + si[center] + append;
}
return si.join( ", " );
}
</script>
<div class="vars">
<var id="INTEGERS">GenerateIntegers()</var>
<var id="INTEGERS_COUNT">INTEGERS.length</var>
<var id="INTEGER_LIST">INTEGERS.join( ", " )</var>
<var id="SORTED_INTS">sortNumbers( INTEGERS )</var>
<var id="SORTED_LIST">SORTED_INTS.join( ", " )</var>
<var id="MEDIAN_LIST">DisplayMedian( SORTED_INTS )</var>
<var id="MEAN">mean( INTEGERS )</var>
<var id="MEDIAN">median( INTEGERS )</var>
<var id="MODE">mode( INTEGERS )</var>
</div>
<div class="problems">
<div id="mean">
<div class="question">
<p>What is the arithmetic mean of the following numbers?</p>
<div class="number-list"><code><var>INTEGER_LIST</var></code></div>
</div>
<p class="solution" data-inexact data-max-error="0.01"><var>MEAN</var></p>
<div class="hints">
<p>To find the mean, add all the numbers and then divide by the number of numbers.</p>
<div>
<div class="number-list"><code><var>INTEGER_LIST</var></code></div>
<p>There are <code><var>INTEGERS_COUNT</var></code> numbers.</p>
</div>
<p>The mean is <code>\displaystyle <var>fractionSimplification( sum(INTEGERS), INTEGERS_COUNT )</var></code>.</p>
</div>
</div>
<div id="median">
<div class="question">
<p>What is the median of the following numbers?</p>
<div class="number-list"><code><var>INTEGER_LIST</var></code></div>
</div>
<p class="solution"><var>MEDIAN</var></p>
<div class="hints">
<div>
<p>First, order the numbers, giving:</p>
<div class="number-list"><code><var>SORTED_LIST</var></code></div>
</div>
<div>
<p data-if="INTEGERS.length % 2 === 0">Since we have <code>2</code> middle numbers, the median is the mean of <strong>those</strong> two numbers!</p>
<p data-else>The median is the 'middle' number:</p>
<div class="number-list"><code><var>MEDIAN_LIST</var></code></div>
<p data-if="SORTED_INTS.length % 2 === 0">The median is <code>\dfrac{<var>SORTED_INTS[ SORTED_INTS.length / 2 - 1 ]</var> + <var>SORTED_INTS[ SORTED_INTS.length / 2 ]</var>}{2}</code>.</p>
</div>
<div>
<p>So the median is <code><var>fractionReduce(2 * MEDIAN, 2)</var></code>.</p>
<p>Another way to find the middle number is to draw the numbers on a number line. If a number appears multiple times, count its corresponding dot multiple times.</p>
<div class="graphie">
init({
range: [ [-0.5, 10.5], [-1, 1] ]
});
style({
stroke: "#666"
}, function() {
numberLine( 0, 10, 1 );
});
var freq = {};
var labels = {};
$.each(INTEGERS, function( index, number ) {
var count = freq[ number ] = (freq[ number ] || 0) + 1;
if ( labels[ number ] ) {
labels[ number ].remove();
}
if ( count >= 2 ) {
labels[ number ] = label( [number, 0.2], "\\scriptsize{" + count + "}", "above", { labelDistance: 0 } );
} else {
circle( [number, 0], 5/40, { stroke: "none", fill: "#6495ed" } );
}
});
</div>
</div>
</div>
</div>
<div id="mode">
<div class="question">
<p>What is the mode of the following numbers?</p>
<div class="number-list"><code><var>INTEGER_LIST</var></code></div>
</div>
<p class="solution" data-forms="integer"><var>MODE</var></p>
<div class="hints">
<p>The mode is the most frequent number.</p>
<div>
<p>We can draw a histogram to see how many times each number appears.</p>
<div class="graphie">
var freq = {};
var maxFreq = 0;
$.each(INTEGERS, function( index, number ) {
var count = freq[ number ] = (freq[ number ] || 0) + 1;
maxFreq = count > maxFreq ? count : maxFreq;
});
init({
range: [ [-0.5, 10.5], [-1, ( maxFreq + 1.5 ) / 2] ]
});
style({
stroke: "#666"
}, function() {
numberLine( 0, 10, 1 );
});
for ( var num in freq ) {
for ( var i = 0, l = freq[ num ]; i < l; i++ ) {
circle( [num, ( i + 1.5 ) / 2], 5/40, { stroke: "none", fill: "#6495ed" } );
}
}
</div>
</div>
<p>There are more <code><var>MODE</var></code>s than any other number, so <code><var>MODE</var></code> is the mode.</p>
</div>
</div>
</div>
</div>
</body>
</html>