######################################################################## ## DESCRIPTION ## A WeBWorK problem that asks students to conduct a hypothesis test ## involving a proportion. ## WeBWorK problem written by JoAnne Taormina, ## ENDDESCRIPTION ## ## KEYWORDS('hypothesis test, 'proportion', '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; $prop = random(.65,.80,.01); $prop_percent = $prop*100; $sample = random(100, 200, 10); $decrease = random(.05,.10,.01); $p_hat = $prop-$decrease; $x = $p_hat*$sample; # round $x to nearest whole number $x = int(1*$x+.5*($x <=> 0))/1; #calculate a new p_hat given x and sample size $p_hat = $x/$sample; # round $p_hat to 4 decimal places $p_hat_rounded = int(10000*$p_hat+.5*($p_hat <=> 0))/10000; $alpha = 5; @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 proportion"); @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 = ($prop, $sample, $x, $p_hat_rounded, "5%"); @choices = @choices[shuffle(5)]; $popup_H0_value = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3], $choices[4]],$prop); @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 proportion"); @choices = ("is", "is greater than", "is less than"); @choices = @choices[shuffle(3)]; $popup_Ha_direction = PopUp(["Choose:",$choices[0], $choices[1], $choices[2]],"is less than"); @choices = ($prop, $sample, $x, $p_hat_rounded, "5%"); @choices = @choices[shuffle(5)]; $popup_Ha_value = PopUp(["Choose:",$choices[0], $choices[1], $choices[2], $choices[3], $choices[4]],$prop); # 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_{\hat{p}} \)"); $radio_samp_dist_mean->extra("\( \mu \)", "\( \bar{x} \)", "\( \hat{p} \)", "\( \mu_{\bar{x}} \)", "\( p \)"); # set up for a multiple choice problem. $radio_dist = new_multiple_choice(); $radio_dist->qa("Choose the correct distribution", "Normal Distribution"); $radio_dist->extra("T-Distribution"); # set up for a multiple choice problem. $radio_dist_reason = new_multiple_choice(); $radio_dist_reason->qa("Why?", "np > 5 and n(1-p) > 5"); $radio_dist_reason->extra("We are provided with \( \sigma \).", "We are not provided with \( \sigma \).", "np > 30 and n(1-p) > 30."); @choices = ("less than or equal to 0.05", "greater than or equal to 0.05", "less than or equal to 0.0005", "greater than or equal to 0.0005","equal to 0.05", "equal to 0.0005"); @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.05"); # set up for a multiple choice problem. $radio_samp_stat = new_multiple_choice(); $radio_samp_stat->qa("Symbol of the sample statistic:", "\( \hat{p} \)"); $radio_samp_stat->extra("\( \mu \)", "\( \bar{x} \)", "\( \mu_{\hat{p}} \)", "\( p \)", "\( \mu_{\bar{x}} \)"); $standard_error = sqrt($prop*(1-$prop)/$sample); $p_value = normal_prob("-infty", $p_hat, mean=>$prop,deviation=>$standard_error ); # round $p_value to 4 decimal places $p_value = int(10000*$p_value+.5*($p_value <=> 0))/10000; @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 <= .05) { $correct_h = "Reject Ho and accept Ha"; $correct_i = "Yes, the vet is correct, because the proportion of people who got relief is significantly less than $prop_percent%."; $extra_i[0] = "No, the vet is not correct, because the proportion of people who got relief is not significantly less than $prop_percent%."; } else { $correct_h = "Fail to reject Ho"; $correct_i = "No, the vet is not correct, because the proportion of people who got relief is not significantly less than $prop_percent%."; $extra_i[0] = "Yes, the vet is correct, because the proportion of people who got relief is significantly less than $prop_percent%."; } $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 vet correct?", $correct_i); $extra_i[1] = "Yes, the vet is correct, because the proportion of people who got relief is not significantly less than $prop_percent%."; $extra_i[2] = "No, the vet is not correct, because the proportion of people who got relief is significantly less than $prop_percent%."; $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 proportion of people who get relief with the medicine $BBOLD really is $prop_percent%, but we incorrectly rejected $prop_percent%.$EBOLD"); $radio_type1_error->extra("the proportion of people who get relief with the medicine $BBOLD really is not $prop_percent&, but we incorrectly rejected $prop_percent%.$EBOLD", "the proportion of people who get relief with the medicine $BBOLD really is $prop_percent%, but we incorrectly failed to reject $prop_percent%.$EBOLD", "the proportion of people who get relief with the medicine $BBOLD really is not $prop_percent%, but we incorrectly failed to reject $prop_percent%.$EBOLD"); # 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 proportion of people who get relief with the medicine $BBOLD really is not $prop_percent%, but we incorrectly failed to reject $prop_percent%.$EBOLD"); $radio_type2_error->extra("the proportion of people who get relief with the medicine $BBOLD really is not $prop_percent%, but we incorrectly rejected $prop_percent%.$EBOLD", "the proportion of people who get relief with the medicine $BBOLD really is $prop_percent%, but we incorrectly failed to reject $prop_percent%.$EBOLD","the proportion of people who get relief with the medicine $BBOLD really is $prop_percent%, but we incorrectly rejected $prop_percent%.$EBOLD"); $alpha = Compute($alpha); $prop = Compute($prop); $p_hat_rounded = Compute($p_hat_rounded); $p_value = Compute($p_value); BEGIN_TEXT A certain medicine is said to be \($prop_percent%\) effective in giving relief to people with allergic reactions to cats and dogs. A vet believes this claims is too high. In a random sample of \($sample\) people with allergies, \($x\) people got relief. Is the vet correct at \( \alpha = $alpha% \)? $PAR $BBOLD (a) $EBOLD State the hypotheses: $BR $BR \(H_0:\) $SPACE The \{ $popup_H0_mean->menu() \} $SPACE of people who get relief from the medicine \{ $popup_H0_direction->menu() \} $SPACE \{ $popup_H0_value->menu() \}. $BR $BR \(H_a:\) $SPACE The \{ $popup_Ha_mean->menu() \} $SPACE of people who get relief from the medicine \{ $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 4 decimal places$EITALIC: \{ ans_rule(5) \} $BR 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($prop->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($p_hat_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.