Title: | 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. |
Authors: | Nicolas Frerebeau [aut, cre] (<https://orcid.org/0000-0001-5759-4944>, Université Bordeaux Montaigne), Anne Philippe [aut] (<https://orcid.org/0000-0002-5331-5087>, Université de Nantes), Brice Lebrun [ctb] (<https://orcid.org/0000-0001-7503-8685>, Logo designer), Arthur Leck [ctb] (<https://orcid.org/0009-0004-8819-9970>, Université Bordeaux Montaigne), Université Bordeaux Montaigne [fnd], CNRS [fnd] |
Maintainer: | Nicolas Frerebeau <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.0.9000 |
Built: | 2024-12-18 21:20:21 UTC |
Source: | https://github.com/tesselle/nexus |
Splits the data into subsets, computes summary statistics for each, and returns the result.
## S4 method for signature 'CompositionMatrix' aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE) ## S4 method for signature 'GroupedComposition' aggregate(x, FUN, ..., simplify = TRUE)
## S4 method for signature 'CompositionMatrix' aggregate(x, by, FUN, ..., simplify = TRUE, drop = TRUE) ## S4 method for signature 'GroupedComposition' aggregate(x, FUN, ..., simplify = TRUE)
x |
A |
by |
A |
FUN |
A |
... |
Further arguments to be passed to |
simplify |
A |
drop |
A |
A matrix
.
N. Frerebeau
Other statistics:
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## 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)
## 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)
Sand, silt, clay compositions of 39 sediment samples at different water depths in an Arctic lake.
arctic
arctic
A data.frame
with 4 variables:
sand
Sand content (percent).
silt
Silt content (percent).
clay
Clay content (percent).
depth
Water depth (m).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Operators performing operations in the simplex.
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
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
x |
A |
y |
A |
%perturbe%
%power%
A CompositionMatrix
object or a numeric
vector (same as x
).
N. Frerebeau
Other operations in the simplex:
closure()
,
perturbation()
,
powering()
,
scalar()
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)
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 Amounts
as_amounts(from, ...) ## S4 method for signature 'CompositionMatrix' as_amounts(from)
as_amounts(from, ...) ## S4 method for signature 'CompositionMatrix' as_amounts(from)
from |
A |
... |
Currently not used. |
N. Frerebeau
Other compositional data tools:
as_composition()
## 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)
## 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)
Coerces an object to a CompositionMatrix
object.
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, verbose = getOption("nexus.verbose") )
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, verbose = getOption("nexus.verbose") )
from |
A |
... |
Currently not used. |
parts |
A |
groups |
An |
verbose |
A |
See vignette("nexus")
.
A CompositionMatrix
object.
N. Frerebeau
Other compositional data tools:
as_amounts()
## 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)
## 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)
Produces a graph of log-ratios.
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)
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)
object |
A |
... |
Currently not used. |
An igraph graph object.
N. Frerebeau
Other plot methods:
barplot()
,
hist()
,
pairs()
,
plot()
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) }
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) }
Coerce to a Data Frame
## S4 method for signature 'CompositionMatrix' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...) ## S4 method for signature 'GroupedComposition' as.data.frame( x, row.names = rownames(x), optional = FALSE, ..., group_var = ".group" ) ## S4 method for signature 'LogRatio' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...) ## S4 method for signature 'GroupedLogRatio' as.data.frame( x, row.names = rownames(x), optional = FALSE, ..., group_var = ".group" ) ## S4 method for signature 'OutlierIndex' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
## S4 method for signature 'CompositionMatrix' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...) ## S4 method for signature 'GroupedComposition' as.data.frame( x, row.names = rownames(x), optional = FALSE, ..., group_var = ".group" ) ## S4 method for signature 'LogRatio' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...) ## S4 method for signature 'GroupedLogRatio' as.data.frame( x, row.names = rownames(x), optional = FALSE, ..., group_var = ".group" ) ## S4 method for signature 'OutlierIndex' as.data.frame(x, row.names = rownames(x), optional = FALSE, ...)
x |
An R object (typically, a |
row.names |
A |
optional |
A |
... |
Currently not used. |
group_var |
A |
A data.frame
.
N. Frerebeau
Other mutators:
mutators
,
totals()
## 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)
## 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)
Displays a compositional bar chart.
## S4 method for signature 'CompositionMatrix' barplot( height, ..., order_columns = FALSE, order_rows = NULL, decreasing = TRUE, space = 0.2, offset = 0.025, color = palette_color_discrete(), border = NA, axes = TRUE, legend = TRUE )
## S4 method for signature 'CompositionMatrix' barplot( height, ..., order_columns = FALSE, order_rows = NULL, decreasing = TRUE, space = 0.2, offset = 0.025, color = palette_color_discrete(), border = NA, axes = TRUE, legend = TRUE )
height |
A |
... |
Further graphical parameters. |
order_columns |
A |
order_rows |
An |
decreasing |
A |
space |
A length-one |
offset |
A length-one |
color |
A palette |
border |
The color to draw the borders. |
axes |
A |
legend |
A |
barplot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return height
).
N. Frerebeau
Other plot methods:
as_graph()
,
hist()
,
pairs()
,
plot()
## 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)
## 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
## S4 method for signature 'CompositionMatrix,CompositionMatrix' rbind2(x, y)
## S4 method for signature 'CompositionMatrix,CompositionMatrix' rbind2(x, y)
x , y
|
A |
rbind2()
combine by rows.
A CompositionMatrix
objects.
N. Frerebeau
Other subsetting methods:
subset()
## 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) ## Split by group ## /!\ Unassigned samples (NA) are discarded ! /!\ (s1 <- split(Y, f = X$groups)) ## Better to use grouped matrix (s2 <- group_split(Y, by = X$groups)) Z <- as_composition(X, groups = 2) (s3 <- group_split(Z)) ## Bind by rows do.call(rbind, s3)
## 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) ## Split by group ## /!\ Unassigned samples (NA) are discarded ! /!\ (s1 <- split(Y, f = X$groups)) ## Better to use grouped matrix (s2 <- group_split(Y, by = X$groups)) Z <- as_composition(X, groups = 2) (s3 <- group_split(Z)) ## Bind by rows do.call(rbind, s3)
Mineral compositions and depths of 25 specimens of boxite.
boxite
boxite
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).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
arctic
,
coxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Identify oxides and major, minor and traces elements in a compositional data matrix.
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)
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)
object |
A |
... |
Currently not used. |
min |
A length-one |
max |
A length-one |
There is no definite classification of what are the major, minor and trace elements are. By default, the following rule of thumb is used:
The major elements are those that define the material under study. Major elements usually have concentrations of above 1%.
Minor elements usually have concentrations between 1% and 0.1%
Trace elements usually have concentrations of less than 0.1%.
A logical
vector.
is_oxide()
uses a regular expression (it does not check if elements exist
or if stoichiometry is valid).
N. Frerebeau
## 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)
## 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)
Closes compositions to sum to 1.
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)
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)
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 |
A numeric
vector or matrix (same as x
).
N. Frerebeau
Other operations in the simplex:
arithmetic
,
perturbation()
,
powering()
,
scalar()
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)
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)
Splits the data into subsets and computes compositional mean for each.
condense(x, ...) ## S4 method for signature 'CompositionMatrix' condense(x, by, verbose = getOption("nexus.verbose"), ...) ## S4 method for signature 'GroupedComposition' condense(x, by = NULL, verbose = getOption("nexus.verbose"), ...)
condense(x, ...) ## S4 method for signature 'CompositionMatrix' condense(x, by, verbose = getOption("nexus.verbose"), ...) ## S4 method for signature 'GroupedComposition' condense(x, by = NULL, verbose = getOption("nexus.verbose"), ...)
x |
A |
... |
Further arguments to be passed to |
by |
A |
verbose |
A |
A CompositionMatrix
object.
N. Frerebeau
Other statistics:
aggregate()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## Data from Aitchison 1986 data("slides") ## Coerce to a compositional matrix coda <- as_composition(slides, groups = 2) ## Compositional mean by group condense(coda)
## Data from Aitchison 1986 data("slides") ## Coerce to a compositional matrix coda <- as_composition(slides, groups = 2) ## Compositional mean by group condense(coda)
Computes the (centered) log-ratio covariance matrix (see below).
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")
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")
x |
A |
... |
Currently not used. |
center |
A |
method |
A |
A matrix
.
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).
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## 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)
## 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)
Mineral compositions, depths and porosity of 25 specimens of coxite.
coxite
coxite
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).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
arctic
,
boxite
,
hongite
,
kongite
,
lava
,
predator
,
slides
Describes an object.
## S4 method for signature 'CompositionMatrix' describe(x) ## S4 method for signature 'GroupedComposition' describe(x)
## S4 method for signature 'CompositionMatrix' describe(x) ## S4 method for signature 'GroupedComposition' describe(x)
x |
A |
describe()
is called for its side-effects. Invisibly returns x
.
N. Frerebeau
## Data from Aitchison 1986 data("slides") ## Coerce to compositional data coda <- as_composition(slides, groups = 2) ## Quick description describe(coda)
## Data from Aitchison 1986 data("slides") ## Coerce to compositional data coda <- as_composition(slides, groups = 2) ## Quick description describe(coda)
Outlier Detection
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, ..., robust = TRUE, method = c("mve", "mcd"), quantile = 0.975 ) ## S4 method for signature 'OutlierIndex' is_outlier(object, robust = TRUE)
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, ..., robust = TRUE, method = c("mve", "mcd"), quantile = 0.975 ) ## S4 method for signature 'OutlierIndex' is_outlier(object, robust = TRUE)
object |
|
reference |
A |
... |
Further parameters to be passed to |
robust |
A |
method |
A |
quantile |
A length-one |
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).
detect_outlier()
returns an OutlierIndex
object.
is_outlier()
returns a logical
vector.
N. Frerebeau
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.
Other outlier detection methods:
plot_outlier
## 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_extract(coda, "CJ") out <- detect_outlier(coda, reference = ref, method = "mcd") plot(out, type = "dotchart")
## 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_extract(coda, "CJ") out <- detect_outlier(coda, reference = ref, method = "mcd") plot(out, type = "dotchart")
Computes the distances between all rows of in x
.
## S4 method for signature 'CompositionMatrix' dist(x, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
## S4 method for signature 'CompositionMatrix' dist(x, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
x |
A |
method |
A |
diag |
A |
upper |
A |
p |
An |
Distances are computed on CLR-transformed data.
A stats::dist
object.
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## 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)
## 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)
Define or remove the (reference) groups to which the observations belong.
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)
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)
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 |
Missing values (NA
) can be used to specify that a sample does not belong
to any group.
group()
returns a grouped object of the same sort as object
.
ungroup()
returns an ungrouped object of the same sort as object
.
N. Frerebeau
Other grouping methods:
group_extract()
,
group_metadata
,
group_split()
,
is_grouped()
## 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_length(coda) group_size(coda)
## 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_length(coda) group_size(coda)
Group-based Subset
group_extract(object, ...) ## S4 method for signature 'GroupedComposition' group_extract(object, which)
group_extract(object, ...) ## S4 method for signature 'GroupedComposition' group_extract(object, which)
object |
A |
... |
Currently not used. |
which |
A |
A CompositionMatrix
object.
N. Frerebeau
Other grouping methods:
group()
,
group_metadata
,
group_split()
,
is_grouped()
## 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_length(coda) group_size(coda)
## 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_length(coda) group_size(coda)
Retrieve the (reference) groups to which the observations belong.
group_levels(object) group_names(object) group_rows(object) group_length(object) group_size(object) group_indices(object) is_assigned(object) any_assigned(object) all_assigned(object) ## S4 method for signature 'ReferenceGroups' group_levels(object) ## S4 method for signature 'ReferenceGroups' group_names(object) ## S4 method for signature 'ReferenceGroups' group_indices(object) ## S4 method for signature 'ReferenceGroups' group_rows(object) ## S4 method for signature 'ReferenceGroups' group_length(object) ## S4 method for signature 'ReferenceGroups' group_size(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)
group_levels(object) group_names(object) group_rows(object) group_length(object) group_size(object) group_indices(object) is_assigned(object) any_assigned(object) all_assigned(object) ## S4 method for signature 'ReferenceGroups' group_levels(object) ## S4 method for signature 'ReferenceGroups' group_names(object) ## S4 method for signature 'ReferenceGroups' group_indices(object) ## S4 method for signature 'ReferenceGroups' group_rows(object) ## S4 method for signature 'ReferenceGroups' group_length(object) ## S4 method for signature 'ReferenceGroups' group_size(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)
object |
A grouped R object. |
group_levels(ReferenceGroups)
: returns a character
vector giving the group
names.
group_names(ReferenceGroups)
: returns a character
vector giving the name of
the group that each observation belongs to.
group_indices(ReferenceGroups)
: returns an integer
vector giving the group
that each value belongs to.
group_rows(ReferenceGroups)
: returns a list
of integer
vectors giving the
observation that each group contains.
group_length(ReferenceGroups)
: gives the total number of groups.
group_size(ReferenceGroups)
: gives the size of each group.
is_assigned(ReferenceGroups)
: returns a logical
vector specifying whether or
not an observation belongs to a group.
any_assigned(ReferenceGroups)
: returns an logical
scalar specifying if any
observation belongs to a group.
all_assigned(ReferenceGroups)
: returns an logical
scalar specifying if all
observations belong to a group.
N. Frerebeau
Other grouping methods:
group()
,
group_extract()
,
group_split()
,
is_grouped()
## 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_length(coda) group_size(coda)
## 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_length(coda) group_size(coda)
Divides a compositional matrix by groups.
group_split(object, ...) ## S4 method for signature 'CompositionMatrix' group_split(object, by, ...) ## S4 method for signature 'GroupedComposition' group_split(object, ...) ## S4 method for signature 'GroupedLogRatio' group_split(object, ...) ## S4 method for signature 'CompositionMatrix' split(x, f, drop = FALSE, ...) ## S4 method for signature 'LogRatio' split(x, f, drop = FALSE, ...)
group_split(object, ...) ## S4 method for signature 'CompositionMatrix' group_split(object, by, ...) ## S4 method for signature 'GroupedComposition' group_split(object, ...) ## S4 method for signature 'GroupedLogRatio' group_split(object, ...) ## S4 method for signature 'CompositionMatrix' split(x, f, drop = FALSE, ...) ## S4 method for signature 'LogRatio' split(x, f, drop = FALSE, ...)
object , x
|
A |
... |
Currently not used. |
by |
A |
f |
A 'factor' in the sense that |
drop |
A |
A list
of CompositionMatrix
objects.
N. Frerebeau
Other grouping methods:
group()
,
group_extract()
,
group_metadata
,
is_grouped()
## 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) ## Split by group ## /!\ Unassigned samples (NA) are discarded ! /!\ (s1 <- split(Y, f = X$groups)) ## Better to use grouped matrix (s2 <- group_split(Y, by = X$groups)) Z <- as_composition(X, groups = 2) (s3 <- group_split(Z)) ## Bind by rows do.call(rbind, s3)
## 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) ## Split by group ## /!\ Unassigned samples (NA) are discarded ! /!\ (s1 <- split(Y, f = X$groups)) ## Better to use grouped matrix (s2 <- group_split(Y, by = X$groups)) Z <- as_composition(X, groups = 2) (s3 <- group_split(Z)) ## Bind by rows do.call(rbind, s3)
Produces an histogram of univariate ILR data (see Filzmoser et al., 2009).
## 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 )
## 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 )
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 |
hist()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
N. Frerebeau
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.
Other plot methods:
as_graph()
,
barplot()
,
pairs()
,
plot()
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Boxplot plot hist(coda, select = "A") hist(coda, select = "B")
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Boxplot plot hist(coda, select = "A") hist(coda, select = "B")
Mineral compositions of 25 specimens of hongite.
hongite
hongite
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).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
arctic
,
boxite
,
coxite
,
kongite
,
lava
,
predator
,
slides
Check if an Object is Grouped
is_grouped(object)
is_grouped(object)
object |
An R object. |
A logical
scalar.
N. Frerebeau
Other grouping methods:
group()
,
group_extract()
,
group_metadata
,
group_split()
Mineral compositions of 25 specimens of kongite.
kongite
kongite
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).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
lava
,
predator
,
slides
Chemical compositions of 23 aphyric Skye lavas.
lava
lava
A data.frame
with 3 variables (percent):
A
Na2O + K2O.
F
Fe2O3.
M
MgO.
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall. doi:10.1007/978-94-009-4109-0.
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
predator
,
slides
Computes the squared Mahalanobis distance of all rows in x
.
## 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"))
## 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"))
x |
A |
center |
A |
cov |
A |
... |
Extra parameters to be passed to |
robust |
A |
method |
A |
A numeric
vector.
N. Frerebeau
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mahalanobis distance mahalanobis(coda)
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mahalanobis distance mahalanobis(coda)
Marginal Compositions
margin(x, ...) ## S4 method for signature 'CompositionMatrix' margin(x, parts = c(1, 2), name = "*")
margin(x, ...) ## S4 method for signature 'CompositionMatrix' margin(x, parts = c(1, 2), name = "*")
x |
A |
... |
Currently not used. |
parts |
An |
name |
A |
A CompositionMatrix
object.
N. Frerebeau
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## 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)
## 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
## S4 method for signature 'CompositionMatrix' mean(x, ...)
## S4 method for signature 'CompositionMatrix' mean(x, ...)
x |
A |
... |
Further arguments to be passed to internal methods. |
Closed vector of the columns geometric means.
A numeric
vector.
N. Frerebeau
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mean mean(coda) ## Quantile quantile(coda)
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mean mean(coda) ## Quantile quantile(coda)
Missing Values Policy
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.
If you need more advanced features (e.g. imputation of missing values), you should consider the compositions or robCompositions package.
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other imputation methods:
replace_NA()
,
replace_zero()
Mixes chemical and petrographic matrices.
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)
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)
x |
A |
y |
A |
... |
Extra parameters to be passed to |
lambda |
A length-one |
mu |
A length-one |
A stats::dist object.
mix(x = matrix, y = matrix)
: First approach of mixed-mode analysis.
mix(x = dist, y = dist)
: Second approach of mixed-mode analysis.
Experimental.
N. Frerebeau
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.
## 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 <- stats::cmdscale(mix1) # Multi-Dimensional Scaling plot(mds1)
## 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 <- stats::cmdscale(mix1) # Multi-Dimensional Scaling plot(mds1)
Getters and setters to retrieve or set parts of an object.
## S4 method for signature 'CompositionMatrix' labels(object, ...) ## S4 method for signature 'LogRatio' labels(object, ...) ## S4 method for signature 'ALR' weights(object, ...) ## S4 method for signature 'LR' weights(object, ...) ## S4 method for signature 'LogRatio' weights(object, ...)
## S4 method for signature 'CompositionMatrix' labels(object, ...) ## S4 method for signature 'LogRatio' labels(object, ...) ## S4 method for signature 'ALR' weights(object, ...) ## S4 method for signature 'LR' weights(object, ...) ## S4 method for signature 'LogRatio' weights(object, ...)
object |
An object from which to get or set element(s). |
... |
Currently not used. |
N. Frerebeau
Other mutators:
as.data.frame()
,
totals()
Displays a matrix of ternary plots.
## S4 method for signature 'CompositionMatrix,missing' plot(x, margin = NULL, ...) ## S4 method for signature 'GroupedComposition,missing' plot( x, ..., margin = NULL, color = palette_color_discrete(), symbol = palette_shape() )
## S4 method for signature 'CompositionMatrix,missing' plot(x, margin = NULL, ...) ## S4 method for signature 'GroupedComposition,missing' plot( x, ..., margin = NULL, color = palette_color_discrete(), symbol = palette_shape() )
x |
A |
margin |
A |
... |
Further graphical parameters. |
color |
A palette |
symbol |
A palette |
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
N. Frerebeau
isopleuros::ternary_pairs()
, isopleuros::ternary_plot()
Other plot methods:
as_graph()
,
barplot()
,
hist()
,
plot()
## 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 plot(coda) ## Center and scale ternary plots plot(coda, by = NULL, center = TRUE, scale = TRUE)
## 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 plot(coda) ## Center and scale ternary plots plot(coda, by = NULL, center = TRUE, scale = TRUE)
Computes a principal components analysis based on the singular value decomposition.
## 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 )
## 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 )
object |
A |
center |
A |
scale |
A |
rank |
An |
sup_row |
A |
sup_col |
A |
weight_row |
A |
weight_col |
A |
A dimensio::PCA
object. See dimensio::pca()
for details.
pca(CompositionMatrix)
: PCA of centered log-ratio, i.e. log-ratio analysis (LRA).
N. Frerebeau
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.
dimensio::pca()
, dimensio::biplot()
, dimensio::screeplot()
,
dimensio::viz_individuals()
, dimensio::viz_variables()
## 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) viz_variables(X)
## 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) viz_variables(X)
Perturbation of two compositions.
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)
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)
x , y
|
A |
... |
Currently not used. |
In compositional geometry, perturbation plays the role of sum (translation). It is the closed component-wise product of two compositions.
A numeric
vector.
N. Frerebeau
Other operations in the simplex:
arithmetic
,
closure()
,
powering()
,
scalar()
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)
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)
Computes an index of association between parts.
pip(x, ...) ## S4 method for signature 'CompositionMatrix' pip(x)
pip(x, ...) ## S4 method for signature 'CompositionMatrix' pip(x)
x |
A |
... |
Currently not used. |
The proportionality index of parts (PIP) is based on the
variation matrix, but maintains the range of values whithin
.
A matrix
.
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
quantile()
,
scale()
,
variance()
,
variance_total()
,
variation()
## 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" )
## 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" )
Displays a density plot.
## S4 method for signature 'LogRatio,missing' plot( x, ..., color = palette_color_discrete(), rug = TRUE, ticksize = 0.05, ncol = NULL, flip = FALSE, xlab = NULL, ylab = NULL, main = NULL, ann = graphics::par("ann"), axes = TRUE, frame.plot = axes, legend = list(x = "top") )
## S4 method for signature 'LogRatio,missing' plot( x, ..., color = palette_color_discrete(), rug = TRUE, ticksize = 0.05, ncol = NULL, flip = FALSE, xlab = NULL, ylab = NULL, main = NULL, ann = graphics::par("ann"), axes = TRUE, frame.plot = axes, legend = list(x = "top") )
x |
A |
... |
Further graphical parameters, particularly,
|
color |
A palette |
rug |
A |
ticksize |
A length-one |
ncol |
An |
flip |
A |
xlab , ylab
|
A |
main |
A |
ann |
A |
axes |
A |
frame.plot |
A |
legend |
A |
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
N. Frerebeau
Other plot methods:
as_graph()
,
barplot()
,
hist()
,
pairs()
## 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) ## Log ratio clr <- transform_clr(coda) ## Density plot plot(clr, flip = TRUE)
## 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) ## Log ratio clr <- transform_clr(coda) ## Density plot plot(clr, flip = TRUE)
Plot Outliers
## 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") )
## 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") )
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 |
plot()
is called for its side-effects: is results in a graphic being
displayed (invisibly return x
).
N. Frerebeau
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.
Other outlier detection methods:
detect_outlier()
## 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_extract(coda, "CJ") out <- detect_outlier(coda, reference = ref, method = "mcd") plot(out, type = "dotchart")
## 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_extract(coda, "CJ") out <- detect_outlier(coda, reference = ref, method = "mcd") plot(out, type = "dotchart")
Perturbation of two compositions.
powering(x, a, ...) ## S4 method for signature 'numeric,numeric' powering(x, a) ## S4 method for signature 'CompositionMatrix,numeric' powering(x, a)
powering(x, a, ...) ## S4 method for signature 'numeric,numeric' powering(x, a) ## S4 method for signature 'CompositionMatrix,numeric' powering(x, a)
x |
A |
a |
A |
... |
Currently not used. |
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.
A numeric
vector.
N. Frerebeau
Other operations in the simplex:
arithmetic
,
closure()
,
perturbation()
,
scalar()
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)
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 at 25 different sites.
predator
predator
A data.frame
with 3 variables (proportions):
P
Predator.
Q
Prey of species Q.
R
Prey of species R.
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall. doi:10.1007/978-94-009-4109-0.
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
slides
Sample Quantiles
## S4 method for signature 'CompositionMatrix' quantile(x, ..., probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE)
## S4 method for signature 'CompositionMatrix' quantile(x, ..., probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE)
x |
A |
... |
Currently not used. |
probs |
A |
na.rm |
A |
names |
A |
A numeric
matrix.
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
scale()
,
variance()
,
variance_total()
,
variation()
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mean mean(coda) ## Quantile quantile(coda)
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Mean mean(coda) ## Quantile quantile(coda)
Multiplicative replacement of missing values.
## S4 method for signature 'CompositionMatrix' replace_NA(x, value)
## S4 method for signature 'CompositionMatrix' replace_NA(x, value)
x |
A |
value |
A |
An CompositionMatrix
object, where all missing values have been
replaced.
N. Frerebeau
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.
Other imputation methods:
missing
,
replace_zero()
## 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
## 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
Multiplicative replacement of zeros.
## S4 method for signature 'CompositionMatrix' replace_zero(x, value, delta = 2/3)
## S4 method for signature 'CompositionMatrix' replace_zero(x, value, delta = 2/3)
x |
A |
value |
A |
delta |
A |
An CompositionMatrix
object, where all zero values have been
replaced.
N. Frerebeau
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.
Other imputation methods:
missing
,
replace_NA()
## 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
## 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
Computes the Aitchison scalar product of two compositions.
scalar(x, y, ...) ## S4 method for signature 'numeric,numeric' scalar(x, y) ## S4 method for signature 'CompositionMatrix,CompositionMatrix' scalar(x, y)
scalar(x, y, ...) ## S4 method for signature 'numeric,numeric' scalar(x, y) ## S4 method for signature 'CompositionMatrix,CompositionMatrix' scalar(x, y)
x , y
|
A |
... |
Currently not used. |
A numeric
vector.
N. Frerebeau
Other operations in the simplex:
arithmetic
,
closure()
,
perturbation()
,
powering()
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)
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
## S4 method for signature 'CompositionMatrix' scale(x, center = TRUE, scale = TRUE)
## S4 method for signature 'CompositionMatrix' scale(x, center = TRUE, scale = TRUE)
x |
A |
center |
A |
scale |
A |
A CompositionMatrix
object.
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
variance()
,
variance_total()
,
variation()
## 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)
## 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)
Mineral compositions of five slides as reported by five analysts.
slides
slides
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).
Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall.
Other datasets:
arctic
,
boxite
,
coxite
,
hongite
,
kongite
,
lava
,
predator
Operators acting on objects to extract or replace parts.
## 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
## 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
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 |
A subsetted object of the same sort as x
.
N. Frerebeau
Other subsetting methods:
bind
## 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)
## 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)
Retrieves or defines the row sums (before closure).
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
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
object |
An object from which to get or set |
value |
A possible value for the |
totals() <- value
returns an object of the same sort as x
with the new
row sums assigned.
totals()
returns the row sums of x
.
N. Frerebeau
Other mutators:
as.data.frame()
,
mutators
## 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)
## 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)
Computes ALR transformation.
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)
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)
object |
A |
... |
Currently not used. |
j |
An |
weights |
A |
The ALR transformation is the logratio of a pair of parts with respect to a fixed part.
An ALR
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
## 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)
## 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)
Computes CLR transformation.
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)
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)
object |
A |
... |
Currently not used. |
weights |
A |
The CLR transformation computes the log of each part relative to the geometric mean of all parts.
A CLR
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_alr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
## 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)
## 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)
Computes ILR transformations.
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)
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)
object |
A |
... |
Currently not used. |
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).
An ILR
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_inverse()
,
transform_lr()
,
transform_plr()
## 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)
## 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)
Computes inverse log-ratio transformations.
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)
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)
object |
A |
origin |
A |
... |
Currently not used. |
A CompositionMatrix
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_lr()
,
transform_plr()
## 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)
## 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)
Computes all pairwise log-ratio transformation.
transform_lr(object, ...) ## S4 method for signature 'CompositionMatrix' transform_lr(object, weights = FALSE) ## S4 method for signature 'GroupedComposition' transform_lr(object, weights = FALSE)
transform_lr(object, ...) ## S4 method for signature 'CompositionMatrix' transform_lr(object, weights = FALSE) ## S4 method for signature 'GroupedComposition' transform_lr(object, weights = FALSE)
object |
A |
... |
Currently not used. |
weights |
A |
A LR
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_plr()
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Pairwise log-ratio lr <- transform_lr(coda)
## Data from Aitchison 1986 data("hongite") ## Coerce to compositional data coda <- as_composition(hongite) ## Pairwise log-ratio lr <- transform_lr(coda)
Computes PLR transformations.
transform_plr(object, ...) ## S4 method for signature 'CompositionMatrix' transform_plr(object, pivot = 1) ## S4 method for signature 'GroupedComposition' transform_plr(object, pivot = 1)
transform_plr(object, ...) ## S4 method for signature 'CompositionMatrix' transform_plr(object, pivot = 1) ## S4 method for signature 'GroupedComposition' transform_plr(object, pivot = 1)
object |
A |
... |
Currently not used. |
pivot |
An |
A PLR
object.
N. Frerebeau
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.
Other log-ratio transformations:
transform_alr()
,
transform_clr()
,
transform_ilr()
,
transform_inverse()
,
transform_lr()
## 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)
## 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)
Computes log-ratio (weighted) variances.
variance(x, ...) ## S4 method for signature 'LogRatio' variance(x, row_weights = NULL, column_weights = TRUE)
variance(x, ...) ## S4 method for signature 'LogRatio' variance(x, row_weights = NULL, column_weights = TRUE)
x |
A |
... |
Currently not used. |
row_weights |
A |
column_weights |
A |
A numeric
vector of individual variances.
N. Frerebeau
Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance_total()
,
variation()
## 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)))
## 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)))
Computes the total (or metric) variance, a global measure of spread.
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)
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)
x |
A |
... |
Currently not used. |
sd |
A |
row_weights |
A |
column_weights |
A |
Two methods are available, see below.
A numeric
vector.
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).
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variation()
## 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)))
## 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)))
Computes the variation matrix (Aitchison 1986, definition 4.4).
variation(x, ...) ## S4 method for signature 'CompositionMatrix' variation(x)
variation(x, ...) ## S4 method for signature 'CompositionMatrix' variation(x)
x |
A |
... |
Currently not used. |
A matrix
.
N. Frerebeau
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.
Other statistics:
aggregate()
,
condense()
,
covariance()
,
dist
,
mahalanobis()
,
margin()
,
mean()
,
pip()
,
quantile()
,
scale()
,
variance()
,
variance_total()
## 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" )
## 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" )