| intervalContainsTruth {dembase} | R Documentation |
Test whether intervals contain specified values. These values
are referred to as 'truth' because intervalContainsTruth
is typically used as part of a simulation study,
where the analyst generates the true values, and then
sees whether the model is able to recover these values.
intervalContainsTruth(interval, truth) ## S4 method for signature 'DemographicArray,DemographicArray' intervalContainsTruth(interval, truth) ## S4 method for signature 'DemographicArray,numeric' intervalContainsTruth(interval, truth)
interval |
A |
truth |
A |
interval must have the same dimensions
and dimscales as truth, and also a dimension
with length 2 and dimtype
"quantile" specifying the intervals.
An interval (l, u) is said to contain a value v
if l <= t <= u. The use of <=, rather than
<, makes no difference
when l and u are real numbers, but does make
a difference when l and u are integers.
truth can be a single number, in which case all dimensions
of interval, other than the quantile dimension, should
have length 1.
intervalContainsTruth is stricter about the compatibility
of its arguments than most functions in dembase.
Although it reorders dimensions and categories
in interval and truth, it does not collapse
or expand dimensions, or drop any levels.
When truth is a DemographicArray
intervalContainsTruth returns a Values
object with 1s and 0s,
rather than an ordinary array of
TRUEs and FALSEs. The advantage of the
Values object is that it can
more easily be collapsed or otherwise manipulated:
see below for an example.
An Values object, consisting
of 1s and 0s, with the same dimensions
as truth, or, if truth is a number,
a single 1 or 0.
Function credibleInterval creates
interval objects of the right form
for intervalContainsTruth. Function MSE,
is another function that may be useful in simulation studies.
interval <- Values(array(c(-0.1, 0.2, 0.4, 0.7),
dim = c(2, 2),
dimnames = list(quantile = c("2.5%", "97.5%"),
sex = c("Female", "Male"))))
truth <- ValuesOne(c(0.3, 0.5),
labels = c("Female", "Male"),
name = "sex")
interval
truth
intervalContainsTruth(interval = interval,
truth = truth)
interval <- ValuesOne(c(5L, 8L),
labels = c("5%", "95%"),
name = "quantile")
truth <- 5L
intervalContainsTruth(interval = interval,
truth = truth)