Skip to content

Commit 65415bf

Browse files
committed
Fix bug 4826 and test stat, update to MathObjects and PGML.
1 parent 82684ff commit 65415bf

File tree

1 file changed

+52
-51
lines changed
  • OpenProblemLibrary/Rochester/setStatistics6CorrelationRegression

1 file changed

+52
-51
lines changed

OpenProblemLibrary/Rochester/setStatistics6CorrelationRegression/ur_stt_6_6a.pg

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,46 @@ DOCUMENT(); # This should be the first executable line in the problem.
1515

1616
loadMacros(
1717
"PGstandard.pl",
18-
"PGchoicemacros.pl",
19-
"PGgraphmacros.pl",
20-
"PGnumericalmacros.pl",
18+
"MathObjects.pl",
19+
"PGML.pl",
20+
"niceTables.pl",
21+
"parserRadioButtons.pl",
2122
"PGstatisticsmacros.pl",
2223
"PGcourse.pl"
2324
);
2425

2526
TEXT(beginproblem());
27+
2628
$showPartialCorrectAnswers = 1;
2729

30+
Context("Numeric");
31+
Context()->{format}{number} = "%.2f"; # Use 2-place decimals for money
32+
33+
@slice = random_subset(6,(0..8));
34+
35+
# bill
36+
2837
@b = (32.98, 49.72, 88.01, 97.34, 64.30, 106.27, 52.44, 70.29, 43.58);
29-
@ab=('32.98', '49.72', '88.01', '97.34', '64.30', '106.27', '52.44', '70.29', '43.58');
38+
39+
@sb = map{ Real($_) } @b[@slice];
40+
41+
# tip
42+
3043
@t = ( 4.50, 5.28, 10.00, 16.00, 7.70, 16.00, 7.00, 10.00, 5.50);
31-
@at =('4.50', '5.28', '10.00', '16.00', '7.70', '16.00', '7.00', '10.00', '5.50');
3244

33-
@slice = NchooseK(9,6);
45+
@st = map{ Real($_) } @t[@slice];
3446

35-
@sb = @b[@slice];
36-
@sab = @ab[@slice];
37-
@st = @t[@slice];
38-
@sat = @at[@slice];
47+
$data = DataTable(
48+
[
49+
['Bill',@{~~@sb}],
50+
['Tip', @{~~@st}]
51+
],
52+
texalignment => 'c|cccccc',
53+
horizontalrules => 1,
54+
rowheaders => 1
55+
);
56+
57+
Context()->{format}{number} = "%g";
3958

4059
$sx = 0;
4160
$sy = 0;
@@ -51,72 +70,54 @@ for($i=0;$i<6;$i++){
5170
$sy2 = $sy2 + ($st[$i])**2;
5271
}
5372

54-
$r = (15*$sxy - $sx * $sy)/sqrt(15*$sx2 - ($sx)**2)/sqrt(15*$sy2 - ($sy)**2);
73+
$r = Real((6*$sxy - $sx * $sy)/sqrt(6*$sx2 - ($sx)**2)/sqrt(6*$sy2 - ($sy)**2));
5574

56-
$t = $r/sqrt((1-$r**2)/5);
75+
$t = Real($r/sqrt((1-$r**2)/4));
5776

58-
$crit = tdistr(4,0.025);
77+
$crit = Real(tdistr(4,0.025));
5978

60-
$mc = new_multiple_choice();
61-
$mc -> qa('Is there a significant correlation?', 'Yes');
62-
$mc -> extra('No');
79+
$yesno = RadioButtons(["Yes","No"],"Yes", separator => '\(\ \)' );
6380

64-
$b0 = ($sy * $sx2 - $sx * $sxy)/(6 * $sx2 - ($sx)**2);
81+
$b0 = Real(($sy * $sx2 - $sx * $sxy)/(6 * $sx2 - ($sx)**2));
6582

66-
$b1 = (6 * $sxy - $sx * $sy)/(6 * $sx2 - ($sx)**2);
83+
$b1 = Real((6 * $sxy - $sx * $sy)/(6 * $sx2 - ($sx)**2));
6784

6885
$bill = random(40,100,5);
6986

70-
$tip = $b0 + $b1*$bill;
87+
$tip = Real(round(100*($b0 + $b1*$bill))*0.01); # round to nearest cent
7188

7289
$se = sqrt(($sy2 - $b0 * $sy - $b1 * $sxy)/4);
7390

7491
$e = $crit * $se * sqrt(1+1/6+(6*($bill-$sx/6)**2)/(6*$sx2-($sx)**2));
7592

76-
$min = $tip - $e;
77-
78-
$max = $tip + $e;
93+
$min = Compute($tip - $e)->cmp(tolType => 'absolute',tolerance =>0.01 );
7994

80-
BEGIN_TEXT
95+
$max = Compute($tip + $e)->cmp(tolType => 'absolute',tolerance =>0.01 );
8196

82-
The amounts of 6 restaurant bills and the corresponding amounts of the tips are given in
83-
the below.
97+
BEGIN_PGML
8498

85-
\[ \begin{array}{c|cccccc}
86-
\mbox{Bill} & $sab[0] & $sab[1] & $sab[2] & $sab[3] & $sab[4] & $sab[5] \cr
87-
\hline
88-
\mbox{Tip} & $sat[0] & $sat[1] & $sat[2] & $sat[3] & $sat[4] & $sat[5] \cr
89-
\end{array} \]
99+
Six restaurant bills and corresponding tips are given in the table below.
90100

91-
Use a 0.05 confidence level to find the following: $BR
101+
[@ $data @]*
92102

93-
The test statistic \( r =\) \{ans_rule(20)\} $BR
103+
We'll use linear regression to estimate how the tip depends on the bill.
94104

95-
The test statistic \( t =\) \{ans_rule(20)\} $BR
105+
The correlation coefficient is [`\ r = \ `][______]{$r}
96106

97-
The critical value \( t =\) \{ans_rule(20)\} $BR
107+
The test statistic is [`\ t = \ `][______]{$t}
98108

99-
\{$mc->print_q()\} $BR
100-
\{$mc->print_a()\} $BR
109+
Use a 0.05 confidence level to find the critical value for the t-statistic:
110+
[`\ t_{\text{crit}} = \ `][______]{$crit}
101111

102-
The regression equation is \(\hat{y}=\) \{ans_rule(10)\} \(+\) \{ans_rule(10)\} \(x.\) $BR
112+
Is there a significant correlation? [_]{$yesno}
103113

104-
If the amount of the bill is $DOLLAR\($bill,\) the best prediction for the amount of the tip is
105-
\{ans_rule(20)\}, $BR
106-
and a prediction interval estimate of the amount amount of the tip is
107-
\{ans_rule(20)\} \(< \mbox{tip} < \) \{ans_rule(20)\}
114+
The regression equation is [`\ `] y = [_____]{$b0} + [______]{$b1} x
108115

109-
END_TEXT
116+
If the amount of the bill is [`$[$bill]`] the best prediction for the amount of the tip is $[______]{$tip}
117+
and a prediction interval estimate of the amount of the tip is
118+
$[______]{$min} < (tip) < $[______]{$max}
110119

111-
ANS(num_cmp($r));
112-
ANS(num_cmp($t));
113-
ANS(num_cmp($crit));
114-
ANS(radio_cmp($mc->correct_ans));
115-
ANS(num_cmp($b0));
116-
ANS(num_cmp($b1));
117-
ANS(num_cmp($tip));
118-
ANS(num_cmp($min));
119-
ANS(num_cmp($max));
120+
END_PGML
120121

121122
ENDDOCUMENT(); # This should be the last executable line in the problem.
122123

0 commit comments

Comments
 (0)