######################################################################## ## DESCRIPTION ## A WeBWorK problem that asks students to conduct a hypothesis test with an ## unknown population standard deviation and a raw data set. ## WeBWorK problem written by JoAnne Taormina, ## ENDDESCRIPTION ## ## KEYWORDS('hypothesis test, 'sample standard deviation', 'p-value') ## ## Author('JoAnne Taormina') ## Institution('Nassau Community College') ######################################################################## DOCUMENT(); # This should be the first executable line in the problem. loadMacros( "PG.pl", "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "PGstatisticsmacros.pl", "PGnumericalmacros.pl", "weightedGrader.pl", "PGstandard.pl", "MathObjects.pl", "parserPopUp.pl", ); install_weighted_grader(); TEXT(beginproblem()); $showPartialCorrectAnswers = 1; $mu = random(8290,8490,10); $sample = 15; # get the data values @data=(); @deviation_from_mean=(); @deviation_from_mean_squared=(); $sum= 0; for($i = 0; $i < $sample; $i++) { $data[$i] = random(-100,190,1)+$mu; $sum += $data[$i]; } $x_bar = $sum/$sample; for($i=0; $i<$sample; $i++){ $deviation_from_mean[$i] = $data[$i] - $x_bar; $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/($sample-1); $s = sqrt($sample_variance); $alpha = 1; # round $s to 4 decimal places $s_rounded = int(10000*$s+.5*($s <=> 0))/10000; # round $x_bar to 2 decimal places $x_bar_rounded = int(100*$x_bar+.5*($x_bar <=> 0))/100; @choices = ("population mean", "sample mean", "population proportion", "sample proportion"); @choices = @choices[shuffle(4)]; $popup_H0_mean = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3]], "population mean"); @choices = ("is", "is greater than", "is less than"); @choices = @choices[shuffle(3)]; $popup_H0_direction = PopUp(["Choose:",$choices[0], $choices[1], $choices[2]],"is"); @choices = ($s_rounded, $sample, $mu, $x_bar_rounded,"1%"); @choices = @choices[shuffle(5)]; $popup_H0_value = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3], $choices[4]],$mu); @choices = ("population mean", "sample mean", "population proportion", "sample proportion"); @choices = @choices[shuffle(4)]; $popup_Ha_mean = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3]], "population mean"); @choices = ("is", "is greater than", "is less than"); @choices = @choices[shuffle(3)]; $popup_Ha_direction = PopUp(["Choose:",$choices[0], $choices[1], $choices[2]],"is greater than"); @choices = ($s_rounded, $sample, $mu, $x_bar_rounded,"1%"); @choices = @choices[shuffle(5)]; $popup_Ha_value = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3], $choices[4]],$mu); # set up for a multiple choice problem. $radio_samp_dist_mean = new_multiple_choice(); $radio_samp_dist_mean->qa("The correct symbol for mean of the sampling distribution is ", "\( \mu_{\bar{x}} \)"); $radio_samp_dist_mean->extra("\( \mu \)", "\( \bar{x} \)", "\( \hat{p} \)", "\( \mu_{\hat{p}} \)", "\( p \)"); # set up for a multiple choice problem. $radio_dist = new_multiple_choice(); $radio_dist->qa("Choose the correct distribution", "T-Distribution"); $radio_dist->extra("Normal Distribution"); # set up for a multiple choice problem. $radio_dist_reason = new_multiple_choice(); $radio_dist_reason->qa("Why?", "We are not provided with \( \sigma \)."); $radio_dist_reason->extra("We are provided with \( \sigma \).", "We are provided with \( \bar{x} \).", "We are not provided with \( \bar{x} \)."); @choices = ("less than or equal to 0.01", "greater than or equal to 0.01", "less than or equal to 0.0001", "greater than or equal to 0.0001","equal to 0.01", "equal to 0.0001"); @perm = shuffle(6); @choices = @choices[@perm]; $popup_p_value = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3], $choices[4], $choices[5]],"less than or equal to 0.01"); # set up for a multiple choice problem. $radio_samp_stat = new_multiple_choice(); $radio_samp_stat->qa("Symbol of the sample statistic:", "\( \bar{x} \)"); $radio_samp_stat->extra("\( \mu \)", "\( \hat{p} \)", "\( \mu_{\hat{p}} \)", "\( p \)", "\( \mu_{\bar{x}} \)"); $standard_error = $s/(sqrt($sample)); $p_value=tprob($sample-1, ($x_bar-$mu)/$standard_error ); #$p_value = normal_prob($x_bar, "infty", mean=>$mu, deviation=>$standard_error ); # round $p_value to 4 decimal places $p_value = int(10000*$p_value+.5*($p_value <=> 0))/10000; $alpha = Compute(1); $mu = Compute($mu); $x_bar_rounded = Compute($x_bar_rounded); $p_value = Compute($p_value); @choices = ("Reject Ho and accept Ha", "Reject Ha and accept Ho", "Fail to reject Ho", "Fail to reject Ha"); @choices = @choices[shuffle(4)]; if($p_value <= .01) { $correct_h = "Reject Ho and accept Ha"; $correct_i = "Yes, because the mean cost of raising a child from birth to age 2 is significantly more than $mu dollars."; $extra_i[0] = "No, because the mean cost of raising a child from birth to age 2 is not significantly more than $mu dollars."; } else { $correct_h = "Fail to reject Ho"; $correct_i = "No, because the mean cost of raising a child from birth to age 2 is not significantly more than $mu dollars."; $extra_i[0] = "Yes, because the mean cost of raising a child from birth to age 2 is significantly more than $mu dollars."; } $popup_conclusion = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3]],$correct_h); # set up for a multiple choice problem. $radio_answer = new_multiple_choice(); $radio_answer->qa("Is the mean cost of raising a child greater than $mu dollars?", $correct_i); $extra_i[1] = "Yes, because the mean cost of raising a child from birth to age 2 is not significantly more than $mu dollars."; $extra_i[2] = "No, because the mean cost of raising a child from birth to age 2 is significantly more than $mu dollars."; $radio_answer->extra($extra_i[0], $extra_i[1], $extra_i[2]); # set up for a multiple choice problem. $radio_type1_error = new_multiple_choice(); $radio_type1_error->qa("If a type I error were made in this test, it would mean", "the mean really is $mu dollars, but we incorrectly rejected $mu dollars."); $radio_type1_error->extra("the mean really is not $mu dollars, but we incorrectly rejected $mu dollars.", "the mean really is $mu dollars, but we incorrectly failed to reject $mu dollars.", "the mean really is not $mu dollars, but we incorrectly failed to reject $mu dollars."); # set up for a multiple choice problem. $radio_type2_error = new_multiple_choice(); $radio_type2_error->qa("If a type 2 error were made in this test, it would mean", "the mean really is not $mu dollars, but we incorrectly failed to reject $mu dollars."); $radio_type2_error->extra("the mean really is not $mu dollars, but we incorrectly rejected $mu dollars.", "the mean really is $mu dollars, but we incorrectly failed to reject $mu dollars.","the mean really is $mu dollars, but we incorrectly rejected $mu dollars."); BEGIN_TEXT The U.S. Department of Agriculture reports that the mean cost of raising a child from birth to age 2 in in a rural area is \( $mu\) dollars. You believe this value is is too low, so you sample \($sample \) rural families and find the following costs (in dollars) of raising a child from birth to age 2. $BR $BR \[ $data[0], \ $data[1], \ $data[2], \ $data[3], \ $data[4], \ $data[5], \ $data[6], \ $data[7], \ $data[8], \ $data[9], \ $data[10], \ $data[11], \ $data[12], \ $data[13], \ $data[14] \] $BR Conduct a hypothesis test based on this sample data, with \( \alpha = 1%\). Answer the question, is the mean cost of raising a child greater than \($mu\) dollars? $PAR $BBOLD (a) $EBOLD State the hypotheses: $BR $BR \(H_0:\) $SPACE The \{ $popup_H0_mean->menu() \} $SPACE cost in dollars of raising a child from birth to age 2 \{ $popup_H0_direction->menu() \} $SPACE \{ $popup_H0_value->menu() \}. $BR $BR \(H_a:\) $SPACE The \{ $popup_Ha_mean->menu() \} $SPACE cost in dollars of raising a child from birth to age 2 \{ $popup_Ha_direction->menu() \} $SPACE \{ $popup_Ha_value->menu() \}. $BR $BR $BBOLD (b) $EBOLD \{ $radio_samp_dist_mean->print_q() \} \{ $radio_samp_dist_mean->print_a() \} $BR $BR $BBOLD (c) $EBOLD The value for the mean of the sampling distribution is: \{ ans_rule(5) \}. $BR $BR $BBOLD (d) $EBOLD \{ $radio_dist->print_q() \} \{ $radio_dist->print_a() \} $BR \{ $radio_dist_reason->print_q() \} \{ $radio_dist_reason->print_a() \} $BR $BR $BBOLD (e) $EBOLD State the decision rule: $BR $BR Reject \(H_0\) at \( \alpha \)= \{ ans_rule(5) \}% if the p-value of the sample statistic is \{ $popup_p_value->menu() \}. $BR $BR $BBOLD (f) Experiment $EBOLD $BR \{ $radio_samp_stat->print_q() \} \{ $radio_samp_stat->print_a() \} $BR Value of the sample statistic $BITALIC rounded to 2 decimal places$EITALIC: \{ ans_rule(7) \} $SPACE P-value of the sample statistic $BITALIC rounded to 4 decimal places$EITALIC: \{ ans_rule(5) \} $BR $BR $BBOLD (h) Conclusion $EBOLD $BR \{ $popup_conclusion->menu() \} at \( \alpha \)= \{ ans_rule(5) \}% $BR $BR $BBOLD (i) Answer the question $EBOLD $BR \{ $radio_answer->print_q() \} \{ $radio_answer->print_a() \} $BR $BR $BBOLD (j) Type I Error $EBOLD $BR \{ $radio_type1_error->print_q() \} \{ $radio_type1_error->print_a() \} $BR $BR $BBOLD (k) Type 2 Error $EBOLD $BR \{ $radio_type2_error->print_q() \} \{ $radio_type2_error->print_a() \} $BR $BR END_TEXT Context("Numeric"); WEIGHTED_ANS( $popup_H0_mean->cmp(),2 ); WEIGHTED_ANS( $popup_H0_direction->cmp(),2 ); WEIGHTED_ANS( $popup_H0_value->cmp(),2 ); WEIGHTED_ANS( $popup_Ha_mean->cmp(),2 ); WEIGHTED_ANS( $popup_Ha_direction->cmp(),2 ); WEIGHTED_ANS( $popup_Ha_value->cmp(),2 ); WEIGHTED_ANS( radio_cmp( $radio_samp_dist_mean->correct_ans() ), 4 ); WEIGHTED_ANS($mu->cmp(tolType=>'absolute',tolerance=>0), 4); WEIGHTED_ANS( radio_cmp( $radio_dist->correct_ans() ), 4 ); WEIGHTED_ANS( radio_cmp( $radio_dist_reason->correct_ans() ), 4 ); WEIGHTED_ANS($alpha->cmp(tolType=>'absolute',tolerance=>0), 2); WEIGHTED_ANS( $popup_p_value->cmp(),4 ); WEIGHTED_ANS( radio_cmp( $radio_samp_stat->correct_ans() ), 4 ); WEIGHTED_ANS($x_bar_rounded->cmp(tolType=>'absolute',tolerance=>0), 8); WEIGHTED_ANS($p_value->cmp(tolType=>'absolute',tolerance=>0), 10); WEIGHTED_ANS( $popup_conclusion->cmp(),10 ); WEIGHTED_ANS($alpha->cmp(tolType=>'absolute',tolerance=>0), 2); WEIGHTED_ANS( radio_cmp( $radio_answer->correct_ans() ), 10 ); WEIGHTED_ANS( radio_cmp( $radio_type1_error->correct_ans() ), 10 ); WEIGHTED_ANS( radio_cmp( $radio_type2_error->correct_ans() ), 10 ); ENDDOCUMENT(); # This should be the last executable line in the problem.