Learn R Programming

Momocs (version 1.0.0)

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, ...)
"mshapes"(x, FUN = mean, ...)
"mshapes"(x, FUN = mean, ...)
"mshapes"(x, FUN = mean, ...)
"mshapes"(x, fac, FUN = mean, nb.pts = 120, ...)
"mshapes"(x, fac, FUN = mean, nb.pts = 120, ...)
"mshapes"(x, fac, FUN = mean, ...)
"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, usingthe first row within every level, but they may not be representive of the group. Also notice that for PCA objects, mean scores are returned within a PCA object (accesible with PCA$x) that can be plotted directly but other slots are left unchanged.

Examples

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

data(bot)
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.

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

data(wings)
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