## WeBWorK Main Forum

### set correct answer to student answer

by Darwyn Cook -
Number of replies: 3
I am working on a question that has two parts, the first is to find a linear regression model for some data. The second part requires the exponential of the model.
The concern is that the with the exponential, what should the tolerances be to allow for small differences in the student answer to the regression question. I could figure this out, but it seems to me that a better way to handle the problem is to use the student answer to the linear regression in the exponent, assuming the regression is correct.
Example:
If the correct answers are
linreg = 0.112345+8.761382t
expreq = e^(0.112345+8.761382t)
and the student puts in 0.11235+8.7614t for the linear regression model, which I will take as correct, then I would like to check their answer to the question about the exponential against e^(0.11235+8.7614t), not what I have as the correct answer.
Is there a way to do this?
In reply to Darwyn Cook

### Re: set correct answer to student answer

by Gavin LaRose -
Hi Darwyn,

I think this should be easy to do with a MultiAnswer grader; see http://webwork.maa.org/wiki/MultiAnswerProblems . For example, something like the following (which is not tested) would probably work.

Cheers,
Gavin

Context()->variables->are( t=>'Real' );
$ans1 = Compute("0.112345+8.761382t");$ans2 = Compute("e^(0.112345+8.761382t)");
$regAns = MultiAnswer($ans1, $ans2 )->with( singleResult => 0, checker => sub { my($cor, $stu,$ansHash ) = @_;
my( $cor1,$cor2 ) = @{$cor}; my($stu1, $stu2 ) = @{$stu};
if ( $cor1 ==$stu1 && $cor2 ==$stu2 ) {
return [1,1];
} elsif ( $cor1 ==$stu1 &&
exp($stu1) ==$stu2 ) {
return [1,1];
} elsif ( $cor1 ==$stu1 ) {
return [1,0];
} elsif ( $cor2 ==$stu2 ) {
# it seems this is unlikely
return [0,1];
} else {
return [0,0];
}
}
BEGIN_TEXT
The linear regression is:
\{ $regAns->ans_blank(25) \}$BR
The exponential regression is:
\{ $regAns->ans_blank(25) \}$BR
$BITALIC(Note that you must enter an answer for both blanks for either to be marked correct.)$EITALIC
END_TEXT
ANS( $regAns->cmp() ); In reply to Darwyn Cook ### Re: set correct answer to student answer by Alex Jordan - I'd offer this approach, rooted in the theory behind the regression equations in the first place. For both, set the domain to be compatible with the data set's t-values. Something like:$f = Formula("0.112345+8.761382t");
$f->{limits} = [2000,2012];$g = Formula("e^(0.112345+8.761382t)");
$g->{limits} = [2000,2012]; The idea is that you want formulas that are valid for interpolation, not extrapolation to the default t-values, which may be far away from the data set's t-values. So even if your student has a line that agrees well with the correct line near t=0, it's no good as a statistical tool if the data came from say [2000,2012], and subtle differences in slope have magnified. Next, I would consider a slight absolute deviation from a linear equation to be acceptable, while a slight relative deviation from an exponential equation is acceptable. So when it came time to enter ANS commands: ANS($f->cmp(
tolType=>'absolute',
tolerance=>0.001,
));
# The student's answer and the correct answer can differ by at most 0.001 for any t in the test domain.

ANS($g->cmp( tolType=>'relative', tolerance=>0.001, )); # The ratio of the student's answer to the correct answer is between 0.999 and 1.001 for any t in the test domain. And of course the 0.001's can be changed to your preferred tolerance. This will almost get perfect correspondence between when$f$is counted correct and when$g$is. The only way to make it better is to make the relative tolerance level in$g's answer call actually be exp(0.001)-1, rather than 0.001. Or conversely, to leave $g's tolerance at 0.001 and set$f's tolerance to ln(1.001).

In reply to Alex Jordan

### Re: set correct answer to student answer

by Darwyn Cook -
I am not sure why I am suddenly thinking about these issues now, but both solutions present pros and cons. Gavin's is spot on what I was looking for, in that I can paste his solution into the problem I described, and also a different problem that deals with quadratic regressions.

However, if I ask follow up questions based on the regressions, it looks like the level of if/then statements could get deep ...

Alex's solution is essentially what I have been doing.

I was trying to figure out a way to pass the student answer back from the answer checker in a global variable, but I think that causes its own set of problems: for example what if the student logged out after having completed the first part of the question and then logged back in. They would have the first part marked correctly, but their answer would no longer be in the global variable I suspect.

These types of issues come up enough that I wonder if there is a generalizable solution.