1. ArchaeoPhases : Allen’s Interval Algebra

=============

```{r, echo = FALSE, message = FALSE} knitr::opts_chunk$set(comment = ““) options(width = 120, max.print = 20) library(ArchaeoPhases)

```

Introduction

Version `ArchaeoPhases 1.6` adds facilities to compute Allen’s interval algebra. This vignette provides an overview of the algebra and illustrates how it might be used analytically and empirically, given MCMC output from a Bayesian calibration.

Overview of Allen’s Interval Algebra

Allen’s interval algebra identifies 13 basic relations that are distinct, exhaustive, and qualitative. The algebra is defined for definite intervals whose endpoints are single values. It can also be used with indefinite intervals whose endpoints are not single values.

It is conventional to express an Allen relation with a notation that indicates two intervals and a set of relations. For example, given definite intervals A and B, where A precedes B, their Allen relation can be represented as A/(p)/B. Given indefinite intervals C and D, where C starts before D starts and ends before D ends, an Allen relation that expresses this incomplete information is C/(pmo)/D. Note that the Allen set (pmo) in the relation of C and D is a superset of the Allen set (p) in the relation of A and B. In this circumstance, when two Allen sets are related as superset/subset, the relation indicated by the superset is weaker and the relation indicated by the subset is stronger. An Allen relation thus provides a precise vocabulary for characterizing the state of knowledge about the relation between two intervals, regardless of whether the intervals are definite or indefinite.

Relation     Converse
precedes (p) (P) preceded by
meets (m) (M) met by
overlaps (o) (O) overlapped by
finished by (F) (f) finishes
contains (D) (d) during
starts (s) (S) started by
equals (e)    

It is often useful to visualize the basic Allen relations as a Nökel lattice. In a Nökel lattice, the immediate neighbors of a relation differ from it in the placement of a single interval end-point.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Loading required package: coda
## Loading required package: hdrcde
## This is hdrcde 3.4
## Plot the basic Allen relations
allen_illustrate("basic") 

##    x y result          node                 title
## p  0 8      1      precedes Basic Allen relations
## m  0 7      1         meets Basic Allen relations
## o  0 6      1      overlaps Basic Allen relations
## F -1 5      1   finished by Basic Allen relations
## s  1 5      1        starts Basic Allen relations
## D -2 4      1      contains Basic Allen relations
## e  0 4      1        equals Basic Allen relations
## d  2 4      1        during Basic Allen relations
## S -1 3      1    started by Basic Allen relations
## f  1 3      1      finishes Basic Allen relations
## O  0 2      1 overlapped by Basic Allen relations
## M  0 1      1        met by Basic Allen relations
## P  0 0      1   preceded by Basic Allen relations

Analytic Inquiry with the Algebra

Interval algebra is carried out with a composition function that returns the relation of two intervals given their relations to a common third interval. As implemented here, the function expects the relation of one interval to the common interval and the relation of the common interval to the remaining interval. The function also accepts a title for the resulting Nokel lattice.

In this example, the composition function deduces that the interval represented by a context inferior to a reference context precedes the interval represented by a context superior to the reference context.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Plot lattice for two contexts on the same line of a Harris matrix
allen_analyze("m", "m", "Composite relation of two contexts on the same line") 

##    x y result          node                                               title
## p  0 8      1      precedes Composite relation of two contexts on the same line
## m  0 7      0         meets Composite relation of two contexts on the same line
## o  0 6      0      overlaps Composite relation of two contexts on the same line
## F -1 5      0   finished by Composite relation of two contexts on the same line
## s  1 5      0        starts Composite relation of two contexts on the same line
## D -2 4      0      contains Composite relation of two contexts on the same line
## e  0 4      0        equals Composite relation of two contexts on the same line
## d  2 4      0        during Composite relation of two contexts on the same line
## S -1 3      0    started by Composite relation of two contexts on the same line
## f  1 3      0      finishes Composite relation of two contexts on the same line
## O  0 2      0 overlapped by Composite relation of two contexts on the same line
## M  0 1      0        met by Composite relation of two contexts on the same line
## P  0 0      0   preceded by Composite relation of two contexts on the same line

The same lattice can be created with a convenience function.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Illustrate composite relations in a stratigraphic sequence
allen_illustrate("sequence") 

##    x y result          node                            title
## p  0 8      1      precedes Composite stratigraphic relation
## m  0 7      0         meets Composite stratigraphic relation
## o  0 6      0      overlaps Composite stratigraphic relation
## F -1 5      0   finished by Composite stratigraphic relation
## s  1 5      0        starts Composite stratigraphic relation
## D -2 4      0      contains Composite stratigraphic relation
## e  0 4      0        equals Composite stratigraphic relation
## d  2 4      0        during Composite stratigraphic relation
## S -1 3      0    started by Composite stratigraphic relation
## f  1 3      0      finishes Composite stratigraphic relation
## O  0 2      0 overlapped by Composite stratigraphic relation
## M  0 1      0        met by Composite stratigraphic relation
## P  0 0      0   preceded by Composite stratigraphic relation

Empirical Inquiry with the Algebra

Empirical inquiry with Allen’s interval algebra compares intervals estimated by Bayesian calibration of age determinations from Anglo-Saxon female burials. First, we check for the expected result of the identity relation by comparing an interval with itself.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Load the Anglo Saxon burials dataset
library(ArchaeoPhases.dataset)
library(ggplot2)
data(AngloSaxonBurials)
## Identify the burials with bead BE1-Dghnt
be1.dghnt <- c("UB-4503 (Lec148)", "UB-4506 (Lec172/2)",
"UB-6038 (CasD183)", "UB-4512 (EH091)", "UB-4501 (Lec014)",
"UB-4507 (Lec187)", "UB-4502 (Lec138)", "UB-4042 (But1674)",
"SUERC-39100 (ERL G266)")
chains <- list(list("BE1-Dghnt" = be1.dghnt,
                    "BE1-Dghnt" = be1.dghnt))
allen_observe(data = AngloSaxonBurials,
              chains = chains) 

##    x y result          node                 title
## p  0 8      0      precedes BE1-Dghnt(e)BE1-Dghnt
## m  0 7      0         meets BE1-Dghnt(e)BE1-Dghnt
## o  0 6      0      overlaps BE1-Dghnt(e)BE1-Dghnt
## F -1 5      0   finished by BE1-Dghnt(e)BE1-Dghnt
## s  1 5      0        starts BE1-Dghnt(e)BE1-Dghnt
## D -2 4      0      contains BE1-Dghnt(e)BE1-Dghnt
## e  0 4      1        equals BE1-Dghnt(e)BE1-Dghnt
## d  2 4      0        during BE1-Dghnt(e)BE1-Dghnt
## S -1 3      0    started by BE1-Dghnt(e)BE1-Dghnt
## f  1 3      0      finishes BE1-Dghnt(e)BE1-Dghnt
## O  0 2      0 overlapped by BE1-Dghnt(e)BE1-Dghnt
## M  0 1      0        met by BE1-Dghnt(e)BE1-Dghnt
## P  0 0      0   preceded by BE1-Dghnt(e)BE1-Dghnt

Next we compare the depositional histories of two bead types recovered from well-dated Anglo Saxon female burials in England.

Note that the Allen relation and its converse are calculated.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Load the Anglo Saxon burials dataset
library(ArchaeoPhases.dataset)
data(AngloSaxonBurials)
## Identify the burials with bead BE1-Dghnt
be1.dghnt <- c("UB-4503 (Lec148)", "UB-4506 (Lec172/2)",
"UB-6038 (CasD183)", "UB-4512 (EH091)", "UB-4501 (Lec014)",
"UB-4507 (Lec187)", "UB-4502 (Lec138)", "UB-4042 (But1674)",
"SUERC-39100 (ERL G266)")
## Identify the burials with bead BE1-CylRound
be1.cylround <- c("UB-4965 (ApD117)", "UB-4735 (Ber022)", "UB-4739 (Ber134/1)", "UB-6473 (BuD250)", "UB-6476 (BuD339)", "UB-4729 (MH068)", "UB-4835 (ApD134)", "UB-4708 (EH083)", "UB-4733 (MH095)", "UB-4888 (MelSG089)", "UB-4963 (SPTip208)", "UB-4890 (MelSG075)", "UB-4732 (MH094)", "SUERC-51539 (ERL G353)", "SUERC-51551 (ERL G193)")
chains <- list(list("BE1-Dghnt" = be1.dghnt, "BE1-CylRound" = be1.cylround), list("BE1-CylRound" = be1.cylround, "BE1-Dghnt" = be1.dghnt))
allen_observe(data = AngloSaxonBurials,
              chains = chains) 

##     x y result          node                     title
## p   0 8 0.0000      precedes BE1-Dghnt(OP)BE1-CylRound
## m   0 7 0.0000         meets BE1-Dghnt(OP)BE1-CylRound
## o   0 6 0.0000      overlaps BE1-Dghnt(OP)BE1-CylRound
## F  -1 5 0.0000   finished by BE1-Dghnt(OP)BE1-CylRound
## s   1 5 0.0000        starts BE1-Dghnt(OP)BE1-CylRound
## D  -2 4 0.0000      contains BE1-Dghnt(OP)BE1-CylRound
## e   0 4 0.0000        equals BE1-Dghnt(OP)BE1-CylRound
## d   2 4 0.0000        during BE1-Dghnt(OP)BE1-CylRound
## S  -1 3 0.0000    started by BE1-Dghnt(OP)BE1-CylRound
## f   1 3 0.0000      finishes BE1-Dghnt(OP)BE1-CylRound
## O   0 2 0.9962 overlapped by BE1-Dghnt(OP)BE1-CylRound
## M   0 1 0.0000        met by BE1-Dghnt(OP)BE1-CylRound
## P   0 0 0.0038   preceded by BE1-Dghnt(OP)BE1-CylRound
## p1  0 8 0.0038      precedes BE1-CylRound(po)BE1-Dghnt
## m1  0 7 0.0000         meets BE1-CylRound(po)BE1-Dghnt
## o1  0 6 0.9962      overlaps BE1-CylRound(po)BE1-Dghnt
## F1 -1 5 0.0000   finished by BE1-CylRound(po)BE1-Dghnt
## s1  1 5 0.0000        starts BE1-CylRound(po)BE1-Dghnt
## D1 -2 4 0.0000      contains BE1-CylRound(po)BE1-Dghnt
## e1  0 4 0.0000        equals BE1-CylRound(po)BE1-Dghnt
## d1  2 4 0.0000        during BE1-CylRound(po)BE1-Dghnt
## S1 -1 3 0.0000    started by BE1-CylRound(po)BE1-Dghnt
## f1  1 3 0.0000      finishes BE1-CylRound(po)BE1-Dghnt
## O1  0 2 0.0000 overlapped by BE1-CylRound(po)BE1-Dghnt
## M1  0 1 0.0000        met by BE1-CylRound(po)BE1-Dghnt
## P1  0 0 0.0000   preceded by BE1-CylRound(po)BE1-Dghnt

It can be useful to observe the frequency with which two intervals are related according to the relations in an Allen set. For instance, we might be interested in which of our two beads might be the trunk from which the other branched. This can be done by observing the frequency with which each bead type is related as row(oFD)col to the other bead. The following code shows that BE1-CylRound is the better trunk candidate.

## Load ArchaeoPhases
library(ArchaeoPhases)
## Load the Anglo Saxon burials dataset
library(ArchaeoPhases.dataset)
data(AngloSaxonBurials)
## Identify the burials with bead BE1-Dghnt
be1.dghnt <- c("UB-4503 (Lec148)", "UB-4506 (Lec172/2)",
"UB-6038 (CasD183)", "UB-4512 (EH091)", "UB-4501 (Lec014)",
"UB-4507 (Lec187)", "UB-4502 (Lec138)", "UB-4042 (But1674)",
"SUERC-39100 (ERL G266)")
## Identify the burials with bead BE1-CylRound
be1.cylround <- c("UB-4965 (ApD117)", "UB-4735 (Ber022)", "UB-4739 (Ber134/1)", "UB-6473 (BuD250)", "UB-6476 (BuD339)", "UB-4729 (MH068)", "UB-4835 (ApD134)", "UB-4708 (EH083)", "UB-4733 (MH095)", "UB-4888 (MelSG089)", "UB-4963 (SPTip208)", "UB-4890 (MelSG075)", "UB-4732 (MH094)", "SUERC-51539 (ERL G353)", "SUERC-51551 (ERL G193)")
chains <- list("BE1-Dghnt" = be1.dghnt, "BE1-CylRound" = be1.cylround)
res <- allen_observe_frequency(AngloSaxonBurials, chains, "oFD")
res$rounded.percentage 
##              BE1-Dghnt BE1-CylRound
## BE1-Dghnt           NA            0
## BE1-CylRound       100           NA