Title: | Binary Grading functions for R. |
---|---|
Description: | Provides functions for matching student-answers to teacher answers for a variety of data types. |
Authors: | Leif Johnson <[email protected]> |
Maintainer: | Leif Johnson <[email protected]> |
License: | GPL-2 |
Version: | 0.2-1 |
Built: | 2025-02-24 04:32:34 UTC |
Source: | https://github.com/ltjohnson/grade |
Binary Grading functions for R.
Package: | grade |
Version: | 0.2 |
Date: | 2009-02-20 |
Title: | Grade |
Author: | Leif Johnson <[email protected]> |
Maintainer: | Leif Johnson <[email protected]> |
URL: | http://www.stat.umn.edu/~leif/software/grade/ |
Depends: | R (>= 2.4.1) |
Description: | Binary Grading functions for R. |
License: | GPL-2 |
Packaged: | Fri Feb 20 10:28:59 2009; leif |
Index:
\link{grade.discreteprobability} Grade Discrete Probability Sets \link{grade.interval} Grade Intervals \link{grade.isscalar} Check if an object is a scalar \link{grade.negative} Check the Sign of a Number \link{grade.number} Grade Single Numbers \link{grade.orderedset} Grade Ordered Sets \link{grade.parse} Parse input \link{grade.parsechunk} \link{grade.parseset} \link{grade.set} Grade Sets \link{grade.truefalse} True/False answers
There are some common arguments across all of the grade functions. These are:
correctans
Input to be the correct answer. May be a
string or a vector. Checks are likely to be more stringent on this
component and result in more errors. E.g. grade.interval
requires that correctans
have length 2.
studentans
Input to check for correctness. May be a string
or a vector. Most of the grade
functions check it against
correctans
useeval
TRUE
or FALSE
. If TRUE
eval
is used to evaluate text elements. If
FALSE
as.numeric
is used to evaluate text
elements. The advantage of using eval
is more forgiveness
for input, e.g. eval
of "pi" returns 3.1415
, or eval
of "1/2" returns 0.5
, but as.numeric
returns
NA
in each case. The disadvantage is that eval
could be abused to run arbitrary code leading to a security
issue. However, the grade
package does not submit any text
to either eval
or as.numeric
that contains any of
the characters '[', ']', '(', ')', '<', '>', '=' or ','. It is unlikely that
code containing function calls could be inserted. So
useeval
defaults to TRUE
. If there are problems, or
you are worried, you can always set useeval=FALSE
.
usena
TRUE
or FALSE
. If TRUE
, NA
is considered to be a valid number. If FALSE
, NA
is considered to be invalid. Default is usena=FALSE
.
useinf
TRUE
or FALSE
. If TRUE
,
Inf
and -Inf
are considered to be valid numbers. If
FALSE
, Inf
and -Inf
are considered to be
invalid. Default is useinf=FALSE
.
quiet
TRUE
or FALSE
. If FALSE
, errors
or bad input result in more warning messages. Default is
quiet=TRUE
.
Leif Johnson <[email protected]>
Maintainer: Leif Johnson <[email protected]>
http://www.stat.umn.edu/~leif/software/grade
Checks a students probability distribution, makes sure that (1) It sums to 1 (2) All elements are >= 0
Optionally, it compares the students to a correct one. Order is optionally enforced.
grade.discreteprobability(correctans, studentans, tolerance=.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE, ordered=FALSE, checkcorrect=TRUE)
grade.discreteprobability(correctans, studentans, tolerance=.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE, ordered=FALSE, checkcorrect=TRUE)
correctans |
a vector of type |
studentans |
a vector of type |
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
ordered |
|
checkcorrect |
|
If checkcorrect=FALSE
, grade.discreteprobability
does not
do any checks on correctans
. In this case to be correct,
studentans
needs to satisfy discrete probability constraints –
all elements >= 0 and sums to 1.
If checkcorrect=TRUE
discrete probability constraints are
enforced on correctans
. studentans
needs to match
correctans
in this case. Order is only enforced if
ordered=TRUE
.
grade.discreteprobability
does not use NA
. If
usena=TRUE
grade.discreteprobability
sets it to
FALSE
and issues a warning message.
TRUE
or FALSE
indicating match success or failure respectively.
FALSE
is also returned if studentans
does not look like a set.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
# TRUE grade.discreteprobability(c(1/2,1/2), "[.5, .5]") # TRUE grade.discreteprobability(NULL, "[0, .33, .17, .5]", checkcorrect=FALSE) # FALSE grade.discreteprobability(NULL, "[-1, 0, 0, 1, 1]", checkcorrect=FALSE) # TRUE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, 1/2, 1/4, 1/4]") # FALSE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, .25, .25, .5]", ordered=TRUE) # TRUE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, .5, .25, .25]", ordered=TRUE)
# TRUE grade.discreteprobability(c(1/2,1/2), "[.5, .5]") # TRUE grade.discreteprobability(NULL, "[0, .33, .17, .5]", checkcorrect=FALSE) # FALSE grade.discreteprobability(NULL, "[-1, 0, 0, 1, 1]", checkcorrect=FALSE) # TRUE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, 1/2, 1/4, 1/4]") # FALSE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, .25, .25, .5]", ordered=TRUE) # TRUE grade.discreteprobability(c(0, 1/2, 1/4, 1/4), "[0, .5, .25, .25]", ordered=TRUE)
Checks a students interval against a correct one.
grade.interval(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.interval(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
correctans |
a vector of type |
studentans |
a vector of type |
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
usena
is ignored in this function. If set to true,
grade.interval
sets it back to false and produces a warning
message.
grade.interval
expects correctans
to be a vector of
length 2, if not it errors out.
If correctans
is in reverse order and quiet=FALSE
,
grade.interval
issues a warning, but continues grading.
TRUE
or FALSE
indicating match success or failure respectively.
FALSE
is also returned if studentans
does not look like an interval.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
grade.interval(c(1,2), "[1,2]") # TRUE grade.interval(c(1,2), "[1.1,2]", tolerance=".01") # FALSE grade.interval(c(1,pi), "(1,3.142)", tolerance=".001") # TRUE
grade.interval(c(1,2), "[1,2]") # TRUE grade.interval(c(1,2), "[1.1,2]", tolerance=".01") # FALSE grade.interval(c(1,pi), "(1,3.142)", tolerance=".001") # TRUE
Sees if studentans
is negative, correctans
is ignored.
grade.negative(correctans=NULL, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.negative(correctans=NULL, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
correctans |
not used in this function, no restrictions are enforced. |
studentans |
a vector of type |
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
TRUE
if (studentans
< -tolerance
)
FALSE
otherwise.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
grade.negative(studentans=0, "1") # FALSE grade.negative(NULL, "1.1", tolerance=".01") # FALSE grade.negative("soup", "-.1", tolerance=.05) # TRUE
grade.negative(studentans=0, "1") # FALSE grade.negative(NULL, "1.1", tolerance=".01") # FALSE grade.negative("soup", "-.1", tolerance=.05) # TRUE
Checks studentans
against correctans
. For scalars only.
grade.number(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.number(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
correctans |
a vector of type |
studentans |
a vector of type |
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
TRUE
if studentans
is within tolerance
of
correctans
. FALSE
otherwise.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
grade
grade.set
grade.negative
grade.number(1, "1") # TRUE grade.number(1, "1.1", tolerance=".01") # FALSE grade.number(pi, "3.142", tolerance=".001") # TRUE grade.number(1, "[1]") # TRUE
grade.number(1, "1") # TRUE grade.number(1, "1.1", tolerance=".01") # FALSE grade.number(pi, "3.142", tolerance=".001") # TRUE grade.number(1, "[1]") # TRUE
Parse input, returning either NULL
or a vector of the values.
grade.isscalar(x, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parse(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parseset(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parsechunk(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.isscalar(x, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parse(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parseset(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.parsechunk(ans, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
x |
argument for grade.isscalar to check |
ans |
input to parse. Can be a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
grade.isscalar
checks to see if x is a finite numeric scalar
(vector of length 1). If usena=TRUE
, NA
is also
accepted. If useinf=TRUE
, Inf
and -Inf
are also
accepted.
Input to the grade.parse
functions can be a string or a vector.
grade.parsechunk
will only return scalars, the other two will
return a vector. All three check return values using
grade.isscalar
on each element.
grade.parse
delegates character
types to either
grade.parsechunk
or grade.parseset
. If the string
contains any of the characters '[', ']', '(', ')', or ',' the string is
sent to grade.parseset
. Otherwise it is sent to
grade.parsechunk
.
If x
is a character
, grade.parsechunk
checks for
any of the forbidden characters '[', ']', '(', ')', or ','. If any are
found grade.parsechunk
refuses to evaluate the string.
If x
is a character
, grade.parsechunk
makes sure
that it looks like a vector or set. I.e. it starts with an open
bracket or parenthesis and ends with a close bracket or parenthesis. No
other brackets or parenthesis are allowed. The middle is expected to be
a comma delimited list. See the examples for more clarification.
If useeval=TRUE
, text elements are evaluated using
eval
. If useeval=FALSE
text elements are coerced
using as.numeric
. eval
is more forgiving to input,
i.e. eval
of text input '1/2' returns .25
, but
as.numeric
of text '1/2' returns NA
. However, eval
does leave an opening for unchecked code to be run in R. Text
containing parenthesis or brackets is not put into either eval
or
as.numeric
by the grade.parse
functions, but there is
still a risk. If you are concerned, set useeval=FALSE
.
grade.parse
and grade.parseset
returns either a vector
of the values, or NULL
if the input was not valid.
grade.parsechunk
returns either a single value, or NULL
if the input was not valid.
grade.isscalar
returns TRUE
if x
is a scalar
(vector of length 1), FALSE
otherwise.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
grade.parse("[1, 2, 3]") # returns c(1,2,3) grade.parse("[NA, 1, 2]") # returns NULL grade.parse("[NA, 1, 2]", usena=TRUE) # returns c(NA, 1, 2) grade.parse("[pi]") # returns 3.141.... grade.parse("[pi]", useeval=FALSE) # returns NULL grade.parsechunk("1") # 1 grade.parsechunk(",1") # NULL grade.parsechunk("[1]", quiet=FALSE) # NULL, with error message grade.parseset("[1,2,3]") # c(1,2,3) grade.isscalar(1) # TRUE grade.isscalar(c(1,2)) # FALSE grade.isscalar(NA) # FALSE grade.isscalar(NA, usena=TRUE) # TRUE grade.isscalar(Inf) # FALSE grade.isscalar(Inf, useinf=TRUE) # TRUE
grade.parse("[1, 2, 3]") # returns c(1,2,3) grade.parse("[NA, 1, 2]") # returns NULL grade.parse("[NA, 1, 2]", usena=TRUE) # returns c(NA, 1, 2) grade.parse("[pi]") # returns 3.141.... grade.parse("[pi]", useeval=FALSE) # returns NULL grade.parsechunk("1") # 1 grade.parsechunk(",1") # NULL grade.parsechunk("[1]", quiet=FALSE) # NULL, with error message grade.parseset("[1,2,3]") # c(1,2,3) grade.isscalar(1) # TRUE grade.isscalar(c(1,2)) # FALSE grade.isscalar(NA) # FALSE grade.isscalar(NA, usena=TRUE) # TRUE grade.isscalar(Inf) # FALSE grade.isscalar(Inf, useinf=TRUE) # TRUE
Checks a the set (vector in R) studentans
against
correctans
. grade.orderedset
enforces order,
grade.set
does not.
grade.set(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.orderedset(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.set(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE) grade.orderedset(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
correctans |
a vector of type |
studentans |
a vector of type |
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
TRUE
if the sets match. FALSE
otherwise.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
.
grade.set(c(1,2), "[1,2]") # TRUE grade.orderedset(c(1,2), "[1,2]") # TRUE grade.set(c(2,1), "[1,2]") # TRUE grade.orderedset(c(2,1), "[1,2]") # FALSE grade.set(c(1,2), "[1.1,2]", tolerance=".01") # FALSE grade.set(c(1,2,3,4,5), "(5,4,3,2,1)") # TRUE grade.set(c(1,2,3,4,5), "(5,4,3,2)") # FALSE grade.orderedset("[NA, 1, 2]", c(NA, 1, 2)) #FALSE, usena=F grade.orderedset("[NA, 1, 2]", c(NA, 1, 2), quiet=FALSE) # FALSE, but with warning grade.orderedset("[NA, 1, 2]", c(NA, 1, 2), usena=TRUE) # TRUE
grade.set(c(1,2), "[1,2]") # TRUE grade.orderedset(c(1,2), "[1,2]") # TRUE grade.set(c(2,1), "[1,2]") # TRUE grade.orderedset(c(2,1), "[1,2]") # FALSE grade.set(c(1,2), "[1.1,2]", tolerance=".01") # FALSE grade.set(c(1,2,3,4,5), "(5,4,3,2,1)") # TRUE grade.set(c(1,2,3,4,5), "(5,4,3,2)") # FALSE grade.orderedset("[NA, 1, 2]", c(NA, 1, 2)) #FALSE, usena=F grade.orderedset("[NA, 1, 2]", c(NA, 1, 2), quiet=FALSE) # FALSE, but with warning grade.orderedset("[NA, 1, 2]", c(NA, 1, 2), usena=TRUE) # TRUE
Checks studentans
against correctans
. For true/false
answers only.
grade.truefalse(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
grade.truefalse(correctans, studentans, tolerance=0.01, useeval=TRUE, usena=FALSE, useinf=FALSE, quiet=TRUE)
correctans |
|
studentans |
|
tolerance |
a |
useeval |
|
usena |
|
useinf |
|
quiet |
|
TRUE
if studentans==correctans
AND both
studentans
and correctans
are TRUE
or FALSE
. FALSE
otherwise.
The grade
main page contains a discussion of the
common parameters correctans, studentans, useeval, usena,
useinf, quiet
. grade.truefalse
does not accept usena
or useinf
. Setting usena=TRUE
or useinf=TRUE
will
result in a warning. tolerance
is not used in
grade.truefalse
. These arguments are included for compatibility
with the other function calls in grade
.
grade.truefalse(TRUE, TRUE) # TRUE grade.truefalse(TRUE, "TRUE") # TRUE grade.truefalse("FALSE", "TRUE") # FALSE ## depending on your environment settings, this next example may work. #grade.truefalse("F", F) # TRUE if your environment has not redefined 'F'
grade.truefalse(TRUE, TRUE) # TRUE grade.truefalse(TRUE, "TRUE") # TRUE grade.truefalse("FALSE", "TRUE") # FALSE ## depending on your environment settings, this next example may work. #grade.truefalse("F", F) # TRUE if your environment has not redefined 'F'