arkhe

Appveyor build status Travis build Status codecov

CRAN Version CRAN checks CRAN Downloads

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Lifecycle: maturing

DOI

Overview

A collection of classes that represent archaeological data. This package provides a set of S4 classes that extend the basic matrix data type (absolute/relative frequency, presence/absence data, co-occurrence matrix, etc.) upon which package developers can build subclasses. It also provides a set of generic methods (mutators and coercion mechanisms) and functions (e.g. predicates). In addition, a few classes of general interest (e.g. that represent stratigraphic relationships) are implemented.

Installation

You can install the released version of arkhe from CRAN with:

install.packages("arkhe")

Or install the development version from GitHub with:

# install.packages("devtools")
remotes::install_github("nfrerebeau/arkhe")

Usage

# Load the package
library(arkhe)
# See the vignette
utils::vignette("arkhe", package = "arkhe")

arkhe provides a set of S4 classes that extend the basic matrix data type. These new classes represent different special types of matrix.

It assumes that you keep your data tidy: each variable (type/taxa) must be saved in its own column and each observation (assemblage/sample) must be saved in its own row.

These new classes are of simple use, on the same way as the base matrix:

# Define a count data matrix
quanti <- CountMatrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10)

# Define a logical matrix
# Data will be coerced with as.logical()
quali <- IncidenceMatrix(data = sample(0:1, 100, TRUE), nrow = 10, ncol = 10)

arkhe uses coercing mechanisms (with validation methods) for data type conversions:

## Create a count matrix
A0 <- matrix(data = sample(0:10, 100, TRUE), nrow = 10, ncol = 10)

## Coerce to absolute frequencies
A1 <- as_count(A0)

## Coerce to relative frequencies
B <- as_abundance(A1)

## Row sums are internally stored before coercing to a frequency matrix
## (use get_totals() to get these values)
## This allows to restore the source data
A2 <- as_count(B)
all(A1 == A2)
#> [1] TRUE

## Coerce to presence/absence
C <- as_incidence(A1)

## Coerce to a co-occurrence matrix
D <- as_occurrence(A1)

Represent stratigraphic relationships:

# Principles of Archaeological Stratigraphy, fig. 12
harris <- read.table(
  header = TRUE,
  text = "lower upper
          2     1
          3     1
          4     1
          5     2
          5     3
          5     4
          6     5
          7     1
          7     6
          8     1
          8     6
          9     7
          9     8"
)

as_stratigraphy(harris)
#> <StratigraphicMatrix: aca09a25-5637-4d61-a55b-13cfe70e0401>
#>  9 x 9 stratigraphic matrix:
#>      upper
#> lower     1     2     3     4     5     6     7     8     9
#>     1 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#>     2  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#>     3  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#>     4  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#>     5 FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
#>     6 FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
#>     7  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
#>     8  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
#>     9 FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE

Contributing

Please note that the arkhe project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.