covw: Weighted means, covariance and scattering matrices...

Description Usage Arguments Value Author(s) Examples

View source: R/util.R

Description

Compute efficiently (via Fortran code) the means, covariance and scattering matrices conditioning on a weighted or indicator matrix

Usage

1
covw(X, Z, normalize = TRUE)

Arguments

X

A (n x p) data matrix, with n observations on p variables.

Z

A (n x G) matrix of weights, with G number of groups.

normalize

A logical indicating if rows of Z should be normalized to sum to one.

Value

A list with the following components:

mean

A (p x G) matrix of weighted means.

S

A (p x p x G) array of weighted covariance matrices.

W

A (p x p x G) array of weighted scattering matrices.

Author(s)

M. Fop and L. Scrucca

Examples

1
2
3
4
5
6
7
# Z as an indicator matrix
X <- iris[,1:4]
Z <- unmap(iris$Species)
str(covw(X, Z))
# Z as a matrix of weights
mod <- Mclust(X, G = 3, modelNames = "VVV")
str(covw(X, mod$z))

Example output

Package 'mclust' version 5.4.7
Type 'citation("mclust")' for citing this R package in publications.
List of 3
 $ mean: num [1:4, 1:3] 5.006 3.428 1.462 0.246 5.936 ...
 $ S   : num [1:4, 1:4, 1:3] 0.1218 0.0972 0.016 0.0101 0.0972 ...
 $ W   : num [1:4, 1:4, 1:3] 6.088 4.862 0.801 0.506 4.862 ...
List of 3
 $ mean: num [1:4, 1:3] 5.006 3.428 1.462 0.246 5.915 ...
 $ S   : num [1:4, 1:4, 1:3] 0.1218 0.0972 0.016 0.0101 0.0972 ...
 $ W   : num [1:4, 1:4, 1:3] 6.088 4.862 0.801 0.506 4.862 ...

mclust documentation built on Nov. 5, 2021, 5:07 p.m.