Learn R Programming

multilevelcoda (version 1.3.3)

complr: Indices from a (dataset of) Multilevel Composition(s)

Description

Compute sets of compositions and log ratio transformation for multilevel compositional data

Usage

complr(data, parts, sbp = NULL, total = 1, idvar = NULL, transform = "ilr")

Value

A complr object with at least the following elements.

X

A vector of class acomp representing one closed composition or a matrix of class acomp representing multiple closed compositions each in one row.

bX

A vector of class acomp representing one closed between-person composition or a matrix of class acomp representing multiple closed between-person compositions each in one row.

wX

A vector of class acomp representing one closed within-person composition or a matrix of class acomp representing multiple closed within-person compositions each in one row.

Z

Log ratio transform of composition.

bZ

Log ratio transform of between-person composition.

wZ

Log ratio transform of within-person composition.

data

The user's dataset or imputed dataset if the iiut data contains zeros.

transform

Type of transform applied on compositional data.

parts

Names of compositional variables.

idvar

Name of the variable containing IDs.

total

Total amount to which the compositions is closed.

Arguments

data

A data.frame or data.table containing data of all variables used in the analysis. It must include a composition and a ID variable. Required.

parts

A character vector specifying the names of compositional variables to be used. For multiple compositions, a list of character vectors.

sbp

A signary matrix indicating sequential binary partition when transform = "ilr". If not supplied, a default sequential binary partition (sbp) will be built using function build.sbp. For multiple compositions, a list of sbps can be supplied.

total

A numeric value of the total amount to which the compositions should be closed. For multiple compositions, a list of numeric values. Default is 1.

idvar

Only for multilevel data, a character string specifying the name of the variable containing participants IDs.

transform

A character value naming a log ratio transformation to be applied on compositional data. Can be either "ilr" (isometric logratio), "alr" (additive logratio), or "clr" (centered logratio). Default is "ilr".

Details

The ilr-transform maps the D-part compositional data from the simplex into non-overlapping subgroups in the (D-1)-dimension Euclidean space isometrically by using an orthonormal basis, thereby preserving the compositional properties and yielding a full-rank covariance matrix. ilr transformation should be preferred. However, the alr and clr are alternatives. The alr-transform maps a D-part composition in the Aitchison-simplex non-isometrically to a (D-1)-dimension Euclidian vectors, commonly treating the last part as the common denominator of the others. alr transformation does not rely on distance which breaks the constraint of compositional data. clr-transform maps a D-part composition in the Aitchison-simplex isometrically to a D-dimensional Euclidian vector subspace. clr transformation is not injetive, resulting in singular covariance matrices.

Examples

Run this code
x1 <- complr(data = mcompd,
                parts = c("TST", "WAKE", "MVPA", "LPA", "SB"),
                idvar = "ID", total = 1440)
str(x1)

x2 <- complr(data = mcompd,
                parts = list(c("TST", "WAKE"), c("MVPA", "LPA", "SB")),
                total = list(c(480), c(960)),
                idvar = "ID",
                transform = "ilr")
str(x2)

x3 <- complr(data = mcompd, sbp = sbp,
                parts = c("TST", "WAKE", "MVPA", "LPA", "SB"),
                idvar = "ID",
                 transform = "ilr")
str(x3)

x_wide <- complr(data = mcompd[!duplicated(ID)], sbp = sbp,
                parts = c("TST", "WAKE", "MVPA", "LPA", "SB"))
str(x_wide)

Run the code above in your browser using DataLab