Idea
Our colleagues over at the economics department became interested in using R/exams for
generating large-scale exams in their introductory economics courses. However, they face the challenge that
so far they had been writing static exercises and modified them by hand if they wanted to reuse them in a
different exam in another semester. To let R/exams do this job it is illustrated how a static arithmetic
exercise can be turned into a dynamic exercise template either in num
format with a numeric solution or into schoice format with a single-choice solution.
The idea for the exercise is a very basic price elasticity of demand task:
Consider the following inverse demand function: p(x)=a-b·x for the price p given the demanded quantity x. What is the price elastiticy of demand at a price of p?
The natural candidates for “parameterizing” this exercise are the
price p
and the parameters a
and b of the inverse demand function.
Based on these the solution is simply:
First, we obtain the demand function by inverting the inverse demand function: x=D(p)=(a-p)/b. Then, at p the price elasticity of demand is D'(p)D(p)p=-1/bxp.
Overview
Below various incarnations of this exercise are provided in both R/Markdown Rmd and R/LaTeX Rnw format.
The following table gives a brief overview of all available versions along with a short description of the idea behind it.
More detailed explanations are provided in the subsequent sections.
#
Exercise templates
Dynamic?
Type
Description
1
elasticity1.Rmd elasticity1.Rnw
No
num
Fixed parameters and numeric solution.
2
elasticity2.Rmd elasticity2.Rnw
No
schoice
As in #1 but with single-choice solution (five answer alternatives).
3
elasticity3.Rmd elasticity3.Rnw
Yes
num
Randomly drawn parameters with dynamic computation of correct solution, based on #1.
4
elasticity4.Rmd elasticity4.Rnw
Yes
schoice
Randomly drawn parameters (as in #3) with dynamically-generated single-choice solution (as in #2), computed by num_to_schoice().
5
elasticity5.Rmd elasticity5.Rnw
Yes
schoice
As in #4 but with the last alternative: None of the above.
Static numeric
The starting point is a completely static exercise as it had been used in a previous
introductory economics exam. The parameters had been set
to p=5, a=50, and b=0.5.
This implies that x=90,
leading to an elasticity of -0.111111.
The corresponding R/exams templates simply hard-code these numbers into the question/solution
and wrap everything into R/Markdown (elasticity1.Rmd)
or R/LaTeX (elasticity1.Rnw).
Note that LaTeX is used in either case for the mathematical notation. In case you are unfamiliar
with the R/exams format, please check out the First Steps tutorial.
The meta-information simply sets extype to num, supplies the exsolution with a precision of three digits,
and allows an extol tolerance of 0.01. To see what the result looks like download the files linked above
and run exams2html() and/or exams2pdf(). (The examples below always use the R/Markdown version but the
R/LaTeX version can be used in exactly the same way.)
library(&quot;exams&quot;)
exams2html(&quot;elasticity1.Rmd&quot;)
exams2pdf(&quot;elasticity1.Rmd&quot;)
Static single-choice
Single-choice versions of exercises are often desired for use in written exams
because they can be conveniently scanned and automatically evaluated. Thus, we need to come up
with a number of incorrect alternative solutions (or “distractors”). If desired, these could include
typical wrong solutions or a None of the others alternative.
The R/exams templates
elasticity2.Rmd and
elasticity2.Rnw are
essentially copies of the static numeric exercise above but:
Question/solution now contain an answerlist (with five alternatives).
The extype has been changed to schoice.
The exsolution now contains a binary coding of the correct solution.
Furthermore, to obtain some basic randomization we have turned on shuffling by setting exshuffle
to TRUE. (Subsampling more than five alternatives would also be possible and would add some further randomization.)
As above exams2html() and/or exams2pdf() can be used to display the exercise interactively in R/exams.
Dynamic numeric
Next, the static exercise from above is made dynamic by drawing the parameters from a suitable
data-generating process. In this case, the following works well:
## p = a - b * x
p