rapports: Compute all pairwise ratios of a set of variables

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

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

Usage

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

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.

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.

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.

Note

This function is mainly for designing a step-by-step analysis or control purposes. To avoid waste of memory, most of the functions in the package actually compute “on fly” the ratios when constructing the matrix or the data frame of p-values.

Author(s)

Emmanuel Curis (emmanuel.curis@parisdescartes.fr)

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
   # 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 )

Example output

Loading required package: igraph

Attaching package:igraphThe following objects are masked frompackage:stats:

    decompose, spectrum

The following object is masked frompackage:base:

    union

 [1] "ID"      "Al"      "Fe"      "Mg"      "Ca"      "Na"      "K"      
 [8] "Ti"      "Mn"      "Ba"      "Site"    "Pays"    "Couleur" "Date"   
[15] "Al.Fe.r" "Al.Mg.r" "Al.Ca.r" "Al.Na.r" "Fe.Mg.r" "Fe.Ca.r" "Fe.Na.r"
[22] "Mg.Ca.r" "Mg.Na.r" "Ca.Na.r"
   ID   Al   Fe   Mg   Ca   Na    K   Ti    Mn    Ba       Site          Pays
1 C01 14.4 7.00 4.30 0.15 0.51 4.25 0.79 0.160 0.019 Llanedeyrn Pays de Galle
2 C02 13.8 7.08 3.43 0.12 0.17 4.14 0.77 0.144 0.020 Llanedeyrn Pays de Galle
3 C03 14.6 7.09 3.88 0.13 0.20 4.36 0.81 0.124 0.019 Llanedeyrn Pays de Galle
4 C04 11.5 6.37 5.64 0.16 0.14 3.89 0.69 0.087 0.009 Llanedeyrn Pays de Galle
5 C05 13.8 7.06 5.34 0.20 0.20 4.31 0.71 0.101 0.021 Llanedeyrn Pays de Galle
6 C06 10.9 6.26 3.47 0.17 0.22 3.40 0.66 0.109 0.010 Llanedeyrn Pays de Galle
  Couleur Date  Al.Fe.r  Al.Mg.r   Al.Ca.r  Al.Na.r  Fe.Mg.r  Fe.Ca.r  Fe.Na.r
1    Gris -300 2.057143 3.348837  96.00000 28.23529 1.627907 46.66667 13.72549
2    Gris -300 1.949153 4.023324 115.00000 81.17647 2.064140 59.00000 41.64706
3    Gris -300 2.059238 3.762887 112.30769 73.00000 1.827320 54.53846 35.45000
4    Gris -300 1.805338 2.039007  71.87500 82.14286 1.129433 39.81250 45.50000
5    Gris -300 1.954674 2.584270  69.00000 69.00000 1.322097 35.30000 35.30000
6    Gris -300 1.741214 3.141210  64.11765 49.54545 1.804035 36.82353 28.45455
   Mg.Ca.r   Mg.Na.r   Ca.Na.r
1 28.66667  8.431373 0.2941176
2 28.58333 20.176471 0.7058824
3 29.84615 19.400000 0.6500000
4 35.25000 40.285714 1.1428571
5 26.70000 26.700000 1.0000000
6 20.41176 15.772727 0.7727273
[1] TRUE

SARP.compo documentation built on May 16, 2021, 1:06 a.m.