Well here it is, for whoever has been following the discussion.
I think it is ok now. I am quite pleased with how it works.
I tried lots of stuff; this is probably the only way to do it.
The subroutines seem to make a copy everything they receive, and are very reluctant to give anything back.
Thanks - hp
## DESCRIPTION
## Statistics
## ENDDESCRIPTION
## KEYWORDS('Statistics','Confidence Intervals')
## Tagged by
## DBsubject('Statistics')
## DBchapter('Confidence Intervals')
## DBsection('Sample Size - Proportion')
## Date('')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
DOCUMENT();
loadMacros(
"PGbasicmacros.pl",
"PGnumericalmacros.pl",
"PGstatisticsmacros.pl" ,
"PGauxiliaryFunctions.pl",
"MathObjects.pl",
"parserMultiAnswer.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
$ppercent = random(40,80,10);
$p = $ppercent / 100;
$confidence = list_random(80,90,95,98,99);
$deg = $confidence / 100;
$E = list_random (1,2,3,4,5,6,8,10);
$dE = $E /100;
$z=udistr (0.5 - $deg/2);
#$ans1 = $z;
$ans2 = ceil($p*(1 - $p)*($z/$dE )**2);
Context()->flags->set(
tolType => 'absolute',
tolerance => 0.0001
);
$ans1 = $z;
$ans12 = MultiAnswer( $ans1, $ans2 )->with(
singleResult => 0,
checker => sub {
my ( $correct, $student, $self ) = @_;
my ( $stu1, $stu2 ) = @{$student};
my $stuCalc = Compute("int(0.99999 + $p*(1 - $p)*($stu1/$dE)^2)");
my ( $cor1, $cor2 ) = @{$correct};
if ( abs($cor1 - $stu1)<0.01 && ( ($stuCalc == $stu2) || ($cor2 == $stu2) )) {
return [1,1];
} elsif ( abs($cor1 - $stu1)<0.01 ) {
return [1,0];
} elsif ( ($stuCalc == $stu2) || ($cor2 == $stu2) ) {
return [0,1];
} else {
return [0,0];
}
}
);
BEGIN_TEXT
It is claimed that $ppercent $PERCENT of households now subscribe to cable TV. You would like to verify this statement for your class in mass communications. You want an estimate within $E percentage points, with a $confidence $PERCENT level of confidence.
$BR
What z-value would you use?
\{ $ans12->ans_rule(25) \} $BR
How large of a sample is required? $BR
\{ $ans12->ans_rule(25) \} $BR \( \bar p (1 - \bar p) (\frac{z}{E})^2 \) $BR Additionally we always round up. $BR
END_TEXT
ANS( $ans12->cmp() );
ENDDOCUMENT();
WeBWorK Problems
access to student responses between evaluations
This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 10 posting(s) in 1 day