Learn R Programming

sda (version 1.0.1)

centroids: Group Centroids, (Pooled) Variances, and Inverse Pooled Correlation Matrix

Description

centroids computes group centroids and optionally the pooled variance, the group specific variances, and the inverse of the pooled correlation matrix.

Usage

centroids(x, L, var.pooled=TRUE, var.groups=FALSE, invcor.pooled=FALSE, shrink=FALSE, verbose=TRUE)

Arguments

x
A matrix containing the data set. Note that the rows are sample observations and the columns are variables.
L
A factor with the group labels.
var.pooled
Estimate the pooled variances.
var.groups
Estimate all group-specific variances.
invcor.pooled
Estimate inverse pooled correlation matrix.
shrink
Use empirical or shrinkage estimator.
verbose
Provide some messages while computing.

Value

  • centroids returns a list with the following components:
  • samplesa vector containing the samples sizes in each group,
  • meansthe empirical group means,
  • var.pooleda vector containing the pooled variances,
  • var.groupsa matrix containing the group-specific variances, and
  • invcor.pooleda matrix containing the inverse pooled correlation matrix (if all correlations are zero a vector of 1s is returned to save space).

Details

If option shrink=TRUE then the shrinkage estimators var.shrink from Opgen-Rhein and Strimmer (2007) and invcor.shrink from Sch"afer and Strimmer (2005) are used.

See Also

var.shrink, invcor.shrink.

Examples

Run this code
library("sda")

## prepare data set
data(iris) # good old iris data
X = as.matrix(iris[,1:4])
Y = iris[,5]

## estimate centroids and empirical pooled variances
centroids(X, Y)

## include also group-specific variances
centroids(X, Y, var.groups=TRUE)

## and inverse pooled correlation
centroids(X, Y, var.groups=TRUE, invcor.pooled=TRUE)

## use shrinkage estimator for variances and correlations
centroids(X, Y, var.groups=TRUE, invcor.pooled=TRUE, shrink=TRUE)

Run the code above in your browser using DataLab