######################################################################## ## DESCRIPTION ## A WeBWork problem that asks students to calculate the standard deviation of a ## data set. ## WeBWorK problem written by JoAnne Taormina, ## ENDDESCRIPTION ## ## KEYWORDS('standard deviation', 'sample', 'population') ## ## Author('JoAnne Taormina') ## Institution('Nassau Community College') ######################################################################## DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGgraphmacros.pl", "weightedGrader.pl", ); # make sure we're in the context we want Context("Numeric"); $total_values=10; # the data @data = (); @sorted = (); for($i = 0; $i < $total_values; $i ++) { $data[$i] = random(10, 90, 1); } @sorted = num_sort(@data); for($i=0; $i<$total_values; $i++){ $sum+=$data[$i]; } $mean = $sum/$total_values; $center1 = $sorted[$total_values/2-1]; $center2 = $sorted[$total_values/2]; $median = ($center1+$center2)/2; @deviation_from_mean=(); @deviation_from_mean_squared=(); for($i=0; $i<$total_values; $i++){ $deviation_from_mean[$i] = $data[$i] - $mean; $deviation_from_mean_squared[$i] = $deviation_from_mean[$i]**2; $sum_deviation_from_mean_squared += $deviation_from_mean_squared[$i]; } $sample_variance = $sum_deviation_from_mean_squared/($total_values-1); $population_variance = $sum_deviation_from_mean_squared/$total_values; $sample_std_dev = sqrt($sample_variance); $population_std_dev = sqrt($population_variance); $mean = Formula("$mean"); $median = Formula("$median"); # the table data $table_start = begintable(3); $table_row[0] = row( "\(x\)", "\( x-\bar{x} \)", "\( (x-\bar{x})^2 \)"); for ( $i = 1; $i <=$total_values; $i++ ) { $table_row[$i] = row( "\( $data[$i-1] \)" , ans_rule(10), ans_rule(10)); } $table_end = endtable(); TEXT(beginproblem()); Context()->texStrings; BEGIN_TEXT (a) Find the mean and median for the following data. $BR $BR \[ $data[0], \ $data[1], \ $data[2], \ $data[3], \ $data[4], \ $data[5], \ $data[6], \ $data[7], \ $data[8], \ $data[9] \] $BR$BR Mean = \{ans_rule(5)\} $BR$BR Median = \{ans_rule(5)\} $BR$BR (b) Fill in the table below to demonstrate each of the steps in finding the standard deviation. Put one number in each blank. Do not round any quantities. $BR$BR $BCENTER $table_start $table_row[0] $table_row[1] $table_row[2] $table_row[3] $table_row[4] $table_row[5] $table_row[6] $table_row[7] $table_row[8] $table_row[9] $table_row[10] $table_end $BR$BR $ECENTER (c) Find the sum of the squared deviations from the mean, sample variance, sample standard deviation, population variance, and the population standard deviation of the data set. If necessary, round quantities to 4 decimal places. For example, 12.34567 becomes 12.3457. $BR$BR Sum of the squared deviations from the mean \( \Sigma(x-\bar{x})^2 \) = \{ ans_rule(10) \} $BR$BR Find the sample variance \( \frac{\Sigma(x-\bar{x})^2}{n-1} \) = \{ ans_rule(10) \} $BR$BR Using your answer for the sample variance, find the sample standard deviation \( \sqrt(\frac{\Sigma(x-\bar{x})^2}{n-1}) \) = \{ ans_rule(10) \} $BR$BR Population variance \( \frac{\Sigma(x-\mu)^2}{N} \) = \{ ans_rule(10) \} $BR$BR Using your answer for the population variance, find the population standard deviation \( \sqrt(\frac{\Sigma(x-\mu)^2}{N}) \) = \{ ans_rule(10) \} END_TEXT Context("Numeric"); for($i=0;$i<$total_values;$i++) { $ans = Formula("$deviation_from_mean[$i]"); WEIGHTED_ANS( $ans->cmp(tolType=>'absolute',tolerance=>0.0001), 3 ); $ans = Formula("$deviation_from_mean_squared[$i]"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0.0001), 3); } WEIGHTED_ANS($mean->cmp(tolType=>'absolute',tolerance=>0), 4); WEIGHTED_ANS($median->cmp(tolType=>'absolute',tolerance=>0), 4); $ans = Formula("$sum_deviation_from_mean_squared"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0),6); $ans = Formula("$sample_variance"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0.001),6); $ans = Formula("$sample_std_dev"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0.001),7); $ans = Formula("$population_variance"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0.001),6); $ans = Formula("$population_std_dev"); WEIGHTED_ANS($ans->cmp(tolType=>'absolute',tolerance=>0.001),7); ENDDOCUMENT();