diff --git a/Contrib/Fitchburg/Algebra/intervals/graphing-intervals.pg b/Contrib/Fitchburg/Algebra/intervals/graphing-intervals.pg new file mode 100644 index 0000000000..6cfbc97606 --- /dev/null +++ b/Contrib/Fitchburg/Algebra/intervals/graphing-intervals.pg @@ -0,0 +1,61 @@ +## DESCRIPTION +## Graphing intervals and linear inequalities +## ENDDESCRIPTION + +## DBsubject(Probability) +## DBchapter(Random variables) +## DBsection(Discrete: probability mass function) +## Institution(Fitchburg State) +## Author(Peter Staab) +## Date(02/10/2024) +## KEYWORDS('inequalities', 'number line graph', 'intervals') + +DOCUMENT(); + +loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl'); + +$x1 = random(1, 5); + +$gt1 = GraphTool("{interval, (-$x1,$x1]}")->with( + availableTools => [ 'IntervalTool', 'IncludeExcludePointTool' ], + numberLine => 1, + bBox => [ -6, 6 ], + ticksDistanceX => 1, + minorTicksX => 0, + useBracketEnds => 0 +); + +$x2 = random(-5, 5); + +$gt2 = GraphTool("{interval, (-inf,$x2)}")->with( + availableTools => [ 'IntervalTool', 'IncludeExcludePointTool' ], + numberLine => 1, + bBox => [ -6, 6 ], + ticksDistanceX => 1, + minorTicksX => 0, + useBracketEnds => 0 +); + +BEGIN_PGML +a) Graph the solution set for the interval [`(-[$x1],[$x1]]`]. + + [_]{$gt1} + +b) Graph the solution set for the linear inequality [`x < [$x2]`]. + + [_]{$gt2} +END_PGML + +BEGIN_PGML_SOLUTION +a) Note that the left endpoint is open and the right one is closed. Thus +graph an open endpoints on the left and a closed one on the left. + +[$gt1->generateAnswerGraph]* + +b) This is the set of all points strictly less than [$x2], so the left endpoint +should go to infinite and right one is open at [$x2]. + +[$gt2->generateAnswerGraph]* +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/contingency_table.pg b/Contrib/Fitchburg/Probability/contingency_table.pg new file mode 100644 index 0000000000..4ea4fb6a7e --- /dev/null +++ b/Contrib/Fitchburg/Probability/contingency_table.pg @@ -0,0 +1,90 @@ +## DESCRIPTION +## Filling in a contingency table and answering probability questions based on it. +## ENDDESCRIPTION + +## DBsubject(Probability) +## DBchapter(Sample Space) +## DBsection(Probability: direct computation, inclusion/exclusion) +## KEYWORDS('contingency table','TV') +## Institution(Fitchburg State University) +## Author(Peter Staab) +## Level(1) + +DOCUMENT(); +loadMacros( + 'PGstandard.pl', 'PGML.pl', + 'niceTables.pl', 'contextPercent.pl', + 'PGcourse.pl' +); + +Context('Percent'); + +do { + $stream = random(35, 65, 5); + + $ssports = random(10, 25); + $stv = random(5, 15); + $smovie = random(10, 20); + $sother = $stream - $ssports - $stv - $smovie; +} until $sother > 5; +$not_stream = 100 - $stream; +do { + $nsports = random(10, 20); + $ntv = random(5, 15); + $nmovie = random(10, 20); + $nother = $not_stream - $nsports - $ntv - $nmovie; +} until $nother > 3; + +BEGIN_PGML +One-hundred (100) people were surveyed about their video watching. They were asked about whether they stream or not and their primary watching preference. The following incomplete table was found: + +[# + [. .] [. Sports .] [. TV series .] [. movies .] [. other .] [. Total .]* + [. Stream .] [. [$ssports] .] [. [_]{$stv} .] [. [$smovie] .] [. [$sother] .] + [. [$stream] .]* + [. Don't Stream .] [. [$nsports] .] [. [$ntv] .] [. [_]{$nmovie} .] + [. [_]{$nother} .][. [_]{$not_stream} .]* + [. Total .] [. [_]{Real($ssports+$nsports)} .] [. [_]{Real($stv+$ntv)} .] + [. [$smovie + $nmovie].] [. [_]{Real($nother+$sother)}.] [. 100 .] +#]{ horizontalrules => 1, padding => [0.25, 0.25]} + +Complete the above table. + +If [`S`] is the event that a person prefers to stream videos, [`M`] is the event that a person prefers to watch movies and [`T`] is the event that a person prefers sports, if a person is selected randomly, find the following probabilities: + +a) [`P(T) = `] [_]{Real(($ssports+$nsports)/100)} +b) [`P(S\text{ and } T) = `] [_]{Real($ssports/100)} +c) [` P(S\text{ or } M) = `] [_]{Real(($stream + $nmovie)/100)} + + +END_PGML + +BEGIN_PGML_SOLUTION +The table needs to be constructed such that all values are filled in and consistent. For example, the total sports are the sum of the above two values or [$ssports+$nsports]. The number of people who preference is to stream movies can be found by [`[$stream] - [$ssports] - [$smovie] - [$sother] = [$stv] `]. Continuing +this, the table can be constructed as + +[# + [. .] [. Sports .] [. TV series .] [. movies .] [. other .] [. Total .]* + [. Stream .] [. [$ssports] .] [. [$stv] .] [. [$smovie] .] [. [$sother] .] + [. [$stream] .]* + [. Don't Stream .] [. [$nsports] .] [. [$ntv] .] [. [$nmovie] .] + [. [$nother] .][. [$not_stream] .]* + [. Total .] [. [$ssports+$nsports] .] [. [$stv+$ntv] .] + [. [$smovie + $nmovie].] [. [$nother+$sother].] [. 100 .] +#]{ horizontalrules => 1, padding => [0.25, 0.25]} + +Next, the events are found by taking the total number of people in a category and dividing by the total (or 100). + +a) This is the sports preference, so take the total sports over 100 or +[@ ($ssports+$nsports)/100 @] + +b) This is the probability that a person perfers to stream sports or [$ssports/100]. + +c) This is the probability that a person prefers streaming or movies. The total number of this is +[` [$stream] + [$nmovie+$smovie] - [$smovie] = [$stream + $nmovie]`], +where the number who prefer streaming movies is double counted in the total. +Therefore the probability is [@($stream+$nmovie)/100@] + +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/cookies.pg b/Contrib/Fitchburg/Probability/cookies.pg index a53493e8ba..e72b60e088 100644 --- a/Contrib/Fitchburg/Probability/cookies.pg +++ b/Contrib/Fitchburg/Probability/cookies.pg @@ -24,25 +24,36 @@ loadMacros( Context("Percent"); -$cookies = random(32, 46); -$nuts = random(10, 16); -$both = random(2, 8); +$chocolate = random(32, 46); +$nuts = random(10, 16); +$both = random(2, 8); $p = randomPerson(); -$allergic = ($cookies + $nuts - $both) / 100; +$allergic = ($chocolate + $nuts - $both) / 100; $safe = 1 - $allergic; BEGIN_PGML -In a box of assorted cookies, [$cookies]% contain chocolate, [$nuts]% +In a box of assorted cookies, [$chocolate]% contain chocolate, [$nuts]% contain nuts, and [$both]% contain both chocolate and nuts. [$p] is allergic to both chocolate and nuts. a) What is the probability that a cookie contains chocolate or nuts - (they can't eat it)? [___________]{Percent($allergic)} + ([$p->they] can't eat it)? [___________]{Percent($allergic)} b) What is the probability that a cookie does not contain chocolate or nuts - (they can eat it)? [___________]{Percent($safe)} + ([$p->they] can eat it)? [___________]{Percent($safe)} END_PGML +BEGIN_PGML_SOLUTION +Without loss of generalization, we can assume that there are 100 cookies in the box. +Then there are [$chocolate] chocolate cookies, [$nuts] cookies with nuts and [$both] contain both. The rest are safe to eat. + +The total number of cookies that [$p] is allergic to is [` [$chocoloate] + [$nuts] - [$both] = [$chocolate+$nuts-$both] `] where the number of cookies with both is +double counted. + +a) There are [@ Percent($allergic) @] that [$p->they] are allergic to. +b) There are [@ Percent($safe) @] that are safe for [$p] to eat. +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/discrete_pdf.pg b/Contrib/Fitchburg/Probability/discrete_pdf.pg new file mode 100644 index 0000000000..96609ab423 --- /dev/null +++ b/Contrib/Fitchburg/Probability/discrete_pdf.pg @@ -0,0 +1,84 @@ +# DESCRIPTION +# A problem that asks students to ... +# +# Modified for WeBWorK by Michael Stassen mstassen(at)fitchburgstate(dot)edu +# ENDDESCRIPTION + +## DBsubject(Probability) +## DBchapter(Random variables) +## DBsection(Discrete: probability mass function) +## KEYWORDS('Discrete Distribution', 'PDF') +## Author('Michael Stassen') +## Institution('Fitchburg State University') + +DOCUMENT(); +loadMacros( + "PGstandard.pl", "PGML.pl", + "contextPercent.pl", "niceTables.pl", + 'PGcourse.pl' +); + +Context("Percent"); +@p = ( + random(.001, .004, .001), + random(.002, .005, .001), + random(.001, .004, .001), + random(.065, .095, .010), + random(.075, .105, .010), + random(.105, .135, .010), + random(.205, .235, .010), + 0, + random(.100, .200, .050), + random(.075, .125, .025), + random(.040, .060, .010) +); +$s = 0; +$s += $_ for (@p); +$p[7] = 1 - $s; + +@PDF = ([ '\(x\)', '\(P(X=x)\)' ]); + +for my $x (0 .. 10) { + my $p = sprintf("%0.3f", $p[$x]); + push(@PDF, [ $x, $p ]); +} + +$x1 = random(3,8); +$p1 = $p[$x1]; +$x2 = random(1,4); +$p2 = 0; +$p2 += $_ for(@p[0..($x2-1)]); +$p3 = 0; +$p3 += $_ for(@p[0..$x2]); +$x4 = random(7,9); +$p4 = 0; +$p4 += $_ for(@p[$x4..$#p]); + +BEGIN_PGML +Use the PDF for the random variable, [`X`] = _score on quiz_, to answer the questions. + +[@ DataTable( + [ @PDF ], + align => '|c|c|', + horizontalrules => 1) +@]* +END_PGML + +BEGIN_PGML +a) [`P(X=[$x1])`] = [____]{Percent($p1)} +b) [`P(X<[$x2])`] = [____]{Percent($p2)} +c) [`P(X \le [$x2])`] = [____]{Percent($p3)} +d) [`P(X \ge [$x4])`] = [____]{Percent($p4)} +e) [`P(X \ge 1)`] = [____]{Percent(1-$p[0])} +END_PGML + +BEGIN_PGML_SOLUTION +a) In this case, read the probabilty off the [`X=[$x1]`] line or [$p1] (or [@ Percent($p1)@]). +b) In this case, add up all of the probabilities for the line above the [`X=[$x2]`] line. This is [$p2] or ([@ Percent($p2) @]). +c) In this case, add up all of the probabilities for the line at and above the [`X=[$x2]`] line. This is [$p3] or ([@ Percent($p3) @]). +d) In this case, add up all o fthe probabilite for the line at and below the [`X=[$x4]`] +line. This is [$p4] or [@ Percent ($p4) @]). +e) In this case, it is easiest to recall that the sum of all of the probabilities must be 1. Therefore, this is the same as [`1-P(X<1)`] which is [@ 1-$p[0] @] or [@ Percent(1-$p[0]) @] +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/ice-cream.pg b/Contrib/Fitchburg/Probability/ice-cream.pg index 72e8829078..a6045a3ba2 100644 --- a/Contrib/Fitchburg/Probability/ice-cream.pg +++ b/Contrib/Fitchburg/Probability/ice-cream.pg @@ -1,5 +1,6 @@ # DESCRIPTION -# A problem that asks students to ... +# A problem that asks students to fill in a contingency table based on ice cream +# flavors and answer questions related to probabilities from the table. # # This problem is derived from a homework problem in Introductory Statistics, # licensed by OpenStax under a Creative Commons Attribution License (CC BY 4.0). @@ -9,6 +10,7 @@ ## DBsubject(Probability) ## DBchapter(Sample Space) ## DBsection(Probability: direct computation, inclusion/exclusion) +## KEYWORDS('contingency table') ## Institution(Fitchburg State University) ## Author(Rachael Norton) @@ -44,17 +46,17 @@ A soft-serve ice cream shop sold [$total] ice creams in a day. The following table identifies the ice creams they sold by flavor and whether they were served in a cup or cone. Fill in the missing values. -[@ DataTable( - [ - ['Flavor', 'Chocolate', 'Vanilla', 'Swirl', 'Strawberry', 'Total'], - ['Cup', $cupchocolate, PGML('[____]{$cupvanilla}'), $cupswirl, $cupstrawberry, $cup], - ['Cone', $conechocolate, $conevanilla, PGML('[____]{$coneswirl}'), $conestrawberry, PGML('[____]{$cone}')], - ['Total', PGML('[____]{$chocolate}'), $vanilla, PGML('[____]{$swirl}'), PGML('[____]{$strawberry}'), PGML('[____]{$total}')], - ], - padding => [0.5, 0.5], - align => '|c|c|c|c|c|c|', - horizontalrules => 1) -@]* +[# + [. .] [. Chocolate .] [. Vanilla .] [. Swirl .] [. Strawberry .] [. Total .]* + [. Cup .] [. [$cupchocolate] .] [. [_]{$cupvanilla} .] + [. [$cupswirl] .] [. [$cupstrawberry] .] [.[$cup].] + [. [$stream] .]* + [. Cone .] [. [$conechocolate] .] [. [$conevanilla] .] [. [_]{$coneswirl} .] + [. [$conestrawberry] .][. [_]{$cone} .]* + [. Total .] [. [_]{Real($chocolate)} .] [.[$vanilla].][. [_]{Real($swirl)} .] + [. [_]{$strawberry} .] [. [_]{Real($total)}.] +#]{ horizontalrules => 1, padding => [0.25, 0.25]} + a) What is the probability that a randomly selected ice cream was served in a cup? [____]{$cup/$total} b) What is the probability that a randomly selected ice cream was either chocolate or swirl? [____]{($chocolate+$swirl)/$total} @@ -63,4 +65,35 @@ d) What is the probability that a randomly selected ice cream was strawberry, gi e) What is the probability that a randomly selected ice cream was not chocolate? [____]{($total-$chocolate)/$total} END_PGML +BEGIN_PGML_SOLUTION +First, fill in the rest of the table, starting with rows or columns that are only +missing one value. Like the total Chocolate must be the sum in that column or +[$chocolate]. Continuing this, you will see that the table is: + +[# + [. .] [. Chocolate .] [. Vanilla .] [. Swirl .] [. Strawberry .] [. Total .]* + [. Cup .] [. [$cupchocolate] .] [. [$cupvanilla] .] + [. [$cupswirl] .] [. [$cupstrawberry] .] [.[$cup].] + [. [$stream] .]* + [. Cone .] [. [$conechocolate] .] [. [$conevanilla] .] [. [$coneswirl] .] + [. [$conestrawberry] .][. [$cone] .]* + [. Total .] [. [$chocolate] .] [.[$vanilla].][. [$swirl] .] + [. [$strawberry] .] [. [$total] .] +#]{ horizontalrules => 1, padding => [0.25, 0.25]} + + +To determine the probabilities, determine the number of instances that satify the condition and the divide by the total. + +a) [`` \frac{[$cup]}{[$total]} ``] + +b) [`` \frac{[$chocolate] + [$swirl]}{[$total]} = \frac{[$chocolate+$swirl]} +{[$total]} ``] + +c) [`` \frac{[$cup]}{[$total]} ``] + +d) [`` \frac{[$cupstrawberry]}{[$cup]}``] where the denominator is just the number of cups served. + +e) [`` 1- \frac{[$chocolate]}{[$total]} = \frac{[$total-$chocolate]}{[$total]} ``] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/living.pg b/Contrib/Fitchburg/Probability/living.pg index c1acbef1da..7fa62e9453 100644 --- a/Contrib/Fitchburg/Probability/living.pg +++ b/Contrib/Fitchburg/Probability/living.pg @@ -45,29 +45,41 @@ $ans3 = Fraction(100 - $b, 100); BEGIN_PGML One hundred nurses were surveyed about their living situation. The results of this survey are given in the following table. ->> -[@ DataTable([ - ['',PGML('_Renter_ (`R`)'), PGML('_Homeowner_ ([`R^{\prime}`])'), PGML('_Total_')], - [PGML('Lives Alone (`A`)'),$a,$b,'50'], - [PGML('Does not live alone (`A^{\prime}`)'), $c, $d, '50'], - [PGML('Total'), $e, $f, 100] -], - padding => [0.5, 0.5], - align => '|l|c|c|c|', - horizontalrules => 1 - ) @]* << - +[# + [. .] [._Renter_ ([`R`]).] [. _Homeowner_ ([`R^{\prime}`]).]* + [.Lives Alone [`A`].] [.[$a].] [.[$b].] [.50.]* + [. Does not live alone [`A^{\prime}`] .] [.[$c].] [.[$d].] [. 50 .]* + [. Total .] [.[$e] .] [.[$f].] [.100.]* +#]{padding => [0.5, 0.5], horizontalrules => 1, texalignment => 'lccc'} If a nurse is selected at random from those surveyed, find the probability of each of the following events. a) The nurse is a renter or lives alone. + Answer: [_]{$ans1}{20} b) The nurse is a homeowner or does not live alone. + Answer: [_]{$ans2}{20} c) The nurse is a renter or does not live alone. + Answer: [_]{$ans3}{20} END_PGML +BEGIN_PGML_SOLUTION +For each of these, we need to find the total number of nurses that are listed in +the table with the given statement. +a) The total number of nurses that rent or live alone is [`[$a]+[$b] +[$c] = [@ 100-$d @] `], +so [`` P(A\text{ or }R) = \frac{[@100-$d@]}{100} ``] + +b) The total number of nurses that owns a home or does not live alone is +[`[$b] + [$d] + [$c] = [@100-$a@] `] so +[``P(R'\text{ or }A') = \frac{[@100-$a@]}{100}``] + +c) The total number of nurses that rents or does not live along is +[`[$a]+[$c]+[$d] = [@100-$b@]`] therefore +[``P(R\text{ or }A') = \frac{[@100-$b@]}{100}``] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/prob-cards-01.pg b/Contrib/Fitchburg/Probability/prob-cards-01.pg index 17ba265058..e8757c7899 100644 --- a/Contrib/Fitchburg/Probability/prob-cards-01.pg +++ b/Contrib/Fitchburg/Probability/prob-cards-01.pg @@ -24,8 +24,7 @@ Context('Fraction'); random_subset(2, 'red', 'gray', 'yellow', 'blue', 'purple'); do { - $num1 = random(5, 9); - $num2 = random(5, 9); + ($num1, $num2) = (random(5, 9), random(5, 9)); } until ($num1 != $num2); $total = $num1 + $num2; @@ -56,4 +55,25 @@ e) [`P(G|E)`] = [__]{$ans5} f) [`P(E|G)`] = [__]{$ans6} END_PGML +BEGIN_PGML_SOLUTION +a) Since there are [$num1] [$color1] cards out of a total of [$total] cards, then +[``` P(G) = \frac{[$num1]}{[$total]} ```] + +b) There are [$even1+$even2] even cards so +[``` P(E) = [$ans2] ```] + +c) There are [$even1] [$color1] even cards so +[``` P(G\text{ and }E) = [$ans3] ```] + +d) The total [$color1] or even cards need to be counted. There are [$num1] [$color1] cards and [$even2] even [$color2] cards, so +[``` P(G\text{ or }E) = \frac{[$num1]+[$even2]}{[$total]} = [$ans4] ```] + +e) This is the probability that the card is [$color1] given that it is even. There are [$even1+$even2] even cards and of those [$even1] are [$colo1], so +[``` P(G|E) = \frac{[$even1]}{[$even1+$even2]} ```] + +f) This is the probability that the card is even given that the card is [$color1]. +There are [$num1] [$color1] cards and of those [$even1] are even. Thus +[``` P(E|G) = \frac{[$even1]}{[$num1]} ```] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/prob-cards-02.pg b/Contrib/Fitchburg/Probability/prob-cards-02.pg index 4165595a8f..d7f4332076 100644 --- a/Contrib/Fitchburg/Probability/prob-cards-02.pg +++ b/Contrib/Fitchburg/Probability/prob-cards-02.pg @@ -23,8 +23,8 @@ Context('Fraction'); ($color1, $color2) = random_subset(2, 'red', 'gray', 'yellow', 'blue', 'purple'); -$num1 = random(5, 11, 1); -$num2 = random(3, $gray, 1); +$num1 = random(5, 11,); +$num2 = random(3, $gray); $total = $num1 + $num2; $ans1 = Fraction($num1**2, $total**2); @@ -45,5 +45,18 @@ b) [`P(E)`] = [__]{$ans2} c) [`P(G_2|G_1)`] = [__]{$ans3} END_PGML +BEGIN_PGML_SOLUTION +a) [`` P(G_1) = \frac{[$num1]}{[$total]} ``] and since the cards are replaced, [`` P(G_2) = \frac{[$num1]}{[$total]} ``] and since these are independent, +[``` P(G_1\text{ and }G_2) = P(G_1) \cdot P(G_2) = + \left(\frac{[$num1]}{[$total]}\right)^2 = [$ans1] ```] + +b) The probability that at least one card is blue is most easily found by +the complement of part a) or [``P(E) = 1- P(G_1\text{ and }G_2) = 1- [$ans1] = [$ans2] ``] + +c) [`P(G_2|G_1)`] is the probability that the second card is green given that +the first one was green. Since these are independent, this is just [` P(G_2)`] or +[`[$ans3]`]. +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/proportions-pets.pg b/Contrib/Fitchburg/Probability/proportions-pets.pg new file mode 100644 index 0000000000..0be4d9afed --- /dev/null +++ b/Contrib/Fitchburg/Probability/proportions-pets.pg @@ -0,0 +1,57 @@ +## DESCRIPTION +## Statistics: Descriptive statistics +## ENDDESCRIPTION + +## Tagged by CTD + +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Summary statistics) +## Date(8/15/12) +## Institution(Fitchburg State) +## Author(Jessie Oehrlein) +## Level(2) +## KEYWORDS('proportions','sample proportion') + +DOCUMENT(); + +loadMacros("PGstandard.pl", "Parser.pl", "PGML.pl"); + +Context("LimitedNumeric"); + +$n = random(100, 1000, 100); +$p = random(10, 90, 10); +$pprop = $p / 100; +$offset = random(-5, 5, 1); +$phat = $p + $offset; +$phatprop = $phat / 100; +$x = $phatprop * $n; + +BEGIN_PGML +Overall, [$p] percent of students at Mythic University have pets. [$n] randomly selected students at were asked whether they have pets, and [$x] of them said that they did. + +Enter each requested value. Proportions should be entered with two decimal points of precision. + +a) [` n `] = [_]{$n} + +b) [` x `] = [_]{$x} + +c) [` p `] = [_]{$pprop} + +d) [` \hat{p} `] = [_]{$phatprop} + +END_PGML + +BEGIN_PGML_SOLUTION + +a) This is the total number of students in the sample or [$n]. + +b) This is the toal number of students with pets and this is [$x]. + +c) This is the population proportion and since the problem says [$p] percent, then +this is [$pprop]. + +d) This is sample proportion and this is [`\frac{[$x]}{[$n]} `] +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Probability/siblings_rel_freq.pg b/Contrib/Fitchburg/Probability/siblings_rel_freq.pg new file mode 100644 index 0000000000..c8e717d10d --- /dev/null +++ b/Contrib/Fitchburg/Probability/siblings_rel_freq.pg @@ -0,0 +1,79 @@ +## DBsubject(Probability) +## DBchapter(Sample Space) +## DBsection(Probability: direct computation, inclusion/exclusion) +## KEYWORDS('relative frequencey', 'probability') +## Level(1) +DOCUMENT(); + +loadMacros("PGstandard.pl", "PGML.pl", "niceTables.pl", "contextPercent.pl"); + +Context("LimitedNumeric"); +loadMacros("fixedPrecision.pl", 'PGcourse.pl') + ; # must come after Context is set. + +$total = random(40, 50, 10); + +@freq = + (random(5, 9), random(7, 13), 0, random(3, 5), random(2, 3), random(1, 2)); +$subtotal = 0; +$subtotal += $_ for (@freq); +$freq[2] = $total - $subtotal; + +@rf = map { FixedPrecision($_ / $total, 3); } @freq; + +$crf[0] = FixedPrecision(100 * $rf[0], 1); +for my $i (1 .. 5) { + $crf[$i] = FixedPrecision($crf[ $i - 1 ] + 100 * $rf[$i], 1); +} + +BEGIN_PGML +[$total] students were surveyed. The number of siblings for each student was recorded. The data is summarized in the following table: + +[@ DataTable( + [ + [['Siblings', headerrow=>1], 'Relative Frequency'], + [0, $rf[0]], + [1, $rf[1]], + [2, $rf[2]], + [3, $rf[3]], + [4, $rf[4]], + [5, $rf[5]], + ], + align => '|c|c|', + horizontalrules => 1 + ) + @]* + +END_PGML + +$s = random(2, 4); + +Context("LimitedPercent-strict"); +Context()->flags->set(forceDecimals => 1); + +$pS = Percent(FixedPrecision(100 * $rf[$s], 1) . '%'); +$pLeast = Percent(FixedPrecision(100 - $crf[ $s - 1 ], 1) . '%'); +$pFewer = Percent(FixedPrecision($crf[ $s - 1 ], 1) . '%'); +$pMost = Percent(FixedPrecision($crf[$s], 1) . '%'); +$pMore = Percent(FixedPrecision(100 - $crf[$s], 1) . '%'); + +BEGIN_PGML +Answer the questions with percents (including the percent sign) and round to one digit past the decimal. + +a) What percent of the students have [$s] siblings? [_____]{$pS} +b) What percent of the students have at least [$s] siblings? [_____]{$pLeast} +c) What percent of the students have fewer than [$s] siblings? [_____]{$pFewer} +d) What percent of the students have at most [$s] siblings? [_____]{$pMost} +e) What percent of the students have more than [$s] siblings? [_____]{$pMore} + +END_PGML + +BEGIN_PGML_SOLUTION +a) In this case, convert the relative frequency in the row with [$s] siblings to a percent. This is [$pS] +b) Sum the relative frequencies in the row with [$s] siblings and below then convert to a percent. This is [$pLeast]. +c) Sum the relative frequencies in the row above the [$s] siblings, then convert to a percent. This is [$pFewer]. +d) Sum the relative frequencies from the top to the row with [$s] siblings, then convert to a percent. This is [$pMost]. +e) Sum the relative frequencies from below the row with [$s] siblings, then convert to a percent. This is [$pMore]. +END_PGML_SOLUTION + +ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/Contrib/Fitchburg/Probability/tree-diagram.pg b/Contrib/Fitchburg/Probability/tree-diagram.pg new file mode 100644 index 0000000000..11b6a2bb32 --- /dev/null +++ b/Contrib/Fitchburg/Probability/tree-diagram.pg @@ -0,0 +1,106 @@ +## DESCRIPTION +## Calculate probabilities of selecting marbles from a bag using a tree diagram. +## +## ENDDESCRIPTION + +## DBsubject(Probability) +## DBchapter(Sample Space) +## DBsection(Probability: direct computation, inclusion/exclusion) +## Institution(Fitchburg State University) +## KEYWORDS('random','with replacement') +## Author(Peter Staab) +## Level(1) + +DOCUMENT(); +loadMacros( + 'PGstandard.pl', 'PGML.pl', + 'PGtikz.pl', 'contextPercent.pl', + 'PGcourse.pl' +); + +Context('Numeric'); + +$red = random(2, 4); +$green = random(5, 7); + +$graph = createTikZImage(); +$graph->tikzLibraries('arrows.meta'); +$graph->BEGIN_TIKZ +\tikzset{>={Stealth[scale=1.5]}} +\filldraw[ + draw=LightBlue, + fill=white, + rounded corners=10pt, + thick,use as bounding box +] (0,0.5) rectangle (6,6); +\draw(3,6) -- (1.5,4.5) node[below] {a R}; +\draw(3,6) -- (4.5,4.5) node[below] {b G}; +\draw(1.5,4) -- (0.5,3) node[below] {c R}; +\draw(1.5,4) -- (2.2,3) node[below] {d G}; +\draw(4.5,4) -- (3.8,3) node [below] {e R}; +\draw(4.5,4) -- (5.5,3) node [below] {f G}; +\draw(0.5,2.5) -- (0.5,1.5) node [below] {g RR}; +\draw(2.2,2.5) -- (2.2,1.5) node [below] {h RG}; +\draw(3.8,2.5) -- (3.8,1.5) node [below] {i GR}; +\draw(5.5,2.5) -- (5.5,1.5) node [below] {j GG}; +END_TIKZ + +$alt_text = + "A tree diagram with the top level two branches. The left is labeled 'a R' " + . "and the second is labeled 'b G'. Each of these is branched. The left branch " + . "branches in two to 'c R' and 'd G'. The right branch splits to 'e R' and 'f G'. " + . "Each of the four branches continue directly below. The bottom row is labeled " + . "'g RR', 'h RG', 'i GR' and 'j GG'."; + +Context('Percent'); + +$ans1 = Real(($red / ($red + $green))**2); +$ans2 = Real(2 * $red * $green / ($red + $green)**2); + +BEGIN_PGML +A bag contains [$red] red and [$green] green marbles. Marbles are selected randomly from +the bag *with* replacement. + +Consider the following tree diagram + +>> [! [$alt_text] !]{$graph}{400} << + +where [`a, b, c, d, e, f, g, h, i`] and [`j`] are whole numbers. Based on this problem, find these numbers; + +a) [_]{Real($red)} +b) [_]{Real($green)} +c) [_]{Real($red)} +d) [_]{Real($green)} +e) [_]{Real($red)} +f) [_]{Real($green)} +g) [_]{Real($red*$red)} +h) [_]{Real($green*$red)} +i) [_]{Real($green*$red)} + + j. [_]{Real($red*$red)} + +Also, calclulate the following: + +a) [`P(RR) = `] [_]{Real($ans1)} +b) [`P(RG\text{ or } GR) = `] [_]{Real($ans2)} + +END_PGML + +BEGIN_PGML_SOLUTION +The top two are just the number of red and green marbles so a) is [$red] and b) is [$blue]. + +The next level is the same so c) is [$red] d) is [$green], e) is [$red] and f) is [$green]. + +The last level is just the product of the number of red and green, so +g) is [$red*$red], h) is [$red*$green] i) is [$red*$green] and j) is [$red*$red]. + +Notice that the sum along the bottom row is +[`[$red*$red] + [$red*$green]+[$green*$red] + [$green*$green] = [@ ($red+$green)**2 @] `] + +a) [`P(RR) = \frac{[$red*$red]}{[@ ($red+$green)**2 @]} = [$ans1] `] + +b) [`P(RG\text{ or } GR) = \frac{[$red*$green]+[$green*$red]}{[@ ($red+$green)**2 @]} + = [$ans2]`] +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Basics/basic-definitions.pg b/Contrib/Fitchburg/Statistics/Basics/basic-definitions.pg new file mode 100644 index 0000000000..7f81123f53 --- /dev/null +++ b/Contrib/Fitchburg/Statistics/Basics/basic-definitions.pg @@ -0,0 +1,96 @@ +# DESCRIPTION +# A problem that asks students to determine the population, variable, +# data, sample, statistic and parameter from a situation. + +# This problem is derived from a homework problem in Introductory Statistics, +# licensed by OpenStax under a Creative Commons Attribution License (CC BY 4.0). +# Modified for WeBWorK by Michael Stassen mstassen(at)fitchburgstate(dot)edu +# ENDDESCRIPTION + +## DBsubject(Statistics) +## DBchapter(Experimental design) +## DBsection(Concepts) +## Keywords('population', 'variable', 'sample', 'parameter','statistic') +## Institution(Fitchburg State University) +## Author(Michael Stassen) + +DOCUMENT(); + +loadMacros('PGstandard.pl', 'PGML.pl', 'parserPopUp.pl', 'PGcourse.pl'); + +@terms = ('Population', 'Variable', 'Sample', 'Parameter', 'Data', 'Statistic'); +@answers = ( + 'All clients of the fitness center', + 'Amount of time a client exercises in the center in a week', + 'The 50 randomly selected clients', + 'The mean amount of time a client exercises in the center per week', + 'The 50 recorded amounts of time', + 'The mean amount of time the 50 selected clients exercise in the center per week' +); +@other = ( + "People who exercise", + "All clients of fitness centers", + 'None of the Above' +); + +@all = (@answers, @other); + +@shuffle = random_subset(8, 0 .. 7); + +%shuff = (map { $_ => $shuffle[$_] } (0 .. 7)); +for my $i (0 .. 5) { + @index = grep { $shuff{$_} == $i } (0 .. 7); + $invshuffle[$i] = $index[0]; +} + +@dd = map { DropDown([ 'A' .. 'I' ], $invshuffle[$_]) } (0 .. 5); + +$showPartialCorrectAnswers = 0; + +BEGIN_PGML +A fitness center is interested in the mean amount of time a client exercises in +the center per week. They randomly select 50 clients and record their time spent exercising for a week. Match each term with the corresponding part of the study. + +[# + [. **1.** [_]{$dd[0]} [$terms[0]].] [. **A.** [$all[$shuffle[0]]] .]* + [. **2.** [_]{$dd[1]} [$terms[1]] .] [. **B.** [$all[$shuffle[1]]] .]* + [. **3.** [_]{$dd[2]} [$terms[2]] .] [. **C.** [$all[$shuffle[2]]] .]* + [. **4.** [_]{$dd[3]} [$terms[3]] .] [. **D.** [$all[$shuffle[3]]] .]* + [. **5.** [_]{$dd[4]} [$terms[4]] .] [. **E.** [$all[$shuffle[4]]] .]* + [. **6.** [_]{$dd[5]} [$terms[5]] .] [. **F.** [$all[$shuffle[5]]] .]* + [. .] [. **G.** [$all[$shuffle[6]]] .]* + [. .] [. **H.** [$all[$shuffle[7]]] .]* + [. .] [. **I.** [$all[8]] .]* +#]{texalignment => 'll'} + +END_PGML + +# the following becomes necessary if we want +# to figure out what questions were asked +# so that we can give explanations for +# them. +# it's useful to define an array of +# explanations that correspond to the +# list of questions we might have asked +@explanations = ( + "the population is the complete group of interest", + "each member of the population or sample has a value of the variable", + "the sample is the selected subset of the population", + "a parameter is a descriptive measure of the population", + "the data is the set of recorded values of the variable", + "a statistic is a descriptive measure of the sample data" +); + +BEGIN_PGML_SOLUTION +1. The answer is [$dd[0]], because [$explanations[0]]. +2. The answer is [$dd[1]], because [$explanations[1]]. +3. The answer is [$dd[2]], because [$explanations[2]]. +4. The answer is [$dd[3]], because [$explanations[3]]. +5. The answer is [$dd[4]], because [$explanations[4]]. +6. The answer is [$dd[5]], because [$explanations[5]]. + +END_PGML_SOLUTION + +COMMENT('This problem is derived from an OpenStax problem'); + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Basics/definition-population.pg b/Contrib/Fitchburg/Statistics/Basics/definition-population.pg new file mode 100644 index 0000000000..f98ebc7631 --- /dev/null +++ b/Contrib/Fitchburg/Statistics/Basics/definition-population.pg @@ -0,0 +1,48 @@ +# DESCRIPTION +# A problem that asks students to determine which group of student is the population. + +# This problem is derived from a homework problem in Introductory Statistics, +# licensed by OpenStax under a Creative Commons Attribution License (CC BY 4.0). +# Modified for WeBWorK by Michael Stassen mstassen(at)fitchburgstate(dot)edu +# ENDDESCRIPTION + +## DBsubject(Statistics) +## DBchapter(Experimental design) +## DBsection(Concepts) +## KEYWORDS('population','mean') +## Institution(Fitchburg State University) +## Author(Michael Stassen) + +DOCUMENT(); + +loadMacros('PGstandard.pl', 'PGML.pl', 'parserRadioButtons.pl', 'PGcourse.pl'); +$showPartialCorrectAnswers = 0; #No guessing +$cc = 'Springfield Community College'; + +$mc = RadioButtons( + [ + "all $cc students", + "all $cc English students", + "all $cc students in her classes", + "all $cc math students" + ], + "all $cc math students", + labels => "ABC" +); + +BEGIN_PGML +A [$cc] instructor is interested in the mean number of days [$cc] +math students are absent from class during a semester. + +What is the population she is interested in? + +[_]{$mc} + +END_PGML + +BEGIN_PGML_SOLUTION +The population is the group of student that the research wants to study. In this case, it is all [$cc] math students. +END_PGML_SOLUTION + +COMMENT('This was derived from an OpenStax problem'); +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_1_RMN.pg b/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_1_RMN.pg index 77b3bb4ec8..bf77a6c568 100644 --- a/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_1_RMN.pg +++ b/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_1_RMN.pg @@ -11,6 +11,7 @@ ## DBsection(One sample mean - z) ## Institution(Fitchburg State University) ## Author(Michael Stassen) +## KEYWORDS('confidence interval', 'sample size','sample proportion') DOCUMENT(); loadMacros( @@ -20,7 +21,6 @@ loadMacros( ); Context("LimitedNumeric"); -loadMacros("fixedPrecision.pl"); # must come after Context is set. $conf = list_random(90, 95); $alpha = 1 - $conf / 100; @@ -56,4 +56,13 @@ d. The [$conf]% confidence interval is from [____]{$p1} to [____]{$p2}. END_PGML +BEGIN_PGML_SOLUTION +a. The sample size is [$n]. +b. The sample proportion is [`\hat{p}=\frac{[$x]}{[$n]}=[$p]`] +c. For a [$conf]% confidence interval, we use the corresponding [`z`]-score of [`z^{\star}=`][$z] and the margin of error is +[``` SE \sqrt{\frac{\hat{p}(1-\hat{p})} {n}} = [$E]```] +d. For the confidence error, the formula is +[``` \hat{p} \pm SE = ([$p1],[$p2])```] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_2_RMN.pg b/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_2_RMN.pg index 1bd19281bf..aad260af85 100644 --- a/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_2_RMN.pg +++ b/Contrib/Fitchburg/Statistics/ConfidenceIntervals/8_3_2_RMN.pg @@ -9,6 +9,7 @@ ## DBsubject(Statistics) ## DBchapter(Confidence intervals) ## DBsection(One sample mean - z) +## KEYWORDS('sample proportion','margin of error', 'confidence interval') ## Institution(Fitchburg State University) ## Author(Michael Stassen) @@ -20,16 +21,14 @@ loadMacros( ); Context("LimitedNumeric"); -loadMacros("fixedPrecision.pl"); # must come after Context is set. $conf = list_random(90, 95, 99); $alpha = 1 - $conf / 100; -$x = random(310, 330, 1); +$x = random(310, 330); $n = 400; -Context("Percent"); -Context()->flags->set( +Context("Percent")->flags->set( decimalPlaces => 1, tolerance => .1, ); @@ -57,4 +56,13 @@ c. The [$conf]% confidence interval is from [____]{$p1} to [____]{$p2}. END_PGML +BEGIN_PGML_SOLUTION + +a. The sample proportion is [`\hat{p}=\frac{[$x]}{[$n]}=`][$p] +b. For a [$conf]% confidence interval, we use the corresponding [`z`]-score of [`z^{\star}=`][$z] and the margin of error is +[``` SE \sqrt{\frac{\hat{p}(1-\hat{p})} {n}} = [$E]```] +c. For the confidence error, the formula is +[``` \hat{p} \pm SE = ([$p1],[$p2])```] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Descriptive/line-graph.pg b/Contrib/Fitchburg/Statistics/Descriptive/line-graph.pg new file mode 100644 index 0000000000..68f482f3ec --- /dev/null +++ b/Contrib/Fitchburg/Statistics/Descriptive/line-graph.pg @@ -0,0 +1,69 @@ +## DESCRIPTION +## Construct a line graph for a dataset. +## ENDDESCRIPTION + +## KEYWORDS('line graph', 'dataset') + +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Graphical representations) +## Date('07/01/2024') +## Author('Peter Staab') +## Institution('Fitchburg State University') + +DOCUMENT(); + +loadMacros( + 'PGstandard.pl', 'PGML.pl', + 'parserGraphTool.pl', 'randomPerson.pl', + 'niceTables.pl', 'PGcourse.pl' +); + +$p_first = randomPerson(); +$p_last = randomLastName(); + +@q = ( + random(1, 3), + random(2, 4), + random(2, 5), + random(3, 6), + random(2, 7), + random(0, 3) +); + +$tab = DataTable([ + [ + [ 'Number of Correct Questions', headerrow => 1 ], + 'Number of Students', + ], + map { [ $_, $q[$_] ] } (0 .. 5) +]); + +$str = join ', ', map {"{point, ($_, $q[$_])}"} (0 .. 5); + +$gt = GraphTool($str)->with( + availableTools => ['PointTool'], + bBox => [ -1, 6, 6, -1 ], + showCoordinateHints => 0, +); + +BEGIN_PGML +Professor [$p_last] [@ $p_first->verb('give') @] [$p_first->their] class a pop quiz with 5 questions. The number of students who answer the correct number of questions is given in the following table. + +[$tab]* + +Construct a line graph below using the point below. Note: the line will not be drawn +between the points. + +>>[_]{$gt} << + + +END_PGML + +BEGIN_PGML_SOLUTION +Place a point on each coordinate point from the table. + +>>[@ $gt->generateAnswerGraph @]*<< +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Descriptive/quantiles.pg b/Contrib/Fitchburg/Statistics/Descriptive/quantiles.pg index 5436cd3f6a..50040e3984 100644 --- a/Contrib/Fitchburg/Statistics/Descriptive/quantiles.pg +++ b/Contrib/Fitchburg/Statistics/Descriptive/quantiles.pg @@ -1,3 +1,14 @@ +## DESCRIPTION +## Find the first, second and third quartiles of a sorted dataset. +## ENDDESCRIPTION +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Graphical representations) +## Institution(Fitchburg State University) +## KEYWORDS('quartiles') +## Author(Peter Staab) +## Date(07/01/2022) + DOCUMENT(); loadMacros("PGstandard.pl", "PGML.pl", "PGstatisticsmacros.pl", 'PGcourse.pl'); @@ -8,46 +19,51 @@ $n = random(15, 25, 2); sub q_index { my ($p, $n) = @_; - my $i = $p * ($n + 1); - return $i; + return $p * ($n + 1); } sub quantile { my ($i, @sorted) = @_; - my $j = int($i); - my $q; - if ($j == $i) { - $q = $sorted[ $j - 1 ]; - } else { - $q = ($sorted[ $j - 1 ] + $sorted[$j]) / 2; - } - return $q; + return $i == int($i) + ? $sorted[ int($i) - 1 ] + : ($sorted[ int($i) - 1 ] + $sorted[ int($i) ]) / 2; } $i1 = q_index(.25, $n); -$Q1 = quantile($i1, @sorted); +$Q1 = quantile($i1, @data); $i2 = q_index(.50, $n); -$Q2 = quantile($i2, @sorted); +$Q2 = quantile($i2, @data); $i3 = q_index(.75, $n); -$Q3 = quantile($i3, @sorted); +$Q3 = quantile($i3, @data); BEGIN_PGML Exam scores for [$n] randomly selected students were recorded. Here are the scores in ascending order: [@ join(', ', @data) @] + +Let [`i`] be the index of the given quartile. + a) Find the first quartile. - [`i`] = [____]{$i1} - [`Q_1`] = [____]{$Q1} + [`i`] = [____]{Compute($i1)} + [`Q_1`] = [____]{Compute($Q1)} b) Find the second quartile. - [`i`] = [____]{$i2} - [`Q_2`] = [____]{$Q2} + [`i`] = [____]{Compute($i2)} + [`Q_2`] = [____]{Compute($Q2)} c) Find the third quartile. - [`i`] = [____]{$i3} - [`Q_3`] = [____]{$Q3} + [`i`] = [____]{Compute($i3)} + [`Q_3`] = [____]{Compute($Q3)} END_PGML +BEGIN_PGML_SOLUTION +The second quartile is just the median. In this case, since the number of points is odd, the second quartile is the middle value. Also, the first quartile is the middle of the smaller half and the third quartile is the larger half. + +a) [` i = [$i1], Q_1 = [$Q1] `] +b) [` i = [$i2], Q_1 = [$Q2] `] +c) [` i = [$i3], Q_1 = [$Q3] `] +END_PGML_SOLUTION + ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/Contrib/Fitchburg/Statistics/Descriptive/stem-leaf.pg b/Contrib/Fitchburg/Statistics/Descriptive/stem-leaf.pg new file mode 100644 index 0000000000..33ec7b146f --- /dev/null +++ b/Contrib/Fitchburg/Statistics/Descriptive/stem-leaf.pg @@ -0,0 +1,63 @@ +## DESCRIPTION +## Produce a table used to create a stem-and-leaf plot +## ENDDESCRIPTION +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Graphical representations) +## Institution(Fitchburg State University) +## KEYWORDS('stem and leaf plot') +## Author(Peter Staab) +## Date(07/01/2022) + +DOCUMENT(); + +loadMacros('PGstandard.pl', 'PGML.pl', 'niceTables.pl', 'PGcourse.pl'); + +@x = map { random(20, 65) } (1 .. 30); + +@leaf2 = num_sort(map { $_ % 10 } grep { 20 <= $_ && $_ < 30 } @x); +@leaf3 = num_sort(map { $_ % 10 } grep { 30 <= $_ && $_ < 40 } @x); +@leaf4 = num_sort(map { $_ % 10 } grep { 40 <= $_ && $_ < 50 } @x); +@leaf5 = num_sort(map { $_ % 10 } grep { 50 <= $_ && $_ < 60 } @x); +@leaf6 = num_sort(map { $_ % 10 } grep { 60 <= $_ && $_ < 70 } @x); + +BEGIN_PGML +Consider the dataset +[``` [@ join(', ',@x) @] ```] + +Fill in the following stem and leaf plot: + +[# + [.stem.][.leaf.]{headerrow => 1}* + [. 2 .] [.[_]{List(@leaf2)->cmp(ordered => 1)} .]* + [. [_]{3} .] [.[_]{List(@leaf3)->cmp(ordered => 1)}.]* + [. [_]{4} .] [.[_]{List(@leaf4)->cmp(ordered => 1)}.]* + [. [_]{5} .] [.[_]{List(@leaf5)->cmp(ordered => 1)}.]* + [. 2 .] [.[_]{List(@leaf6)->cmp(ordered => 1)}.]* +#] + +The numbers in the leaves should be ordered and separated by commas. +END_PGML + +$sol_table = DataTable( + [ + [ [ 'stem', headerrow => 1 ], 'leaf' ], + [ 2, join(', ', @leaf2) ], + [ 3, join(', ', @leaf3) ], + [ 4, join(', ', @leaf4) ], + [ 5, join(', ', @leaf5) ], + [ 6, join(', ', @leaf6) ], + ], + align => 'll' +); + +BEGIN_PGML_SOLUTION +Recall for a Stem and Leaf plot, the stem is the first digit and the leaves are the second +digit. In this case, + + + +[$sol_table]* +END_PGML_SOLUTION + +ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Distributions/6_2_RMN.pg b/Contrib/Fitchburg/Statistics/Distributions/6_2_RMN.pg index d1932b2624..ec8b13e71c 100644 --- a/Contrib/Fitchburg/Statistics/Distributions/6_2_RMN.pg +++ b/Contrib/Fitchburg/Statistics/Distributions/6_2_RMN.pg @@ -1,5 +1,6 @@ # DESCRIPTION -# A problem that asks students to ... +# A problem that asks students to find the values of probabilities under the +# normal curve. # # This problem is derived from a homework problem in Introductory Statistics, # licensed by OpenStax under a Creative Commons Attribution License (CC BY 4.0). @@ -9,17 +10,14 @@ ## DBsubject(Probability) ## DBchapter(Continuous distributions) ## DBsection(Gaussian normal) +## KEYWORDS('normal distribution','percentile') ## Institution(Fitchburg State University) ## Author(Michael Stassen) DOCUMENT(); loadMacros( - 'PGstandard.pl', - "PGML.pl", - "contextPercent.pl", - "PGnumericalmacros.pl", - "PGstatisticsmacros.pl", - # "Stats.pl", + 'PGstandard.pl', 'PGML.pl', + 'contextPercent.pl', 'PGstatisticsmacros.pl', 'PGcourse.pl' ); @@ -38,11 +36,11 @@ $Pa = normal_prob($Za, 'infty'); $b = random(1, 5); $Zb = normal_distr(.5 - $b / 100); -$Xb = $mu + $sigma * 1.75; +$Xb = $mu + $sigma * $Zb; $d = random(15, 30, 5); $Zd = normal_distr(.5 - $d / 100); -$Xd = $mu - $sigma * .84; +$Xd = $mu - $sigma * $Zd; $m = random(50, 90, 10); $Zm = normal_distr($m / 200); @@ -53,10 +51,43 @@ BEGIN_PGML IQ is normally distributed with a mean of [$mu] and a standard deviation of [$sigma]. Suppose one individual is randomly chosen. -b. Find the probability that the person has an IQ greater than [$a].[____]{$Pa} -c. Find the minimum IQ to be in the top 4% of all IQs. [____]{$Xb} -d. Find the 20th Percentile (20% of IQs are less than this value). [____]{$Xd} +a. Find the probability that the person has an IQ greater than [$a].[____]{$Pa} +b. Find the minimum IQ to be in the top [$b]% of all IQs. [____]{$Xb} +d. Find the 20th Percentile ([$d]% of IQs are less than this value). [____]{$Xd} END_PGML +BEGIN_PGML_SOLUTION +These questions ask for probabilities values on a normal distribution. If one has access +to software that allows one to look up the values on non-standard normal, these answers +can typically be just entered in the software. + +If only the standard normal is available, recall to convert to the standard normal, use +the [`z`]-score or +[``` z = \frac{x - \mu}{\sigma} = \frac{x-[$mu]}{[$sigma]}. ```] + +Lastly, if only the left tail of the normal curve is known (which is common), recall that +[``` P(a \leq Z \leq b) = P(Z \leq b) - P(Z \leq a) ```] + +a) [`` P(X > [$a]) = 1 - P(X < [$a]) = [$Pa] ``] + +b) In this case, we seek [`a`] such that [` P(X>a) = [@ $b*0.01@]`]. This may be +needed to be changed to [` P (X [$b]) = [$Pb]`] +c. Find [`P([$c] < X < [$c]) = [$Pcd] `] +d. One needs the value [`a`] such that [`P(Z < a) = 0.9 `] on the standard +normal curve. This can be found to be [`a=[$Zk]`] and then converting to the given +distribution with +[``` x = \mu + a \sigma = [$mu] + [$Zk] \cdot [$sigma] = [$Xk] ```] +e. First, one needs to find the value of [`a`] such that [` P(-a < Z< a = [$m/100])`] on +the standard normal curve. This can be done easier knowing that there is [@ 1-$m/100 @] in the two tails and thus [@ (1-$m/100)*0.5 @] in one tail so that +[``` P(-a < Z < a) = [$m/100]```] +is true for the same value of [`a`] as +[``` P(Z71)`] which again can be found directly or using the standard normal +which results in [`P(Z > [$Zm])`]. Either technique results in [$Pc]. +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Distributions/normal-01.pg b/Contrib/Fitchburg/Statistics/Distributions/normal-01.pg index 77cc54f914..24a9d2b521 100644 --- a/Contrib/Fitchburg/Statistics/Distributions/normal-01.pg +++ b/Contrib/Fitchburg/Statistics/Distributions/normal-01.pg @@ -41,4 +41,18 @@ e. [`P(Z < [$f]) = `][____]{Percent(normal_prob(-'infty',$f))} END_PGML +BEGIN_PGML_SOLUTION +These are all standard normal and can either be looked up in table or using software. +There may be needed to convert to a different tail. For example, if you have +a right tail, to switch to a left tail with +[``` P(X>a) = 1- P(X`] and [`\geq`]. + +a) [@normal_prob(-'infty',$a)@] +b) [@normal_prob($a,'infty')@] +c) [@normal_prob($b,'infty')@] +d) [@normal_prob($e,'infty')@] +e) [@normal_prob(-'infty',$f)@] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/Contrib/Fitchburg/Statistics/Distributions/pz_2_RMN.pg b/Contrib/Fitchburg/Statistics/Distributions/pz_2_RMN.pg index ec20205746..4edb755942 100644 --- a/Contrib/Fitchburg/Statistics/Distributions/pz_2_RMN.pg +++ b/Contrib/Fitchburg/Statistics/Distributions/pz_2_RMN.pg @@ -52,4 +52,14 @@ b. [`P([$c] \le Z \le [$d]) = `][____]{Percent($Pcd)} END_PGML +BEGIN_PGML_SOLUTION +Depending on the tools that you have, these can be found exactly using software or if your software (or tables) only has a left tail, which is common, you'll need to +use +[``` P(a \leq X \leq b) = P(X \geq b) - P(X \geq a). ```] + +In either case, +a) [$Pab] +b) [$Pcd] +END_PGML_SOLUTION + ENDDOCUMENT(); diff --git a/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_04_LinearIneq.pg b/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_04_LinearIneq.pg index 5253690196..9d0fbd40ab 100644 --- a/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_04_LinearIneq.pg +++ b/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_04_LinearIneq.pg @@ -1,12 +1,13 @@ ##DESCRIPTION ## Linear Inequalities -## + ##ENDDESCRIPTION ## DBsubject(Algebra) ## DBchapter(Algebra of real numbers and simplifying expressions) ## DBsection(Inequalities and intervals) ## Institution(The College of Idaho) ## Author(RA Cruz) +## Date(10/01/2007) ## MLT(Graph_to_interval) ## MLTleader(1) ## MO(1) @@ -16,84 +17,65 @@ ## Section1('4.1') ## Problem1('') ## KEYWORDS('inequalities') -## Date: 2007/10 - -DOCUMENT(); # This should be the first executable line in the problem. -loadMacros( - "PGstandard.pl", - "PGchoicemacros.pl", - "MathObjects.pl", - "PGgraphmacros.pl", - "PGnauGraphics.pl", - "contextInequalitiesAllowStrings.pl", - "answerHints.pl", - "CofIdaho_macros.pl", - "PGcourse.pl" -); +DOCUMENT(); # This should be the first executable line in the problem. -TEXT(beginproblem()); +loadMacros('PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'PGcourse.pl'); -###################################### # Setup -Context("Inequalities-AllowStrings"); - -$a = random(-5,1,1); -$b = $a + random(1,4,1); -@interval = (Interval("[$a,$b]"),Interval("($a,$b)")); -$choose = random(0,1,1); - -@slice = NchooseK(3,3); -@colors = ("blue", "red", "green"); -@sc = @colors[@slice]; #scrambled colors - -$graph = init_graph(-6,-1,6,1,'pixels'=>[300,50]); - -$graph->moveTo(-6,0); #Draw x-axis and tick marks -$graph->lineTo(6,-0); -$i = -5; -do { - $lab=new Label($i,-.5,"$i",'black','center','center'); - $graph->lb($lab); - $graph->moveTo($i,.25); - $graph->lineTo($i,-.25); - $i++; -} until ($i > 5); - -$f = FEQ("0 for x in $interval[$choose] using color=$sc[0] and weight=3"); -add_functions( $graph,$f); - -###################################### -# Main text +Context("Interval"); + +$a = random(-5, 1); +$b = $a + random(1, 4); +$r1 = random(0, 1); +$left = $r1 ? '[' : '('; +$left_sym = ($r1 ? '\fill' : '\draw') . "[blue]($a,0) circle[radius=3pt];"; + +$r2 = random(0, 1); +$right = $r2 ? ']' : ')'; +$right_sym = ($r2 ? '\fill' : '\draw') . "[blue]($b,0) circle[radius=3pt];"; + +$sol = Interval("$left$a,$b$right"); + +$graph = createTikZImage(); +$graph->tikzLibraries('arrows.meta'); +$graph->BEGIN_TIKZ +\tikzset{>={Stealth[scale=1.5]}} +\filldraw[ + draw=LightBlue, + fill=white, + rounded corners=10pt, + thick,use as bounding box +] (-6,-1) rectangle (6,1); +\draw[<->] (-6,0) -- (6,0); +\draw[blue, very thick] ($a,0) -- ($b,0); +$left_sym; +$right_sym; +\foreach \x in {-5,-4,...,1,1,2,...,5} \draw (\x,0.2) -- (\x,-0.2) node [scale=1.5, below] {\(\x\)}; +END_TIKZ + +$alt_text = + "A graph of just the x-axis with a line segment from ($a,0) to ($b,0). " + . "At the left end is an " + . ($r1 ? 'closed' : 'open') + . ' circle. ' + . "At the right end is an " + . ($r2 ? 'closed' : 'open') + . ' circle.'; + +BEGIN_PGML +>> [! [$alt_text] !]{$graph}{400} << -BEGIN_TEXT -\{ Plot($graph, tex_size => 600) \} -$BR $BR Express the inequality shown in the graph above using interval notation. -$PAR -Answer: \{ans_rule(25) \} -END_TEXT -###################################### -# Answer +Answer: [_]{$sol} +END_PGML -Context()->strings->add("No solution"=>{}); - -ANS($interval[$choose]->cmp->withPostFilter(AnswerHints( - sub { - my ($correct,$student,$ans) = @_; - return $student =~ /[=><]/; - } => ["Enter your answer with interval notation.", - checkCorrect => 1, - score => 0] -))); - -$showPartialCorrectAnswers = 1; - -###################################### - - -; +BEGIN_PGML_SOLUTION +Note that the left endpoint is [@ $r1 ? 'closed' : 'open' @] and +the right endpoint is [@ $r2 ? 'closed' : 'open' @]. +Therefore the interval is from [$a] ([@ $r1 ? 'inclusive' : 'exclusive' @]) +to [$b] ([@ $r2 ? 'inclusive' : 'exclusive' @]). The interval is [`[$sol]`]. +END_PGML_SOLUTION ENDDOCUMENT(); - diff --git a/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_05_LinearIneq.pg b/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_05_LinearIneq.pg index 48351a7206..dd78602705 100644 --- a/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_05_LinearIneq.pg +++ b/OpenProblemLibrary/CollegeOfIdaho/setAlgebra_04_01_LinearInequalities/41IntAlg_05_LinearIneq.pg @@ -1,6 +1,6 @@ ##DESCRIPTION ## Linear Inequalities -## +## ##ENDDESCRIPTION ## DBsubject(Algebra) ## DBchapter(Algebra of real numbers and simplifying expressions) @@ -18,54 +18,37 @@ ## KEYWORDS('inequalities') ## Date: 2007/10 -DOCUMENT(); # This should be the first executable line in the problem. +DOCUMENT(); # This should be the first executable line in the problem. loadMacros( - "PGstandard.pl", - "PGchoicemacros.pl", - "MathObjects.pl", - "contextInequalitiesAllowStrings.pl", - "answerHints.pl", - "PGcourse.pl" + "PGstandard.pl", "PGML.pl", + "contextInequalitiesAllowStrings.pl", "answerHints.pl", + "PGcourse.pl" ); -TEXT(beginproblem()); - -###################################### -# Setup - -$a = random(-10,10,1); - -###################################### -# Main text - -BEGIN_TEXT +Context('Inequalities-AllowStrings'); + +$a = random(-10, 10, 1); +$ans = Interval("(-inf,$a)"); +$cmp = $ans->cmp->withPostFilter(AnswerHints( + sub { + my ($correct, $student, $ans) = @_; + return $student =~ /[=><]/; + } => [ + "Enter your answer with interval notation.", + checkCorrect => 1, + score => 0 + ] +)); + +BEGIN_PGML Express the inequality using interval notation. -\[ x<$a \] -Answer: \{ans_rule(20) \} -END_TEXT - -###################################### -# Answer - -Context("Inequalities-AllowStrings"); -Context()->strings->add("No solution"=>{}); +[``` x<[$a] ```] +Answer: [_]{$cmp} +END_PGML -$ans = Interval("(-infinity,$a)"); -ANS($ans->cmp->withPostFilter(AnswerHints( - sub { - my ($correct,$student,$ans) = @_; - return $student =~ /[=><]/; - } => ["Enter your answer with interval notation.", - checkCorrect => 1, - score => 0] -))); +BEGIN_PGML_SOLUTION +If you need to, draw a number line and note that all values from [` -\infty `] to [`[$a]`], but not including it, therefore the interval should be [`[$ans]`]. +END_PGML_SOLUTION -$showPartialCorrectAnswers = 1; - -###################################### - - -; ENDDOCUMENT(); - diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_07_pictDistnsWGraphs.pg b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_07_pictDistnsWGraphs.pg new file mode 100644 index 0000000000..1c258d971c --- /dev/null +++ b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_07_pictDistnsWGraphs.pg @@ -0,0 +1,113 @@ +## DESCRIPTION +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Graphical representations) +## Institution(The College of Idaho) +## Author(R Cruz, L Danielson, J Guild) +## Level(1) +## TitleText1('The Basic Practice of Statistics') +## AuthorText1('David Moore') +## EditionText1('5e') +## Section1('1') +## Problem1('') +## KEYWORDS('statistics', 'quantitative data', 'categorical data', 'histogram') + +# updated by Peter Staab (Fitchburg State) on 2024.01.31 + +DOCUMENT(); + +loadMacros( + 'PGstandard.pl', 'PGML.pl', 'contextPercent.pl', + + 'PGtikz.pl', 'parserPopUp.pl', + 'PGstatisticsmacros.pl', 'PGcourse.pl' +); + +# generate some data is is skewed rigt + +@cutoffs = (59, 62, 65, 68, 71, 74, 77, 80); +do { + @norm_rands = urand(70, 5, 40, 1); + @h = (); + $max = 0; + for $i (0 .. $#cutoffs - 1) { + $h[$i] = + scalar(grep { $_ >= $cutoffs[$i] && $_ < $cutoffs[ $i + 1 ] } + @norm_rands); + $max = $h[$i] if $h[$i] > $max; + } + +} until $max <= 10; + +$num_students = 0; +$num_students += $h[$_] for (0 .. $#h); + +# generate the rectangles +$rects = ''; +for $i (0 .. $#h) { + $rects .= + "\\filldraw[fill=LightBlue] ({$cutoffs[$i]-59},0) rectangle ({$cutoffs[$i+1]-59},{$h[$i]});\n"; +} + +$xticks = join(', ', @cutoffs); +$graph = createTikZImage(); +$graph->tikzLibraries('arrows.meta'); +$graph->BEGIN_TIKZ +\tikzset{>={Stealth[scale=1.5]},xscale=0.5} +\filldraw[ + draw=LightBlue, + fill=white, + rounded corners=10pt, + thick,use as bounding box +] (-2,11.5) rectangle (22,-1); +$rects; +\draw (0,0) rectangle (21,11); +\foreach \x in {$xticks} \draw ({\x-59},0) -- ({\x-59},-0.25) node [below] {\x}; +\foreach \y in {1,2,...,11} \draw(0,{\y}) -- (-0.25,{\y}); +\foreach \y in {5,10} \draw (0,{\y}) -- (-0.5,{\y}) node [left] {\y}; +END_TIKZ + +$alt_text = + "A histogram of the $num_students students. The cutoff values are " + . join(', ', @cutoffs) + . ' and there are 7 bars. From left to right the ' + . "heights are " + . join(', ', @h) . '.'; + +Context('Percent'); +$k = random(0, 4); + +# number of students in a random interval +$stud = $h[$k] + $h[ $k + 1 ]; + +$inter = Percent($stud / $num_students); +$dd = DropDown([ '59-65', '62-68', '65-71', '68-74', '71-77', '74-80' ], $k); + +$over74 = Percent(($h[5] + $h[6]) / $num_students); + +BEGIN_PGML +The histogram below shows the heights of [$num_students] students. + +>> [! [$alt_text] !]{$graph}{400} << + +a) How many students are between 65 and 68 inches in height? [_]{Real($h[2])} + +b) What percent of students have height greater than 74 inches? [_]{$over74} + +c) Which interval is about [$inter] perecent of the students. [_]{$dd} + +Note: on b) include the % sign. +END_PGML + +BEGIN_PGML_SOLUTION + +a) This is interpreting the height of the bar between 65 and 68, which is [$h[2]]. + +b) The height of the bars that are greater than 74 is [$h[5]]+[$h[6]]=[$h[5]+$h[6]], so the percent is [` \frac{[$h[5]+$h[6]]}{[$num_students]} = [$over74].`] + +c) Note that [$inter] percent of the students is [`[$inter] \cdot +[$num_students] = [$stud]`]. Of the possible intervals, the only result is [$dd]. + +END_PGML_SOLUTION + +ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs.pg b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs.pg new file mode 100644 index 0000000000..5eb7d96cd8 --- /dev/null +++ b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs.pg @@ -0,0 +1,98 @@ +## DESCRIPTION +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Graphical representations) +## Institution(The College of Idaho) +## Author(R Cruz, L Danielson, J Guild) +## Level(1) +## TitleText1('The Basic Practice of Statistics') +## AuthorText1('David Moore') +## EditionText1('5e') +## Section1('1') +## KEYWORDS('statistics', 'quantitative data', 'categorical data', 'histogram') + +DOCUMENT(); + +loadMacros( + 'PGstandard.pl', 'PGML.pl', + 'PGtikz.pl', 'parserPopUp.pl', + 'PGstatisticsmacros.pl', 'PGcourse.pl' +); + +# generate some data is is skewed right + +do { + $n = random(5, 15); + @norm_rands = urand(5, 20, 150, 1); + @unif_rands = map { random(25, 99); } (1 .. $n); + @h = (); + for $i (0 .. 9) { + $h[$i] = scalar(grep { $_ >= 10 * $i && $_ < 10 * ($i + 1) } + (@norm_rands, @unif_rands)); + } +} until $h[0] <= 30 && $h[1] <= 30; + +$num_students = 0; +$num_students += $h[$_] for (0 .. 9); + +# generate the rectangles +$rects = ''; +for $i (0 .. 9) { + $rects .= + "\\filldraw[fill=Goldenrod] ({$i+0.5},0) rectangle ({$i+1.5},{0.35*$h[$i]});\n"; +} + +$graph = createTikZImage(); +$graph->tikzLibraries('arrows.meta'); +$graph->BEGIN_TIKZ +\tikzset{>={Stealth[scale=1.5]}} +\filldraw[ + draw=LightBlue, + fill=white, + rounded corners=10pt, + thick,use as bounding box +] (-1,-1) rectangle (11.5,11.5); +$rects; +\draw (0.5,0) rectangle (11.5,11); +\foreach \x in {10,20,...,100} \draw ({0.1*\x+0.5},0) -- ({0.1*\x+0.5},-0.1) node [scale=1.5, below] {\x}; +\foreach \y in {1,2,...,29} \draw(0.5,{0.35*\y}) -- (0.4,{0.35*\y}); +\foreach \y in {5,10,15,20,25,30} \draw (0.5,{0.35*\y}) -- (0.3,{0.35*\y}) node [scale=1.5, left] {\y}; +END_TIKZ + +$dol = random(30, 60, 10); +$num_b = 0; +$num_b += $h[$_] for (0.1 * $dol .. 9); +$ans_b = Real(100 * $num_b / $num_students); + +$dd = DropDown([ 'skewed left', 'skewed right', 'symmetric' ], 1); + +BEGIN_PGML +In a statistics class with [$num_students] students, the professor records +how much money each student has in their possession during the first class +of the semester. The histogram below is of the data collected. + +>> [! alt text !]{$graph}{400} << + +a) The number of students with less than ten dollars in their posession is +[_]{Real($h[0])} + +b) The percentage of students with more than $[$dol] in their possession is +[_]{$ans_b} + +c) The histogram is [_]{$dd} + +END_PGML + +BEGIN_PGML_SOLUTION +a) The number of students with less than ten dollars in their possession from the histogram is [$h[0]]. + +b) To determine the percentage of students with more than $[$dol] in their possession, +first use the histogram to count the number of students. This is +[```[@ join('+', @h[0.1*$dol..9]) @] = [$num_b] ```] +Then find the percentage using +[``` 100 \frac{[$num_b]}{[$num_students]} = [$ans_b] ```] + +c) The peak to the left and a long tail to the right, so this is skewed right. +END_PGML_SOLUTION + +ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/01Stats_08_PictDistnsWGraphs.pg b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/01Stats_08_PictDistnsWGraphs.pg deleted file mode 100644 index 88c276d903..0000000000 --- a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/01Stats_08_PictDistnsWGraphs.pg +++ /dev/null @@ -1,111 +0,0 @@ -## DESCRIPTION -## DBsubject(Statistics) -## DBchapter(Exploratory data analysis/descriptive statistics) -## DBsection(Graphical representations) -## Institution(The College of Idaho) -## Author(R Cruz, L Danielson, J Guild) -## Level(1) -## TitleText1('The Basic Practice of Statistics') -## AuthorText1('David Moore') -## EditionText1('5e') -## Section1('1') -## Problem1('') -## KEYWORDS('statistics', 'quantitative data', 'categorical data', 'histogram') - -DOCUMENT(); # This should be the first executable line in the problem. - -loadMacros( - 'PGstandard.pl', 'PGML.pl', - 'parserRadioButtons.pl', 'PGtikz.pl', - 'PGcourse.pl' -); - -# Setup - -# Create a distribution to more easily answer the questions below -do { - @y = map { random(50 - 15 * $_, 60 - 15 * $_) } (0 .. 3); - $y[$_] = random(0, 1) * random(0, 3) for (4 .. 9); - $y[10] = random(1, 2); - $total = 0; - $total += $_ for @y; - $over30 = 0; - $over30 += $y[$_] for (3 .. 10); -} until ($over30 / $total > 0.08 && $over30 / $total < 0.12); - -# create the tikz code to make the bars for this. -$bars = ''; -for $i (0 .. $#y) { - $bars .= - "\filldraw[fill=LightBlue, draw = black] ({10*$i/12},0) rectangle ({(10*($i+1))/12}, {$y[$i]/7}); \n"; -} - -$graph = createTikZImage(); -$graph->tikzLibraries('arrows.meta'); -$graph->tikzOptions('yscale = 0.6'); -$graph->BEGIN_TIKZ -\tikzset{>={Stealth[scale=1.25]}} -\filldraw[ - draw=LightBlue, - fill=white, - rounded corners=10pt, - thick, use as bounding box -] (-1.25,-1) rectangle (10,10); -\foreach \y in {5,10,...,60} - \draw[lightgray] (-0.5,{\y/7}) -- ({115/12},{\y/7}); -\draw (-0.5,0) -- (9.5,0) -- (9.5,9.5)-- (-0.5, 9.5) --cycle; -\foreach \x in {0,10,...,110} - \draw({\x/12},5pt) -- ({\x/12},-5pt) node [below] {\(\x\)}; - -%\foreach \y in {1,...,20} \draw[thin, lightgray] (0,{\y/2.5}) -- (9.5,{\y/2.5}); -\foreach \y in {10,20,...,60} - \draw (-0.4,{\y/7}) -- (-0.6,{\y/7}) node[left] {\(\y\)}; -$bars - -END_TIKZ - -$rb2 = RadioButtons( - [ 'symmetric', 'skewed right', 'skewed left', 'none of the above' ], 1); - -$rb3 = RadioButtons( - [ - "above 30$PERCENT", - "between 20$PERCENT and 30$PERCENT", - "about 10$PERCENT", - "less than 3$PERCENT" - ], - 2 -); - -$showPartialCorrectAnswers = 0; - -BEGIN_PGML -In a statistics class with [$total] students, the professor records how much money -each student has in their possession during the first class of the semester. -The histogram below is of the data collected. - - -[! alt text !]{$graph}{450} - -a) The number of students with under $10 in their possession is [_]{$y[0]}{5} - -b) The histogram is - - [_]{$rb2} - -c) The percentage of students with over $30 in their possession is - - [_]{$rb3} -END_PGML - -BEGIN_PGML_SOLUTION -For this, read off the approximate bar heights to answer the questions. - -a) This needs a careful eye, but the answer is [$y[0]]. - -b) Because there is a large peak on the left and a long tail to the right, this is _skewed right_. - -c) For this, total all of the heights of the bars. The total heights of those over $30 is [$over30] and since there are [$total] students, this is about 10%. -END_PGML_SOLUTION - -ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/Ref_1_4.gif b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/Ref_1_4.gif deleted file mode 100644 index 197e2c952b..0000000000 Binary files a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch01PicturingDistributionsWithGraphs/01Stats_08_PictDistnsWGraphs/Ref_1_4.gif and /dev/null differ diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData.pg b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData.pg new file mode 100644 index 0000000000..3f349bd102 --- /dev/null +++ b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData.pg @@ -0,0 +1,91 @@ +## DESCRIPTION +## DBsubject(Statistics) +## DBchapter(Exploratory data analysis/descriptive statistics) +## DBsection(Description of distributions) +## Institution(The College of Idaho) +## Author(R Cruz, L Danielson, J Guild) +## Level(1) +## Static(1) +## MO(1) +## TitleText1('The Basic Practice of Statistics') +## AuthorText1('David Moore') +## EditionText1('5e') +## Section1('2') +## Problem1('') +## KEYWORDS('statistics', 'skewed', 'mean', 'median') + +# Updated by Peter Staab (Fitchburg State) on 2024.01.22 + +DOCUMENT(); # This should be the first executable line in the problem. + +loadMacros( + 'PGstandard.pl', 'PGML.pl', + 'PGtikz.pl', 'PGstatisticsmacros.pl', + 'parserPopUp.pl', 'PGcourse.pl' +); + +$s = random(0, 2); + +@norm_rands = urand(10 + 6 * ($s - 1), 3, 100, 0); +@unif_rands = map { random(6, 14) - 5 * ($s - 1) } (1 .. 25); + +@h = (); +for $i (0 .. 20) { + $h[$i] = scalar(grep { $_ == $i } (@norm_rands, @unif_rands)); +} + +# generate the rectangles +$rects = ''; +for $i (1 .. 20) { + $rects .= + "\\filldraw[fill=Goldenrod] ({$i-0.5},0) rectangle ({$i+0.5},$h[$i]);\n"; +} + +$graph = createTikZImage(); +$graph->tikzLibraries('arrows.meta'); +$graph->BEGIN_TIKZ +\tikzset{>={Stealth[scale=1.5]}} +\filldraw[ + draw=LightBlue, + fill=white, + rounded corners=10pt, + thick,use as bounding box +] (-1,-1) rectangle (21,21); +$rects; +\draw (0.5,0) rectangle (20.5,21); +\foreach \x in {5,10,15,20} \draw (\x,0) -- (\x,-0.1) node [scale=2, below] {\x}; +\foreach \y in {5,10,15,20} \draw (0.5,\y) -- (0.3,\y) node [scale=2, left] {\y}; +END_TIKZ + +$skew = DropDown([ 'right', 'symmetric', 'left' ], $s); +$middle = DropDown([ 'mean', 'about equal', 'median' ], $s); + +BEGIN_PGML +Consider the histogram shown below. + +[! alttest !]{$graph}{400} + +a) Is this data skewed to the right, close to symmetric, or skewed to the left? [_]{$skew} + +b) Which is bigger for this data set, the mean or the median, or are they about equal? [_]{$middle} + +END_PGML + +if ($s == 0) { +BEGIN_PGML_SOLUTION +In this case, since there is a peak to the left and a tail on the right, this is skewed +to the right. The mean is closer to the peak and the median (middle of the data) is to the right of the mean, so the median is larger. +END_PGML_SOLUTION +} elsif ($s == 1) { +BEGIN_PGML_SOLUTION +In this case, the histogram appears relatively symmetric (though not perfect). +Because it is symmetric, the mean and median is about equal. +END_PGML_SOLUTION +} else { +BEGIN_PGML_SOLUTION +In this case, since there is a peak to the right and a tail on the left, this is skewed +to the left. The mean is closer to the peak and the median (middle of the data) is to the left of the mean, so the mean is larger. +END_PGML_SOLUTION + +} +ENDDOCUMENT(); diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/02Stats_01_DescrData.pg b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/02Stats_01_DescrData.pg deleted file mode 100644 index 61060a1148..0000000000 --- a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/02Stats_01_DescrData.pg +++ /dev/null @@ -1,88 +0,0 @@ -## DESCRIPTION -## DBsubject(Statistics) -## DBchapter(Exploratory data analysis/descriptive statistics) -## DBsection(Description of distributions) -## Institution(The College of Idaho) -## Author(R Cruz, L Danielson, J Guild) -## Level(1) -## Static(1) -## MO(1) -## TitleText1('The Basic Practice of Statistics') -## AuthorText1('David Moore') -## EditionText1('5e') -## Section1('2') -## Problem1('') -## KEYWORDS('statistics', 'skewed', 'mean', 'median') - -DOCUMENT(); # This should be the first executable line in the problem. - -loadMacros( - "PGstandard.pl", - "MathObjects.pl", - "PGcourse.pl" -); - -TEXT(beginproblem()); - -###################################### -# Setup - -@pic= ("3-413210.gif", "3-118225.gif"); -@ANSWER1=("SKEWED RIGHT", "SKEWED LEFT"); -@ANSWER2=("MEAN", "MEDIAN"); -$choose = random(0,1,1); - -###################################### -# Main text - -BEGIN_TEXT -Consider the histogram shown below. -$BR -$BCENTER -\{ image($pic[$choose], height=>300, width=>400, tex_size => 600) \} -$ECENTER - -$PAR -(a) Is this data skewed to the right, symmetric, or skewed to the left? \{ ans_rule(20)\} -$BR -(Enter "SKEWED RIGHT", "SYMMETRIC", or "SKEWED LEFT" without the quotations.) - -$PAR -(b) Which is bigger for this data set, the mean or the median, or are they about equal? \{ ans_rule(20)\} -$BR -(Enter "MEAN", "MEDIAN" or "ABOUT EQUAL" without the quotations.) - -END_TEXT - -###################################### -# Answers - -$showPartialCorrectAnswers = 1; - -Context()->strings->add("mean"=>{},"median"=>{},"about equal"=>{}, - "skewed left"=>{},"skewed right"=>{},"symmetric"=>{}); - -$ans_a = String($ANSWER1[$choose]); -ANS($ans_a->cmp); - -$ans_b = String($ANSWER2[$choose]); -ANS($ans_b->cmp); - -ENDDOCUMENT(); # This should be the last executable line in the problem. - - - - - - - - - - - - - - - - - diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-118225.gif b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-118225.gif deleted file mode 100644 index d85ee1df55..0000000000 Binary files a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-118225.gif and /dev/null differ diff --git a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-413210.gif b/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-413210.gif deleted file mode 100644 index 45e3479d74..0000000000 Binary files a/OpenProblemLibrary/CollegeOfIdaho/setStatistics_Ch02DescribingData/02Stats_01_DescrData/3-413210.gif and /dev/null differ diff --git a/OpenProblemLibrary/Rochester/setProbability7RandomVariables/p1.pg b/OpenProblemLibrary/Rochester/setProbability7RandomVariables/p1.pg index 7389954fea..1cf36f9889 100644 --- a/OpenProblemLibrary/Rochester/setProbability7RandomVariables/p1.pg +++ b/OpenProblemLibrary/Rochester/setProbability7RandomVariables/p1.pg @@ -10,58 +10,75 @@ ## Level(1) ## KEYWORDS('Random Variable', 'Probability Density Function', 'PDF', 'Probability Distribution') +# updated by Peter Staab (Fitchburg State University) on 2024.01.25 -DOCUMENT(); # This should be the first executable line in the problem. +DOCUMENT(); # This should be the first executable line in the problem. -loadMacros( - "PGstandard.pl", - "PGchoicemacros.pl", - "PGgraphmacros.pl", - "PGcourse.pl" -); +loadMacros('PGstandard.pl', 'PGML.pl', 'parserPopUp.pl', 'PGcourse.pl'); -TEXT(beginproblem()); $showPartialCorrectAnswers = 0; +@b1 = (random(0, .3, .1), random(.1, .3, .1), random(.1, .3, .1)); +$b1[3] = 1 - $b1[0] - $b1[1] - $b1[2]; + +@b2 = (random(0, .3, .1), random(.1, .3, .1), random(-0.3, -0.1, .1)); +$b2[3] = 1 - $b2[0] - $b2[1] - $b2[2]; +@b2 = random_subset(4, @b2); + +do { + @b3 = map { random(0, 0.3, 0.1) } (1 .. 4); + $sum = 0; + $sum += $_ for (@b3); +} until $sum != 1; + +@dropdowns = ( + DropDown([ 'Valid', 'Invalid' ], 0), + DropDown([ 'Valid', 'Invalid' ], 1), + DropDown([ 'Valid', 'Invalid' ], 1) +); + +@opts = random_subset(3, 0 .. 2); + +BEGIN_PGML +Determine whether the following are valid probability models or not. Determine if each is a valid or invalid probability model. + +a) Table 1 + + [# [.Event.][.[`e_1`].] [. [`e_2`].] [.[`e_3`].] [. [`e_4`].]* + [. Probability .] [. [$b1[0]] .][. [$b1[1]] .][. [$b1[2]] .][. [$b1[3]] .]* + #]{horizontalrules => 1} + + Answer: [_]{$dropdowns[$opts[0]]} + +b) Table 2 + + [# [.Event.][.[`e_1`].] [. [`e_2`].] [.[`e_3`].] [. [`e_4`].]* + [. Probability .] [. [$b2[0]] .][. [$b2[1]] .][. [$b2[2]] .][. [$b2[3]] .]* + #]{horizontalrules => 1} + + + Answer: [_]{$dropdowns[$opts[1]]} -$b[0] = random(0,.3,.1); -$b[1] = random(.1,.3,.1); -$b[2] = random(.1,.3,.1); -$b[3] = 1-$b[0]-$b[1]-$b[2]; +c) Table 3 -$b1 = random(0,.3,.1); -$b2 = random(.1,.3,.1); -$b3 = random(-.3,-.1,.1); -$b4 = 1-$b1-$b2-$b3; + [# [.Event.][.[`e_1`].] [. [`e_2`].] [.[`e_3`].] [. [`e_4`].]* + [. Probability .] [. [$b3[0]] .][. [$b3[1]] .][. [$b3[2]] .][. [$b3[3]] .]* + #]{horizontalrules => 1} -$a = random(2,5,1); + Answer: [_]{$dropdowns[$opts[2]]} -@second_row = ($b[0], $b[1], $b[2], $b[3]); -@slice = NchooseK(4,4); -@ssecond_row = @second_row[@slice]; -BEGIN_TEXT -Determine whether the following are valid probability models or not. Type "VALID" if it is -valid, or type "INVALID" if it is not. $PAR -(a) $PAR -\{begintable(5)\} -\{row("Event", "\( e_1\)", "\( e_2\)", "\(e_3\)", "\( e_4\)")\} -\{row(" Probability", "\($ssecond_row[0]\)", "\($ssecond_row[1]\)", "\($ssecond_row[2]\)", "\($ssecond_row[3]\)" )\} -\{endtable()\} -Answer: \{ans_rule(10)\}$PAR +END_PGML -(b) $PAR -\{begintable(5)\} -\{row("Event", "\( e_1\)", "\( e_2\)", "\( e_3\)", "\( e_4\)")\} -\{row(" Probability ", "\($b1\)", "\($b2\)", "\($b3\)", "\($b4\)" )\} -\{endtable()\} +BEGIN_PGML_SOLUTION +Recall that for a discrete probability distriubution, all probability values [` p_i `] must satisfy [` 0 \leq p_i \leq 1 `] and [` p_1 + p_2 + \cdots + p_n = 1 `]. -Answer: \{ans_rule(10)\} +a) This satsifies both conditions. -END_TEXT -ANS(str_cmp("VALID")); -ANS(str_cmp("INVALID")); +b) One of the values is less than 0, so this is not valid. -ENDDOCUMENT(); # This should be the last executable line in the problem. +c) The sum of the probabilities is not 1, so this is not valid. +END_PGML_SOLUTION +ENDDOCUMENT(); # This should be the last executable line in the problem. diff --git a/OpenProblemLibrary/Rochester/setProbability7RandomVariables/ur_pb_7_3.pg b/OpenProblemLibrary/Rochester/setProbability7RandomVariables/ur_pb_7_3.pg index fcffc54d1c..276fca7627 100644 --- a/OpenProblemLibrary/Rochester/setProbability7RandomVariables/ur_pb_7_3.pg +++ b/OpenProblemLibrary/Rochester/setProbability7RandomVariables/ur_pb_7_3.pg @@ -11,63 +11,85 @@ ## Level(2) ## KEYWORDS('Random Variable', 'Discrete', 'Probability Density Function', 'PDF', 'Probability Distribution') -DOCUMENT(); # This should be the first executable line in the problem. +# updated by Peter Staab (Fitchburg State) on 2024.01.25 -loadMacros( - "PGstandard.pl", - "PGchoicemacros.pl", - "PGcourse.pl" +DOCUMENT(); + +loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl'); + +$a1 = random(1, 20); +@a = ('X', $a1 .. $a1 + 4); + +do { + @p = ('P(X)', map { random(.1, .3, .1) } (1 .. 3), 0.1); + $p[5] = 1 - $p[1] - $p[2] - $p[3] - $p[4]; +} until $p[2] != $p[3]; + +@event = ( + "P(x=$a[3])", "P(x>$a[3])", + "P(x\ge $a[2])", "P(x\le $a[4])", + "P(x\ge $a[4] \mbox{ or } x<$a[2])", "P(x<$a[5])", + "P(x=$a[1])", "P($a[1]\le x <$a[3])" +); + +@ans = ( + $p[3], + $p[4] + $p[5], + 1 - $p[1], + 1 - $p[5], + $p[1] + $p[4] + $p[5], + 1 - $p[5], + $p[1], $p[1] + $p[2] ); -TEXT(beginproblem()); -$showPartialCorrectAnswers = 1; - -$a1 = random(1,20,1); -$a2 = $a1+1; -$a3 = $a2+1; -$a4 = $a3+1; -$a5 = $a4+1; - -$p1 = random(.1,.3,.1); -$p2 = random(.1,.2,.1); -$p3 = random(.1,.2,.1); -while($p2==$p3) {$p3 = random(.1,.2,.1);} -$p4 = .1; -$p5 = 1-$p1-$p2-$p3-$p4; - -@event = ("\(P(x=$a3)\)", - "\(P(x>$a2)\)", - "\(P(x\ge $a2)\)", - "\(P(x\le $a4)\)", - "\(P(x\ge $a4 \mbox{ or } x<$a2)\)", - "\(P(x<$a5)\)", - "\(P(x=$a1)\)", - "\(P($a1\le x <$a3)\)"); - -@ans = ($p3, ($p3+$p4+$p5), ($p2+$p3+$p4+$p5), ($p1+$p2+$p3+$p4), - ($p4+$p5+$p1), ($p1+$p2+$p3+$p4), $p1, -($p1+$p2)); - -@slice = NchooseK(8,3); -@sevent = @event[@slice]; -@sans = @ans[@slice]; - -BEGIN_TEXT -\{begintable(6)\} -\{row("\(x\)", "\($a1\)", "\($a2\)", "\($a3\)", "\($a4\)", "\($a5\)")\} -\{row("\(P(x)\)", "\($p1\)", "\($p2\)", "\($p3\)", "\($p4\)", "\($p5\)")\} -\{endtable()\} -Given the discrete probability distribution above, determine the following: $PAR -(a) $SPACE $sevent[0] \(=\) \{ans_rule(10)\} $PAR -(b) $SPACE $sevent[1] \(=\) \{ans_rule(10)\} $PAR -(c) $SPACE $sevent[2] \(=\) \{ans_rule(10)\} - - -END_TEXT - -ANS(num_cmp($sans[0])); -ANS(num_cmp($sans[1])); -ANS(num_cmp($sans[2])); - - -ENDDOCUMENT(); # This should be the last executable line in the problem. +@slice = random_subset(3, 0 .. $#event); + +$tab = DataTable( + [ [@a], [@p] ], + align => '|c|r|r|r|r|r|', + horizontalrules => 1 +); + +BEGIN_PGML +Given the discrete probability distribution: +[$tab]* + +determine the following: + +a) [`[$event[$slice[0]]] =`] [_]{$ans[$slice[0]]} + +b) [`[$event[$slice[1]]] =`] [_]{$ans[$slice[1]]} + +c) [`[$event[$slice[2]]] =`] [_]{$ans[$slice[2]]} + +END_PGML + +@explanations = ( + "Since this is just the value \(X=$a[3]\), this is just " + . "\(P(X =$a[3]) = $ans[0]\)", + "For \(P(x>$a[3])\), sum the values in the table for \( x > $a[3]\) and " + . "the result is $ans[1]", + "For \(P(x\ge $a[2])\), sum the values in the table and the result is $ans[2]", + "For \(P(x\le $a[4])\), sum the values in the table and the result is $ans[3]", + "For \(P(x\ge $a[4] \mbox{ or } x<$a[2])\), sum the values in the table " + . "greater than or equal to $a[4] and less than $a[2] and the result is " + . "$ans[4]", + "For \(P(x<$a[5]])\), sum the values in the table for \( x < $a[5]\) and " + . "the result is $ans[5]", + "Since this is just the value \(X=$a[1]\), this is just " + . "\(P(X =$a[1]) = $ans[6]\)", + "For \(P($a[1]\le x <$a[3]\), sum the values for $a[1] and $a[2] in the table. " + . "The result is $ans[7]." +); + +BEGIN_PGML_SOLUTION +For each of these, sum the values for the given probability. + +a) [$explanations[$slice[0]]]* + +d) [$explanations[$slice[1]]]* + +c) [$explanations[$slice[2]]]* +END_PGML_SOLUTION + +ENDDOCUMENT(); # This should be the last executable line in the problem. \ No newline at end of file diff --git a/OpenProblemLibrary/Rochester/setStatistics2Measures/ur_stt_2_4.pg b/OpenProblemLibrary/Rochester/setStatistics2Measures/ur_stt_2_4.pg index 8f9a34b598..1d1df75fdf 100644 --- a/OpenProblemLibrary/Rochester/setStatistics2Measures/ur_stt_2_4.pg +++ b/OpenProblemLibrary/Rochester/setStatistics2Measures/ur_stt_2_4.pg @@ -16,67 +16,53 @@ ## Problem1('7') ## KEYWORDS('Measure', 'Mean', 'Median', 'Skew','statistics','measures','mean','median') -DOCUMENT(); # This should be the first executable line in the problem. - -loadMacros( - "PGstandard.pl", - "PGchoicemacros.pl", - "PGgraphmacros.pl", - "PGcourse.pl" -); - -TEXT(beginproblem()); -$showPartialCorrectAnswers = 1; - -$median = random(70,85,1); -$a6 = $median; -$b5 = $a6-3; -$a5 = random($b5,$a6,1); -$b4 = $b5-5; -$a4 = random($b4,$b5,1); -$b3 = $b4-10; -$a3 = random($b3,$b4,1); -$b2 = $b3-15; -$a2 = random($b2,$b3,1); -$b1 = $b2-20; -$a1 = random($b1,$b2,1); -$a7 = $a6+1; -$c8 = $a7+2; -$a8 = random($a7,$c8,1); -$c9 = $c8+3; -$a9 = random($a8,$c9,1); -$c10 = $c9+4; -$a10 = random($a9,$c10,1); -$a11 = random($a10,100,1); - -$mean = ($a1+$a2+$a3+$a4+$a5+$a6+$a7+$a8+$a9+$a10+$a11)/11; - -$median11 = $median * 11; -$mean11 = ($a1+$a2+$a3+$a4+$a5+$a6+$a7+$a8+$a9+$a10+$a11); - -if ($mean11 > $median11) { $ans='SR';} -if ($mean11 < $median11) { $ans='SL';} -if ($mean11 == $median11) { $ans='SYM';} - -BEGIN_TEXT +DOCUMENT(); +loadMacros('PGstandard.pl', 'PGML.pl', 'parserPopUp.pl', 'PGcourse.pl'); + +# Pick the median. +$median = random(70, 85, 1); + +# Total number of points will be 2n+1 and add n points above and below the median. +$n = random(4, 6); +@pts = ($median); +for (1 .. 4) { + push(@pts, random($median - 10, $median), random($median, $median + 10)); +} +@pts = random_subset(scalar(@pts), @pts); + +$sum = 0; +$sum += $_ for (@pts); +$mean = Real($sum / scalar(@pts)); + +$sym = $mean > $median ? 0 : $mean < $median ? 1 : 2; +$dd = DropDown([ 'skewed left', 'skewed right', 'symmetric' ], $sym); + +BEGIN_PGML Calculate the mean and median of the following grades on a math test: -\[ $a11, \ $a10, \ $a9, \ $a8, \ $a7, \ $a6, \ $a5, \ $a4, \ $a3, \ $a2, \ $a1 \] +[``` [@ join(', ', @pts) @] ```] + +a) Mean = [_]{$mean} + +b) Median = [_]{Real($median)} -Mean = \{ans_rule(10)\} $BR +c) Is this data set skewed to the right, symmetric, or skewed to the left? [_]{$dd} -Median = \{ans_rule(10)\} $BR +END_PGML -Is this data set skewed to the right, symmetric, or skewed to the left? $BR -(Enter SR, SYM, or SL); +BEGIN_PGML_SOLUTION +a) The mean is found by sum of the value over the number of values or +[``` \text{mean}= \frac{[$sum]}{[@ 2*$n+1 @]} = [$mean] ```] -\{ans_rule(10)\} +b) The median is the middle value. We can order the data to get -END_TEXT +[``` [@ join(', ', num_sort(@pts)) @] ```] +and this shows the middle value is [$median] -ANS(num_cmp($mean)); -ANS(num_cmp($median)); -ANS(str_cmp($ans)); +c) Since the mean is [@ $sym == 0 ? 'greater' : $sym == 1 ? 'smaller' : 'equal' @] to +the median the data is +[@ $sym == 0 ? 'skewed left' : $sym == 1 ? 'skewed right' : 'symmetric' @]. +END_PGML_SOLUTION -ENDDOCUMENT(); # This should be the last executable line in the problem. +ENDDOCUMENT(); # This should be the last executable line in the problem.