/exercises/standard_deviation.html
HTML | 327 lines | 295 code | 32 blank | 0 comment | 0 complexity | 2abe00eb39e3c7e598d2015251f3f331 MD5 | raw file
- <!DOCTYPE html>
- <html data-require="math math-format word-problems stat">
- <head>
- <meta charset="UTF-8" />
- <title>Standard deviation</title>
- <script src="../khan-exercise.js"></script>
- <style>
- #answer_area .short input[type=text] {
- width: 40px;
- }
- </style>
- </head>
- <body>
- <div class="exercise">
- <div class="vars">
- <var id="DATA_POINTS">randRange( 4, 6 )</var>
- <var id="POPULATION">randRange( 20, 50 )</var>
- <var id="TGT_MEAN">animalAvgLifespan( 1 )</var>
- <var id="TGT_STDDEV">animalStddevLifespan( 1 )</var>
- <var id="DATA">jQuery.map( randGaussian( TGT_MEAN, TGT_STDDEV, DATA_POINTS ), function( lifespan ) {
- lifespan = lifespan < 1 ? 1 : round( lifespan );
- return randRange( 1, lifespan );
- } )</var>
- <var id="MEAN">roundTo( 1, mean( DATA ) )</var>
- <var id="SQR_DEV">jQuery.map( DATA, function( x ) { return roundTo( 2, ( x - MEAN ) * ( x - MEAN ) ); })</var>
- <var id="VARIANCE">roundTo( 2, sum( SQR_DEV ) / ( DATA_POINTS - 1 ) )</var>
- <var id="VARIANCE_POP">roundTo( 2, sum( SQR_DEV ) / DATA_POINTS )</var>
- <var id="STDDEV">roundTo( 1, stdDev( DATA ) )</var>
- <var id="STDDEV_POP">roundTo( 1, stdDevPop( DATA ) )</var>
- </div> <!-- vars -->
- <div class="problems">
- <div id="population">
- <div class="problem" data-else>
- <p>You have found the following ages (in years) of all <var>plural( DATA_POINTS, animal( 1 ) )</var> at your local zoo:</p>
- <p><code>\qquad<var>DATA.join( ",\\enspace " )</var></code></p>
- </div>
- <p class="question">
- What is the average age of the <var>plural( animal( 1 ) )</var> at your zoo? What is the standard deviation?
- You may round your answers to the nearest tenth.
- </p>
- <div class="solution" data-type="multiple">
- <p>
- Average age:
- <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>mean( DATA )</var></span> years old
- </p>
- <p>
- Standard deviation:
- <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>stdDevPop( DATA )</var></span> years
- </p>
- <div class="example">decimals, like <code>7.5</code></div>
- <div class="example">answers within <code>\pm 0.15</code> are accepted to allow for rounding part-way through</div>
- </div> <!-- solution -->
- <div class="hints">
- <p>
- Because we have data for all <var>plural( DATA_POINTS, animal( 1 ) )</var> at the zoo, we are able
- to calculate the <span class="hint_blue">population mean</span>
- <code>(\color{<var>BLUE</var>}{\mu})</code> and
- <span class="hint_pink">population standard deviation</span> <code>(\color{<var>PINK</var>}{\sigma})</code>.
- </p>
- <div>
- <p>
- 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>
- ages and divide by <code class="hint_green"><var>DATA_POINTS</var></code>.
- </p>
- <p>
- <code>
- \color{<var>BLUE</var>}{\mu} \quad = \quad
- \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{N}} x_i}{\color{<var>GREEN</var>}{N}} \quad = \quad
- \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} x_i}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
- </code>
- </p>
- </div>
- <p>
- <code>
- \color{<var>BLUE</var>}{\mu} \quad = \quad
- \dfrac{<var>plus.apply( KhanUtil, DATA )</var>}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
- \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var> old}}
- </code>
- </p>
- <div>
- <p>
- Find the <span class="hint_purple">squared deviations from the mean</span> for each <var>animal(1)</var>.
- </p>
- <div class="fake_header">
- <span style="width: 100px;">
- Age<br/>
- <code>x_i</code>
- </span><span style="width: 150px;">
- <span class="hint_gray">Distance from the mean</span>
- <code>(x_i - \color{<var>BLUE</var>}{\mu})</code>
- </span><span style="width: 150px;">
- <code>(x_i - \color{<var>BLUE</var>}{\mu})^2</code>
- </span>
- </div>
- <div class="fake_row" data-each="DATA as i, POINT">
- <span style="width: 100px;">
- <code><var>POINT</var></code> <var>plural( "year", POINT )</var>
- </span><span style="width: 150px;" class="hint_gray">
- <code><var>roundTo( 2, POINT - MEAN )</var></code> <var>plural( "year", roundTo( 2, POINT - MEAN ) )</var>
- </span><span style="width: 150px;" class="hint_purple">
- <code><var>SQR_DEV[ i ]</var></code> <var>plural( "year", SQR_DEV[ i ] )</var><code>^2</code>
- </span>
- </div>
- </div>
- <div>
- <p>
- Because we used the <span class="hint_blue">population mean</span><code>(\color{<var>BLUE</var>}{\mu})</code> to compute the
- <span class="hint_purple">squared deviations from the mean</span>, we can find the <span class="hint_red">variance</span>
- <code>(\color{red}{\sigma^2})</code>, without introducing any bias, by simply averaging the
- <span class="hint_purple">squared deviations from the mean</span>:
- </p>
- <p>
- <code>
- \color{red}{\sigma^2} \quad = \quad
- \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{N}} (x_i - \color{<var>BLUE</var>}{\mu})^2}{\color{<var>GREEN</var>}{N}}
- </code>
- </p>
- </div>
- <p>
- <code>
- \color{red}{\sigma^2} \quad = \quad
- \dfrac{<var>plus.apply( KhanUtil, jQuery.map( SQR_DEV, function( x ) { return "\\color{purple}{" + x + "}"; }) )</var>}
- {\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
- </code>
- </p>
- <p>
- <code>
- \color{red}{\sigma^2} \quad = \quad
- \dfrac{\color{purple}{<var>roundTo( 2, sum( SQR_DEV ) )</var>}}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
- \color{red}{<var>VARIANCE_POP</var>\text{ <var>plural( "year", VARIANCE_POP )</var>}^2}
- </code>
- </p>
- <div>
- <p>
- As you might guess from the notation, the <span class="hint_pink">population standard deviation</span>
- <code>(\color{<var>PINK</var>}{\sigma})</code> is found by taking the square root of the <span class="hint_red">population variance</span>
- <code>(\color{red}{\sigma^2})</code>.
- </p>
- <p>
- <code>\color{<var>PINK</var>}{\sigma} = \sqrt{\color{red}{\sigma^2}}</code>
- </p>
- </div>
- <p>
- <code>
- \color{<var>PINK</var>}{\sigma} = \sqrt{\color{red}{<var>VARIANCE_POP</var>\text{ <var>plural( "year", VARIANCE_POP )</var>}^2}} =
- \color{<var>PINK</var>}{<var>STDDEV_POP</var>\text{ <var>plural( "year", STDDEV_POP )</var>}}
- </code>
- </p>
- <p><strong>
- The average <var>animal( 1 )</var> at the zoo is <var>plural( MEAN, "year" )</var> old with a standard deviation
- of <var>plural( STDDEV_POP, "year" )</var>.
- </strong></p>
- </div> <!-- hints -->
- </div> <!-- population -->
- <div id="sample">
- <div class="problem" data-else>
- <p>
- You have found the following ages (in years) of <var>plural( DATA_POINTS, animal( 1 ) )</var>
- randomly selected from the <var>plural( POPULATION, animal( 1 ) )</var> at your local zoo:
- </p>
- <p><code>\qquad<var>DATA.join( ",\\enspace " )</var></code></p>
- </div>
- <p class="question">
- Based on your sample, what is the average age of the <var>plural( animal( 1 ) )</var>? What is the standard deviation?
- You may round your answers to the nearest tenth.
- </p>
- <div class="solution" data-type="multiple">
- <p>
- Average age:
- <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>mean( DATA )</var></span> years old
- </p>
- <p>
- Standard deviation:
- <span class="sol short" data-type="decimal" data-inexact data-max-error="0.15"><var>stdDev( DATA )</var></span> years
- </p>
- <div class="example">decimals, like <code>0.75</code></div>
- <div class="example">answers within <code>\pm 0.15</code> are accepted to allow for rounding part-way through</div>
- </div> <!-- solution -->
- <div class="hints">
- <p>
- Because we only have data for a small sample of the <var>plural( POPULATION, animal( 1 ) )</var>, we are only able
- to estimate the population mean and standard deviation by finding the <span class="hint_blue">sample mean</span>
- <code>(\color{<var>BLUE</var>}{\overline{x}})</code> and
- <span class="hint_pink">sample standard deviation</span> <code>(\color{<var>PINK</var>}{s})</code>.
- </p>
- <div>
- <p>
- 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>
- samples and divide by <code class="hint_green"><var>DATA_POINTS</var></code>.
- </p>
- <p>
- <code>
- \color{<var>BLUE</var>}{\overline{x}} \quad = \quad
- \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{n}} x_i}{\color{<var>GREEN</var>}{n}} \quad = \quad
- \dfrac{\sum\limits_{i=1}^{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} x_i}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}}
- </code>
- </p>
- </div>
- <p>
- <code>
- \color{<var>BLUE</var>}{\overline{x}} \quad = \quad
- \dfrac{<var>plus.apply( KhanUtil, DATA )</var>}{\color{<var>GREEN</var>}{<var>DATA_POINTS</var>}} \quad = \quad
- \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var> old}}
- </code>
- </p>
- <p>
- Find the <span class="hint_purple">squared deviations from the mean</span> for each sample. Since we don't know the
- population mean, estimate the mean by using the <span class="hint_blue">sample mean</span> we just calculated
- <code>(\color{<var>BLUE</var>}{\overline{x}} = \color{<var>BLUE</var>}{<var>MEAN</var>\text{ <var>plural( "year", MEAN )</var>}})</code>.
- </p>
- <div>
- <div class="fake_header">
- <span style="width: 100px;">
- Age<br/>
- <code>x_i</code>
- </span><span style="width: 150px;">
- <span class="hint_gray">Distance from the mean</span>
- <code>(x_i - \color{<var>BLUE</var>}{\overline{x}})</code>
- </span><span style="width: 150px;">
- <code>(x_i - \color{<var>BLUE</var>}{\overline{x}})^2</code>
- </span>
- </div>
- <div class="fake_row" data-each="DATA as i, POINT">
- <span style="width: 100px;">
- <code><var>POINT</var></code> <var>plural( "year", POINT )</var>
- </span><span style="width: 150px;" class="hint_gray">
- <code><var>roundTo( 2, POINT - MEAN )</var></code> <var>plural( "year", roundTo( 2, POINT - MEAN ) )</var>
- </span><span style="width: 150px;" class="hint_purple">
- <code><var>SQR_DEV[ i ]</var></code> <var>plural( "year", SQR_DEV[ i ] )</var><code>^2</code>
- </span>
- </div>
- </div>
- <div>
- <p>
- Normally we can find the variance <code>(\color{red}{s^2})</code> by averaging the
- <span class="hint_purple">squared deviations from the mean</span>. But remember we don't know the real
- population mean—we had to estimate it by using the <span class="hint_blue">sample mean</span>.
- </p>
- <p>
- The age of any particular <var>animal( 1 )</var> in our sample is likely to be closer to the average age
- of the <var>plural( DATA_POINTS, animal( 1 ) )</var> we sampled than it is to the average age
- of all <var>plural( POPULATION, animal( 1 ) )</var> in the zoo.
- Because of that, the <span class="hint_purple">squared deviations from the mean</span> we calculated will
- probably underestimate the actual deviations from the population mean.
- </p>
- <p>
- To compensate for this underestimation, rather than simply averaging the <span class="hint_purple">squared deviations from the mean</span>,
- we total them and divide by <code class="hint_green">n - 1</code>.
- </p>
- <p>
- <code>
- \color{red}{s^2} \quad = \quad
- \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}}
- </code>
- </p>
- </div>
- <p>
- <code>
- \color{red}{s^2} \quad = \quad
- \dfrac{<var>plus.apply( KhanUtil, jQuery.map( SQR_DEV, function( x ) { return "\\color{purple}{" + x + "}"; }) )</var>}
- {\color{<var>GREEN</var>}{<var>DATA_POINTS</var> - 1}}
- </code>
- </p>
- <p>
- <code>
- \color{red}{s^2} \quad = \quad
- \dfrac{\color{purple}{<var>roundTo( 2, sum( SQR_DEV ) )</var>}}{\color{<var>GREEN</var>}{<var>DATA_POINTS - 1</var>}} \quad = \quad
- \color{red}{<var>VARIANCE</var>\text{ <var>plural( "year", VARIANCE )</var>}^2}
- </code>
- </p>
- <div>
- <p>
- As you might guess from the notation, the sample standard deviation <code>(\color{<var>PINK</var>}{s})</code> is
- found by taking the square root of the sample variance <code>(\color{red}{s^2})</code>.
- </p>
- <p>
- <code>\color{<var>PINK</var>}{s} = \sqrt{\color{red}{s^2}}</code>
- </p>
- </div>
- <p>
- <code>
- \color{<var>PINK</var>}{s} = \sqrt{\color{red}{<var>VARIANCE</var>\text{ <var>plural( "year", VARIANCE )</var>}^2}} =
- \color{<var>PINK</var>}{<var>STDDEV</var>\text{ <var>plural( "year", STDDEV )</var>}}
- </code>
- </p>
- <p><strong>
- We can estimate that the average <var>animal( 1 )</var> at the zoo is <var>plural( MEAN, "year" )</var> old with a standard deviation
- of <var>plural( STDDEV, "year" )</var>.
- </strong></p>
- </div> <!-- hints -->
- </div> <!-- sample -->
- </div> <!-- problems -->
- </div> <!-- exercise -->
- </body>
- </html>