# \donttest{
### Example starts ###
library(mvMORPH)
set.seed(2508)
# Loading the data
data(phyllostomid)
phyllos_data = phyllostomid$mandible[,-1]
phyllos_tree = phyllostomid$tree
# Perfoming the P3CA on the complete dataset - Analytical solution
p3ca_phyllos = p3ca(phyllos_data, phyllos_tree, q=5, model='lambda')
p3ca_phyllos$logLik
p3ca_phyllos$par
# Dataset including missing values
id_for_nas = sample(1:length(phyllos_data),100)
phyllos_data_nas = phyllos_data
phyllos_data_nas[id_for_nas]=NA
# Perfoming the P3CA on the incomplete dataset - EM algorithm
p3ca_phyllos_nas = p3ca(phyllos_data_nas, phyllos_tree, q=5, model='lambda')
p3ca_phyllos_nas$logLik
p3ca_phyllos_nas$par
# Visualising and comparing the reduced spaces (by hand) obtained on the
# original and imputed datasets
par(mfrow=c(1,2))
axes=1:2
plot(p3ca_phyllos$scores[,axes], pch=19, col=c('dodgerblue3','forestgreen')[phyllostomid$grp1],
xlab = paste('P3C',axes[1],' ',round(p3ca_phyllos$varExp[axes[1]],1),'%', sep=''),
ylab = paste('P3C',axes[2],' ',round(p3ca_phyllos$varExp[axes[2]],1),'%', sep=''),
main = paste('P3CA (AS) - ', p3ca_phyllos$model, ' ',
round(p3ca_phyllos$par,1), sep=''))
plot(p3ca_phyllos_nas$scores[,axes], pch=19, col=c('dodgerblue3','forestgreen')[phyllostomid$grp1],
xlab = paste('P3C',axes[1],' ',round(p3ca_phyllos_nas$varExp[axes[1]],1),'%', sep=''),
ylab = paste('P3C',axes[2],' ',round(p3ca_phyllos_nas$varExp[axes[2]],1),'%', sep=''),
main = paste('P3CA (EM) - ', p3ca_phyllos_nas$model, ' ',
round(p3ca_phyllos_nas$par,1), sep=''))
# We can also visualize the shapes changes along PCs using "pcaShape"
proj_shape <- pcaShape(p3ca_phyllos, axis=1, ndim=2, spp="Ametrida", plot=TRUE)
polygon(proj_shape$Ametrida)
### Example ends ###
# }
Run the code above in your browser using DataLab