Learn R Programming

Momocs (version 1.2.9)

mshapes: Mean shape calculation for Coo, Coe, etc.

Description

Quite a versatile function that calculates mean (or median, or whatever function) on list or an array of shapes, an Ldk object. It can also be used on OutCoe and OpnCoe objects. In that case, the reverse transformation (from coefficients to shapes) is calculated, (within groups defined with the fac argument if provided) and the Coe object is returned.

Usage

mshapes(x, ...)

# S3 method for list mshapes(x, FUN = mean, ...)

# S3 method for array mshapes(x, FUN = mean, ...)

# S3 method for Ldk mshapes(x, FUN = mean, ...)

# S3 method for OutCoe mshapes(x, fac, FUN = mean, nb.pts = 120, ...)

# S3 method for OpnCoe mshapes(x, fac, FUN = mean, nb.pts = 120, ...)

# S3 method for LdkCoe mshapes(x, fac, FUN = mean, ...)

# S3 method for PCA mshapes(x, fac, ...)

MSHAPES(x, ...)

Arguments

x

a list, array, Ldk, LdkCoe, OutCoe or OpnCoe or PCA object

...

useless here.

FUN

a function to compute the mean shape (mean by default, by median can be considered)

fac

factor from the $fac slot (only for Coe objects). See examples below.

nb.pts

numeric the number of points for calculated shapes (only Coe objects)

Value

the averaged shape; on Coe objects, a list with two components: $Coe object of the same class, and $shp a list of matrices of (x, y) coordinates.

Details

Note that on Coe objects, the average can be made within levels of the passed $fac (if any); in that case, the other columns of the fac are also returned, using the first row within every level, but they may not be representative of the group. Also notice that for PCA objects, mean scores are returned within a PCA object (accessible with PCA$x) that can be plotted directly but other slots are left unchanged.

See Also

Other multivariate: CLUST, KMEANS, LDA, MANOVA_PW, MANOVA, PCA, classification_metrics

Examples

Run this code
# NOT RUN {
#### on shapes
mshapes(wings)
mshapes(wings$coo)
mshapes(coo_sample(bot, 24)$coo)
stack(wings)
coo_draw(mshapes(wings))

bot.f <- efourier(bot, 12)
mshapes(bot.f) # the mean (global) shape
ms <- mshapes(bot.f, 'type')
ms$Coe
class(ms$Coe)
ms <- ms$shp
coo_plot(ms$beer)
coo_draw(ms$whisky, border='forestgreen')
tps_arr(ms$whisky, ms$beer) #etc.

op <- npoly(filter(olea, view=='VL'), 5)
ms <- mshapes(op, 'var') #etc
ms$Coe
panel(Opn(ms$shp), names=TRUE)

wp <- fgProcrustes(wings, tol=1e-4)
ms <- mshapes(wp, 1)
ms$Coe
panel(Ldk(ms$shp), names=TRUE) #etc.
panel(ms$Coe) # equivalent (except the $fac slot)
# }

Run the code above in your browser using DataLab