PageRenderTime 175ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/exercises/standard_deviation.html

https://github.com/beneater/khan-exercises
HTML | 327 lines | 295 code | 32 blank | 0 comment | 0 complexity | 2abe00eb39e3c7e598d2015251f3f331 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html data-require="math math-format word-problems stat">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Standard deviation</title>
  6. <script src="../khan-exercise.js"></script>
  7. <style>
  8. #answer_area .short input[type=text] {
  9. width: 40px;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <div class="exercise">
  15. <div class="vars">
  16. <var id="DATA_POINTS">randRange( 4, 6 )</var>
  17. <var id="POPULATION">randRange( 20, 50 )</var>
  18. <var id="TGT_MEAN">animalAvgLifespan( 1 )</var>
  19. <var id="TGT_STDDEV">animalStddevLifespan( 1 )</var>
  20. <var id="DATA">jQuery.map( randGaussian( TGT_MEAN, TGT_STDDEV, DATA_POINTS ), function( lifespan ) {
  21. lifespan = lifespan &lt; 1 ? 1 : round( lifespan );
  22. return randRange( 1, lifespan );
  23. } )</var>
  24. <var id="MEAN">roundTo( 1, mean( DATA ) )</var>
  25. <var id="SQR_DEV">jQuery.map( DATA, function( x ) { return roundTo( 2, ( x - MEAN ) * ( x - MEAN ) ); })</var>
  26. <var id="VARIANCE">roundTo( 2, sum( SQR_DEV ) / ( DATA_POINTS - 1 ) )</var>
  27. <var id="VARIANCE_POP">roundTo( 2, sum( SQR_DEV ) / DATA_POINTS )</var>
  28. <var id="STDDEV">roundTo( 1, stdDev( DATA ) )</var>
  29. <var id="STDDEV_POP">roundTo( 1, stdDevPop( DATA ) )</var>
  30. </div> <!-- vars -->
  31. <div class="problems">
  32. <div id="population">
  33. <div class="problem" data-else>
  34. <p>You have found the following ages (in years) of all <var>plural( DATA_POINTS, animal( 1 ) )</var> at your local zoo:</p>
  35. <p><code>\qquad<var>DATA.join( ",\\enspace " )</var></code></p>
  36. </div>
  37. <p class="question">
  38. What is the average age of the <var>plural( animal( 1 ) )</var> at your zoo? What is the standard deviation?
  39. You may round your answers to the nearest tenth.
  40. </p>
  41. <div class="solution" data-type="multiple">
  42. <p>
  43. Average age:
  44. <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>mean( DATA )</var></span> years old
  45. </p>
  46. <p>
  47. Standard deviation:
  48. <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>stdDevPop( DATA )</var></span> years
  49. </p>
  50. <div class="example">decimals, like <code>7.5</code></div>
  51. <div class="example">answers within <code>\pm 0.15</code> are accepted to allow for rounding part-way through</div>
  52. </div> <!-- solution -->
  53. <div class="hints">
  54. <p>
  55. Because we have data for all <var>plural( DATA_POINTS, animal( 1 ) )</var> at the zoo, we are able
  56. to calculate the <span class="hint_blue">population mean</span>
  57. <code>(\color{<var>BLUE</var>}{\mu})</code> and
  58. <span class="hint_pink">population standard deviation</span> <code>(\color{<var>PINK</var>}{\sigma})</code>.
  59. </p>
  60. <div>
  61. <p>
  62. To find the <span class="hint_blue">population mean</span>, add up the values of all <code class="hint_green"><var>DATA_POINTS</var></code>
  63. ages and divide by <code class="hint_green"><var>DATA_POINTS</var></code>.
  64. </p>
  65. <p>
  66. <code>
  67. \color{<var>BLUE</var>}{\mu} \quad = \quad
  68. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{N}} x_i}{\color{<var>GREEN</var>}{N}} \quad = \quad
  69. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} x_i}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
  70. </code>
  71. </p>
  72. </div>
  73. <p>
  74. <code>
  75. \color{<var>BLUE</var>}{\mu} \quad = \quad
  76. \dfrac{<var>plus.apply( KhanUtil, DATA )</var>}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
  77. \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var> old}}
  78. </code>
  79. </p>
  80. <div>
  81. <p>
  82. Find the <span class="hint_purple">squared deviations from the mean</span> for each <var>animal(1)</var>.
  83. </p>
  84. <div class="fake_header">
  85. <span style="width: 100px;">
  86. Age<br/>
  87. <code>x_i</code>
  88. </span><span style="width: 150px;">
  89. <span class="hint_gray">Distance from the mean</span>
  90. <code>(x_i - \color{<var>BLUE</var>}{\mu})</code>
  91. </span><span style="width: 150px;">
  92. <code>(x_i - \color{<var>BLUE</var>}{\mu})^2</code>
  93. </span>
  94. </div>
  95. <div class="fake_row" data-each="DATA as i, POINT">
  96. <span style="width: 100px;">
  97. <code><var>POINT</var></code> <var>plural( "year", POINT )</var>
  98. </span><span style="width: 150px;" class="hint_gray">
  99. <code><var>roundTo( 2, POINT - MEAN )</var></code> <var>plural( "year", roundTo( 2, POINT - MEAN ) )</var>
  100. </span><span style="width: 150px;" class="hint_purple">
  101. <code><var>SQR_DEV[ i ]</var></code> <var>plural( "year", SQR_DEV[ i ] )</var><code>^2</code>
  102. </span>
  103. </div>
  104. </div>
  105. <div>
  106. <p>
  107. Because we used the <span class="hint_blue">population mean</span><code>(\color{<var>BLUE</var>}{\mu})</code> to compute the
  108. <span class="hint_purple">squared deviations from the mean</span>, we can find the <span class="hint_red">variance</span>
  109. <code>(\color{red}{\sigma^2})</code>, without introducing any bias, by simply averaging the
  110. <span class="hint_purple">squared deviations from the mean</span>:
  111. </p>
  112. <p>
  113. <code>
  114. \color{red}{\sigma^2} \quad = \quad
  115. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{N}} (x_i - \color{<var>BLUE</var>}{\mu})^2}{\color{<var>GREEN</var>}{N}}
  116. </code>
  117. </p>
  118. </div>
  119. <p>
  120. <code>
  121. \color{red}{\sigma^2} \quad = \quad
  122. \dfrac{<var>plus.apply( KhanUtil, jQuery.map( SQR_DEV, function( x ) { return "\\color{purple}{" + x + "}"; }) )</var>}
  123. {\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
  124. </code>
  125. </p>
  126. <p>
  127. <code>
  128. \color{red}{\sigma^2} \quad = \quad
  129. \dfrac{\color{purple}{<var>roundTo( 2, sum( SQR_DEV ) )</var>}}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
  130. \color{red}{<var>VARIANCE_POP</var>\text{ <var>plural( "year", VARIANCE_POP )</var>}^2}
  131. </code>
  132. </p>
  133. <div>
  134. <p>
  135. As you might guess from the notation, the <span class="hint_pink">population standard deviation</span>
  136. <code>(\color{<var>PINK</var>}{\sigma})</code> is found by taking the square root of the <span class="hint_red">population variance</span>
  137. <code>(\color{red}{\sigma^2})</code>.
  138. </p>
  139. <p>
  140. <code>\color{<var>PINK</var>}{\sigma} = \sqrt{\color{red}{\sigma^2}}</code>
  141. </p>
  142. </div>
  143. <p>
  144. <code>
  145. \color{<var>PINK</var>}{\sigma} = \sqrt{\color{red}{<var>VARIANCE_POP</var>\text{ <var>plural( "year", VARIANCE_POP )</var>}^2}} =
  146. \color{<var>PINK</var>}{<var>STDDEV_POP</var>\text{ <var>plural( "year", STDDEV_POP )</var>}}
  147. </code>
  148. </p>
  149. <p><strong>
  150. The average <var>animal( 1 )</var> at the zoo is <var>plural( MEAN, "year" )</var> old with a standard deviation
  151. of <var>plural( STDDEV_POP, "year" )</var>.
  152. </strong></p>
  153. </div> <!-- hints -->
  154. </div> <!-- population -->
  155. <div id="sample">
  156. <div class="problem" data-else>
  157. <p>
  158. You have found the following ages (in years) of <var>plural( DATA_POINTS, animal( 1 ) )</var>
  159. randomly selected from the <var>plural( POPULATION, animal( 1 ) )</var> at your local zoo:
  160. </p>
  161. <p><code>\qquad<var>DATA.join( ",\\enspace " )</var></code></p>
  162. </div>
  163. <p class="question">
  164. Based on your sample, what is the average age of the <var>plural( animal( 1 ) )</var>? What is the standard deviation?
  165. You may round your answers to the nearest tenth.
  166. </p>
  167. <div class="solution" data-type="multiple">
  168. <p>
  169. Average age:
  170. <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>mean( DATA )</var></span> years old
  171. </p>
  172. <p>
  173. Standard deviation:
  174. <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>stdDev( DATA )</var></span> years
  175. </p>
  176. <div class="example">decimals, like <code>0.75</code></div>
  177. <div class="example">answers within <code>\pm 0.15</code> are accepted to allow for rounding part-way through</div>
  178. </div> <!-- solution -->
  179. <div class="hints">
  180. <p>
  181. Because we only have data for a small sample of the <var>plural( POPULATION, animal( 1 ) )</var>, we are only able
  182. to estimate the population mean and standard deviation by finding the <span class="hint_blue">sample mean</span>
  183. <code>(\color{<var>BLUE</var>}{\overline{x}})</code> and
  184. <span class="hint_pink">sample standard deviation</span> <code>(\color{<var>PINK</var>}{s})</code>.
  185. </p>
  186. <div>
  187. <p>
  188. To find the <span class="hint_blue">sample mean</span>, add up the values of all <code class="hint_green"><var>DATA_POINTS</var></code>
  189. samples and divide by <code class="hint_green"><var>DATA_POINTS</var></code>.
  190. </p>
  191. <p>
  192. <code>
  193. \color{<var>BLUE</var>}{\overline{x}} \quad = \quad
  194. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{n}} x_i}{\color{<var>GREEN</var>}{n}} \quad = \quad
  195. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} x_i}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
  196. </code>
  197. </p>
  198. </div>
  199. <p>
  200. <code>
  201. \color{<var>BLUE</var>}{\overline{x}} \quad = \quad
  202. \dfrac{<var>plus.apply( KhanUtil, DATA )</var>}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
  203. \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var> old}}
  204. </code>
  205. </p>
  206. <p>
  207. Find the <span class="hint_purple">squared deviations from the mean</span> for each sample. Since we don't know the
  208. population mean, estimate the mean by using the <span class="hint_blue">sample mean</span> we just calculated
  209. <code>(\color{<var>BLUE</var>}{\overline{x}} = \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var>}})</code>.
  210. </p>
  211. <div>
  212. <div class="fake_header">
  213. <span style="width: 100px;">
  214. Age<br/>
  215. <code>x_i</code>
  216. </span><span style="width: 150px;">
  217. <span class="hint_gray">Distance from the mean</span>
  218. <code>(x_i - \color{<var>BLUE</var>}{\overline{x}})</code>
  219. </span><span style="width: 150px;">
  220. <code>(x_i - \color{<var>BLUE</var>}{\overline{x}})^2</code>
  221. </span>
  222. </div>
  223. <div class="fake_row" data-each="DATA as i, POINT">
  224. <span style="width: 100px;">
  225. <code><var>POINT</var></code> <var>plural( "year", POINT )</var>
  226. </span><span style="width: 150px;" class="hint_gray">
  227. <code><var>roundTo( 2, POINT - MEAN )</var></code> <var>plural( "year", roundTo( 2, POINT - MEAN ) )</var>
  228. </span><span style="width: 150px;" class="hint_purple">
  229. <code><var>SQR_DEV[ i ]</var></code> <var>plural( "year", SQR_DEV[ i ] )</var><code>^2</code>
  230. </span>
  231. </div>
  232. </div>
  233. <div>
  234. <p>
  235. Normally we can find the variance <code>(\color{red}{s^2})</code> by averaging the
  236. <span class="hint_purple">squared deviations from the mean</span>. But remember we don't know the real
  237. population mean&mdash;we had to estimate it by using the <span class="hint_blue">sample mean</span>.
  238. </p>
  239. <p>
  240. The age of any particular <var>animal( 1 )</var> in our sample is likely to be closer to the average age
  241. of the <var>plural( DATA_POINTS, animal( 1 ) )</var> we sampled than it is to the average age
  242. of all <var>plural( POPULATION, animal( 1 ) )</var> in the zoo.
  243. Because of that, the <span class="hint_purple">squared deviations from the mean</span> we calculated will
  244. probably underestimate the actual deviations from the population mean.
  245. </p>
  246. <p>
  247. To compensate for this underestimation, rather than simply averaging the <span class="hint_purple">squared deviations from the mean</span>,
  248. we total them and divide by <code class="hint_green">n - 1</code>.
  249. </p>
  250. <p>
  251. <code>
  252. \color{red}{s^2} \quad = \quad
  253. \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{n}} (x_i - \color{<var>BLUE</var>}{\overline{x}})^2}{\color{<var>GREEN</var>}{n - 1}}
  254. </code>
  255. </p>
  256. </div>
  257. <p>
  258. <code>
  259. \color{red}{s^2} \quad = \quad
  260. \dfrac{<var>plus.apply( KhanUtil, jQuery.map( SQR_DEV, function( x ) { return "\\color{purple}{" + x + "}"; }) )</var>}
  261. {\color{<var>GREEN</var>}{<var>DATA_POINTS</var> - 1}}
  262. </code>
  263. </p>
  264. <p>
  265. <code>
  266. \color{red}{s^2} \quad = \quad
  267. \dfrac{\color{purple}{<var>roundTo( 2, sum( SQR_DEV ) )</var>}}{\color{<var>GREEN</var>}{<var>DATA_POINTS - 1</var>}} \quad = \quad
  268. \color{red}{<var>VARIANCE</var>\text{ <var>plural( "year", VARIANCE )</var>}^2}
  269. </code>
  270. </p>
  271. <div>
  272. <p>
  273. As you might guess from the notation, the sample standard deviation <code>(\color{<var>PINK</var>}{s})</code> is
  274. found by taking the square root of the sample variance <code>(\color{red}{s^2})</code>.
  275. </p>
  276. <p>
  277. <code>\color{<var>PINK</var>}{s} = \sqrt{\color{red}{s^2}}</code>
  278. </p>
  279. </div>
  280. <p>
  281. <code>
  282. \color{<var>PINK</var>}{s} = \sqrt{\color{red}{<var>VARIANCE</var>\text{ <var>plural( "year", VARIANCE )</var>}^2}} =
  283. \color{<var>PINK</var>}{<var>STDDEV</var>\text{ <var>plural( "year", STDDEV )</var>}}
  284. </code>
  285. </p>
  286. <p><strong>
  287. We can estimate that the average <var>animal( 1 )</var> at the zoo is <var>plural( MEAN, "year" )</var> old with a standard deviation
  288. of <var>plural( STDDEV, "year" )</var>.
  289. </strong></p>
  290. </div> <!-- hints -->
  291. </div> <!-- sample -->
  292. </div> <!-- problems -->
  293. </div> <!-- exercise -->
  294. </body>
  295. </html>