WeBWorK Problems

Syntax for an array value within a weighted answer

Syntax for an array value within a weighted answer

by tim Payer -
Number of replies: 1
Greetings all,

I am stumped by the change in syntax required for an array value referenced from within a weighted Grader problem.:

The offending piece of code is here:

WEIGHTED_ANS( ($tcrit[$r])->cmp, 4 );

Does anyone know of the adjustment that I must make so that an array element can be used in a weighted grader?


Thanks, the code block is below:

##DESCRIPTION
##  Two sample t-test on mu 
##  with interpretation of p-value.
##ENDDESCRIPTION

##KEYWORDS('confidence interval', 'confidence interpretation')

## 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",
"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 17.1  ##################
## Note that this problem will have fixed values until R studio can
## be enabled in this problem.

$n1 = 18;
$n2 = 15;
$pad1 = Compute("0.1743");
$pad2 = Compute("0.8819");
$xbw = 3.505556;
$xbc = 1.426667;
$sdw = 0.8206685;
$sdc = 0.6616718;
$dfw = Compute("30.97757");
$dfwf =floor($dfw);
$dff =Compute("$dfwf");

$popup10 = PopUp(
["Choose:", 'independent', 'dependent'], 'independent');
$popup11 = PopUp(
["Choose:", 'pass', 'fail'], 'pass');
$popup12 = PopUp(
["??", '<', '>'], '>');
$popup13 = PopUp(
["??", '<', '>'], '>');
$popup14 = PopUp(
["alpha", '0.99', '0.95','0.90', '0.80','0.50', '0.20','0.10', '0.05','0.01', '0.005'], '0.01');

$popup22 = PopUp(
["??", '<', '>'], '>');
$popup23 = PopUp(
["??", '<', '>'], '>');
$popup24 = PopUp(
["alpha", '0.99', '0.95','0.90', '0.80','0.50', '0.20','0.10', '0.05','0.01', '0.005'], '0.01');


$popup15 = PopUp(
["Choose:", 'mean', 'median'], 'mean');

$popup16 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-1');

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

$popup18 = PopUp(
["Choose:", 'whey-protein and amino acid', 'carbohydrate only'], 'whey-protein and amino acid');

$popup26 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-2');

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

$popup28 = PopUp(
["Choose:", 'whey-protein and amino acid', 'carbohydrate only'], 'carbohydrate only');

$popup30 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-1');

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

$popup32 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-2');

$popup33 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-1');

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

$popup35 = PopUp(
["Choose:", 'mu-1', 'eta-1', 'sigma-1', 'p-1', 'x-bar-1', 'x-tilde-1', 'p-hat-1','mu-2', 'eta-2', 'sigma-2', 'p-2', 'x-bar-2', 'x-tilde-2', 'p-hat-2'], 'mu-2');

$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.025', '0.01', '0.005', '0.0005');
@alfap = ( '20%','10%', '5%','2.5%', '1%', '0.5%', '0.05%');

#@tcrit =('0.85377','1.31038', '1.69724', '2.0423', '2.4573', '2.7500', '3.646');
$tcrit =Compute("1.31038");


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

############Start Problem 16.2  ##################

$xbg = random(4.2, 6.3, 0.1);
$xbb = random(3.2, 5.3, 0.1);
$sdg = random(0.5, 1.2, 0.1);
$sdb = random(0.3, 0.9, 0.1);
$ng = random(21, 35, 0.1);
$nb = random(21, 35, 0.1);
#$ng =35;
#$nb =35;



#$df = Compute("($sdg**2/$ng+$sdb**2/$nb)**2/(($sdg**2/$ng)**2/($ng-1)+($sdb**2/$nb)**2/($nb-1)");
## Could not find the "syntax error" above in the expanded form, used variables below:
$dfn =Compute("($sdg**2/$ng+$sdb**2/$nb)**2");
$dfd1 =Compute("($sdg**2/$ng)**2/($ng-1)");
$dfd2 =Compute("(($sdb**2/$nb)**2)/($nb-1)");
$df = Compute("$dfn/($dfd1+$dfd2)");
$dff1 = floor($df);
#$dff =Compute("$dff1");





####  Begin Problem...

 
BEGIN_PGML 
   *Drawn from Lecture Notes: Week 8 Day 2.*  
*17.1)*  Physiologists were interested in whether the consumption of supplements consisting of whey protein, amino acids, creatine, and carbohydrate combined with a strength training program promotes greater gains in fat-free mass (FFM) than did carbohydrate-only drinks when combined with the same exercise program. In a double blind and randomized experiment, [$n1] men were assigned to the treatment group (whey protein supplements) and [$n2] men were assigned to the control group(carbohydrates only). Both groups participated in two hour work-out periods for four days a week for ten consecutive weeks. At the end of each work-out period and individual consumed their respective "smoothie" drink. The results in FFM after ten weeks was recorded and can be accessed in an MS excel csv file on your Canvas page under the following name:  
 
  *Stat_109_HW_17p1.csv*


*17.1) Step 1:  Preliminary Checks*  
* The data sets are collected from [$popup10->menu]* and random samples.
* Both data sets [$popup11->menu]* a normality test because by the Anderson-Darling normality test:

END_PGML
BEGIN_TEXT
$PAR
$PAR
\{
DataTable(
[
['\(\hspace{40pt}\) \(\Large{p_1}\) '.$popup12->menu.'\(\hspace{2pt} \Large{\alpha}\) $BR '.$pad1->ans_rule(5).' '.$popup13->menu.'\(\hspace{2pt}\)'.$popup14->menu.' ','  ','\(\hspace{40pt}\) \(\Large{p_2}\) '.$popup22->menu.'\(\hspace{2pt} \Large{\alpha}\) $BR '.$pad2->ans_rule(5).''.$popup23->menu.'\(\hspace{2pt}\)'.$popup24->menu.' '],
  ], 
  caption => ' ',
  midrules=>0, 
  align => 'p{4.5in} p{0.1in}p{4in}'
);
\}
$PAR
$BR
END_TEXT
BEGIN_PGML

With these preliminary checks met we can run a hypothesis test on two [$popup15->menu]* values.

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

END_PGML 
BEGIN_TEXT
$PAR
$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( "two_special_char.png", width=>245, height=>349, tex_size=>700 ) ] ,' ',]
  ], 
  caption => 'English text equivalence with special symbols: ',
  midrules=>0, 
  align => 'p{3in} p{0.1in} p{2in}p{3in}'
);
\}
$PAR
$BR
END_TEXT

BEGIN_PGML
*17.1,  Step 2)*   Declare the variables for this hypothesis test:  
 
[$popup16->menu]* = The [$popup17->menu]* fat free mass in kg gained by athletes consuming a [$popup18->menu]* smoothie after each workout for a ten week program.  
 
[$popup26->menu]* = The [$popup27->menu]* fat free mass in kg gained by athletes consuming a [$popup28->menu]* smoothie after each workout for a ten week program.


*17.1,  Step 3)*  Choose the correct hypothesis statement to test the physiologist's claim that whey protein and amino acid drinks result in greater FFM gains than mere carbohydrate drinks for an after work-out replenishment. Test the hypothesis at a [$LOS]%  LOS.  

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



*17.1,  Step 4)*  Calculate for the degrees of freedom for this hypothesis test.  
 

df = [_______]

Round your df value down to the next available integer value in the t-table:

t-table df = [_______]
 
*17.1,  Step 5)*  Determine the decision line and associated t-critical value for this hypothesis test: 
 
t-critical =  [_______]
 




END_PGML

#Adapted weighted answers values:  

## Problems 17.1 ##
WEIGHTED_ANS( ($popup10)->cmp, 2 );
WEIGHTED_ANS( ($popup11)->cmp, 2 );

WEIGHTED_ANS( ($popup12)->cmp, 2 );
WEIGHTED_ANS( ($pad1)->cmp, 15 );
WEIGHTED_ANS( ($popup13)->cmp, 2 );
WEIGHTED_ANS( ($popup14)->cmp, 2 );

WEIGHTED_ANS( ($popup22)->cmp, 2 );
WEIGHTED_ANS( ($pad2)->cmp, 15 );
WEIGHTED_ANS( ($popup23)->cmp, 2 );
WEIGHTED_ANS( ($popup24)->cmp, 2 );

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

WEIGHTED_ANS( ($popup16)->cmp, 2 );
WEIGHTED_ANS( ($popup17)->cmp, 2 );
WEIGHTED_ANS( ($popup18)->cmp, 2 );

WEIGHTED_ANS( ($popup26)->cmp, 2 );
WEIGHTED_ANS( ($popup27)->cmp, 2 );
WEIGHTED_ANS( ($popup28)->cmp, 2 );

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

WEIGHTED_ANS( ($popup33)->cmp, 2 );
WEIGHTED_ANS( ($popup34)->cmp, 2 );
WEIGHTED_ANS( ($popup35)->cmp, 2 );

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


WEIGHTED_ANS( ($dfw)->cmp, 15 );
WEIGHTED_ANS( ($dff)->cmp, 3 );

#WEIGHTED_ANS( ($tcrit)->cmp, 4 );
WEIGHTED_ANS( ($tcrit[$r])->cmp, 4 );


BEGIN_PGML_SOLUTION


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



END_PGML_SOLUTION

ENDDOCUMENT();
In reply to tim Payer

Re: Syntax for an array value within a weighted answer

by tim Payer -
Nevermind!

I found my error, sorry for the false positive...

Tim