resolve_probabilistically: Resolves messy dates by a random draw

resolve_probabilisticallyR Documentation

Resolves messy dates by a random draw

Description

These functions resolve messydates by drawing one precise date at random from the dates that each value can be. random() expands all elements of the vector into one combined set of dates and draws a single value from it. vrandom() draws from each element separately, and so returns a vector of the same length as the input. Repeated draws give a distribution of results, which shows how much an analysis depends on the imprecision of the dates.

Usage

random(..., na.rm = TRUE)

## S3 method for class 'mdate'
random(..., na.rm = TRUE, approx_range = 0, uncertain_p = 1)

vrandom(..., na.rm = TRUE)

## S3 method for class 'mdate'
vrandom(..., na.rm = TRUE, approx_range = 0, uncertain_p = 1)

Arguments

...

a mdate object

na.rm

Should NAs be removed? FALSE by default. As in base R, with na.rm = FALSE one NA makes the result of min() or max() NA.

approx_range

The range by which to widen approximate values (~ or ⁠%⁠). The range is in units of the component that each mark is written on, as in compatible_dates(). With the default of 0, approximate values are not widened. With a positive value, the draw uses trapezoidal weights, see the section "Approximate and uncertain values".

uncertain_p

The probability that an uncertain value (⁠?⁠ or ⁠%⁠) is correct. Give one number for all values, or one number for each value, for example a column that holds the reliability of each source. With probability 1 - uncertain_p, vrandom() gives NA for an uncertain value, and random() leaves it out of the draw. The default of 1 treats uncertain values as correct. uncertain_p = 0 is the same as uncertain = "drop".

Details

By default, each date that a value can be has the same chance of being drawn. For a ⁠[]⁠ ("one member of") set, this is a draw from the candidates themselves. For a {} ("all members of") set, it is a draw of one of the occurrences. The arguments approx_range and uncertain_p change the draw for approximate and uncertain values.

Value

An mdate of precise dates or date-times. The ⁠v*()⁠ functions give one value for each element of x, with NA for a missing value and for the empty set, {}. The other functions give one value for the whole vector.

Approximate and uncertain values

The two annotations have different effects on a random draw.

An approximate value (~) can be outside the dates that it names. With a positive approx_range, the dates it names (the core) have a weight of 1, and the dates that approx_range adds on each side have a weight that falls linearly to 0. A range widens at each end by the marks of that end, so the weight is 1 across the range and falls to 0 beyond an approximate end. The core and the full range are the "yolk" and the "egg" of the egg-yolk model of regions with indeterminate boundaries (Cohn and Gotts 1996). The linear fall between them is an assumption of this package.

An uncertain value (⁠?⁠) is a record that the source itself doubts. The doubt is about whether the record is correct at all, so it does not change the dates that the value can be. Instead, uncertain_p gives the probability that the record is correct. Repeated draws then show how much a result depends on doubtful records.

References

Cohn, A. G. and Gotts, N. M. (1996). "The 'egg-yolk' representation of regions with indeterminate boundaries". In P. A. Burrough and A. U. Frank (eds.), Geographic Objects with Indeterminate Boundaries, GISDATA 2, pp. 171-187. London: Taylor & Francis.

Examples

d <- as_messydate(c("2008-03-25", "?2012-02-27", "2001-01?", "2001~",
  "2001-01-01..2001-02-02", "{2001-01-01,2001-02-02}",
  "{2001-01,2001-02-02}", "2008-XX-31", "-0050-01-01"))
d
random(d)
vrandom(d)

messydates documentation built on Dec. 3, 2026, 5:09 p.m.