Title: | Sourcing Archaeological Materials by Chemical Composition |
Version: | 0.6.0 |
Maintainer: | Nicolas Frerebeau <nicolas.frerebeau@u-bordeaux-montaigne.fr> |
Description: | Exploration and analysis of compositional data in the framework of Aitchison (1986, ISBN: 978-94-010-8324-9). This package provides tools for chemical fingerprinting and source tracking of ancient materials. |
License: | GPL (≥ 3) |
URL: | https://codeberg.org/tesselle/nexus, https://packages.tesselle.org/nexus/, https://tesselle.r-universe.dev/nexus |
BugReports: | https://codeberg.org/tesselle/nexus/issues |
Depends: | R (≥ 3.5), dimensio (≥ 0.14.0) |
Imports: | arkhe (≥ 1.11.0), graphics, grDevices, isopleuros (≥ 1.4.0), khroma (≥ 1.16.0), MASS, methods, stats, utils |
Suggests: | cluster, folio (≥ 1.5.0), fontquiver, igraph, knitr, markdown, rsvg, svglite, tinysnapshot, tinytest |
VignetteBuilder: | knitr |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
X-schema.org-applicationCategory: | Archaeological Science |
X-schema.org-isPartOf: | https://www.tesselle.org |
X-schema.org-keywords: | archaeology, archaeological-science, archaeometry, compositional-data, provenance-studies, r-package |
Collate: | 'AllClasses.R' 'AllGenerics.R' 'aggregate.R' 'barplot.R' 'bind.R' 'boxplot.R' 'chemistry.R' 'coerce.R' 'condense.R' 'covariance.R' 'data.R' 'describe.R' 'dist.R' 'graph.R' 'group.R' 'hist.R' 'margin.R' 'mean.R' 'mix.R' 'mutators.R' 'nexus-internal.R' 'nexus-package.R' 'outliers.R' 'pairs.R' 'pca.R' 'plot.R' 'quantile.R' 'reexport.R' 'replace.R' 'scale.R' 'show.R' 'simplex.R' 'split.R' 'subset.R' 'summary.R' 'transform_alr.R' 'transform_clr.R' 'transform_ilr.R' 'transform_inverse.R' 'transform_lr.R' 'transform_plr.R' 'validate.R' 'variance.R' 'variation.R' 'zzz.R' |
NeedsCompilation: | no |
Packaged: | 2025-06-02 12:46:19 UTC; nfrerebeau |
Author: | Nicolas Frerebeau |
Repository: | CRAN |
Date/Publication: | 2025-06-02 13:40:02 UTC |
nexus: Sourcing Archaeological Materials by Chemical Composition
Description
Exploration and analysis of compositional data in the framework of Aitchison (1986, ISBN: 978-94-010-8324-9). This package provides tools for chemical fingerprinting and source tracking of ancient materials.
Details
Version | 0.6.0 |
License | GPL-3 |
CRAN DOI | doi:10.32614/CRAN.package.nexus |
Zenodo DOI | doi:10.5281/zenodo.10225630 |
Archéosciences Bordeaux (UMR 6034)
Maison de l'Archéologie
Université Bordeaux Montaigne
F-33607 Pessac cedex
France
Package options
nexus uses the following options()
to configure behavior:
-
nexus.verbose
: alogical
scalar. Should R report extra information on progress? Defaults tointeractive()
.
Author(s)
Maintainer: Nicolas Frerebeau nicolas.frerebeau@u-bordeaux-montaigne.fr (ORCID)
Authors:
Anne Philippe anne.philippe@univ-nantes.fr (ORCID)
Other contributors:
Brice Lebrun (ORCID) (Logo designer) [artist]
Université Bordeaux Montaigne (03pbgwk21) [funder]
CNRS (02feahw73) [funder]
See Also
Useful links:
Report bugs at https://codeberg.org/tesselle/nexus/issues
Compositional Matrix
Description
An S4 class to represent compositional data.
Usage
is_composition(object)
Arguments
object |
A |
Slots
totals
A
numeric
vector to store the absolute row sums (before the closure of the compositions).
Coerce
In the code snippets below, x
is a CompositionMatrix
object.
as.data.frame(x)
Coerces to a
data.frame
.
Subset
In the code snippets below, x
is a CompositionMatrix
object.
x[i, j]
Extract parts of a matrix (see
[
).
Note
This class inherits from NumericMatrix
.
Author(s)
N. Frerebeau
See Also
Other classes:
GroupedComposition-class
,
GroupedLogRatio-class
,
LogRatio-class
,
NumericMatrix-class
,
OutlierIndex-class
,
ReferenceGroups-class
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## codaccess
dim(coda) # Get the matrix dimensions
row(coda) # Get the row indexes
col(coda, as.factor = TRUE) # Get the column indexes
nrow(coda) # Get the number of rows
ncol(coda) # Get the number of columns
dimnames(coda) # Get the dimension names
rownames(coda) <- LETTERS[1:25] # Set the row names
rownames(coda) # Get the rownames
colnames(coda) <- letters[21:25] # Set the column names
colnames(coda) # Get the column names
Grouped Compositional Matrix
Description
An S4 class to represent grouped compositional data.
Coerce
In the code snippets below, x
is a GroupedComposition
object.
as.data.frame(x)
Coerces to a
data.frame
.
Note
This class inherits from CompositionMatrix
and
ReferenceGroups
.
Author(s)
N. Frerebeau
See Also
Other classes:
CompositionMatrix-class
,
GroupedLogRatio-class
,
LogRatio-class
,
NumericMatrix-class
,
OutlierIndex-class
,
ReferenceGroups-class
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## codaccess
dim(coda) # Get the matrix dimensions
row(coda) # Get the row indexes
col(coda, as.factor = TRUE) # Get the column indexes
nrow(coda) # Get the number of rows
ncol(coda) # Get the number of columns
dimnames(coda) # Get the dimension names
rownames(coda) <- LETTERS[1:25] # Set the row names
rownames(coda) # Get the rownames
colnames(coda) <- letters[21:25] # Set the column names
colnames(coda) # Get the column names
Grouped Log-Ratio Matrix
Description
An S4 class to represent grouped log-ratio.
Coerce
In the code snippets below, x
is a GroupedLogRatio
object.
as.data.frame(x)
Coerces to a
data.frame
.
Note
This class inherits from LogRatio
and
ReferenceGroups
.
Author(s)
N. Frerebeau
See Also
Other classes:
CompositionMatrix-class
,
GroupedComposition-class
,
LogRatio-class
,
NumericMatrix-class
,
OutlierIndex-class
,
ReferenceGroups-class
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## codaccess
dim(coda) # Get the matrix dimensions
row(coda) # Get the row indexes
col(coda, as.factor = TRUE) # Get the column indexes
nrow(coda) # Get the number of rows
ncol(coda) # Get the number of columns
dimnames(coda) # Get the dimension names
rownames(coda) <- LETTERS[1:25] # Set the row names
rownames(coda) # Get the rownames
colnames(coda) <- letters[21:25] # Set the column names
colnames(coda) # Get the column names
Log-Ratio Matrix
Description
S4 classes to represent log-ratio data transformations.
Usage
is_logratio(object)
Arguments
object |
A |
Slots
totals
A
numeric
vector to store the absolute row sums (before the closure of the compositions).parts
A
character
vector to store the original part names.ratio
A
character
vector to store the ratio names.order
An
integer
vector to store the original ordering of the columns.base
A
numeric
matrix to store the basis of the transformation.weights
A
numeric
vector to store the weights assigned to the respective log-ratios.
Coerce
In the code snippets below, x
is a LogRatio
object.
as.data.frame(x)
Coerces to a
data.frame
.
Note
These classes inherit from matrix
.
Author(s)
N. Frerebeau
See Also
transform_lr()
, transform_clr()
, transform_alr()
,
transform_ilr()
, transform_plr()
Other classes:
CompositionMatrix-class
,
GroupedComposition-class
,
GroupedLogRatio-class
,
NumericMatrix-class
,
OutlierIndex-class
,
ReferenceGroups-class
Numeric Matrix
Description
S4 classes that represent a m \times p
numeric matrix.
Slots
.Data
A
m \times p
numeric
matrix
.
Note
This class inherits from matrix
.
Author(s)
N. Frerebeau
See Also
Other classes:
CompositionMatrix-class
,
GroupedComposition-class
,
GroupedLogRatio-class
,
LogRatio-class
,
OutlierIndex-class
,
ReferenceGroups-class
Outliers
Description
An S4 class to store the result of outlier detection.
Slots
samples
A
character
vector to store the sample identifiers.standard
A
numeric
matrix giving the standard squared Mahalanobis distances.robust
A
numeric
matrix giving the robust squared Mahalanobis distances.limit
A
numeric
value giving the cut-off value used for outliers detection (quantile of the Chi-squared distribution).dof
A (non-negative)
numeric
value giving the degrees of freedom.
Coerce
In the code snippets below, x
is an OutlierIndex
object.
as.data.frame(x)
Coerces to a
data.frame
.
Author(s)
N. Frerebeau
See Also
Other classes:
CompositionMatrix-class
,
GroupedComposition-class
,
GroupedLogRatio-class
,
LogRatio-class
,
NumericMatrix-class
,
ReferenceGroups-class
Grouped Data
Description
A virtual S4 class to represent reference groups.
Usage
is_grouped(object)
Arguments
object |
A |
Slots
group_indices
An
integer
vector to store the group that each value belongs to.group_levels
A
character
vector to store the values of the grouping variables.group_ordered
A
logical
scalar to determine if the levels should be regarded as ordered (in the order given).
Author(s)
N. Frerebeau
See Also
Other classes:
CompositionMatrix-class
,
GroupedComposition-class
,
GroupedLogRatio-class
,
LogRatio-class
,
NumericMatrix-class
,
OutlierIndex-class
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## codaccess
dim(coda) # Get the matrix dimensions
row(coda) # Get the row indexes
col(coda, as.factor = TRUE) # Get the column indexes
nrow(coda) # Get the number of rows
ncol(coda) # Get the number of columns
dimnames(coda) # Get the dimension names
rownames(coda) <- LETTERS[1:25] # Set the row names
rownames(coda) # Get the rownames
colnames(coda) <- letters[21:25] # Set the column names
colnames(coda) # Get the column names
Compute Summary Statistics of Data Subsets
Description
Splits the data into subsets, computes summary statistics for each, and returns the result.
Usage
## S4 method for signature 'CompositionMatrix'
aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE)
## S4 method for signature 'GroupedComposition'
aggregate(x, FUN, ..., simplify = TRUE)
Arguments
x |
A |
by |
A |
FUN |
A |
... |
Further arguments to be passed to |
simplify |
A |
drop |
A |
Value
A matrix
.
Author(s)
N. Frerebeau
See Also
Other statistics:
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to a compositional matrix
coda <- as_composition(slides)
## Compositional mean by slide
aggregate(coda, by = slides$slide, FUN = mean)
## Metric variance by slide
aggregate(coda, by = slides$slide, FUN = variance_total)
Arctic Lake
Description
Sand, silt, clay compositions of 39 sediment samples at different water depths in an Arctic lake.
Usage
arctic
Format
A data.frame
with 4 variables:
sand
Sand content (percent).
silt
Silt content (percent).
clay
Clay content (percent).
depth
Water depth (m).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Operations in the Simplex
Description
Operators performing operations in the simplex.
Usage
x %perturbe% y
x %power% y
## S4 method for signature 'CompositionMatrix,CompositionMatrix'
x %perturbe% y
## S4 method for signature 'CompositionMatrix,numeric'
x %power% y
## S4 method for signature 'numeric,CompositionMatrix'
x %power% y
Arguments
x |
A |
y |
A |
Details
%perturbe%
%power%
Value
A CompositionMatrix
object or a numeric
vector (same as x
).
Author(s)
N. Frerebeau
See Also
Other operations in the simplex:
closure()
,
perturbation()
,
powering()
,
scalar()
Examples
x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))
## Perturbation
perturbation(x, y)
x + y
## Powering
powering(y, 2)
y * 2
## Scalar product
scalar(x, y)
Coerce to a Data Frame
Description
Coerce to a Data Frame
Usage
## S4 method for signature 'CompositionMatrix'
as.data.frame(x, ..., group_var = ".group", group_after = 0)
## S4 method for signature 'LogRatio'
as.data.frame(x, ..., group_var = ".group", group_after = 0)
## S4 method for signature 'OutlierIndex'
as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
Arguments
x |
An R object (typically, a |
... |
Further parameters to be passed to
|
group_var |
A |
group_after |
An |
row.names |
A |
optional |
A |
Value
A data.frame
.
Author(s)
N. Frerebeau
See Also
Other mutators:
labels()
,
totals()
,
weights()
Examples
## Create a count matrix
A1 <- matrix(data = sample(1:100, 100, TRUE), nrow = 20)
## Coerce to compositions
B <- as_composition(A1)
## Row sums are internally stored before coercing to relative frequencies
totals(B)
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
Coerce to Amounts
Description
Coerce to Amounts
Usage
as_amounts(from, ...)
## S4 method for signature 'CompositionMatrix'
as_amounts(from)
Arguments
from |
A |
... |
Currently not used. |
Value
Author(s)
N. Frerebeau
See Also
Other compositional data tools:
as_composition()
Examples
## Create a count matrix
A1 <- matrix(data = sample(1:100, 100, TRUE), nrow = 20)
## Coerce to compositions
B <- as_composition(A1)
## Row sums are internally stored before coercing to relative frequencies
totals(B)
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
Coerce to a Closed Compositional Matrix
Description
Coerces an object to a CompositionMatrix
object.
Usage
as_composition(from, ...)
## S4 method for signature 'numeric'
as_composition(from)
## S4 method for signature 'matrix'
as_composition(from)
## S4 method for signature 'data.frame'
as_composition(
from,
parts = NULL,
groups = NULL,
autodetect = TRUE,
verbose = getOption("nexus.verbose")
)
Arguments
from |
A |
... |
Currently not used. |
parts |
A |
groups |
An |
autodetect |
A |
verbose |
A |
Details
See vignette("nexus")
.
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
See Also
Other compositional data tools:
as_amounts()
Examples
## Create a count matrix
A1 <- matrix(data = sample(1:100, 100, TRUE), nrow = 20)
## Coerce to compositions
B <- as_composition(A1)
## Row sums are internally stored before coercing to relative frequencies
totals(B)
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
Graph of Log-ratios
Description
Produces a graph of log-ratios.
Usage
as_graph(object, ...)
## S4 method for signature 'LR'
as_graph(object)
## S4 method for signature 'ALR'
as_graph(object)
## S4 method for signature 'ILR'
as_graph(object)
Arguments
object |
A |
... |
Currently not used. |
Value
An igraph graph object.
Author(s)
N. Frerebeau
See Also
Other plot methods:
barplot()
,
boxplot()
,
hist()
,
pairs()
,
plot()
Examples
if (requireNamespace("igraph", quietly = TRUE)) {
library(igraph)
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Pairwise log-ratio
lr <- transform_lr(coda)
lr_graph <- as_graph(lr)
plot(lr_graph)
## Additive log-ratio
alr <- transform_alr(coda)
alr_graph <- as_graph(alr)
plot(alr_graph)
## Isometric log-ratio
ilr <- transform_ilr(coda)
ilr_graph <- as_graph(ilr)
plot(ilr_graph)
plr <- transform_plr(coda)
plr_graph <- as_graph(plr)
plot(plr_graph)
}
Barplot of Compositional Data
Description
Displays a compositional bar chart.
Usage
## S4 method for signature 'CompositionMatrix'
barplot(
height,
...,
order_columns = FALSE,
order_rows = NULL,
decreasing = TRUE,
names = TRUE,
space = 0.2,
offset = 0.025,
color = NULL,
border = NA,
axes = TRUE,
legend = TRUE
)
Arguments
height |
A |
... |
Further graphical parameters. |
order_columns |
A |
order_rows |
An |
decreasing |
A |
names |
A |
space |
A length-one |
offset |
A length-one |
color |
A (named) vector of colors (will be mapped to the group names
of |
border |
The color to draw the borders. |
axes |
A |
legend |
A |
Value
barplot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return height
).
Author(s)
N. Frerebeau
See Also
Other plot methods:
as_graph()
,
boxplot()
,
hist()
,
pairs()
,
plot()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Bar plot
barplot(coda)
## Data from Day et al. 2011
data("kommos", package = "folio")
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, groups = 1) # Coerce to compositional data
## Use ceramic types for grouping
barplot(coda, order_columns = TRUE)
## Display only minor elements
minor <- coda[, is_element_minor(coda)]
barplot(minor, order_columns = TRUE)
Combine Two Composition Matrices
Description
Combine Two Composition Matrices
Usage
## S4 method for signature 'CompositionMatrix,CompositionMatrix'
rbind2(x, y)
## S4 method for signature 'GroupedComposition,GroupedComposition'
rbind2(x, y)
Arguments
x , y |
A |
Details
rbind2()
combine by rows.
Value
A CompositionMatrix
objects.
Author(s)
N. Frerebeau
See Also
Other subsetting methods:
subset()
Examples
## Create a data.frame
X <- data.frame(
samples = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
groups = c("X", "X", "X", "X", NA, NA, "Y", "Y", "Y"),
Ca = c(7.72, 7.32, 3.11, 7.19, 7.41, 5, 4.18, 1, 4.51),
Fe = c(6.12, 5.88, 5.12, 6.18, 6.02, 7.14, 5.25, 5.28, 5.72),
Na = c(0.97, 1.59, 1.25, 0.86, 0.76, 0.51, 0.75, 0.52, 0.56)
)
## Coerce to a compositional matrix
Y <- as_composition(X, parts = c("Ca", "Fe", "Na"))
## Split by group
## /!\ Unassigned samples (NA) are discarded ! /!\
(s1 <- split(Y, f = X$groups))
## Better to use grouped matrix
Y <- group(Y, by = X$groups)
(s2 <- group_split(Y))
## Bind by rows
do.call(rbind, s2)
Boxite Mineralogy
Description
Mineral compositions and depths of 25 specimens of boxite.
Usage
boxite
Format
A data.frame
with 5 variables (minerals):
A
Albite (weight percent).
B
Blandite (weight percent).
C
Cornite (weight percent).
D
Daubite (weight percent).
E
Endite (weight percent).
depth
Depth (meter).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
arctic
,
coxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Boxplot of Log-Ratios
Description
Displays box-and-whisker plots of the given (grouped) values.
Usage
## S4 method for signature 'LogRatio'
boxplot(
x,
...,
range = 1.5,
width = NULL,
varwidth = FALSE,
notch = FALSE,
outline = TRUE,
plot = TRUE,
horizontal = FALSE,
xlab = NULL,
ylab = NULL,
main = NULL,
sub = NULL,
ann = graphics::par("ann")
)
## S4 method for signature 'GroupedLogRatio'
boxplot(
x,
...,
range = 1.5,
width = NULL,
varwidth = FALSE,
notch = FALSE,
outline = TRUE,
plot = TRUE,
horizontal = FALSE,
color = NULL,
xlab = NULL,
ylab = NULL,
main = NULL,
sub = NULL,
ann = graphics::par("ann"),
legend = list(x = "topright")
)
Arguments
x |
A |
... |
Further graphical parameters. |
range |
A length-one |
width |
A |
varwidth |
A |
notch |
A |
outline |
A |
plot |
A |
horizontal |
A |
xlab , ylab |
A |
main |
A |
sub |
A |
ann |
A |
color |
A (named) vector of colors (will be mapped to the group names
of |
legend |
A |
Value
boxplot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
Author(s)
N. Frerebeau
See Also
Other plot methods:
as_graph()
,
barplot()
,
hist()
,
pairs()
,
plot()
Examples
## Data from Day et al. 2011
data("kommos", package = "folio")
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, parts = 3:22) # Coerce to compositional data
## Log ratio
clr <- transform_clr(coda)
## Boxplot
boxplot(clr)
## Use ceramic types for grouping
grp <- group(coda, by = kommos$type)
clr <- transform_clr(grp)
boxplot(clr)
Chemical Elements and Oxides
Description
Identify oxides and major, minor and traces elements in a compositional data matrix.
Usage
is_element_major(object, ...)
is_element_minor(object, ...)
is_element_trace(object, ...)
is_oxide(object, ...)
## S4 method for signature 'character'
is_oxide(object)
## S4 method for signature 'CompositionMatrix'
is_oxide(object)
## S4 method for signature 'CompositionMatrix'
is_element_major(object, min = 1/100, max = Inf)
## S4 method for signature 'CompositionMatrix'
is_element_minor(object, min = 0.1/100, max = 1/100)
## S4 method for signature 'CompositionMatrix'
is_element_trace(object, min = -Inf, max = 0.1/100)
Arguments
object |
A |
... |
Currently not used. |
min |
A length-one |
max |
A length-one |
Details
There is no definite classification of what are the major, minor and trace elements are. By default, the following rule of thumb is used:
- major elements
The major elements are those that define the material under study. Major elements usually have concentrations of above 1%.
- minor elements
Minor elements usually have concentrations between 1% and 0.1%
- trace elements
Trace elements usually have concentrations of less than 0.1%.
Value
A logical
vector.
Note
is_oxide()
uses a regular expression (it does not check if elements exist
or if stoichiometry is valid).
Author(s)
N. Frerebeau
Examples
## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, groups = 1) # Use ceramic types for grouping
is_element_major(coda)
is_element_minor(coda)
is_element_trace(coda)
is_oxide(coda)
Closure Operation
Description
Closes compositions to sum to 1.
Usage
closure(x, ...)
## S4 method for signature 'numeric'
closure(x, total = 1, na.rm = TRUE)
## S4 method for signature 'matrix'
closure(x, total = 1, na.rm = TRUE)
Arguments
x |
A |
... |
Currently not used. |
total |
A numeric vector specifying the total amount to which the compositions should be closed (defaults to 1). |
na.rm |
A |
Value
A numeric
vector or matrix (same as x
).
Author(s)
N. Frerebeau
See Also
Other operations in the simplex:
arithmetic
,
perturbation()
,
powering()
,
scalar()
Examples
x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))
## Perturbation
perturbation(x, y)
x + y
## Powering
powering(y, 2)
y * 2
## Scalar product
scalar(x, y)
Compositional Mean of Data Subsets
Description
Splits the data into subsets and computes compositional mean for each.
Usage
condense(x, ...)
## S4 method for signature 'CompositionMatrix'
condense(x, by, ignore_na = FALSE, ignore_zero = TRUE, verbose = FALSE, ...)
## S4 method for signature 'GroupedComposition'
condense(
x,
by = NULL,
ignore_na = FALSE,
ignore_zero = TRUE,
verbose = FALSE,
...
)
Arguments
x |
A |
... |
Currently not used. |
by |
A |
ignore_na |
A |
ignore_zero |
A |
verbose |
A |
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
See Also
Other statistics:
aggregate()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to a compositional matrix
coda <- as_composition(slides, groups = 2)
## Compositional mean by group
condense(coda)
Covariance Matrix
Description
Computes the (centered) log-ratio covariance matrix (see below).
Usage
covariance(x, ...)
## S4 method for signature 'CompositionMatrix'
covariance(x, center = TRUE, method = "pearson")
## S4 method for signature 'ALR'
covariance(x, method = "pearson")
## S4 method for signature 'CLR'
covariance(x, method = "pearson")
Arguments
x |
A |
... |
Currently not used. |
center |
A |
method |
A |
Value
A matrix
.
Methods (by class)
-
covariance(ALR)
: Computes the log-ratio covariance matrix (Aitchison 1986, definition 4.5). -
covariance(CLR)
: Computes the centered log-ratio covariance matrix (Aitchison 1986, definition 4.6).
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
See Also
Other statistics:
aggregate()
,
condense()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Log-ratio covariance matrix
## (Aitchison 1986, definition 4.5)
covariance(coda, center = FALSE)
## Centered log-ratio covariance matrix
## (Aitchison 1986, definition 4.6)
covariance(coda, center = TRUE)
Coxite Mineralogy
Description
Mineral compositions, depths and porosity of 25 specimens of coxite.
Usage
coxite
Format
A data.frame
with 5 variables (minerals):
A
Albite (weight percent).
B
Blandite (weight percent).
C
Cornite (weight percent).
D
Daubite (weight percent).
E
Endite (weight percent).
depth
Depth (meter).
porosity
Porosity (percent).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
arctic
,
boxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Data Description
Description
Describes an object.
Usage
## S4 method for signature 'CompositionMatrix'
describe(x)
## S4 method for signature 'GroupedComposition'
describe(x)
Arguments
x |
A |
Value
describe()
is called for its side-effects. Invisibly returns x
.
Author(s)
N. Frerebeau
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides)
## Quick description
describe(coda)
## Group
coda <- group(coda, by = slides$slide)
describe(coda)
Outlier Detection
Description
Outlier Detection
Usage
detect_outlier(object, reference, ...)
is_outlier(object, ...)
## S4 method for signature 'CompositionMatrix,missing'
detect_outlier(
object,
...,
robust = TRUE,
method = c("mve", "mcd"),
quantile = 0.975
)
## S4 method for signature 'CompositionMatrix,CompositionMatrix'
detect_outlier(
object,
reference,
...,
quantile = 0.975,
robust = TRUE,
method = c("mve", "mcd")
)
## S4 method for signature 'OutlierIndex'
is_outlier(object, robust = TRUE)
Arguments
object |
|
reference |
A |
... |
Further parameters to be passed to |
robust |
A |
method |
A |
quantile |
A length-one |
Details
An outlier can be defined as having a very large Mahalanobis distance from all observations. In this way, a certain proportion of the observations can be identified, e.g. the top 2% of values (i.e. values above the 0.98th percentile of the Chi-2 distribution).
On the one hand, the Mahalanobis distance is likely to be strongly affected by the presence of outliers. Rousseeuw and van Zomeren (1990) thus recommend using robust methods (which are not excessively affected by the presence of outliers).
On the other hand, the choice of the threshold for classifying an observation as an outlier should be discussed. There is no apparent reason why a particular threshold should be applicable to all data sets (Filzmoser, Garrett, and Reimann 2005).
Value
-
detect_outlier()
returns anOutlierIndex
object. -
is_outlier()
returns alogical
vector.
Author(s)
N. Frerebeau
References
Filzmoser, P., Garrett, R. G. & Reimann, C. (2005). Multivariate outlier detection in exploration geochemistry. Computers & Geosciences, 31(5), 579-587. doi:10.1016/j.cageo.2004.11.013.
Filzmoser, P. & Hron, K. (2008). Outlier Detection for Compositional Data Using Robust Methods. Mathematical Geosciences, 40(3), 233-248. doi:10.1007/s11004-007-9141-5.
Filzmoser, P., Hron, K. & Reimann, C. (2012). Interpretation of multivariate outliers for compositional data. Computers & Geosciences, 39, 77-85. doi:10.1016/j.cageo.2011.06.014.
Rousseeuw, P. J. & van Zomeren, B. C. (1990). Unmasking Multivariate Outliers and Leverage Points. Journal of the American Statistical Association, 85(411): 633-639. doi:10.1080/01621459.1990.10474920.
Santos, F. (2020). Modern methods for old data: An overview of some robust methods for outliers detection with applications in osteology. Journal of Archaeological Science: Reports, 32, 102423. doi:10.1016/j.jasrep.2020.102423.
See Also
Other outlier detection methods:
plot_outlier
Examples
## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, parts = 3:17, groups = 1)
## Detect outliers
out <- detect_outlier(coda)
plot(out, type = "dotchart")
plot(out, type = "distance")
## Detect outliers according to CJ
ref <- group_subset(coda, which = "CJ")
out <- detect_outlier(coda, reference = ref, method = "mcd")
plot(out, type = "dotchart")
Distances
Description
Computes the distances between all rows of in x
.
Usage
## S4 method for signature 'CompositionMatrix'
dist(x, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
Arguments
x |
A |
method |
A |
diag |
A |
upper |
A |
p |
An |
Details
Distances are computed on CLR-transformed data.
Value
A stats::dist
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Aitchison distance
## (euclidean distance between CLR-transformed compositions)
d <- dist(coda)
## Cluster dendrogram
h <- hclust(d, method = "ward.D2")
plot(h)
Geometric Mean
Description
Geometric Mean
Usage
gmean(x, trim = 0, ignore_na = FALSE, ignore_zero = TRUE)
Arguments
x |
A |
trim |
A length-one |
ignore_na |
A |
ignore_zero |
A |
Value
A numeric
vector.
Group by One or More Variables
Description
Define or remove the (reference) groups to which the observations belong.
Usage
group(object, ...)
ungroup(object, ...)
## S4 method for signature 'CompositionMatrix'
group(object, by, verbose = getOption("nexus.verbose"), ...)
## S4 method for signature 'GroupedComposition'
group(object, by, add = FALSE, verbose = getOption("nexus.verbose"), ...)
## S4 method for signature 'GroupedComposition'
ungroup(object)
## S4 method for signature 'GroupedLR'
ungroup(object)
## S4 method for signature 'GroupedCLR'
ungroup(object)
## S4 method for signature 'GroupedALR'
ungroup(object)
## S4 method for signature 'GroupedILR'
ungroup(object)
## S4 method for signature 'GroupedPLR'
ungroup(object)
Arguments
object |
An R object (typically, a |
... |
Further parameters to be passed to internal methods. |
by |
A possible value for the groups of |
verbose |
A |
add |
A |
Details
Missing values (NA
) can be used to specify that a sample does not belong
to any group.
Value
-
group()
returns a grouped object of the same sort asobject
. -
ungroup()
returns an ungrouped object of the same sort asobject
.
Author(s)
N. Frerebeau
See Also
Other grouping methods:
group_names()
,
group_split()
,
group_subset()
,
is_assigned()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides, groups = 2)
## Grouping metadata
group_levels(coda)
group_names(coda)
group_indices(coda)
group_rows(coda)
group_n(coda)
group_size(coda)
Grouping Metadata
Description
Retrieve the (reference) groups to which the observations belong.
Usage
group_names(object)
group_levels(object)
group_factor(object, ...)
group_rows(object)
group_n(object)
group_size(object)
group_indices(object)
## S4 method for signature 'ReferenceGroups'
group_levels(object)
## S4 method for signature 'ReferenceGroups'
group_names(object)
## S4 method for signature 'ReferenceGroups'
group_factor(object, exclude = NA)
## S4 method for signature 'ReferenceGroups'
group_indices(object)
## S4 method for signature 'ReferenceGroups'
group_rows(object)
## S4 method for signature 'ReferenceGroups'
group_n(object)
## S4 method for signature 'ReferenceGroups'
group_size(object)
Arguments
object |
A grouped R object. |
... |
Currently not used. |
exclude |
A |
Value
-
group_levels()
returns acharacter
vector giving the group names. -
group_size()
returns aninteger
vector giving the size of each group. -
group_n()
gives the total number of groups. -
group_names()
returns acharacter
vector giving the name of the group that each observation belongs to. -
group_factor()
returns afactor
vector giving the name of the group that each observation belongs to. -
group_indices()
returns aninteger
vector giving the group that each value belongs to. -
group_rows()
returns alist
ofinteger
vectors giving the observation that each group contains.
Author(s)
N. Frerebeau
See Also
Other grouping methods:
group()
,
group_split()
,
group_subset()
,
is_assigned()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides, groups = 2)
## Grouping metadata
group_levels(coda)
group_names(coda)
group_indices(coda)
group_rows(coda)
group_n(coda)
group_size(coda)
Divide into Groups
Description
Divides a compositional matrix by groups.
Usage
group_split(object, ...)
## S4 method for signature 'CompositionMatrix'
split(x, f, drop = FALSE, ...)
## S4 method for signature 'LogRatio'
split(x, f, drop = FALSE, ...)
## S4 method for signature 'GroupedComposition'
group_split(object, ...)
## S4 method for signature 'GroupedLogRatio'
group_split(object, ...)
Arguments
object , x |
A |
... |
Currently not used. |
f |
A |
drop |
A |
Value
A list
of CompositionMatrix
objects.
Author(s)
N. Frerebeau
See Also
Other grouping methods:
group()
,
group_names()
,
group_subset()
,
is_assigned()
Examples
## Create a data.frame
X <- data.frame(
samples = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
groups = c("X", "X", "X", "X", NA, NA, "Y", "Y", "Y"),
Ca = c(7.72, 7.32, 3.11, 7.19, 7.41, 5, 4.18, 1, 4.51),
Fe = c(6.12, 5.88, 5.12, 6.18, 6.02, 7.14, 5.25, 5.28, 5.72),
Na = c(0.97, 1.59, 1.25, 0.86, 0.76, 0.51, 0.75, 0.52, 0.56)
)
## Coerce to a compositional matrix
Y <- as_composition(X, parts = c("Ca", "Fe", "Na"))
## Split by group
## /!\ Unassigned samples (NA) are discarded ! /!\
(s1 <- split(Y, f = X$groups))
## Better to use grouped matrix
Y <- group(Y, by = X$groups)
(s2 <- group_split(Y))
## Bind by rows
do.call(rbind, s2)
Group-based Subset
Description
Group-based Subset
Usage
group_subset(object, ...)
## S4 method for signature 'GroupedComposition'
group_subset(object, which)
## S4 method for signature 'GroupedLogRatio'
group_subset(object, which)
Arguments
object |
A |
... |
Currently not used. |
which |
A |
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
See Also
Other grouping methods:
group()
,
group_names()
,
group_split()
,
is_assigned()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides, groups = 2)
## Grouping metadata
group_levels(coda)
group_names(coda)
group_indices(coda)
group_rows(coda)
group_n(coda)
group_size(coda)
Histogram of Compositional Data
Description
Produces an histogram of univariate ILR data (see Filzmoser et al., 2009).
Usage
## S4 method for signature 'CompositionMatrix'
hist(
x,
...,
select = 1,
breaks = "Sturges",
freq = FALSE,
labels = FALSE,
main = NULL,
sub = NULL,
ann = graphics::par("ann"),
axes = TRUE,
frame.plot = axes
)
Arguments
x |
A |
... |
Further graphical parameters. |
select |
A length-one |
breaks |
An object specifying how to compute the breakpoints
(see |
freq |
A |
labels |
A |
main |
A |
sub |
A |
ann |
A |
axes |
A |
frame.plot |
A |
Value
hist()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
Author(s)
N. Frerebeau
References
Filzmoser, P., Hron, K. & Reimann, C. (2009). Univariate Statistical Analysis of Environmental (Compositional) Data: Problems and Possibilities. Science of The Total Environment, 407(23): 6100-6108. doi:10.1016/j.scitotenv.2009.08.008.
See Also
Other plot methods:
as_graph()
,
barplot()
,
boxplot()
,
pairs()
,
plot()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Boxplot plot
hist(coda, select = "A")
hist(coda, select = "B")
Hongite Mineralogy
Description
Mineral compositions of 25 specimens of hongite.
Usage
hongite
Format
A data.frame
with 5 variables (minerals):
A
Albite (weight percent).
B
Blandite (weight percent).
C
Cornite (weight percent).
D
Daubite (weight percent).
E
Endite (weight percent).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
arctic
,
boxite
,
coxite
,
kongite
,
lava
,
predator
,
slides
Grouped Data
Description
Retrieve the (reference) groups to which the observations belong.
Usage
is_assigned(object)
any_assigned(object)
all_assigned(object)
## S4 method for signature 'ReferenceGroups'
is_assigned(object)
## S4 method for signature 'ReferenceGroups'
any_assigned(object)
## S4 method for signature 'ReferenceGroups'
all_assigned(object)
Arguments
object |
A grouped R object. |
Value
-
is_assigned()
returns alogical
vector specifying whether or not an observation belongs to a group. -
any_assigned()
returns anlogical
scalar specifying if any observation belongs to a group. -
all_assigned()
returns anlogical
scalar specifying if all observations belong to a group.
Author(s)
N. Frerebeau
See Also
Other grouping methods:
group()
,
group_names()
,
group_split()
,
group_subset()
Examples
## Data from Aitchison 1986
data("slides")
## Coerce to compositional data
coda <- as_composition(slides, groups = 2)
## Grouping metadata
group_levels(coda)
group_names(coda)
group_indices(coda)
group_rows(coda)
group_n(coda)
group_size(coda)
Kongite Mineralogy
Description
Mineral compositions of 25 specimens of kongite.
Usage
kongite
Format
A data.frame
with 5 variables (minerals):
A
Albite (weight percent).
B
Blandite (weight percent).
C
Cornite (weight percent).
D
Daubite (weight percent).
E
Endite (weight percent).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
lava
,
predator
,
slides
Labels
Description
Find a suitable set of labels from an object.
Usage
## S4 method for signature 'CompositionMatrix'
labels(object, ...)
## S4 method for signature 'LogRatio'
labels(object, ...)
Arguments
object |
An object from which to get the labels. |
... |
Currently not used. |
Author(s)
N. Frerebeau
See Also
Other mutators:
as.data.frame()
,
totals()
,
weights()
Skye Lavas Compositions
Description
Chemical compositions of 23 aphyric Skye lavas.
Usage
lava
Format
A data.frame
with 3 variables (percent):
A
Na2O + K2O.
F
Fe2O3.
M
MgO.
Source
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall. doi:10.1007/978-94-009-4109-0.
See Also
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
predator
,
slides
Mahalanobis Distance
Description
Computes the squared Mahalanobis distance of all rows in x
.
Usage
## S4 method for signature 'CompositionMatrix'
mahalanobis(x, center, cov, ..., robust = TRUE, method = c("mve", "mcd"))
## S4 method for signature 'ILR'
mahalanobis(x, center, cov, ..., robust = TRUE, method = c("mve", "mcd"))
Arguments
x |
A |
center |
A |
cov |
A |
... |
Extra parameters to be passed to |
robust |
A |
method |
A |
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Mahalanobis distance
mahalanobis(coda)
Marginal Compositions
Description
Marginal Compositions
Usage
margin(x, ...)
## S4 method for signature 'CompositionMatrix'
margin(x, parts = c(1, 2), name = "*")
Arguments
x |
A |
... |
Currently not used. |
parts |
An |
name |
A |
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Marginal compositions
mar <- margin(coda, parts = c("B", "D"))
head(mar)
Compositional Mean
Description
Compositional Mean
Usage
## S4 method for signature 'CompositionMatrix'
mean(x, ..., ignore_na = FALSE, ignore_zero = TRUE)
Arguments
x |
A |
... |
Currently not used. |
ignore_na |
A |
ignore_zero |
A |
Details
Closed vector of the columns geometric means.
Value
A numeric
vector.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Mean
mean(coda)
## Quantile
quantile(coda)
Missing Values Policy
Description
Missing Values Policy
Details
Compositional data are quantitative positive descriptions of the parts of some whole, carrying relative, rather than absolute, information (ie. only relative changes are relevant; Aitchison 1986).
Basically, three situations can be outlined regarding missing values in compositions:
Unobserved quantities.
Amounts observed, but which happen to be below the detection limit (thus interpreted as small unknown values).
Absolutely zero quantities.
These situations can be represented in several ways:
The presence of zeros.
The presence of missing values (
NA
).
When creating a CompositionMatrix
object, the presence of zero
and NA
values is allowed: this makes it possible to explore and
visualize the data while preserving the missing structure. However, the
user must deal with these missing values before proceeding further (e.g.
by removing incomplete cases or replacing the values concerned): log-ratio
transformations cannot be computed in the presence of zeros or missing
values.
Note
If you need more advanced features (e.g. imputation of missing values), you should consider the compositions or robCompositions package.
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other imputation methods:
replace_NA()
,
replace_zero()
Mixed-Mode Analysis
Description
Mixes chemical and petrographic matrices.
Usage
mix(x, y, ...)
## S4 method for signature 'matrix,matrix'
mix(x, y, lambda = 1, ...)
## S4 method for signature 'dist,dist'
mix(x, y, mu = 0.5)
Arguments
x |
A |
y |
A |
... |
Extra parameters to be passed to |
lambda |
A length-one |
mu |
A length-one |
Value
A stats::dist object.
Methods (by class)
-
mix(x = matrix, y = matrix)
: First approach of mixed-mode analysis. -
mix(x = dist, y = dist)
: Second approach of mixed-mode analysis.
Note
Experimental.
Author(s)
N. Frerebeau
References
Baxter, M. J., Beardah, C. C., Papageorgiou, I., Cau, M. A., Day, P. M. & Kilikoglou, V. (2008). On Statistical Approaches to the Study of Ceramic Artefacts Using Geochemical and Petrographic Data. Archaeometry, 50(1): 142-157. doi:10.1111/j.1475-4754.2007.00359.x.
Beardah, C. C., Baxter, M. J., Papageorgiou, I. & Cau, M. A. (2003). "Mixed-Mode" Approaches to the Grouping of Ceramic Artefacts Using S-Plus. In M. Doerr and A. Sarris, The Digital Heritage of Archaeology, p. 261-266. Athens: Archive of Monuments and Publications, Hellenic Ministry of Culture.
Gower, J. C. (1971). A general coefficient of similarity and some of its properties. Biometrics, 27(4):857-874. doi:10.2307/2528823.
Examples
## Can Sora datasets
## Data from Cau (1999) and Cau et al. (2007)
path_chem <- system.file("extdata", "cansora_chemistry.csv", package = "nexus")
chemistry <- read.csv(path_chem, header = TRUE, row.names = 1)
path_petro <- system.file("extdata", "cansora_petrography.csv", package = "nexus")
petrography <- read.csv(path_petro, header = TRUE, row.names = 1)
## Prepare chemical data
major <- c("Fe2O3", "Al2O3", "MnO", "P2O5", "TiO2",
"MgO", "CaO", "Na2O", "K2O", "SiO2")
chem <- chemistry[-1, major]
## Prepare petrographic data
petro <- petrography[-c(7, 8), -1]
petro <- cdt(petro) # Get the complete disjunctive table
## First approach
mix1 <- mix(as.matrix(chem), as.matrix(petro), lambda = 2)
mds1 <- pcoa(mix1) # Multi-Dimensional Scaling
plot(mds1)
Plot Compositional Data
Description
Displays a matrix of ternary plots.
Usage
## S4 method for signature 'CompositionMatrix'
pairs(x, margin = NULL, ...)
## S4 method for signature 'GroupedComposition'
pairs(x, ..., margin = NULL, color = NULL, symbol = NULL)
Arguments
x |
A |
margin |
A |
... |
Further graphical parameters. |
color |
A (named) vector of colors (will be mapped to the group names
of |
symbol |
A (named) vector of colors (will be mapped to the group names
of |
Value
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
Author(s)
N. Frerebeau
See Also
isopleuros::ternary_pairs()
, isopleuros::ternary_plot()
Other plot methods:
as_graph()
,
barplot()
,
boxplot()
,
hist()
,
plot()
Examples
## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, parts = 3:8, groups = 1)
## Use ceramic types for grouping
pairs(coda)
## Center and scale ternary plots
pairs(coda, by = NULL, center = TRUE, scale = TRUE)
Principal Components Analysis
Description
Computes a principal components analysis based on the singular value decomposition.
Usage
## S4 method for signature 'CompositionMatrix'
pca(
object,
center = TRUE,
scale = FALSE,
rank = NULL,
sup_row = NULL,
sup_col = NULL,
weight_row = NULL,
weight_col = NULL
)
## S4 method for signature 'LogRatio'
pca(
object,
center = TRUE,
scale = FALSE,
rank = NULL,
sup_row = NULL,
sup_col = NULL,
weight_row = NULL,
weight_col = NULL
)
Arguments
object |
A |
center |
A |
scale |
A |
rank |
An |
sup_row |
A |
sup_col |
A |
weight_row |
A |
weight_col |
A |
Value
A dimensio::PCA
object. See dimensio::pca()
for details.
Methods (by class)
-
pca(CompositionMatrix)
: PCA of centered log-ratio, i.e. log-ratio analysis (LRA).
Author(s)
N. Frerebeau
References
Aitchison, J. and Greenacre, M. (2002). Biplots of compositional data. Journal of the Royal Statistical Society: Series C (Applied Statistics), 51: 375-392. doi:10.1111/1467-9876.00275.
Filzmoser, P., Hron, K. and Reimann, C. (2009). Principal component analysis for compositional data with outliers. Environmetrics, 20: 621-632. doi:10.1002/env.966.
See Also
dimensio::pca()
, dimensio::biplot()
, dimensio::screeplot()
,
dimensio::viz_individuals()
, dimensio::viz_variables()
Examples
## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, groups = 1) # Use ceramic types for grouping
## Log-Ratio Analysis
X <- pca(coda)
## Biplot
biplot(X)
## Explore results
viz_individuals(X, extra_quali = group_names(coda))
viz_variables(X)
Perturbation Operation
Description
Perturbation of two compositions.
Usage
perturbation(x, y, ...)
## S4 method for signature 'numeric,numeric'
perturbation(x, y)
## S4 method for signature 'CompositionMatrix,numeric'
perturbation(x, y)
## S4 method for signature 'CompositionMatrix,matrix'
perturbation(x, y)
Arguments
x , y |
A |
... |
Currently not used. |
Details
In compositional geometry, perturbation plays the role of sum (translation). It is the closed component-wise product of two compositions.
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other operations in the simplex:
arithmetic
,
closure()
,
powering()
,
scalar()
Examples
x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))
## Perturbation
perturbation(x, y)
x + y
## Powering
powering(y, 2)
y * 2
## Scalar product
scalar(x, y)
Proportionality Index of Parts (PIP)
Description
Computes an index of association between parts.
Usage
pip(x, ...)
## S4 method for signature 'CompositionMatrix'
pip(x)
Arguments
x |
A |
... |
Currently not used. |
Details
The proportionality index of parts (PIP) is based on the
variation matrix, but maintains the range of values whithin
(0,1)
.
Value
A matrix
.
Author(s)
N. Frerebeau
References
Egozcue, J. J.. & Pawlowsky-Glahn, V. (2023). Subcompositional Coherence and and a Novel Proportionality Index of Parts. SORT, 47(2): 229-244. doi:10.57645/20.8080.02.7.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Variation matrix
## (Aitchison 1986, definition 4.4)
(varia <- variation(coda))
## Cluster dendrogram
d <- as.dist(varia)
h <- hclust(d, method = "ward.D2")
plot(h)
## Heatmap
stats::heatmap(
varia,
distfun = stats::as.dist,
hclustfun = function(x) stats::hclust(x, method = "ward.D2"),
symm = TRUE,
scale = "none"
)
Plot Log-Ratios
Description
Displays a scatter plot.
Usage
## S4 method for signature 'LogRatio,missing'
plot(
x,
...,
jitter_factor = 1,
jitter_amount = NULL,
xlab = NULL,
ylab = NULL,
main = NULL,
sub = NULL,
ann = graphics::par("ann"),
axes = TRUE,
frame.plot = axes
)
## S4 method for signature 'GroupedLogRatio,missing'
plot(
x,
...,
jitter_factor = 1,
jitter_amount = NULL,
color = NULL,
symbol = NULL,
xlab = NULL,
ylab = NULL,
main = NULL,
sub = NULL,
ann = graphics::par("ann"),
axes = TRUE,
frame.plot = axes,
legend = list(x = "topright")
)
Arguments
x |
A |
... |
Further graphical parameters. |
jitter_factor , jitter_amount |
A length-one |
xlab , ylab |
A |
main |
A |
sub |
A |
ann |
A |
axes |
A |
frame.plot |
A |
color |
A (named) vector of colors (will be mapped to the group names
of |
symbol |
A (named) vector of colors (will be mapped to the group names
of |
legend |
A |
Value
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
Author(s)
N. Frerebeau
See Also
Other plot methods:
as_graph()
,
barplot()
,
boxplot()
,
hist()
,
pairs()
Examples
## Data from Day et al. 2011
data("kommos", package = "folio")
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, parts = 3:22) # Coerce to compositional data
## Log ratio
clr <- transform_clr(coda)
## Boxplot
plot(clr)
## Use ceramic types for grouping
grp <- group(coda, by = kommos$type)
clr <- transform_clr(grp)
plot(clr)
Plot Outliers
Description
Plot Outliers
Usage
## S4 method for signature 'OutlierIndex,missing'
plot(
x,
...,
type = c("dotchart", "distance"),
robust = TRUE,
symbols = c(16, 1, 3),
xlim = NULL,
ylim = NULL,
xlab = NULL,
ylab = NULL,
main = NULL,
sub = NULL,
ann = graphics::par("ann"),
axes = TRUE,
frame.plot = axes,
panel.first = NULL,
panel.last = NULL,
legend = list(x = "topleft")
)
Arguments
x |
An |
... |
Further parameters to be passed to |
type |
A |
robust |
A |
symbols |
A lenth-three vector of symbol specification for non-outliers and outliers (resp.). |
xlim |
A length-two |
ylim |
A length-two |
xlab , ylab |
A |
main |
A |
sub |
A |
ann |
A |
axes |
A |
frame.plot |
A |
panel.first |
An an |
panel.last |
An |
legend |
A |
Value
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
Author(s)
N. Frerebeau
References
Filzmoser, P., Garrett, R. G. & Reimann, C. (2005). Multivariate outlier detection in exploration geochemistry. Computers & Geosciences, 31(5), 579-587. doi:10.1016/j.cageo.2004.11.013.
Filzmoser, P. & Hron, K. (2008). Outlier Detection for Compositional Data Using Robust Methods. Mathematical Geosciences, 40(3), 233-248. doi:10.1007/s11004-007-9141-5.
Filzmoser, P., Hron, K. & Reimann, C. (2012). Interpretation of multivariate outliers for compositional data. Computers & Geosciences, 39, 77-85. doi:10.1016/j.cageo.2011.06.014.
See Also
Other outlier detection methods:
detect_outlier()
Examples
## Data from Day et al. 2011
data("kommos", package = "folio") # Coerce to compositional data
kommos <- remove_NA(kommos, margin = 1) # Remove cases with missing values
coda <- as_composition(kommos, parts = 3:17, groups = 1)
## Detect outliers
out <- detect_outlier(coda)
plot(out, type = "dotchart")
plot(out, type = "distance")
## Detect outliers according to CJ
ref <- group_subset(coda, which = "CJ")
out <- detect_outlier(coda, reference = ref, method = "mcd")
plot(out, type = "dotchart")
Powering Operation
Description
Perturbation of two compositions.
Usage
powering(x, a, ...)
## S4 method for signature 'numeric,numeric'
powering(x, a)
## S4 method for signature 'CompositionMatrix,numeric'
powering(x, a)
Arguments
x |
A |
a |
A |
... |
Currently not used. |
Details
In compositional geometry, powering replaces the product of a vector by a scalar (scaling) and is defined as the closed powering of the components by a given scalar.
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other operations in the simplex:
arithmetic
,
closure()
,
perturbation()
,
scalar()
Examples
x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))
## Perturbation
perturbation(x, y)
x + y
## Powering
powering(y, 2)
y * 2
## Scalar product
scalar(x, y)
Predator-Prey Compositions
Description
Predator-prey compositions at 25 different sites.
Usage
predator
Format
A data.frame
with 3 variables (proportions):
P
Predator.
Q
Prey of species Q.
R
Prey of species R.
Source
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall. doi:10.1007/978-94-009-4109-0.
See Also
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
slides
Sample Quantiles
Description
Sample Quantiles
Usage
## S4 method for signature 'CompositionMatrix'
quantile(x, ..., probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE)
Arguments
x |
A |
... |
Currently not used. |
probs |
A |
na.rm |
A |
names |
A |
Value
A numeric
matrix.
Author(s)
N. Frerebeau
References
Filzmoser, P., Hron, K. & Reimann, C. (2009). Univariate Statistical Analysis of Environmental (Compositional) Data: Problems and Possibilities. Science of The Total Environment, 407(23): 6100-6108. doi:10.1016/j.scitotenv.2009.08.008.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
scale()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Mean
mean(coda)
## Quantile
quantile(coda)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- arkhe
- khroma
color
,palette_color_continuous
,palette_color_discrete
,palette_color_picker
,palette_line
,palette_shape
,palette_size_diverging
,palette_size_sequential
Missing Values Replacement
Description
Multiplicative replacement of missing values.
Usage
## S4 method for signature 'CompositionMatrix'
replace_NA(x, value)
Arguments
x |
A |
value |
A |
Value
An CompositionMatrix
object, where all missing values have been
replaced.
Author(s)
N. Frerebeau
References
Martín-Fernández, J. A., Barceló-Vidal, C. & Pawlowsky-Glahn, V. (2003). Dealing with Zeros and Missing Values in Compositional Data Sets Using Nonparametric Imputation. Mathematical Geology, 35(3): 253-278. doi:10.1023/A:1023866030544.
See Also
Other imputation methods:
missing
,
replace_zero()
Examples
## Data from Martín-Fernández et al. 2003
X <- data.frame(
X1 = c(0.0000, 0.1304, 0.1963),
X2 = c(0.1250, 0.3151, NA),
X3 = c(0.1237, NA, NA),
X4 = c(0.7253, 0.2002, 0.0819),
X5 = c(0.0260, 0.3543, 0.0114)
)
## Coerce to a compositional matrix
Y <- as_composition(X)
## Replace zeros
Z <- replace_NA(Y, value = 0.2)
Z
Zero-Replacement
Description
Multiplicative replacement of zeros.
Usage
## S4 method for signature 'CompositionMatrix'
replace_zero(x, value, delta = 2/3)
Arguments
x |
A |
value |
A |
delta |
A |
Value
An CompositionMatrix
object, where all zero values have been
replaced.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Martín-Fernández, J. A., Barceló-Vidal, C. & Pawlowsky-Glahn, V. (2003). Dealing with Zeros and Missing Values in Compositional Data Sets Using Nonparametric Imputation. Mathematical Geology, 35(3): 253-278. doi:10.1023/A:1023866030544.
See Also
Other imputation methods:
missing
,
replace_NA()
Examples
## Data from Martín-Fernández et al. 2003
X <- data.frame(
X1 = c(0.0000, 0.1304, 0.1963),
X2 = c(0.1250, 0.3151, NA),
X3 = c(0.1237, NA, NA),
X4 = c(0.7253, 0.2002, 0.0819),
X5 = c(0.0260, 0.3543, 0.0114)
)
## Coerce to a compositional matrix
Y <- as_composition(X)
## Replace zeros
Z <- replace_zero(Y, value = 0.02, delta = 2/3)
Z
Scalar Product
Description
Computes the Aitchison scalar product of two compositions.
Usage
scalar(x, y, ...)
## S4 method for signature 'numeric,numeric'
scalar(x, y)
## S4 method for signature 'CompositionMatrix,CompositionMatrix'
scalar(x, y)
Arguments
x , y |
A |
... |
Currently not used. |
Value
A numeric
vector.
Author(s)
N. Frerebeau
See Also
Other operations in the simplex:
arithmetic
,
closure()
,
perturbation()
,
powering()
Examples
x <- as_composition(c(1, 2, 3))
y <- as_composition(c(1, 2, 1))
## Perturbation
perturbation(x, y)
x + y
## Powering
powering(y, 2)
y * 2
## Scalar product
scalar(x, y)
Scaling and Centering of Compositional Data
Description
Scaling and Centering of Compositional Data
Usage
## S4 method for signature 'CompositionMatrix'
scale(x, center = TRUE, scale = TRUE)
Arguments
x |
A |
center |
A |
scale |
A |
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Boogaart, K. G. van den & Tolosana-Delgado, R. (2013). Analyzing Compositional Data with R. Berlin Heidelberg: Springer-Verlag. doi:10.1007/978-3-642-36809-7.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
variance()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Center and scale
scaled <- scale(coda, center = TRUE, scale = TRUE)
mean(scaled)
head(scaled)
Thin Sections Compositions
Description
Mineral compositions of five slides as reported by five analysts.
Usage
slides
Format
A data.frame
with 9 variables:
analyst
Analyst number.
slide
Slide number.
quartz
Quartz (percent).
microcline
Microcline (percent).
plagioclass
Plagioclass (percent).
biotite
Biotite (percent).
muscovite
Muscovite (percent).
opaques
Opaque minerals (percent).
nonopaques
Non-opaque minerals (percent).
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
See Also
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
predator
Extract or Replace Parts of an Object
Description
Operators acting on objects to extract or replace parts.
Usage
## S4 method for signature 'CompositionMatrix,missing,missing,missing'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,missing,missing,logical'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,index,missing,missing'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,index,missing,logical'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,missing,index,missing'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,missing,index,logical'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,index,index,missing'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'CompositionMatrix,index,index,logical'
x[i, j, ..., drop = TRUE]
## S4 replacement method for signature 'CompositionMatrix'
x[i, j, ...] <- value
## S4 replacement method for signature 'CompositionMatrix'
x[[i, j, ...]] <- value
Arguments
x |
An object from which to extract element(s) or in which to replace element(s). |
i , j |
Indices specifying elements to extract or replace. Indices are
|
... |
Currently not used. |
drop |
A |
value |
A possible value for the element(s) of |
Value
A subsetted object of the same sort as x
.
Author(s)
N. Frerebeau
See Also
Other subsetting methods:
bind
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
head(coda)
## Subset
coda[[1, 1]] # Get the first value
coda[1] # Get the first value
coda[, ] # Get all values
coda[1, ] # Get the first row
## Subcomposition
subcoda <- coda[, 1:3] # Get the first three column
head(subcoda)
Matrix Transpose
Description
Matrix Transpose
Usage
## S4 method for signature 'CompositionMatrix'
t(x)
## S4 method for signature 'LogRatio'
t(x)
Arguments
x |
A |
Value
A matrix
, with dim and dimnames constructed appropriately from those of x
.
Note
Implemented only to ensure that t()
always returns a base matrix
.
Author(s)
N. Frerebeau
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
head(coda)
## Subset
coda[[1, 1]] # Get the first value
coda[1] # Get the first value
coda[, ] # Get all values
coda[1, ] # Get the first row
## Subcomposition
subcoda <- coda[, 1:3] # Get the first three column
head(subcoda)
Row Sums
Description
Retrieves or defines the row sums (before closure).
Usage
totals(object)
totals(object) <- value
## S4 method for signature 'CompositionMatrix'
totals(object)
## S4 method for signature 'LogRatio'
totals(object)
## S4 replacement method for signature 'CompositionMatrix'
totals(object) <- value
Arguments
object |
An object from which to get or set |
value |
A possible value for the |
Value
-
totals() <- value
returns an object of the same sort asobject
with the new row sums assigned. -
totals()
returns the row sums ofobject
.
Author(s)
N. Frerebeau
See Also
Other mutators:
as.data.frame()
,
labels()
,
weights()
Examples
## Create a count matrix
A1 <- matrix(data = sample(1:100, 100, TRUE), nrow = 20)
## Coerce to compositions
B <- as_composition(A1)
## Row sums are internally stored before coercing to relative frequencies
totals(B)
## This allows to restore the source data
A2 <- as_amounts(B)
## Coerce to a data.frame
X <- as.data.frame(B)
head(X)
Additive Log-Ratios (ALR)
Description
Computes ALR transformation.
Usage
transform_alr(object, ...)
## S4 method for signature 'CompositionMatrix'
transform_alr(object, j = ncol(object), weights = FALSE)
## S4 method for signature 'GroupedComposition'
transform_alr(object, j = ncol(object), weights = FALSE)
## S4 method for signature 'CLR'
transform_alr(object, j = ncol(object))
## S4 method for signature 'GroupedCLR'
transform_alr(object, j = ncol(object), weights = FALSE)
Arguments
object |
A |
... |
Currently not used. |
j |
An |
weights |
A |
Details
The ALR transformation is the logratio of a pair of parts with respect to a fixed part.
Value
An ALR
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Greenacre, M. J. (2021). Compositional Data Analysis. Annual Review of Statistics and Its Application, 8(1): 271-299. doi:10.1146/annurev-statistics-042720-124436.
See Also
Other log-ratio transformations:
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Additive log-ratio
alr <- transform_alr(coda)
## Inverse transformation
inv_alr <- transform_inverse(alr)
all.equal(coda, inv_alr)
Centered Log-Ratios (CLR)
Description
Computes CLR transformation.
Usage
transform_clr(object, ...)
## S4 method for signature 'CompositionMatrix'
transform_clr(object, weights = FALSE)
## S4 method for signature 'GroupedComposition'
transform_clr(object, weights = FALSE)
## S4 method for signature 'ALR'
transform_clr(object)
## S4 method for signature 'GroupedALR'
transform_clr(object)
Arguments
object |
A |
... |
Currently not used. |
weights |
A |
Details
The CLR transformation computes the log of each part relative to the geometric mean of all parts.
Value
A CLR
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Greenacre, M. J. (2021). Compositional Data Analysis. Annual Review of Statistics and Its Application, 8(1): 271-299. doi:10.1146/annurev-statistics-042720-124436.
See Also
Other log-ratio transformations:
transform_alr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Centered log-ratio
clr <- transform_clr(coda)
## Inverse transformation
inv_clr <- transform_inverse(clr)
all.equal(coda, inv_clr)
Isometric Log-Ratios (ILR)
Description
Computes ILR transformations.
Usage
transform_ilr(object, ...)
## S4 method for signature 'CompositionMatrix'
transform_ilr(object)
## S4 method for signature 'GroupedComposition'
transform_ilr(object)
## S4 method for signature 'CLR'
transform_ilr(object)
## S4 method for signature 'GroupedCLR'
transform_ilr(object)
## S4 method for signature 'ALR'
transform_ilr(object)
## S4 method for signature 'GroupedALR'
transform_ilr(object)
Arguments
object |
A |
... |
Currently not used. |
Details
The ILR transformation provides the coordinates of any composition with
respect to a given orthonormal basis. transform_ilr()
uses the orthonormal
basis (Helmert matrix) originally defined by Egozcue et al. (2003).
Value
An ILR
object.
Author(s)
N. Frerebeau
References
Egozcue, J. J., Pawlowsky-Glahn, V., Mateu-Figueras, G. & Barceló-Vidal, C. (2003). Isometric Logratio Transformations for Compositional Data Analysis. Mathematical Geology, 35(3), 279-300. doi:10.1023/A:1023818214614.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Greenacre, M. J. (2021). Compositional Data Analysis. Annual Review of Statistics and Its Application, 8(1): 271-299. doi:10.1146/annurev-statistics-042720-124436.
See Also
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Isometric log-ratio
ilr <- transform_ilr(coda)
plr <- transform_plr(coda)
## Inverse transformation
inv_ilr <- transform_inverse(ilr)
all.equal(coda, inv_ilr)
inv_plr <- transform_inverse(plr)
all.equal(coda, inv_plr)
Inverse Log-Ratio Transformation
Description
Computes inverse log-ratio transformations.
Usage
transform_inverse(object, origin, ...)
## S4 method for signature 'CLR,missing'
transform_inverse(object)
## S4 method for signature 'GroupedCLR,missing'
transform_inverse(object)
## S4 method for signature 'ALR,missing'
transform_inverse(object)
## S4 method for signature 'GroupedALR,missing'
transform_inverse(object)
## S4 method for signature 'ILR,missing'
transform_inverse(object)
## S4 method for signature 'GroupedILR,missing'
transform_inverse(object)
## S4 method for signature 'matrix,ILR'
transform_inverse(object, origin)
Arguments
object |
A |
origin |
A |
... |
Currently not used. |
Value
A CompositionMatrix
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Egozcue, J. J., Pawlowsky-Glahn, V., Mateu-Figueras, G. & Barceló-Vidal, C. (2003). Isometric Logratio Transformations for Compositional Data Analysis. Mathematical Geology, 35(3), 279-300. doi:10.1023/A:1023818214614.
Fišerová, E. & Hron, K. (2011). On the Interpretation of Orthonormal Coordinates for Compositional Data. Mathematical Geosciences, 43(4), 455‑468. doi:10.1007/s11004-011-9333-x.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
See Also
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_lr()
,
transform_plr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Centered log-ratio
clr <- transform_clr(coda)
## Inverse transformation
inv_clr <- transform_inverse(clr)
all.equal(coda, inv_clr)
Pairwise Log-Ratios (LR)
Description
Computes all pairwise log-ratio transformation.
Usage
transform_lr(object, ...)
## S4 method for signature 'CompositionMatrix'
transform_lr(object, weights = FALSE)
## S4 method for signature 'GroupedComposition'
transform_lr(object, weights = FALSE)
Arguments
object |
A |
... |
Currently not used. |
weights |
A |
Value
A LR
object.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Greenacre, M. J. (2021). Compositional Data Analysis. Annual Review of Statistics and Its Application, 8(1): 271-299. doi:10.1146/annurev-statistics-042720-124436.
See Also
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_plr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Pairwise log-ratio
lr <- transform_lr(coda)
Pivot Log-Ratios (PLR)
Description
Computes PLR transformations.
Usage
transform_plr(object, ...)
## S4 method for signature 'CompositionMatrix'
transform_plr(object, pivot = 1)
## S4 method for signature 'GroupedComposition'
transform_plr(object, pivot = 1)
Arguments
object |
A |
... |
Currently not used. |
pivot |
An |
Value
A PLR
object.
Author(s)
N. Frerebeau
References
Fišerová, E. & Hron, K. (2011). On the Interpretation of Orthonormal Coordinates for Compositional Data. Mathematical Geosciences, 43(4), 455‑468. doi:10.1007/s11004-011-9333-x.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Greenacre, M. J. (2021). Compositional Data Analysis. Annual Review of Statistics and Its Application, 8(1): 271-299. doi:10.1146/annurev-statistics-042720-124436.
Hron, K., Filzmoser, P., de Caritat, P., Fišerová, E. & Gardlo, A. (2017). Weighted Pivot Coordinates for Compositional Data and Their Application to Geochemical Mapping. Mathematical Geosciences, 49(6), 797-814. doi:10.1007/s11004-017-9684-z.
See Also
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Isometric log-ratio
ilr <- transform_ilr(coda)
plr <- transform_plr(coda)
## Inverse transformation
inv_ilr <- transform_inverse(ilr)
all.equal(coda, inv_ilr)
inv_plr <- transform_inverse(plr)
all.equal(coda, inv_plr)
Univariate Isometric Log-Ratios (ILR)
Description
Computes univariate ILR coordinates.
Usage
univariate_ilr(object, ...)
## S4 method for signature 'numeric'
univariate_ilr(object)
## S4 method for signature 'matrix'
univariate_ilr(object)
Arguments
object |
A |
... |
Currently not used. |
Details
The ILR transformation provides the coordinates of any composition with
respect to a given orthonormal basis. transform_ilr()
uses the orthonormal
basis (Helmert matrix) originally defined by Egozcue et al. (2003).
Value
Same as object
.
Author(s)
N. Frerebeau
References
Filzmoser, P., Hron, K. & Reimann, C. (2009). Univariate Statistical Analysis of Environmental (Compositional) Data: Problems and Possibilities. Science of The Total Environment, 407(23), 6100-6108. doi:10.1016/j.scitotenv.2009.08.008.
Filzmoser, P., Hron, K. & Reimann, C. (2010). The Bivariate Statistical Analysis of Environmental (Compositional) Data. Science of The Total Environment, 408(19), 4230-4238. doi:10.1016/j.scitotenv.2010.05.011.
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Isometric log-ratio
ilr <- transform_ilr(coda)
plr <- transform_plr(coda)
## Inverse transformation
inv_ilr <- transform_inverse(ilr)
all.equal(coda, inv_ilr)
inv_plr <- transform_inverse(plr)
all.equal(coda, inv_plr)
Log-Ratios Variances
Description
Computes log-ratio (weighted) variances.
Usage
variance(x, ...)
## S4 method for signature 'LogRatio'
variance(x, row_weights = NULL, column_weights = TRUE)
Arguments
x |
A |
... |
Currently not used. |
row_weights |
A |
column_weights |
A |
Value
A numeric
vector of individual variances.
Author(s)
N. Frerebeau
References
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance_total()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Total variance (1)
variance_total(coda)
## Metric standard deviation
variance_total(coda, sd = TRUE)
## CLR transformation
clr <- transform_clr(coda)
## Individual log-ratio variances
variance(clr)
## Total log-ratio variance (2)
variance_total(clr)
## Proportionality between (1) and (2)
## See Aitchison 1997
variance_total(coda) * (1 / ncol(coda)) * (1 - (1 / nrow(coda)))
Total Variance
Description
Computes the total (or metric) variance, a global measure of spread.
Usage
variance_total(x, ...)
## S4 method for signature 'CompositionMatrix'
variance_total(x, sd = FALSE)
## S4 method for signature 'LogRatio'
variance_total(x, row_weights = NULL, column_weights = TRUE)
Arguments
x |
A |
... |
Currently not used. |
sd |
A |
row_weights |
A |
column_weights |
A |
Details
Two methods are available, see below.
Value
A numeric
vector.
Methods (by class)
-
variance_total(CompositionMatrix)
: The total variance of compositional data is the trace of the centred log-ratio covariance matrix (i.e. totvar1 in Aitchison 1997). -
variance_total(LogRatio)
: Computes the total log-ratio variance. This is identical to the weighted sum-of-squared distances between samples (i.e. totvar2 in Aitchison 1997).
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Aitchison, J. (1997). The One-Hour Course in Compositional Data Analysis or Compositional Data Analysis Is Simple. In V. Pawlowsky-Glahn (ed.), IAMG'97. Barcelona: International Center for Numerical Methods in Engineering (CIMNE), p. 3-35.
Boogaart, K. G. van den & Tolosana-Delgado, R. (2013). Analyzing Compositional Data with R. Berlin Heidelberg: Springer-Verlag. doi:10.1007/978-3-642-36809-7.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Hron, K. & Kubáček. L. (2011). Statistical Properties of the Total Variation Estimator for Compositional Data. Metrika, 74 (2): 221-230. doi:10.1007/s00184-010-0299-3.
Pawlowsky-Glahn, V. & Egozcue, J. J. (2001). Geometric Approach to Statistical Analysis on the Simplex. Stochastic Environmental Research and Risk Assessment, 15(5): 384-398. doi:10.1007/s004770100077.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variation()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Total variance (1)
variance_total(coda)
## Metric standard deviation
variance_total(coda, sd = TRUE)
## CLR transformation
clr <- transform_clr(coda)
## Individual log-ratio variances
variance(clr)
## Total log-ratio variance (2)
variance_total(clr)
## Proportionality between (1) and (2)
## See Aitchison 1997
variance_total(coda) * (1 / ncol(coda)) * (1 - (1 / nrow(coda)))
Variation Matrix
Description
Computes the variation matrix (Aitchison 1986, definition 4.4).
Usage
variation(x, ...)
## S4 method for signature 'CompositionMatrix'
variation(x)
Arguments
x |
A |
... |
Currently not used. |
Value
A matrix
.
Author(s)
N. Frerebeau
References
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
See Also
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
Examples
## Data from Aitchison 1986
data("hongite")
## Coerce to compositional data
coda <- as_composition(hongite)
## Variation matrix
## (Aitchison 1986, definition 4.4)
(varia <- variation(coda))
## Cluster dendrogram
d <- as.dist(varia)
h <- hclust(d, method = "ward.D2")
plot(h)
## Heatmap
stats::heatmap(
varia,
distfun = stats::as.dist,
hclustfun = function(x) stats::hclust(x, method = "ward.D2"),
symm = TRUE,
scale = "none"
)
Weights
Description
Extract weights from an object.
Usage
## S4 method for signature 'ALR'
weights(object, ...)
## S4 method for signature 'LR'
weights(object, ...)
## S4 method for signature 'LogRatio'
weights(object, ...)
Arguments
object |
An object for which the extraction of weights is meaningful. |
... |
Currently not used. |
Author(s)
N. Frerebeau
See Also
Other mutators:
as.data.frame()
,
labels()
,
totals()