R/cluster_alg.R

Defines functions cluster_alg

Documented in cluster_alg

#' Clustering Method for ClusterCV
#'
#' This function is used in ClusterCVMain to implement the clustering method
#' that is specified in input of the function.
#'
#' @param alg - algorithm selected in the ClusterCVMain or ClusterCV input
#' @param train_sub - training sub-matrix
#' @param i - current number of clusters
#' @return cluster assignment for each observation of the training sub-matrix
#'
#' @import stats kernlab
#'
#' @export
cluster_alg<-function(alg, train_sub, i){

  # Run kmneans, in specified
  # Else, run spectral
  if(alg=="k.means"){

    train.k <- stats::kmeans(train_sub, centers=i)
    clust <- train.k$cluster

  }
  else if(alg=="spectral"){

    train_mat <- as.matrix(train_sub)
    train.k <- kernlab::specc(train_mat,centers=i)
    clust <- train.k@.Data
  }

  # Return cluster assignments
  return(clust)

}
pangoria/clusterEstimation documentation built on Dec. 22, 2021, 6:39 a.m.