Forums

Search results: 133

WeBWorK Problems -> Chemistry Problems - Ionic Equations

by Eric Stroyan -
I would like to write problems that require the student to take a reaction, write out the total ionic equation, and then write the net ionic equation. Students would be presented with a reaction
AgNO_{3}(aq) + NaCl(aq) --> AgCl(s) + NaNO_{3}(aq)
be expected to write the total ionic equation,
Ag^{+1}(aq) + NO_{3}^{-1}(aq) + Na^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s) + Na^{+1}(aq) + NO_{3}^{-1}(aq)
Then give the net ionic equation
Ag^{+1}(aq) + Cl^{-1}(aq) --> AgCl(s)
I have discovered that contextReaction.pl does not like all the charges and state designators.
Has anyone modified contextReaction.pl to do something like this, or does anyone have similar problems currently working? any help would be appreciated.

I have also updated (fixed) many of my extant chemistry problems if anyone wants copies, I can share them, just let me know.

I am also interested in any routines to calculate formula mass from a formula. My current approach is not too efficient. I have a database of all the compounds with atomic number and total amounts of constituents that I search and calculate from that information. I have had some success with using regexes to extract information from a TeX formula, but have not gotten anything to work reliably (I've been using the CPAN modules for Chemistry::..., but have not gotten far enough.

Any help is appreciated.

WeBWorK Problems -> Student Answers Vanishing

by Chris Pinto -
I have a somewhat strange issue. I have written a chemistry problem which displays as a table with many answer boxes. The question renders fine, it accepts answers without issue, it grades answers without issue. If, however, a student (or instructor) returns to the question later, half the answers are not displayed (only the first 31 are displayed).

I am running WebWork 2.10 (commit id: 6543eb8286a482c347ffce684472238f78c4573a), on an Amazon Linux server. At the moment, I can't upgrade to 2.12 (largely because of some issues with the Perl dependencies).

Answers that are entered get saved to the MySQL database (they are visible by doing

select last_answer from COURSE_problem_user where user_id='USERID' and set_id='Ionic' and problem_id=1;

The past answers are also visible if I go to View Past Answers

Only when returning to the problem, does an error appear:
  • Odd number of elements in hash assignment at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 881.
When I dump the output from to Utils.pm --> decodeAnswers(), I see:
$VAR1 = [ 'AnSwEr0001', 'Ru', 'AnSwEr0002', '+3', ... 'AnSwEr0030', '+4', 'AnSwEr0031', 'As', 'AnSwEr0032' ];

The output just stops at answer 32, and doesn't have a matching field (explaining the odd number of elements error).

Deleting my question and replacing it with another one that works fine, still produces the error when existing answers are populated.

PG Code for question:

##DESCRIPTION
## Chemistry problem: determine cations and anions
##ENDDESCRIPTION

##KEYWORDS('Chemistry', 'ionic', 'ions')

## DBsubject('Chemistry')
## DBchapter('Ionic')
## DBsection('Naming')
## Date('26/11/2013')
## Author('Chris')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
);


@cations = (
["hydrogen", "H", [1],0],
["lithium", "Li", [1],0],
["sodium", "Na", [1],0],
["potassium", "K", [1],0],
["rubidium", "Rb", [1],0],
["cesium", "Cs", [1],0],
["beryllium", "Be", [2],0],
["magnesium", "Mg", [2],0],
["calcium", "Ca", [2],0],
["strontium", "Sr", [2],0],
["barium", "Ba", [2],0],
["scandium", "Sc", [3],0],
["yttrium", "Y", [3],0],
["lutetium", "Lu", [3],0],
["titanium", "Ti", [2,3,4],0],
["zirconium", "Zr", [4],0],
["hafnium", "Hf", [4], 0],
["vanadium", "V", [2,3,4,5],0],
["niobium", "Nb", [3,5],0],
["tantalum", "Ta", [5],0],
["chromium", "Cr", [2,3,6],0],
["molybdenum", "Mo", [6],0],
["tungsten", "W", [6],0],
["manganese", "Mn", [2,3,4,7],0],
["rhenium", "Re", [4,6,7],0],
["iron", "Fe", [2,3],0],
["ruthenium", "Ru", [3],0],
["osmium", "Os", [3,4],0],
["cobalt", "Co", [2,3],0],
["rhodium", "Rh", [3],0],
["iridium", "Ir", [3,4],0],
["nickel", "Ni", [2,3],0],
["palladium", "Pd", [2,4],0],
["platinum", "Pt", [2,4],0],
["copper", "Cu", [1,2],0],
["silver", "Ag", [1],0],
["gold", "Au", [1,3],0],
["zinc", "Zn", [2],0],
["cadmium", "Cd", [2],0],
["mercury", "Hg", [1,2],0],
["boron", "B", [3],0],
["aluminum", "Al", [3],0],
["gallium", "Ga", [3],0],
["indium", "In", [1,3],0],
["thallium", "Tl", [1,3],0],
["germanium", "Ge", [2,4],0],
["tin", "Sn", [2,4],0],
["lead", "Pb", [2,4],0],
["bismuth", "Bi", [3,5],0],
["ammonium", "NH4", [1], 1,0],
);

@anions = (
["carbide", "C", 4, 0],
["silicide", "Si", 4,0],
["nitride", "N", 3,0],
["phosphide", "P", 3,0],
["arsenide", "As", 3,0],
["oxide", "O", 2,0],
["sulfide", "S", 2,0],
["selenide", "Se", 2,0],
["telluride", "Te", 2,0],
["fluoride", "F", 1,0],
["chloride", "Cl", 1,0],
["bromide", "Br", 1,0],
["iodide", "I", 1,0],
["acetate", "CH3COO", 1,1],
["bicarbonate", "HCO3",1,1],
["chlorate", "ClO3", 1,1],
["cyanide", "CN", 1,1],
["hydrogen sulfate", "HSO4", 1,1],
["hydroxide", "OH", 1,1],
["nitrate", "NO3", 1,1],
["nitrite", "NO2", 1,1],
["permanganate", "MnO4", 1,1],
["carbonate", "CO3", 2,1],
["chromate", "CrO4", 2,1],
["dichromate", "Cr2O7", 2,1],
["hydrogen phosphate", "HPO4", 2,1],
["oxide", "O",2,0],
["sulfate", "SO4", 2,1],
["sulfite", "SO3", 2,1],
["thiosulfate", "S2O3", 2,1],
["phosphate", "PO4", 3,1]
);
@roman = ("I","II","III","IV","V","VI","VII","VIII","IX","X");


$table_row="";
my @answers = ();

$num = 20;
$num++;
for ($i = 0; $i < $num; $i++) {
@cat = @{$cations[random(0,$#cations)]};
$cat_v = $cat[2][random(0,$#{$cat[2]})];
@an = @{$anions[random(0,$#anions)]};

$an_v = $an[2];
$gcf = gcf($cat_v, $an_v);
$orig = $cat_v . ", " . $an_v;
$cat_v_orig = $cat_v;
$an_v_orig = $an_v;
$cat_v /= $gcf;
$an_v /= $gcf;
$formula_ans = ($cat[3] && ($an_v > 1)?"(":"") . $cat[1] . ($cat[3] && ($an_v > 1)?")":"") . ($an_v > 1? $an_v:"") . ($an[3] && ($cat_v > 1)?"(":"") . $an[1] . ($an[3] && ($cat_v > 1)?")":"") . ($cat_v > 1 ? $cat_v :"");
$formula_disp = $formula_ans;
$formula_disp =~ s!([0-9]+)!<sub>$1</sub>!g;
$name = $cat[0] . " " . ($#{$cat[2]} > 0? "(" .$roman[$cat_v_orig-1] . ")" : "") . " " . $an[0];
if($i==0){
$table_row .= row($formula_disp, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);
}else{
$table_row .= row($formula_disp, ans_rule(15), ans_rule(15), ans_rule(15), ans_rule(15));
push(@answers, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);
}
 
}




Context()->normalStrings;


# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
# Print problem number and point value (weight) for the problem
BEGIN_TEXT

For each ionic compound below, identify the cation and anion, and write the charges. Do NOT include the charge in the cation/anion column. You must include the plus sign and minus sign. The first one is done for you. $PAR

$BCENTER
\{ begintable(2) \}
\{ row( "Formula", "Cation", "Cation Charge", "Anion", "Anion Charge") \}
$table_row
\{ endtable() \}
$ECENTER

END_TEXT

for my $i (0 .. $#answers) {
ANS(std_cs_str_cmp($answers[$i]));
}


ENDDOCUMENT();



Any suggestions on how to fix this issue would be appreciated.
Thanks,
-Chris

WeBWorK Problems -> Variables in strings -> Re: Variables in strings

by Michael Gage -
There is another approach.

It's not hard to convert a hex string to an integer.

hex() does this -- in pure pearl. Google "perl hex" for more details.

These two snippets of code are in compoundProblem.pl -- an obsolete macro file that has been replaced by scaffold.pl -- and in randomizeProblem.pl.

#
# Hex encoding is shifted by 10 to obfuscate it further.
# (shouldn't be a problem since the status will be made of
# printable characters, so they are all above ASCII 32)
#
sub toHex {main::spf(ord(shift)-10,"%X")}
sub fromHex {main::spf(hex(shift)+10,"%c")}

spf -- is the PG equivalent of sprintf from perl (or fortran)

I think you could use a custom answer checker to check the student's answer.
As usual the hardest part would be giving reasonable error messages if the syntax
That's probably the right fix, but just to make sure this gets settled for future users as well could you submit this message to bugzilla (http://bugs.webwork.maa.org/).  Please include the path to the specific problem(s) that caused this.  If the problems are not in the library just copy the text of the problem into the bug report.   We can update compoundProblem.pl and answerDiscussion.pl.  CompoundProblem is a bit obsolete itself -- you might look into using scaffold.pl  instead -- but the original problem itself would need to be reworked to use scaffold.pl.

Thanks.
-- Mike



WeBWorK Problems -> Too many answer blanks

by Eric Stroyan -
I was recently reviewing old chemistry problems (schedule change, teaching chem again) that I recalled worked correctly the last time I used them (2011).
The issue is that when a student selects the problem they get the error

"PG question processing error messages

PG warning messages


------
No answer blank provided for answer evaluator AnSwEr0003

------
Answer evaluator AnSwEr0003 was not executed due to errors.
========"

I have pasted the offending code below. I just don't see where the issue is. Any help would be appreciated.

Code:
##DESCRIPTION
#
#number of ions in ionic compound
#
##ENDDESCRIPTION
DOCUMENT();
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
);
#
#identify number of ions in a formula
#
TEXT(&beginproblem);
#
#Below is a portion of the macro normally stored in the macros directory
# usually loaded in loadMacros as ionic_compounds_ammonium.pl
#
%compounds=(
1=>{name=>"Ammonium Acetate",
formula=>"NH_{4}C_{2}H_{3}O_{2}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>1},
{ion=>"C_{2}H_{3}O_{2}^{-}", name=>"acetate", count=>1}],
composition=>[
 {atom=>7, count=>1},
 {atom=>1, count=>7},
 {atom=>6, count=>2},
 {atom=>8, count=>2},]},
2=>{name=>"Ammonium Bromate",
formula=>"NH_{4}BrO_{3}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>1},
{ion=>"BrO_{3}^{-}", name=>"bromate", count=>1}],
composition=>[
 {atom=>7, count=>1},
 {atom=>1, count=>4},
 {atom=>35, count=>1},
 {atom=>8, count=>3},]},
3=>{name=>"Ammonium carbonate",
formula=>"(NH_{4})_{2}CO_{3}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>2},
  {ion=>"CO_{3}^{2-}", name=>"carbonate", count=>1}],
composition=>[
 {atom=>7, count=>2},
 {atom=>1, count=>8},
 {atom=>6, count=>1},
 {atom=>8, count=>3},]},
);
#
# get information on one of the compounds
#
$count=keys %compounds;
@items=(1..$count);
$S = list_random(@items);
$name = $compounds{$S}{name};
$form = $compounds{$S}{formula};
$i=0.;
for $who (@{$compounds{$S}{ions}})
 {$n=$i;
  $ion_at[$i]=$who->{ion};
  $name_ion[$i]=$who->{name};
  $N_ion[$i] = $who->{count};
  $i=$i+1;
  }
$i=0;
#
BEGIN_TEXT
Enter the correct number of each ion listed for \($form\).$BR
END_TEXT
#
# Generate answer blanks
#
for ($i=0;$i<=$n;$i++)
{
BEGIN_TEXT
Number of $name_ion[$i] ions = \{ans_rule(5)\}. $BR
END_TEXT
}
#
# Set up correct answers
#
$i=0;
for ($i=0;$i<=$n;$i++)
{$ans[$i]=$N_ion[$i];
push(@ans, $ans[$i]);
}
$answers = ~~@ans;
#
# Check student answers
#
&ANS(num_cmp($answers,reltol=>1,format=>'%0.4g') );

ENDDOCUMENT();
Greetings,

I am getting an error that states that a matrix element cant be converted as Real. But this error is dependent upon a particular seed value: 675
I have been unable to trace its source.

Why would this matrix element pass in some cases but not others?

Any help would be most appreciated, and I plan on taking the Problem authoring course Again this June just for issues like this one.

Thanks, Tim

##DESCRIPTION
##  One way ANOVA
##ENDDESCRIPTION

##KEYWORDS('ANOVA')

## DBsubject('Statisitics')
## DBchapter('confidence intervals')
## DBsection('Real Numbers')
## Date('11/7/2016')
## Author('Tim Payer')
# DESCRIPTION  t-tests, two sample-t
# 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",
);


############ Start Problem 25.1  ##################

### Summarized Data table values:
@nn =();
$nn[0] = "Control";
$nn[1] = "Flea beetle";
$nn[2] = "CO potato beetle";
$nn[3] = "Wireworm";
$nn[4] = "Psyllid";

@nr =();
$nr[0] = random(15,22,1);
$nr[1] = random(19,27,1);
$nr[2] = random(23,29,1);
$nr[3] = random(9,14,1);
$nr[4] = random(16,24,1);

@sr =();
$sr[0] = random(2.7,2.9,0.01);
$sr[1] = random(3.7,3.9,0.01);
$sr[2] = random(2.9,3.2,0.01);
$sr[3] = random(3.3,3.6,0.01);
$sr[4] = random(2.5,2.7,0.01);

@xr =();
$xr[0] = random(9,9.5,0.01);
$xr[1] = random(28,32,0.01);
$xr[2] = random(27,29.5,0.01);
$xr[3] = random(16,18.5,0.1);
$xr[4] = random(21,23.5,0.1);

$jnn = join("$BR ",@nn);
$jn = join("$BR ",@nr);
$jx = join("$BR ",@xr,);
$js = join("$BR ",@sr);

## Preliminary Checks:  Step 1 ####

$popup1 = PopUp(
["Choose:", 'independent', 'dependent'], 'independent');

$popup2 = PopUp(
["Choose:", 'pass', 'fail'], 'pass');

## Preliminary Checks:  Step 1b, Equal variances ####

$nprime = Compute("4/(1/$nr[0]+1/$nr[1]+1/$nr[2]+1/$nr[3]+1/$nr[4])");
$npff =floor($nprime);
$npf = Compute("$npff");  ## n-prime-1: the harmonic mean of sample size
$npc = Compute("$npff+1");

$dfhn =Compute("5");  ## df Hartley's for numerator: # of Groups
$dfhd =Compute("$npf"); ## df Hartley's for denominator: # n' - 1.

$popup5 = PopUp(
["Choose:", 'Reject', 'Do Not Reject'], 'Do Not Reject');

$popup6 = PopUp(
["Choose:", 'Reject', 'Do Not Reject'], 'Reject');

$popup7 = PopUp(
["??", '40%','20%','10%', '5%','2.5%', '2%', '1%', '0.1%', '0.01%'], '5%');

$popup8 = PopUp(
["Choose:", 'Reject', 'Do Not Reject'], 'Do Not Reject');


## Using a matrix to determine F-critical for Hartleys test, alpha = 0.05
##  Listing the F-Critical values for Hartley's with df = (5, 13:22)



$M1 = Matrix([1.72, 2.35, 3.03, 4.02, 4.86, 8.35, 13.29], [1.70, 2.31, 2.96, 3.90, 4.69, 7.92, 12.37], [1.68, 2.27, 2.90, 3.81, 4.56, 7.57, 11.62], [1.67, 2.24, 2.85, 3.72, 4.44, 7.27, 11.01], [1.65, 2.22, 2.81, 3.65, 4.34, 7.02, 10.50], [1.64, 2.20, 2.77, 3.59, 4.25, 6.81, 10.07], [1.63, 2.18, 2.74, 3.53, 4.17, 6.62, 9.71], [1.62, 2.16, 2.71, 3.48, 4.10, 6.46, 9.39], [1.61, 2.14, 2.68, 3.44, 4.04, 6.32, 9.11], [1.61, 2.13, 2.66, 3.40, 3.99, 6.19, 8.87] );

$fsamh = Compute("$sr[1]**2/$sr[4]**2");  ## F-sample for Hartleys
$rw =$npf-12;  ## Letting dfw reset from rows 13-22 to rows 1-10
$fcrth = $M1->element($rw, 3);  ## Hartleys F-Critical for 5% 

##Trouble shooting for  error, until then $pp = "(p > 0.20)";    #####
$mr1 =$M1->element($rw, 1);
$mr2 = $M1->element($rw, 2);
$mr3 = $M1->element($rw, 3);
$mr4 = $M1->element($rw, 4);
$mr5 = $M1->element($rw, 5);
$mr6 = $M1->element($rw, 6);
$mr7 = $M1->element($rw, 7);

$pp = "(p > 0.20)";
$fsmh = Compute("2.2");  ## Delete when done
$ph = "(0.0001 < p < 0.001)";
######################################
########################################################
if($fsamh < $mr1){
      $pp = "(p > 0.20)";
    } elsif(($mr1 < $fsamh) and ($fsamh < $mr2) ) {
      $pp = "(0.10 < p < 0.20)";
    } elsif(($mr2 < $fsamh) and ($fsamh < $mr3) ) {
      $pp = "(0.05 < p < 0.10)";
    } elsif(($mr3 < $fsamh) and ($fsamh < $mr4) ) {
      $pp = "(0.02 < p < 0.05)";
    } elsif(($mr4 < $fsamh) and ($fsamh < $mr5) ) {
      $pp = "(0.01 < p < 0.02)";
    } elsif(($mr5 < $fsamh) and ($fsamh < $mr6) ) {
      $pp = "(0.001 < p < 0.01)";
    } elsif(($mr7 < $fsamh) and ($fsamh < $mr7) ) {
      $pp = "(0.0001 < p < 0.001)";
     } else{
     $pp = "(p < 0.0001)";
}






#########################################
$popup9 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], '<');

$popup99 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], '<');

$popup19 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], '>');

$popup29 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], '>');

$popupph = PopUp(
["which bracketed p-value?",
"(p > 0.40)", "(p > 0.20)","(0.20 < p < 0.40)","(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.001 < p < 0.01)", "(0.0001 < p < 0.001)",  "(p < 0.0001)"], $pp );

$popup10 = PopUp(
["alpha",  '0.20','0.10', '0.05', '0.02', '0.01', '0.001', '0.0001'], '0.05');

$popup11 = PopUp(
["??", 'all met, we can proceed', 'not met, we can not proceed', 'mostly met, we can proceed'], 'all met, we can proceed');





### Declaration of Variables: Step 2  ####

$popup3 = PopUp(
["Choose:",   'x-bar-i', 'mu-i', 'x-tilde-i', 'eta-i'], 'mu-i');

$popup4 = PopUp(
["Choose:", 'mean', 'median','standard deviation of', 'proportion of'], 'mean');

### Declaration of Hypothesis: Step 3  ####

$popup30 = PopUp(
["??", 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'], 'D');

$popup31 = PopUp(
["??", 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'], 'C');

$r = list_random(0, 1, 2, 3, 4, 5, 6);  ## permits random selections of a specified range.
@alfa = ( '0.20','0.10', '0.05','0.02', '0.01', '0.001', '0.0001');
@alfap = ( '20%','10%', '5%','2%', '1%', '0.1%', '0.01%');
$alfp = "$alfap[$r]";

$LOS =Compute("100*$alfa[$r]");
$poplos = PopUp(
["alpha", '0.40', '0.20','0.10', '0.05','0.025', '0.02', '0.01', '0.001', '0.0001'], $alfa[$r]);

###  Calculate values for ANOVA Table: Step 4

$h1=0;
foreach my $i (0..4) {
   $sm1 =Compute("$h1 + $nr[$i]");   ## Summing all sample sizes
   $h1 = $sm1;
}

$h2=0;
foreach my $i (0..4) {
   $sm2 =Compute("$h2 + $nr[$i]*$xr[$i]");   ## Summing all n*xbars 
   $h2 = $sm2;
}

$gm2 =Compute("$sm2/$sm1");   ## the grand mean

$h3=0;
foreach my $i (0..4) {
   $sm3 =Compute("$h3 + $nr[$i]*($xr[$i]-$gm2)**2");   ## Summing to ssb 
   $h3 = $sm3;
}

$h4=0;
foreach my $i (0..4) {
   $sm4 =Compute("$h4 + ($nr[$i]-1)*($sr[$i])**2");   ## Summing to SSW
   $h4 = $sm4;
}

$ssb=Compute("$sm3");
$ssw2 =Compute("$sm4");
$ssw1 =sprintf("%0.2f",$ssw2);
$ssw =Compute("$ssw1");
$sst = Compute("$ssb+$ssw");
$dfb = Compute("4");
$dfw = Compute("$sm1-5");
$dft = Compute("$dfb+$dfw");
$msb = Compute("$ssb/$dfb");
$msw2 = Compute("$ssw/$dfw");
$msw1 = sprintf("%0.2f",$msw2);
$msw = Compute("$msw1");
$fsam = Compute("$msb/$msw");

### A 2x7 matrix to find f-critical and bracket -p for the ANOVA test.  ####

$M2 = Matrix([1.55, 2.04, 2.53, 3.16, 3.65, 5.31, 7.06], [1.53, 2.00, 2.46, 3.06, 3.51, 5.02, 6.55]);

if(($dfw >= 60) &&($dfw < 100)){
      $ra =1;
     @fcrit =('1.55','2.04', '2.53', '3.16', '3.65', '5.31', '7.06');
      } else{
      $ra =2;
     @fcrit =('1.53','2.00', '2.46', '3.06', '3.51', '5.02', '6.55');
}

$fcrt =Compute("$fcrit[$r]");

if($fsam < $M2->element($ra, 1)){
      $pa = "(p > 0.20)";
    } elsif(($M2->element($ra,1) < $fsam) and ($fsam < $M2->element($ra,2)) ) {
      $pa = "(0.10 < p < 0.20)";
    } elsif(($M2->element($ra,2) < $fsam) and ($fsam < $M2->element($ra,3)) ) {
      $pa = "(0.05 < p < 0.10)";
    } elsif(($M2->element($ra,3) < $fsam) and ($fsam < $M2->element($ra,4)) ) {
      $pa = "(0.02 < p < 0.05)";
    } elsif(($M2->element($ra,4) < $fsam) and ($fsam < $M2->element($ra,5)) ) {
      $pa = "(0.01 < p < 0.02)";
    } elsif(($M2->element($ra,5) < $fsam) and ($fsam < $M2->element($ra,6)) ) {
      $pa = "(0.001 < p < 0.01)";
     } elsif(($M2->element($ra,6) < $fsam) and ($fsam < $M2->element($ra,7)) ) {
      $pa = "(0.0001 < p < 0.001)";
     } else{
     $pa = "(p < 0.0001)";
}

$pop21 = PopUp(
["which bracketed p-value?",
"(p > 0.40)", "(p > 0.20)","(0.20 < p < 0.40)","(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.001 < p < 0.01)", "(0.0005 < p < 0.005)",  "(p < 0.001)", "(p < 0.0001)"], $pa );

#### Write a Statistical conclusion to the ANOVA hypothesis.

$popup40 = PopUp(
["??", '40%','20%','10%', '5%','2.5%', '2%', '1%', '0.1%', '0.01%'], $alfp);

if($fsam < $fcrt){
      $inf = "<";
      $inp = ">";
      $rj = "Do Not Reject";
      $conc = "does not vary";
      } else{
        $inf = ">";
$inp = "<";
$rj = "Reject";
        $conc = "varies";
}

$popup41 = PopUp(
["Choose:", 'Reject', 'Do Not Reject'], $rj);

$popup33 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], $inf);

$popup34 = PopUp(
["??", '<', '>', '=', '< or =', '> or ='], $inf);

$popup44 = PopUp(
["??", '<', '>'], $inp);

$popup45 = PopUp(
["which bracketed p-value?",
"(p > 0.40)", "(p > 0.20)","(0.20 < p < 0.40)","(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.001 < p < 0.01)", "(0.0005 < p < 0.005)",  "(p < 0.001)", "(p < 0.0001)"], $pa );

$popup46 = PopUp(
["??", '<', '>'], $inp);

$popup47 = PopUp(
["alpha", '0.40', '0.20','0.10', '0.05','0.025', '0.02', '0.01', '0.001', '0.0001'], $alfa[$r] );

$popup48 = PopUp(
["Choose:", 'varies', 'does not vary'], 'varies');


####  Begin Problem...

 
BEGIN_PGML 
   *Drawn from Lecture Notes: Week 11 Day 2 and Week 12 Day 2.*   
 
*25.2)* When plants are attacked by insects they release chemical compounds that attract other insects that prey on the attacking insects. The protective compounds that were released by the potato plant, _Solanum tuberosumin,_ in response to attacks from various pests were examined in an experiment in Arizona. The investigators compared the amount of defensive compounds released by the potato plant while under the attack of four insects and a control plot that was unmolested by insect pests. The mean emissions of defensive compounds released by the potato plants in response to each treatment were measured over a period of 24 hours. The results are summarized in the table below. Use a one way ANOVA hypothesis at a [$LOS]%  LOS with preliminary checks to determine if the mean rate of the compounds released in nanograms per hour (ng/hr) is significantly different for at least one of the attacking insects.
END_PGML 
BEGIN_TEXT
$PAR
$PAR
\{
DataTable(
[
['Potato psyllid,  $BITALIC Paratrioza cockerelli $EITALIC'.$BR.image( "psyllid.png", width=>848, height=>544, tex_size=>700 ).$BR.'Colorado potato beetles feeding: $BR $BITALIC Leptinotarsa decemlineata $EITALIC'.$BR.image( "CO_potatobug.png", width=>301, height=>301, tex_size=>700 ),'  ',['Flea beetles: $BITALIC Coleoptera Chrysomelidae $EITALIC'.$BR.image( "fleabeetle.png", width=>1113, height=>624, tex_size=>700 ).$BR.'Wire worms feed on a potato piece: $BR $BITALIC Melanotus communis $EITALIC'.$BR.image( "wireworm.png", width=>477, height=>293, tex_size=>700 ) ]]], 
  caption => 'Four Common Pests of the Potato Plant, $BITALIC Solanum tuberosumin $EITALIC',
  midrules=>0, 
  align => 'p{3in} p{0.1in} p{4.2in}'
);
\}
$PAR

$BR
*Image sources: $BR
*Colorado potato beetle image source: Chalotte Glen, Pender County NC, Cooperative Extension: http://pendergardener.blogspot.com/2011_04_01_archive.html \{ htmlLink( "http://pendergardener.blogspot.com/2011_04_01_archive.html","pendergardener.blogspot" ) \} $BR
*wire worm image source: wollygreen.com:   http://www.woollygreen.com/useful-info/bad-bad-beasties/how-to-get-rid-of-wire-worms/ \{ htmlLink( "http://www.woollygreen.com/useful-info/bad-bad-beasties/how-to-get-rid-of-wire-worms/","wireworms" ) \} $BR
*flea beetle and potato psyllid image source: amdro.com:   http://www.amdro.com/learn/regional-pests/common-summer-pests-of-the-southwest \{ htmlLink( "http://www.amdro.com/learn/regional-pests/common-summer-pests-of-the-southwest","psyllid and flea beetles" ) \} $BR

$BR
$PAR
\{
DataTable(
[
[['Treatment ', headerrow => 1],'N','\(\bar x\) compound $BR emission rate $BR (ng/hour)', 'Standard $BR deviation',],
[[$jnn ], $jn, $jx, $js],
], 
caption => ' ',
midrules => 1,
align => '|p{1.2in}|p{0.3in}|p{1.1in}|p{0.8in}|',
);
\}
$BR
END_TEXT
BEGIN_PGML 
*25.2) Step 1a:  Preliminary Checks*  
* The data sets are collected from [$popup1->menu]* and random samples.
* With summarized data, we assume that all data sets [$popup2->menu]* a normality test by the Anderson-Darling normality test, as we are using mean values.  

*25.2)  Step 1b:*   Check for Homoscedastity (equal variances):
END_PGML
BEGIN_TEXT
\{
DataTable(
[
[['Because of unequal sample sizes we must first calculate a harmonic mean for the grouped sample size, \(n^{\prime}.\) '],' ','\(\displaystyle{n^{\prime} = \frac{k}{\frac{1}{n_1}+\frac{1}{n_2}+...+\frac{1}{n_k}}}\) '],
], 
caption => ' ',
midrules => 0,
align => 'p{3.8in}p{0.3in}p{3in}',
);
\}
END_TEXT
BEGIN_PGML 
 [`n'`] = [_____]  Use at least second decimal accuracy  
 [`n'`] = [_____]  Rounded up to the next integer for f-table use.  
 
Establish the decision line for Hartley's Equal variance test. Recognize that this is NOT the decision line for the ANOVA test, rather it is the decision line for the preliminary check of equal variances, without which we can not proceed with the ANOVA test.  
For Hartley's test: df = (k, [`n'`]-1) = [`\Large{(}`] [____] [`\Large{,}`][____] [`\Large{)}`]
 
 [`\hspace{50pt}`] [$popup5->menu]* [`\hspace{120pt}`] [$popup6->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 equal variances." ' ) \} 
END_TEXT
BEGIN_PGML
[`\hspace{120pt} \Large{F_{critical} =}`] [____]

*25.2) Step 1c:*  The statistical conclusion for Hartley's F test is:  

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

END_PGML
BEGIN_TEXT
$PAR
  \{
DataTable(
[
[' \(\large{F}\)-Notational $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{10pt}\)  \(\large{F_{sample}}\) \(\hspace{2pt}\) '.$popup9->menu.' \(\hspace{2pt}\) \(\large{F _{critical}}\) $BR $BR '.$fsmh->ans_rule(5).' '.$popup99->menu. ' '.$fcrth->ans_rule(5). ' '],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'
);
\}

\{
DataTable(
[
['p-Notational $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{115pt}\) \(\Large{p} \hspace{2pt}\) '.$popup19->menu.'\(\hspace{2pt} \Large{\alpha}\) $BR $BR '.$popupph->menu.''.$popup29->menu.''.$popup10->menu.'' ],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'
);
\}
$BR
$BR
END_TEXT 
BEGIN_PGML

With the preliminary checks of independent and random samples, a normal distribution and equal variances, [$popup11->menu]* with a one-way ANOVA test.


*25.2)  Step 2:*   Declare the variables for this hypothesis test:  

END_PGML 
BEGIN_TEXT
$PAR
\{
DataTable(
[
['$BBOLD Note! $EBOLD Because of the limitations in software most special characters cannot be included in a "pop-up" answer format and yet they are needed for the hypothesis formation. The pop-up selections will be in the text-form for the special characters embedded within the pop-up answer. Use the table at the right as a guide if needed.','  ',[image( "musubi.png", width=>189, height=>198, tex_size=>700 )],[image( "muby4.png", width=>258, height=>266, tex_size=>700 ) ] ] 
  ], 
  caption => 'English text equivalence for the Variable and Hypothesis Options: ',
  midrules=>0, 
  align => 'p{2.5in} p{0.1in} p{2in}p{2.5in}'
);
\}
$PAR
END_TEXT

BEGIN_PGML
*25.2)  Step 2:*   Declare the variables for this hypothesis test:  
 
[$popup3->menu]* = The [$popup4->menu]* emission rate in (ng/hour) for a potato plant responding to an attack from the [`i^{th}`] insect.
.  


*25.2)  Step 3)*  Choose the correct hypothesis statement to test the claim that the mean emission rate in (ng/hour) for a potato plant varies depending upon the type of attacking insect. Test the hypothesis at a [$LOS]%  LOS.  

 
[``\Large{H_o:}``] [$popup30->menu]*  
 
[``\Large{H_a:}``] [$popup31->menu]* 
 
[``\Large{\alpha =}``] [$poplos->menu]*

 
*25.2)  Step 4)*  Complete the partially filled ANOVA table as an aid in forming the  conclusion for the ANOVA hypothesis.  
END_PGML
BEGIN_TEXT
\{
DataTable(
[
[['Source ', headerrow => 1],'Sum of Squares $BR (SS)', 'Degrees of $BR  freedom: df','Mean Squares $BR (MS)','F-sample'],
[['Between $BR Groups'], 'SSB = $ssb',  '\(df_b\) ='.$dfb->ans_rule(1).'', 'MSB ='.$msb->ans_rule(4).'', '\(F_{Sample}\) ='.$fsam->ans_rule(4).''],
[['Within $BR Groups'], 'SSW ='.$ssw->ans_rule(4).'' , '\(df_w\) ='.$dfw->ans_rule(1).'', 'MSW = $msw' , '$BBOLD Bracketed p-value: $EBOLD'],
[['Total'], 'SST ='.$sst->ans_rule(4).'', '\(df_t\) ='.$dft->ans_rule(1).'', '', ' '.$pop21->menu.''],
], 
caption => 'ANOVA TABLE ',
midrules => 1,
align => '|p{0.6in}|p{1.3in}|p{1.1in}||p{1.4in}|p{2in}|',
);
\}
$BR
$BR
END_TEXT

BEGIN_PGML

 
*25.2),  Step 5)*  Write a statistical conclusion for the ANOVA hypothesis.  
 
 
At the [$popup40->menu]*  LOS we [$popup41->menu]*  the null hypothesis of  [``\large{H_o  }``], because:  

END_PGML 

BEGIN_TEXT
$PAR
\{
DataTable(
[
[' df and \(\large{F}\) $BR Notation $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{2pt}\) \(df = (df_B , df_W\)) = \(\large{(}\) '.$dfb->ans_rule(1).'\(\large{,}\)'.$dfw->ans_rule(1).'\(\large{)}\) $BR $BR \(\hspace{11pt}\) \(\large{F_{sample}}\) \(\hspace{1pt}\) '.$popup33->menu.' \(\hspace{1pt}\) \(\large{F_{critical}}\)   $BR $BR '.$fsam->ans_rule(5).' '.$popup34->menu.''.$fcrt->ans_rule(5).'' ],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'

);
\}

$PAR
\{
DataTable(
[
['p-Notational $BR Support: $BR $BR Numeric $BR Validation: ',' \(\hspace{65pt}\) \(\Large{p} \hspace{2pt}\) '.$popup44->menu.'\(\hspace{2pt} \Large{\alpha}\) $BR $BR \(\Large{p} = \hspace{2pt}\)'.$popup45->menu.''.$popup46->menu.''.$popup47->menu.'' ],
  ], 
  caption => '  ',
  midrules=>0, 
  align => 'p{1.2in}p{7in}'
);
\}

$PAR
$BR



END_TEXT

BEGIN_PGML

*25.2),  Step 6)*   Write an English sentence conclusion.  
 
The evidence supports the case that mean rate of emissions in (ng/hour) for the potato plant [$popup48->menu]* according to which insect is attacking the plant.
 
 
END_PGML

#Adapted weighted answers values:  

## Problems 25.3 ##

##Preliminary checks:

WEIGHTED_ANS( ($popup1)->cmp, 1 );
WEIGHTED_ANS( ($popup2)->cmp, 1 );

## Check for Equal Variances: 

WEIGHTED_ANS( ($nprime)->cmp, 5 );
WEIGHTED_ANS( ($npc)->cmp, 1 );

WEIGHTED_ANS( ($dfhn)->cmp, 2 );
WEIGHTED_ANS( ($dfhd)->cmp, 2 );
WEIGHTED_ANS( ($popup5)->cmp, 1 );
WEIGHTED_ANS( ($popup6)->cmp, 1 );
WEIGHTED_ANS( ($fcrth)->cmp, 3 );
WEIGHTED_ANS( ($popup7)->cmp, 1 );
WEIGHTED_ANS( ($popup8)->cmp, 1 );
WEIGHTED_ANS( ($popup9)->cmp, 1 );
WEIGHTED_ANS( ($fsmh)->cmp, 7 );
WEIGHTED_ANS( ($popup99)->cmp, 1 );
WEIGHTED_ANS( ($fcrth)->cmp, 5 );
WEIGHTED_ANS( ($popup19)->cmp, 1 );
WEIGHTED_ANS( ($popupph)->cmp, 4 );
WEIGHTED_ANS( ($popup29)->cmp, 1 );
WEIGHTED_ANS( ($popup10)->cmp, 2 );
WEIGHTED_ANS( ($popup11)->cmp, 1 );
## Declare Variables:

WEIGHTED_ANS( ($popup3)->cmp, 2 );
WEIGHTED_ANS( ($popup4)->cmp, 2 );

##Declare Hypothesis and LOS:

WEIGHTED_ANS( ($popup30)->cmp, 2 );
WEIGHTED_ANS( ($popup31)->cmp, 2 );

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

### ANOVA Table Entries: 
#WEIGHTED_ANS( ($ssb)->cmp, 2 );
WEIGHTED_ANS( ($ssw)->cmp, 2 );
WEIGHTED_ANS( ($sst)->cmp, 2 );
WEIGHTED_ANS( ($dfb)->cmp, 2 );
WEIGHTED_ANS( ($dfw)->cmp, 3 );
WEIGHTED_ANS( ($dft)->cmp, 1 );
WEIGHTED_ANS( ($msb)->cmp, 3 );
#WEIGHTED_ANS( ($msw)->cmp, 3 );
WEIGHTED_ANS( ($fsam)->cmp, 4 );
WEIGHTED_ANS( ($pop21)->cmp, 2 );


##### ANOVA Statistical Conclusion:  Step 5

WEIGHTED_ANS( ($popup40)->cmp, 2 );
WEIGHTED_ANS( ($popup41)->cmp, 2 );
WEIGHTED_ANS( ($dfb)->cmp, 2 );
WEIGHTED_ANS( ($dfw)->cmp, 2 );
WEIGHTED_ANS( ($popup33)->cmp, 1 );
WEIGHTED_ANS( ($fsam)->cmp, 3 );
WEIGHTED_ANS( ($popup34)->cmp, 1 );
WEIGHTED_ANS( $fcrt->cmp() ->withPostFilter(AnswerHints(
$fcrt => "Yes!",
$fin => "No, We should never round a df up to infinity",  
)),4 );


WEIGHTED_ANS( ($popup44)->cmp, 1 );
WEIGHTED_ANS( ($popup45)->cmp, 3 );
WEIGHTED_ANS( ($popup46)->cmp, 1 );
WEIGHTED_ANS( ($popup47)->cmp, 1 );
WEIGHTED_ANS( ($popup48)->cmp, 1 );

###############################




BEGIN_PGML_SOLUTION


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

Hartley's F-critical = [$fcrth]  
Hartley's F-sample = [$fsmh]  
Hartley's bracketed p-value = [$ph]  
 
SSB = [$ssb]  
SSW = [$ssw]  
SST = [$sst]  
dfb = [$dfb]  
dfw = [$dfw]  
rw = [$rw]  
dft = [$dft]  
msb = [$msb]  
msw = [$msw]  
fcrt = [$fcrt]  
fsam = [$fsam]  
mr1 = [$mr1]  
fsamh = [$fsamh]  
pp = [$pp]  
fsmh = [$fsmh]    
 

END_PGML_SOLUTION

ENDDOCUMENT();