forked from openwebwork/webwork-open-problem-library
-
Notifications
You must be signed in to change notification settings - Fork 4
/
stat300_hw01_q02.pg
277 lines (227 loc) · 5.46 KB
/
stat300_hw01_q02.pg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
## DBsubject(Statistics)
## DBchapter(Nonparametric methods)
## DBsection(Rank sum test)
## Date(2014/01/19)
## Institution(University of British Columbia)
## Author(Jonathan Baik)
## Level(4)
## TitleText1('No Text')
## AuthorText1('?')
## EditionText1('?')
## Section1('.')
## Problem1('')
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"parserRadioButtons.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"unionTables.pl",
"RserveClient.pl",
"PGcourse.pl"
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context->("Numeric");
# Problem text
$prob_text = "
In an environmental study into the wildlife in two comparable lakes,
samples of small frogs were taken from each. The frogs were of the same
species and all of similar ages, each being weighed. Their weights (in g)
are given below:
";
# Part a
$qu1 = "Which graphical method would best display the above data?";
$ans1 = "Side-by-side boxplots";
$fake1a = "A histogram";
$fake2a = "Two histograms plotted on the same axis";
$fake3a = "A stem-and-leaf plot";
$fake4a = "A scatter plot";
$mc1 = new_multiple_choice();
$mc1->qa(
$qu1,
$ans1
);
$mc1->extra(
$fake1a, $fake2a, $fake3a, $fake4a
);
# Part b
$qu2 = "If using the Wilcoxon rank sum test on the above data, which of the following best describes the null hypothesis?";
$ans2 = "There is no difference between the distributions of the weights of the frogs in the two lakes.";
$fake1b = "The sample means of the weights of the frogs in the two lakes are equal.";
$fake2b = "The medians of the distributions of weights of frogs in the two lakes are equal.";
$fake3b = "There is no correlation between the weights of the frogs in the two lakes.";
$fake4b = "The weights of the frogs is independent of which lake they were chosen from.";
$mc2 = new_multiple_choice();
$mc2->qa(
$qu2,
$ans2
);
$mc2->extra(
$fake1b, $fake2b, $fake3b, $fake4b
);
# Part c
$qu3 = "In conducting a hypothesis test here, would you take a one-sided or two-sided alternative?";
$ans3 = "Two-sided";
$fake1c = "One-sided";
$mc3 = new_multiple_choice();
$mc3->qa(
$qu3,
$ans3
);
$mc3->extra(
$fake1c
);
# Part d
# Let us do this in R!
rserve_start();
## Randomly generate parameters
rserve_eval("x <- round(rnorm(10, mean=14, sd=1.2),1)");
rserve_eval("y <- round(rnorm(8, mean=13.6, sd=1.1),1)");
rserve_eval("wilcoxtest <- wilcox.test(x=x,y=y,alternative='two.sided',mu=0,paired=FALSE,conf.int=FALSE,exact=TRUE);1+1;");
# Get the P-value
@x = rserve_eval("x");
@y = rserve_eval("y");
@tst = rserve_eval('as.numeric(wilcoxtest$statistic)');
@p = rserve_eval('as.numeric(wilcoxtest$p.value)');
$ans_d = join ", ", @p;
rserve_finish();
# Part e
$qu5 = "Would you reject or not reject your null hypothesis at the 5$PERCENT significance level?";
# answer for answer e
if($ans_d < 0.05) {
$ans5 = "Reject";
$fake1e = "Not reject";
} else {
$fake1e = "Reject";
$ans5 = "Not reject";
}
# Make the mc question
$mc5 = new_multiple_choice();
$mc5->qa(
$qu5,
$ans5
);
$mc5->extra(
$fake1e
);
# Set up table
$x = sprintf("%.1f", join ", ", @x);
$y = sprintf("%.1f", join ", ", @y);
unshift(@x, "Lake 1");
unshift(@y, "Lake 2");
##############################################################
#
# Text
#
#
Context()->texStrings;
BEGIN_TEXT
$prob_text
$BR
$BR
$BCENTER
Weight
\{
BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>4).
AlignedRow( [@x], align=>LEFT, separation=>0).
AlignedRow( [@y], align=>LEFT, separation=>0).
EndTable()
\}
$ECENTER
$BR
$BR
$BBOLD Part a) $EBOLD
$BR
\{ $mc1->print_q() \}
$BR
\{ $mc1->print_a() \}
$BR
$BR
$BBOLD Part b) $EBOLD
$BR
\{ $mc2->print_q() \}
$BR
\{ $mc2->print_a() \}
$BR
$BR
$BBOLD Part c) $EBOLD
$BR
\{ $mc3->print_q() \}
$BR
\{ $mc3->print_a() \}
$BR
$BR
$BBOLD Part d) $EBOLD
$BR
Provide the P-value of your test to 3 decimal places.
$BR
\{ ans_rule(12) \}
$BR
$BR
$BBOLD Part e) $EBOLD
\{ $mc5->print_q() \}
$BR
\{ $mc5->print_a() \}
$BR
END_TEXT
#######
ANS( radio_cmp($mc1->correct_ans()) );
ANS( radio_cmp($mc2->correct_ans()) );
ANS( radio_cmp($mc3->correct_ans()) );
ANS( num_cmp($ans_d, tol=> 0.001, tolType=>"absolute") );
ANS( radio_cmp($mc5->correct_ans()) );
##############################################################
#
# Solution
#
Context()->texStrings;
Context()->{format}{number} = "%.2f";
BEGIN_SOLUTION
$BBOLD Part a) $EBOLD
$BR
$BR
Side-by-side boxplots
$BR
$BR
$BBOLD Part b) $EBOLD
$BR
$BR
There is no difference between the distributions of the weights of the frogs in the two lakes.
$BR
$BR
$BBOLD Part c) $EBOLD
$BR
$BR
Two-sided.
$BR
$BR
$BBOLD Part d) $EBOLD
$BR
$BR
The test can be performed in R with the data in vectors $BITALIC x $EITALIC and $BITALIC y $EITALIC (say) as follows:
$BR
$BR
$BITALIC
wilcoxtest <- wilcox.test(x=x,y=y,alternative='two.sided',mu=0,paired=FALSE,conf.int=FALSE,exact=TRUE)
$EITALIC
$BR
$BR
The test statistic is denoted \(W\) in R and is $BITALIC wilcoxtest\{$DOLLAR\}statistic $EITALIC. The P-value is $BITALIC wilcoxtest\{$DOLLAR\}p.value $EITALIC.
$BR
$BR
$BBOLD Part e) $EBOLD
$BR
$BR
If $BITALIC wilcoxtest\{$DOLLAR\}p.value $EITALIC < 0.05, we reject the null hypothesis at the 5\{$PERCENT\} significance level, otherwise we do not reject the null hypothesis.
END_SOLUTION
ENDDOCUMENT();