WeBWorK Problems

Syntax error for weighted AnswerHints?

Syntax error for weighted AnswerHints?

by tim Payer -
Number of replies: 0
Greetings,

I am having problems getting a weighted answer hint to display.
I have no error statements, but neither are the answer hints displaying for the specific wrong answers submitted.

Could you perchance see where my glitch is creating this non-responsiveness?
I appreciate so much any help.

The weighted answer segment is shown below:

And below this is the code block for the problem...

WEIGHTED_ANS( $dl4-> cmp-> withPostFilter(AnswerHints(
['3.22', '4.61', '4.64', '5.99', '6.25', '7.78', '7.81', '7.82', '9.21', '9.49', '9.84', '11.34', '11.67', '13.82', '16.27', '18.47', '21.11', '23.51'] => "No. You have used the wrong degrees of freedom",
 $halfa[$r1] => "No, you must adjust your alpha to handle a one tailed test.",
 $wct[$r1] => "Yes!",
  )), 6 );

##DESCRIPTION
##  Hypothesis test on Independence of attributes, one tailed.
##ENDDESCRIPTION

##KEYWORDS('Independence of attributes')

## DBsubject('Statisitics')
## DBchapter('Hypothesis test')
## DBsection('Real Numbers')
## Date('11/7/2016')
## Author('Tim Payer')
# DESCRIPTION  Hypothesis test on one proportion.
# Use correct notation.
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(Random variables)
## DBsection(Expectation)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, translate, notation)
DOCUMENT();

loadMacros(
"PGstandard.pl",
"PGunion.pl",
"PGnumericalmacros.pl",
"PGstatisticsmacros.pl",
"MathObjects.pl",
"parserPopUp.pl",
"PGML.pl",
"unionTables.pl",
"niceTables.pl",
"PGcourse.pl",
"PGchoicemacros.pl",
  "answerHints.pl",
"weightedGrader.pl"
);

install_weighted_grader();

#Text(beginproblem());   #uncomment

#install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context("Numeric");
Context()->flags->set(
  tolerance => 0.01,
  tolType => "absolute",
);



### Prob 21.3 ########


### STEP  1: Hypothesis declaration: 

$ho1 = PopUp(
["Choose:", 'traffic accidents','T. gondii carriers' ],  'T. gondii carriers');

$ho2 = PopUp(
["Choose:", 'dependent upon','independent of' ],  'independent of');

$ho3 = PopUp(
["Choose:", 'traffic accidents.','T. gondii carriers.' ],  'traffic accidents.');

$ha1 = PopUp(
["Choose:", 'traffic accidents','T. gondii carriers' ],  'T. gondii carriers');

$ha2 = PopUp(
["Choose:", 'dependent upon','independent of' ],  'dependent upon');

$ha3 = PopUp(
["Choose:", 'traffic accidents.','T. gondii carriers.' ],  'traffic accidents.');

$ha4 = PopUp(
["Choose:", 'traffic accidents','T. gondii carriers' ],  'T. gondii carriers');

$ha5 = PopUp(
["Choose:", 'less','greater', 'about the same' ],  'greater');

$ha6 = PopUp(
["Choose:", 'have been in traffic accidents','are T. gondii carriers' ],  'have been in traffic accidents');

$ha7 = PopUp(
["Choose:", 'have not been in traffic accidents.','are not T. gondii carriers.' ],  'have not been in traffic accidents.');

$r = list_random(0, 1, 2, 3, 4, 5, 6);  ##  random selections of a specified range.
$r1 = list_random( 0, 1, 2);
@t1 =(' 0.10',' 0.05', ' 0.01');
@tp1 =('10%','5%', '1%');
@wct =( '1.64', '2.71' ,'5.41');  ## df =1, one tailed
@halfa =( '2.71', '3.84' ,'6.63');  ## df =1, neglecting to double alpha

$poplos = PopUp(
['alpha ?', ' 0.20',' 0.10',' 0.05',' 0.025',' 0.02', ' 0.01',' 0.005', ' 0.002', ' 0.001', ' 0.0001', ' 0.0005', ' 0.00005'], $t1[$r1] );

### STEP 2:  Ample sample? 

$as00 = Compute("38.5");
$asp00 = PopUp(
["Choose:",  '>', '> or =','=', '<', '< or ='], '> or =');

$as01 = Compute("146.5");
$asp01 = PopUp(
["Choose:",  '>', '> or =','=', '<', '< or ='], '> or =');

$as10 = Compute("38.5");

$asp10 = PopUp(
["Choose:",  '>', '> or =','=', '<', '< or ='], '> or =');

$as11 = Compute("146.5");
$asp11 = PopUp(
["Choose:",  '>', '> or =','=', '<', '< or ='], '> or =');

$popup6 = PopUp(
["Choose:",  'are', 'are not'],'are');

$popup7 = PopUp(
["Choose:",  'have', 'do not have'], 'have');

###  STEP 3: Decision Line

$dl1 = PopUp(
["+/-?",  '+', '-', '+ or -' ], '+');

$dl2 = PopUp(
["reject or not?", 'Reject Ho', 'Do not reject Ho'],'Do not reject Ho');

$dl3 = PopUp(
["reject or not?", 'Reject Ho', 'Do not reject Ho'],'Reject Ho');


$dl4 = PopUp(
["X^2-critical?", '1.64', '2.71', '3.22', '3.84', '4.61', '4.64', '5.41', '5.99', '6.25', '6.63', '7.78', '7.81', '7.82', '9.21', '9.49', '9.84', '10.83','11.34', '11.67', '13.82', '15.14', '16.27', '18.47', '21.11', '23.51' ], $wct[$r1]); 

###  STEP 4:

$wc =$wct[$r1];
$wsam = Compute("1.5508771930");

if($wsam > $wc) {
  $inq = ">";
  $in = "<"; 
  $rj = "reject";
  $dc = "fits";
  $con2 = "increase";
} else {
  $inq = "<";
  $in = ">";
  $rj = "do not reject";
  $dc = "does not fit";
  $con2 = "reduction";
}


$pop14 = PopUp(
["LOS ??", '20%','10%','5%','2.5%', '2%', '1%','0.5%','0.2%','0.1%', '0.05%','0.01%' ], $tp1[$r1]);


$pop15 = PopUp(
["reject ?", "reject", "do not reject"], $rj);

$pop16 = PopUp(
["?", ">", "=", "<"], $inq);

$pop17 = PopUp(
["?", ">", "=", "<"], $inq);

$pop18 = PopUp(
["+/-?", "-", "+", "+ or -"], "+");

$pop182 = PopUp(
["+/-?", "-", "+", "+ or -"], "+");

$pop19 = PopUp(
["X^2-critical?", '1.64', '2.71', '3.22', '3.84', '4.61', '4.64', '5.41', '5.99', '6.25', '6.63', '7.78', '7.81', '7.82', '9.21', '9.49', '9.84', '10.83','11.34', '11.67', '13.82', '16.27', '18.47', '21.11', '23.51' ], $wct[$r1]); 

$pop20 = PopUp(
["?", ">","=", "<"], $in);

$th = Compute("$wsam");

## 2-tailed p-value brackets for chi-square, df = 2, X^2 = 0.6910569 #####
if($th > 21.11){
$pt1 = "(p < 0.0001)";
 } elsif(($th > 16.27 ) &&($th < 21.11)) {
   $pt1 = "(0.0001 < p < 0.001)";
 } elsif(($th > 11.34 ) &&($th < 16.27)) {
   $pt1 = "(0.001 < p < 0.01)";
 } elsif(($th > 9.84 ) &&($th < 11.34)) {
   $pt1 = "(0.01 < p < 0.02)";
 } elsif(($th > 7.81 ) &&($th < 9.84)) {
   $pt1 = "(0.02 < p < 0.05)";
 } elsif(($th > 6.25 ) &&($th < 7.81)) {
   $pt1 = "(0.05 < p < 0.10)";
 } elsif(($th > 4.64 ) &&($th < 6.25)) {
   $pt1 = "(0.10 < p < 0.20)";
} else {
   $pt1 = "(p > 0.20)";
}


$pop21 = PopUp(
["which bracketed p-value?",
"(p > 0.20)","(p > 0.10)","(0.10 < p < 0.20)", "(0.05 < p < 0.10)", "(0.025 < p < 0.05)", "(0.02 < p < 0.05)", "(0.01 < p < 0.025)","(0.01 < p < 0.02)",  "(0.005 < p < 0.01)", "(0.002 < p < 0.01)", "(0.001 < p < 0.01)","(0.001 < p < 0.005)", "(0.001 < p < 0.002)",  "(0.0005 < p < 0.001)", "(0.0001 < p < 0.001)", "(0.0005 < p < 0.005)", "(p < 0.005)", "(p < 0.001)", "(p < 0.0005)"], $pt1);


$pop22 = PopUp(
["?", ">","=", "<"], $in);

$pop23 = PopUp(
['alpha ?', ' 0.20',' 0.10',' 0.05',' 0.025',' 0.02', ' 0.01',' 0.005', ' 0.002', ' 0.001', ' 0.0005'], $t1[$r1] );

###  STEP 5:

$pop24 = PopUp(
["Choose:",  'does not fit', 'fits'],  $dc);

###  STEP 6:

$pop41 = PopUp(
["Choose:",  'does not fit', 'fits'],  'fits');

$pop42 = PopUp(
["Choose:",  'an agreement', 'a disagreement'],  'a disagreement');

$pop43 = PopUp(
["Choose:",  'by no more than', 'at rates that exceed', 'to a lesser extent than', 'in numbers that are not much different than', 'in numbers that differ by at least as much as'  ], 'in numbers that differ by at least as much as');


####  Begin Problem...
 

BEGIN_PGML  
*Drawn From Lecture:  Week 9 Day 3, and Week 3 Day 3*  

END_PGML 
BEGIN_TEXT
\{
DataTable(
[
[['$BBOLD 21.3) $EBOLD  $BITALIC Toxoplama gondii $EITALIC is a protozoan parasite capable of infecting any warm blooded animal, including humans. But it is only the host of $BITALIC felids $EITALIC such as the domestic cat for which the parasite $BITALIC T. gondii $EITALIC can undergo sexual reproduction. '],[''],[image( "Toxop.png", width=>350, height=>120, tex_size=>700 )]],
  ], 
  caption => 'Are Driving Accidents More Likely to Occur for $BITALIC Toxoplasma gondii $EITALIC Hosts?',
  midrules=>0, 
  align => 'p{5in}p{0.3}p{3.3in}'
);
\}

END_TEXT 

BEGIN_PGML 

Humans may acquire the parasite via contact with cat feces. Pregnant women are advised not to change the cat litter box for fear of transmission of _T. gondii_ to her fetus. Roughly a quarter of all humans are infected. Because _T. gondii_ tends to affect the brain of its victims, it seems likely that it affects the behavior of its host as well. For example, _T. gondii_ is known to affect the behavior of rats and mice.   Infected rats lose their fear of cats, and in fact may be attracted to cat smells (Vyas et al. 2007). In this way the parasite has a higher probability of reaching its final host, the cat. In humans, toxoplasmosis may be associated with some mental illnesses, and it may be associated with risky behavior. Yerli et al. (2006) compared the prevalence of _T. gondii_ in a sample of 185 drivers between 21 and 40 years old who had been involved in a driving accident (cases) with a sample of 185 drivers of similar age and sex who had not had accidents (controls). The researchers were interested in whether the proportion of carriers for _T. gondii_ is greater among the population that has been in a traffic accident as opposed to those who have not been in a traffic accident. Their data is shown in the table above.  
 
  Source:  The Analysis of Biological Data 2nd Ed.: Whitlock and Shluter, pg 243-245.   

*21.3)*   Using an appropriate chi-square hypothesis test, test the hypothesis that the likelihood of drawing a _T. gondii_ carrier is greater when the individual has been in a traffic accident. Let [`\alpha`] = [$tp1[$r1]]. Indicate in your conclusion whether the data gives evidence for a higher proportion of _T. gondii_ carriers among drivers who have had accidents.
 
 

*21.3) Step 1* Make the selections that will complete the best declaration for this hypothesis test. State the LOS.  
 
[`H_o :`] The incidence of [$ho1->menu]* is [$ho2->menu]* the incidence of [$ho3->menu]*  
[`H_A :`] The incidence of [$ha1->menu]* is [$ha2->menu]* the incidence of [$ha3->menu]* Specifically, [$ha4->menu]* occur with [$ha5->menu]* frequency among those who [$ha6->menu]* than with those who [$ha7->menu]*
 
[``\Large{\alpha =}``] [$poplos->menu]*  

*21.3) Step 2:*  Preliminary check on sample size.  
Verify that each expected value, [`E_{i,j} \geq 5`].  
Where _i_ = Row #, and _j_ = Column #.
 
[`E_{0,0}`]= [_____]* [$asp00->menu]* 5  
[`E_{0,1}`]= [_____]* [$asp01->menu]* 5  
[`E_{1,0}`]= [_____]* [$asp10->menu]* 5  
[`E_{1,1}`]= [_____]* [$asp11->menu]* 5  
 
 
All expected values [$popup6->menu]* greater than or equal to 5, therefore we [$popup7->menu]* a large enough sample to run a chi-square hypothesis test.  
 
 
 
 
*21.3)  Step 3:*  Form the decision line for this hypothesis.  
 
 
 [`\hspace{50pt}`] [$dl2->menu]* [`\hspace{120pt}`] [$dl3->menu]* 
END_PGML 
BEGIN_TEXT
\{ image( "DecisionLine2.png", width=>690, height=>25, tex_size=>700, extra_html_tags=>'alt="A decision for the hypothesis on the mean." ' ) \} 
END_TEXT

BEGIN_PGML
[`\hspace{100pt} \Large{\chi^2_{critical} =}`] [$dl1->menu]* [$dl4->menu]*  
 
 
*21.2) Step 4:*  The statistical conclusion for this hypothesis test is:  

At the [$pop14->menu]*  LOS we [$pop15->menu]*  the null hypothesis of  [``\large{H_o  }``], because:

END_PGML
BEGIN_TEXT
$PAR
  \{
DataTable(
[
[' \(\large{\chi^2}\)-Notational $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{10pt}\)  \(\large{\chi^2_{sample}}\) \(\hspace{2pt}\) '.$pop16->menu.' \(\hspace{2pt}\) '.$pop182->menu.' \(\hspace{2pt}\) \(\large{\chi^2_{critical}}\) $BR $BR '.$wsam->ans_rule(5).' '.$pop17->menu.''.$pop18->menu.''.$pop19->menu.'' ],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'
);
\}

$PAR
\{
DataTable(
[
['p-Notational $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{115pt}\) \(\Large{p} \hspace{2pt}\) '.$pop20->menu.'\(\hspace{2pt} \Large{\alpha}\) $BR $BR '.$pop21->menu.''.$pop22->menu.''.$pop23->menu.'' ],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'
);
\}

$PAR


END_TEXT
BEGIN_PGML

*21.2) Step 5:*  The English conclusion for this hypothesis test is:  

The evidence supports the case that the comb distribution of the chicken offspring [$pop24->menu]* the Mendelian ratio of 9:3:3:1.
 

 
###  b and c might be pushed onto another problem after 21.3..?  

*21.3b)* Support your conclusion with estimated conditional probabilities from the data. Use the following variables within your conditional probabilities and include the resulting numerical probability associated with each notation. First use probability notation and resulting values to compare the probability of having an accident given the driver is infected with _Toxoplasma_ versus the with _Toxoplasma_  given the driver was in an accident versus the probability the driver is infected with _Toxoplasma_ given the driver was not in an accident. Use 3rd decimal accuracy.

*21.3c)* Regardless of the p-value you found in this hypothesis, suppose that your hypothesis test returns a p-value of p = 0.015. What does the p-value mean in the context of this hypothesis? Consider that if the p-value is a probability, then there is a 1.5% chance that what event will occur?


 

END_PGML

#Adapted weighted answers values:  

## Problems 21.1 ##

###  STEP 1   Hypothesis and LOS  ####

WEIGHTED_ANS( ($ho1)->cmp, 1 );
WEIGHTED_ANS( ($ho2)->cmp, 1 );
WEIGHTED_ANS( ($ho3)->cmp, 1 );
WEIGHTED_ANS( ($ha1)->cmp, 1 );
WEIGHTED_ANS( ($ha2)->cmp, 1 );
WEIGHTED_ANS( ($ha3)->cmp, 1 );
WEIGHTED_ANS( ($ha4)->cmp, 1 );
WEIGHTED_ANS( ($ha5)->cmp, 1 );
WEIGHTED_ANS( ($ha6)->cmp, 1 );
WEIGHTED_ANS( ($ha7)->cmp, 1 );

WEIGHTED_ANS( ($poplos)->cmp, 2 );

###  STEP 2:  Ample Sample? ####

WEIGHTED_ANS( ($as00)->cmp, 4 );
WEIGHTED_ANS( ($asp00)->cmp, 1 );
WEIGHTED_ANS( ($as01)->cmp, 4 );
WEIGHTED_ANS( ($asp01)->cmp, 1 );
WEIGHTED_ANS( ($as10)->cmp, 4 );
WEIGHTED_ANS( ($asp10)->cmp, 1 );
WEIGHTED_ANS( ($as11)->cmp, 4 );
WEIGHTED_ANS( ($asp11)->cmp, 1 );

WEIGHTED_ANS( ($popup6)->cmp, 2 );
WEIGHTED_ANS( ($popup7)->cmp, 2 );


###  STEP 3   ####

##  Note below that numeric values and variables need to be converted to 
## strings (text) by the addition of a leading blank space between the quote
## and the numeric value. Variables can read and rendered within popups
## by inserting periods before and after entry, called concatenation.
## all shown in this example below:

WEIGHTED_ANS( ($dl2)->cmp, 2 );
WEIGHTED_ANS( ($dl3)->cmp, 2 );
WEIGHTED_ANS( ($dl1)->cmp, 2 );
WEIGHTED_ANS( $dl4-> cmp-> withPostFilter(AnswerHints(
['3.22', '4.61', '4.64', '5.99', '6.25', '7.78', '7.81', '7.82', '9.21', '9.49', '9.84', '11.34', '11.67', '13.82', '16.27', '18.47', '21.11', '23.51'] => "No. You have used the wrong degrees of freedom",
 $halfa[$r1] => "No, you must adjust your alpha to handle a one tailed test.",
 $wct[$r1] => "Yes!",
  )), 6 );


###  STEP 4   ####

WEIGHTED_ANS( ($pop14)->cmp, 3 );
WEIGHTED_ANS( ($pop15)->cmp, 3 );
WEIGHTED_ANS( ($pop16)->cmp, 3 );
WEIGHTED_ANS( ($pop182)->cmp, 3 );
WEIGHTED_ANS( ($wsam)->cmp, 16 );
WEIGHTED_ANS( ($pop17)->cmp, 3 );
WEIGHTED_ANS( ($pop18)->cmp, 3);
WEIGHTED_ANS( ($pop19)->cmp, 6 );
WEIGHTED_ANS( ($pop20)->cmp, 3 );
WEIGHTED_ANS( ($pop21)->cmp, 4 );
WEIGHTED_ANS( ($pop22)->cmp, 3 );
WEIGHTED_ANS( ($pop23)->cmp, 4 );

###  STEP 5   ####

WEIGHTED_ANS( ($pop24)->cmp, 4);




BEGIN_PGML_SOLUTION


The correct answers are coming....in 2017, Hah!

Chi- Critical = $wct[$r1]  
r1 = [$r1]

 

END_PGML_SOLUTION

ENDDOCUMENT();