zarquon42b / Morpho

R-package providing a toolset for (3D-based) Geometric Morphometrics
51 stars 16 forks source link

getPCscores fails with sizeshape=TRUE #21

Open daskandalis opened 3 years ago

daskandalis commented 3 years ago

Expected behaviour: Expected PC scores from aligned data, but this fails when sizeshape=TRUE.

library(Morpho)
data(boneData)
proc <- procSym(boneLM[,,-c(1:2)], sizeshape=TRUE)
newdata <- boneLM[,,c(1:2)]
newdataAlign <- align2procSym(proc,newdata)
scores <- getPCscores(newdataAlign,proc$PCs,proc$mshape)
zarquon42b commented 3 years ago

Hi, sorry for my very very belated answer. If you select sizeshape=T, then the first entry in the PC-scores captures the variability of the log transformed CS. In that case you will need to process the logCS separately: usinig your example, you can do this like:

x <- newdataAlign
x <- sweep(x,1:2,proc$mshape)
size <- log(apply(newdata,3,cSize))
meanLogCS <- mean(log(proc$size))
size <- size-meanLogCS
x <- vecx(x)
x <- cbind(size,x)
scores <- x%*%(proc$PCs)

You will get some distortions though because the scaling in full PCA is based on a sample wide optimization of size. When you do this post-hoc, your results can deviate (slightly).