pb_basis {coda.base} | R Documentation |
Exact method to calculate the principal balances of a compositional dataset. Different methods to approximate the principal balances of a compositional dataset are also included.
pb_basis(X, method, rep = 0, ordering = TRUE, ...)
X |
compositional dataset |
method |
method to be used with Principal Balances. Methods available are: 'exact', 'lsearch' or method to be passed to hclust function (for example 'ward.D' or 'ward.D2' to use Ward method). |
rep |
Number of restartings to be used with the local search algorithm. If zero is supplied (default), one local search is performed using an starting point close to the principal component solution. |
ordering |
should the principal balances found be returned ordered? (first column, first principal balance and so on) |
... |
parameters passed to hclust function |
matrix
Pawlowsky-Glahn, V., Egozcue, J.J., Tolosana-Delgado R. (2011). Principal balances. in proceeding of the 4th International Workshop on Compositional Data Analysis (CODAWORK'11) (available online at http://www-ma3.upc.edu/users/ortego/codawork11-Proceedings/Admin/Files/FilePaper/p55.pdf)
set.seed(1) X = matrix(exp(rnorm(5*100)), nrow=100, ncol=5) # Optimal variance obtained with Principal components (v1 <- apply(coordinates(X, 'pc'), 2, var)) # Optimal variance obtained with Principal balances (v2 <- apply(coordinates(X,pb_basis(X, method='exact')), 2, var)) # Solution obtained using a hill climbing algorithm from pc approximation apply(coordinates(X,pb_basis(X, method='lsearch')), 2, var) # Solution obtained using a hill climbing algorithm using 10 restartings apply(coordinates(X,pb_basis(X, method='lsearch', rep=10)), 2, var) # Solution obtained using Ward method (v3 <- apply(coordinates(X,pb_basis(X, method='ward.D2')), 2, var)) # Solution obtained using Old Ward function (in R versions <= 3.0.3) apply(coordinates(X,pb_basis(X, method='ward.D')), 2, var) # Plotting the variances barplot(rbind(v1,v2,v3), beside = TRUE, legend = c('Principal Components','PB (Exact method)','PB (Ward approximation)'), names = paste0('Comp.', 1:4), args.legend = list(cex = 0.8), ylab = 'Variance')