intervalContainsTruth: Test whether intervals contain true values

Description Usage Arguments Details Value See Also Examples

Description

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.

Usage

1
2
3
4
5
6
7
intervalContainsTruth(interval, truth)

## S4 method for signature 'DemographicArray,DemographicArray'
intervalContainsTruth(interval, truth)

## S4 method for signature 'DemographicArray,numeric'
intervalContainsTruth(interval, truth)

Arguments

interval

A DemographicArray, with a quantile dimension of length 2.

truth

A DemographicArray, or a single number.

Details

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.

Value

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.

See Also

Function credibleInterval creates interval objects of the right form for intervalContainsTruth. Function MSE, is another function that may be useful in simulation studies.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)

StatisticsNZ/dembase documentation built on Dec. 25, 2021, 4:49 p.m.