Learn R Programming

compositions (version 1.40-5)

var.acomp: Variances and covariances of amounts and compositions

Description

Compute the (co)variance matrix in the several approaches of compositional and amount data analysis.

Usage

var(x,…)
    # S3 method for default
var(x, y=NULL, na.rm=FALSE, use, …)
    # S3 method for acomp
var(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rcomp
var(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for aplus
var(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rplus
var(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rmult
var(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
  cov(x,y=x,…)
    # S3 method for default
cov(x, y=NULL, use="everything", 
       method=c("pearson", "kendall", "spearman"), …)
    # S3 method for acomp
cov(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rcomp
cov(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for aplus
cov(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rplus
cov(x,y=NULL,…,robust=getOption("robust"), 
       use="all.obs",giveCenter=FALSE)
    # S3 method for rmult
cov(x,y=NULL,…,robust=getOption("robust"), 
    use="all.obs",giveCenter=FALSE)

Arguments

x

a dataset, eventually of amounts or compositions

y

a second dataset, eventually of amounts or compositions

na.rm

see var

use

see var

method

see cov

further arguments to var e.g. use

robust

A description of a robust estimator. FALSE for the classical estimators. See robustnessInCompositions for further details.

giveCenter

If TRUE the center used in the variance calculation is reported as a "center" attribute. This is especially necessary for robust estimations, where a reasonable center can not be computed independently for the me variance calculation.

Value

The variance matrix of x or the covariance matrix of x and y.

Details

The basic functions of var, cov are turned to S3-generics. The original versions are copied to the default method. This allows us to introduce generic methods to handle variances and covariances of other data types, such as amounts or compositions.

If classed amounts or compositions are involved, they are transformed with their corresponding transforms, using the centered default transform (cdt). That implies that the variances have to be interpreded in a log scale level for acomp and aplus.

We should be aware that variance matrices of compositions (acomp and rcomp) are singular. They can be transformed to the correponding nonsingular variances of ilr or ipt-space by clrvar2ilr.

In R versions older than v2.0.0, var and cov were defined in package ``base'' instead of in ``stats''. This might produce some misfunction.

See Also

cdt, clrvar2ilr, clo, mean.acomp, acomp, rcomp, aplus, rplus, variation

Examples

Run this code
# NOT RUN {
data(SimulatedAmounts)
meanCol(sa.lognormals)
var(acomp(sa.lognormals))
var(rcomp(sa.lognormals))
var(aplus(sa.lognormals))
var(rplus(sa.lognormals))
cov(acomp(sa.lognormals5[,1:3]),acomp(sa.lognormals5[,4:5]))
cov(rcomp(sa.lognormals5[,1:3]),rcomp(sa.lognormals5[,4:5]))
cov(aplus(sa.lognormals5[,1:3]),aplus(sa.lognormals5[,4:5]))
cov(rplus(sa.lognormals5[,1:3]),rplus(sa.lognormals5[,4:5]))
cov(acomp(sa.lognormals5[,1:3]),aplus(sa.lognormals5[,4:5]))

svd(var(acomp(sa.lognormals)))

# }

Run the code above in your browser using DataLab