#'@title Optimum number of covariates used as environmental markers
#'
#' @description Optimizes environmental variables matrix using PCA algorithms and Hierarchical Clustering
#' @author Germano Martins F Costa Neto <germano.cneto@usp.br>
#' @param .dfcov Kernel of environmental covariates (see envK function)
#' @param .size number of covariates per group
#' @param res.hcpc if TRUE perform the hierachical clustering
#' @importFrom FactoMineR PCA
#' @importFrom FactoMineR HCPC
#' @seealso envK
#' @seealso envKernel
OtimCov = function(.dfcov,.size=1,res.hcpc=TRUE){
oticv<-c()
Ws.red <- FactoMineR::PCA(t(.dfcov))
Ws.red <- FactoMineR::HCPC(Ws.red,consol = T,graph = F)
A<-Ws.red$call$X$clust
for(i in 1:nlevels(A)){
line<-sample(1:dim(Ws.red$call$X[Ws.red$call$X$clust == levels(A)[i],])[1], size = .size, replace = FALSE)
oticv<-rbind(oticv,rownames(Ws.red$call$X[Ws.red$call$X$clust == levels(A)[i],])[line])
}
COV <- data.frame(cov=oticv)
if(res.hcpc == TRUE){
return(list(res.hcpc = Ws.red, newCov=.dfcov[,match(COV$cov,colnames(.dfcov))]))
}
if(res.hcpc == FALSE){
return(.dfcov[,match(COV$cov,colnames(.dfcov))])
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.