## WeBWorK Problems

### Phantom Questions in the Code

by Gregory Varner -
Number of replies: 1

I had previously authored a regression equation (last I used it I thought it was working fine).

I went to use it this year and noticed that it is creating 11 answers, despite having only 10 question blanks in the question. In addition, it is not computing one of my solutions (ans_we) despite being told to.

I have attached the code. It is set up so that I can change the values of the table without having to go through the painful process of actually messing with a table (and so that if I decided to randomize I could).

Any help as to why this is happening would be appreciated.

(Please ignore the comments about the error threshold being from error analysis. It was, but then I messed with it before realizing what was going on.)



DOCUMENT();        # This should be the first executable line in the problem.

"PGstandard.pl",

"MathObjects.pl",

"PGchoicemacros.pl",

"PGcourse.pl"

);

TEXT(beginproblem());

#  Set-up

$n = 7;$x[0] = 0;

$x[1] = 10;$x[2] = 20;

$x[3] = 30;$x[4] = 40;

$x[5] = 50;$x[6] = 55;

$my[0] = 66.6;$my[1] = 67.1;

$my[2] = 70.0;$my[3] = 71.8;

$my[4] = 74.3;$my[5] = 76.2;

$my[6] = 76.3;$wy[0] = 73.1;

$wy[1] = 74.7;$wy[2] = 77.4;

$wy[3] = 78.8;$wy[4] = 79.7;

$wy[5] = 81;$wy[6] = 81.2;

#############first line

$smx =0;$smy =0;

$smxy =0;$smx2 =0;

$smy2 =0;$meanmx =0;

$meanmy =0; for($i=0; $i<$n; $i++) {$smx = $smx +$x[$i];$smy = $smy +$my[$i];$smxy = $smxy + ($x[$i]*$my[$i]);$smx2 = $smx2 + ($x[$i]*$x[$i]);$smy2 = $smy2 + ($my[$i]*$my[$i]);$meanmx = $meanmx+$x[$i];$meanmy = $meanmy+$my[$i]; }$meanmx = $meanmx/$n;

$meanmy =$meanmy/$n;$ssmxy = $n*$smxy-(($smx*$smy));

$ssmx =$n*$smx2-($smx*$smx);$ssmy = $n*$smy2-($smy*$smy);

$mr = sprintf("%0.3f",$ssmxy/sqrt($ssmx*$ssmy));

$mb1a =$ssmxy/$ssmx;$mb1 = sprintf("%0.3f",$ssmxy/$ssmx);

$mb0 = sprintf("%0.3f",$meanmy-$mb1a*$meanmx);

#######################second line

$swx =0;$swy =0;

$swxy =0;$swx2 =0;

$swy2 =0;$meanwx =0;

$meanwy =0; for($i=0; $i<$n; $i++) {$swx = $swx +$x[$i];$swy = $swy +$wy[$i];$swxy = $swxy + ($x[$i]*$wy[$i]);$swx2 = $swx2 + ($x[$i]*$x[$i]);$swy2 = $swy2 + ($wy[$i]*$wy[$i]);$meanwx = $meanwx+$x[$i];$meanwy = $meanwy+$wy[$i]; }$meanwx = $meanwx/$n;

$meanwy =$meanwy/$n;$sswxy = $n*$swxy-(($swx*$swy));

$sswx =$n*$swx2-($swx*$swx);$sswy = $n*$swy2-($swy*$swy);

$wr = sprintf("%0.3f",$sswxy/sqrt($sswx*$sswy));

$wb1a =$sswxy/$sswx;$wb1 = sprintf("%0.3f",$sswxy/$sswx);

$wb0 = sprintf("%0.3f",$meanwy-$wb1a*$meanwx);

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

#  Main

BEGIN_TEXT

$BBOLD Note: The problem covers problems 1-4 from Section 2.3 of College Algebra an Applied Approach.$EBOLD

$PAR$BBOLD Note on Rounding: Your answers are dependent on rounding. Be sure to round as the problem specifies. $EBOLD$PAR

$BR The following questions use the following information from the Bureau of Justice Statistics.$BR

\{begintable(2)\}

\{row("Birth Year (Years after 1960)", "Male Life Expectancy in U.S.", "Female Life Expectancy in U.S.")\}

\{row("$$x[0]$$", "$$my[0]$$", "$$wy[0]$$")\}

\{row("$$x[1]$$", "$$my[1]$$", "$$wy[1]$$")\}

\{row("$$x[2]$$", "$$my[2]$$", "$$wy[2]$$")\}

\{row("$$x[3]$$", "$$my[3]$$", "$$wy[3]$$")\}

\{row("$$x[4]$$", "$$my[4]$$", "$$wy[4]$$")\}

\{row("$$x[5]$$", "$$my[5]$$", "$$wy[5]$$")\}

\{row("$$x[6]$$", "$$my[6]$$", "$$wy[6]$$")\}

\{endtable()\}

$BR (a) Find the linear regression models that gives the life expectancy of men M(x) and of women W(x) in terms of birth year in years after 1960 (you will find two models). (Round to three decimal places.)$BR

$$M(x) =$$ \{ans_rule(20)\}

with $$r =$$ \{ans_rule(15)\}.

$BR $$W(x) =$$ \{ans_rule(20)\} with $$r =$$ \{ans_rule(15)\}.$PAR

$BR b) For what birth year are the life expectancies equal? (Round answers to one decimal place)$BR

The life expectancies will be equal $$x=$$ \{ans_rule(10)\} years after 1960.

$BR The life expectancy will be approximately \{ans_rule(10)\} years.$PAR

$BR c) What is the life expectancy for both sexes if they are born in 2030? (Round answers to one decimal place)$BR

The life expectancy for a male will be \{ans_rule(10)\} years.

$BR The life expectancy for a female will be \{ans_rule(10)\} years.$PAR

$BR How many years after 1960 does the person need to be born to have a life expectancy of 100? (Round answers to one decimal place.)$BR

A male would need to be born \{ans_rule(10)\} years after 1960.

$BR A female would need to be born \{ans_rule(10)\} years after 1960. END_TEXT ################################################# # Answers$showPartialCorrectAnswers = 1;

$ans_ma = "$mb0 + $mb1*x"; ANS(fun_cmp($ans_ma,tol=>0.002 ,tolType=> 'absolute'));

$ans_mb = Compute($mr)->with(tolType=>'absolute', tolerance=>'0.002');

ANS($ans_mb->cmp->withPostFilter(AnswerHints( sub { my ($correct,$student,$anshash) = @_;

return abs($student-$correct) < .01;

} => ["Your answer is close.  Try the calculation using more accuracy."])));

$ans_wa = "$wb0 + $wb1*x"; ANS(fun_cmp($ans_wa,tol=>0.002 ,tolType=> 'absolute'));

$ans_wb = Compute($wr)->with(tolType=>'absolute', tolerance=>'0.002');

ANS($ans_wb->cmp->withPostFilter(AnswerHints( sub { my ($correct,$student,$anshash) = @_;

return abs($student-$correct) < .01;

} => ["Your answer is close.  Try the calculation using more accuracy."])));

$ans_c = sprintf("%0.3f",($wb0-$mb0)/($mb1-$wb1)); ANS(num_cmp($ans_c,tol=>16 ,tolType=> 'absolute'));  #Calculated from error analysis

$ans_d = sprintf("%0.3f",$mb0+($mb1*$ans_c));

ANS(num_cmp($ans_d,tol=>3.5 ,tolType=> 'absolute')); #calculated from error analysis$ans_me = sprintf("%0.3f",$mb0+($mb1*(2030-1960)));

$ans_we = sprintf("%0.3f",$wb0+($wb1*(2030-1960)));$ans_mf = sprintf("%0.3f",(100-$mb0)/$mb1);

$ans_we = sprintf("%0.3f",(100-$wb0)/$wb1); ANS(num_cmp($ans_me,tol=>3 ,tolType=> 'absolute'));    #all calculated from error analysis

ANS(num_cmp($ans_we,tol=>5 ,tolType=> 'absolute')); ANS(num_cmp($ans_mf,tol=>2 ,tolType=> 'absolute'));