Learn R Programming

SARP.compo (version 0.1.5)

calc.rapports: Compute all pairwise ratios of a set of variables

Description

This function computes all pairwise ratios or differences of a set of variables in a given data frame

Usage

calc.rapports( d, noms, log = FALSE, isoler = FALSE )

Value

These function returns the original data.frame with additional columns corresponding to all pairwise ratios added as the last columns of the data.frame.

These variables have their name constructed as the concatenation of the names of the two variables used, the first one being at the numerator, separated with a dot and with the additional suffix .r (or .r.log is working on difference of logarithms).

Their order is determined by the order given in noms: the first variable of the list, V1, is used to compute ratios with all others (V1/V2, V1/V3 and so on). Then the second one is used for ratios further ones (V2/V3 and so on), and so on until the last one.

Arguments

d

The data frame that contains the variables. Other objects will be coerced as data frames using as.data.frame

noms

A character vector containing the column names of the compositional variables to be used for ratio computations. Names absent from the data frame will be ignored with a warning.

Optionnally, an integer vector containing the column numbers can be given instead. They will be converted to column names before further processing.

log

If TRUE, values in the columns are assumed to be log-transformed, and consequently ratios are computed as differences of the columns. The result is in the log scale.

If FALSE, values are assumed to be raw data and ratios are computed directly.

isoler

If TRUE, the result data frame will not include the original values.

Author

Emmanuel Curis (emmanuel.curis@parisdescartes.fr)

Details

Use this function to compute all pairwise ratio of a set of numerical variables. If non-numerical variables are given in the list of variables, they will be ignores with a warning.

Since the ratio of variables i and j is the inverse of the ratio of variables j and i, only one of them is computed. The order is determined by the order of the variables in noms. In matrix notations, only the upper right matrix is computed, withour the diagonal.

See Also

creer.Mp to create a matrix of p-values for all pairwise tests of ratio changes.

Examples

Run this code
   # load the potery data set
   data( poteries )

   # Compute all ratios in the potery data set   
   d.r <- calc.rapports( d = poteries, noms = c( 'Al', 'Fe', 'Mg', 'Ca',
   'Na' ) )
   names( d.r )
   head( d.r )

   identical( d.r$Al.Fe.r, d.r$Al / d.r$Fe )

Run the code above in your browser using DataLab