cov.W: Within-group covariance matrix

Description Usage Arguments Value See Also Examples

Description

Computes the pooled within-group covariance matrix. The effect of sexual dimorphism can be removed by using, for each group, the average of the covariance matrix of males and the covariance matrix of females.

Usage

1
cov.W(X, groups, sex = NULL, weighted = FALSE)

Arguments

X

a data matrix with variables in columns and group names as row names

groups

a character / factor vector containing grouping variable

sex

NULL (default). A character / factor vector containing sex variable, to remove sexual dimorphism by averaging males and females in each group

weighted

logical. If FALSE (default), the average of all the within-group covariance matrices is used. If TRUE, the within-group covariance matrices are weighted by their sample size.

Value

The pooled within-group covariance matrix

See Also

cov

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Data matrix of 2D landmark coordinates
data("Tropheus.IK.coord")
coords <- which(names(Tropheus.IK.coord) == "X1"):which(names(Tropheus.IK.coord) == "Y19")
proc.coord <- as.matrix(Tropheus.IK.coord[coords])

# Pooled within-group covariance matrix for all populations (weighted by sample size)
W <- cov.W(proc.coord, groups = Tropheus.IK.coord$POP.ID, weighted = TRUE)

# Pooled within-group covariance matrix for all populations (unweighted)
W <- cov.W(proc.coord, groups = Tropheus.IK.coord$POP.ID)

# Within-group covariance matrix for all populations, pooled by sex
W.mf <- cov.W(proc.coord, groups = Tropheus.IK.coord$POP.ID, sex = Tropheus.IK.coord$Sex)

vcvComp documentation built on Dec. 17, 2020, 9:07 a.m.