### Install clustMD Package Source: https://cran.r-project.org/web/packages/clustMD/readme/README.html Install the clustMD package from CRAN. This is the first step before using any of its functions. ```r install.packages("clustMD") ``` -------------------------------- ### Prepare and Cluster Mixed Data with clustMD Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html This example demonstrates data preparation steps including transformation, ordering, and standardization, followed by fitting a mixed data clustering model using the clustMD function. Ensure data is correctly formatted and variable types are specified. ```R data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg ## Not run: res <- clustMD(X = Y, G = 3, CnsIndx = 8, OrdIndx = 11, Nnorms = 20000, MaxIter = 500, model = "EVI", store.params = FALSE, scale = TRUE, startCL = "kmeans", autoStop= TRUE, ma.band=30, stop.tol=0.0001) ``` -------------------------------- ### Fit clustMD model with a list of arguments Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Use clustMDlist when you have prepared all arguments for the clustMD function as a list. This is a wrapper function for clustMD. ```R data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg argList <- list(X=Y, G=3, CnsIndx=8, OrdIndx=11, Nnorms=20000, MaxIter=500, model="EVI", store.params=FALSE, scale=TRUE, startCL="kmeans", autoStop=FALSE, ma.band=50, stop.tol=NA) ## Not run: res <- clustMDlist(argList) ``` -------------------------------- ### M.step Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Performs the M-step of the (MC)EM algorithm. This is an internal function. ```APIDOC ## M-step of the (MC)EM algorithm ### Description Internal function. ### Usage ``` M.step( tau, N, sumTauEz, J, OrdIndx, D, G, Y, CnsIndx, sumTauS, model, a, nom.ind.Z ) ``` ### Arguments `tau` | a `N x G` matrix of cluster membership probabilities. `N` | number of observations. `sumTauEz` | the sum across all observations of observed and expected latent continuous values mutiplied by the posterior probability of belonging to each cluster. `J` | the number of variables. `OrdIndx` | the sum of the number of continuous and ordinal (including binary) variables. `D` | dimension of the latent data. `G` | the number of mixture components. `Y` | a `N x J` data matrix. `CnsIndx` | the number of continuous variables. `sumTauS` | the sum across all observations of outer product of observed and expected latent continuous values mutiplied by the posterior probability of belonging to each cluster. `model` | which `clustMD` covariance model is fitted. `a` | a `G x D` matrix of the entries of A. `nom.ind.Z` | the latent dimensions corresponding to each nominal variable. ### Value Output required for `clustMD` function. ``` -------------------------------- ### Calculate Mode of a Sample Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Computes the mode of a given sample. If there are multiple modes (a tie), the function returns the minimum value among them. ```R modal.value(x) ``` -------------------------------- ### Print method for clustMD objects Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Prints a concise summary of a clustMD object, including the number of clusters, covariance model, and estimated BIC. ```R print(x, ...) ``` -------------------------------- ### M-step of the (MC)EM algorithm Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function for the M-step of the (MC)EM algorithm. Used within the clustMD function. ```R M.step( tau, N, sumTauEz, J, OrdIndx, D, G, Y, CnsIndx, sumTauS, model, a, nom.ind.Z ) ``` -------------------------------- ### Summary for clustMD objects Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Prints a summary of a 'clustMD' object, detailing cluster counts, covariance models, BIC, cluster observations, and cluster means. ```R summary(object, ...) ``` -------------------------------- ### Plotting method for clustMD objects Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Generates graphical summaries for a fitted clustMD object. Includes plots of cluster means, variances/covariance matrices, and clustering uncertainties. ```R plot(x, ...) ``` -------------------------------- ### Fit Parallel Clustering Models with clustMDparallel Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Use this function to fit multiple clustering models in parallel for mixed data. It requires data preprocessing, including standardization and potential category merging. The `models` argument specifies which covariance structures to fit. ```R data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg ## Not run: res <- clustMDparallel(X = Y, G = 1:3, CnsIndx = 8, OrdIndx = 11, Nnorms = 20000, MaxIter = 500, models = c("EVI", "EII", "VII"), store.params = FALSE, scale = TRUE, startCL = "kmeans", autoStop= TRUE, ma.band=30, stop.tol=0.0001) res$BICarray ## End(Not run) ``` -------------------------------- ### Approximate Observed Log Likelihood Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Approximates the observed log likelihood for the clustMD model. Requires various parameters related to data, model, and cluster components. ```R ObsLogLikelihood( N, CnsIndx, G, Y, mu, Sigma, pi.vec, patt.indx, zlimits, J, OrdIndx, probs.nom, model, perc.cut, K ) ``` -------------------------------- ### ObsLogLikelihood Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Approximates the observed log likelihood. This is an internal function. ```APIDOC ## Approximates the observed log likelihood. ### Description Approximates the observed log likelihood. ### Usage ``` ObsLogLikelihood( N, CnsIndx, G, Y, mu, Sigma, pi.vec, patt.indx, zlimits, J, OrdIndx, probs.nom, model, perc.cut, K ) ``` ### Arguments `N` | the number of observations. `CnsIndx` | the number of continuous variables. `G` | the number of mixture components. `Y` | an `N x J` data matrix. `mu` | a `D x G` matrix of means. `Sigma` | a `D x D x G` array of covariance parameters. `pi.vec` | the mixing weights. `patt.indx` | a list of length equal to the number of observed response patterns. Each entry of the list details the observations for which that response pattern was observed. `zlimits` | the truncation points for the latent data. `J` | the number of variables. `OrdIndx` | the sum of the number of continuous and ordinal (including binary) variables. `probs.nom` | an array containing the response probabilities for each nominal variable for each cluster `model` | the covariance model fitted to the data. `perc.cut` | threshold parameters. `K` | the number of levels for each variable. ### Value Output required for `clustMD` function. ``` -------------------------------- ### clustMDlist Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Fits the clustMD model to a dataset with mixed data types by accepting arguments as a list. This function is a wrapper for the main `clustMD` function. ```APIDOC ## clustMDlist ### Description A function that fits the clustMD model to a data set consisting of any combination of continuous, binary, ordinal and nominal variables. This function is a wrapper for `clustMD` that takes arguments as a list. ### Usage ```R clustMDlist(arglist) ``` ### Arguments `arglist` | a list of input arguments for `clustMD`. See `clustMD`. ### Value A `clustMD` object. See `clustMD`. ### References McParland, D. and Gormley, I.C. (2016). Model based clustering for mixed data: clustMD. Advances in Data Analysis and Classification, 10 (2):155-169. ### See Also `clustMD` ### Examples ```R data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg argList <- list(X=Y, G=3, CnsIndx=8, OrdIndx=11, Nnorms=20000, MaxIter=500, model="EVI", store.params=FALSE, scale=TRUE, startCL="kmeans", autoStop=FALSE, ma.band=50, stop.tol=NA) ## Not run: res <- clustMDlist(argList) ## End(Not run) ``` ``` -------------------------------- ### Perform Model Based Clustering with clustMD() Source: https://cran.r-project.org/web/packages/clustMD/readme/README.html Cluster the Byar dataset using the `clustMD()` function. This involves data preprocessing steps like transforming skewed variables, ordering variables, adjusting categorical variable indexing, standardizing continuous variables, and merging categories for efficiency. Use this function for single model fitting. ```r data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg res <- clustMD(X=Y, G=3, CnsIndx=8, OrdIndx=11, Nnorms=20000, MaxIter=500, model="EVI", store.params=FALSE, scale=TRUE, startCL="kmeans") ``` -------------------------------- ### Calculate latent data moments (general) Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function to calculate the first and second moments of latent data. Requires extensive parameters defining data dimensions, mixture components, and model specifications. ```R z.moments( D, G, N, CnsIndx, OrdIndx, zlimits, mu, Sigma, Y, J, K, norms, nom.ind.Z, patt.indx ) ``` -------------------------------- ### Run Multiple Models in Parallel with clustMDparallel() Source: https://cran.r-project.org/web/packages/clustMD/readme/README.html Fit multiple clustering models in parallel using `clustMDparallel()`. This function takes a range of cluster numbers and a vector of covariance models to fit. It is useful for exploring different model configurations and selecting the optimal one based on BIC. ```r data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg res <- clustMDparallel(X=Y, G=1:3, CnsIndx=8, OrdIndx=11, Nnorms=20000, MaxIter=500, models=c("EVI", "EII", "VII"), store.params=FALSE, scale=TRUE, startCL="kmeans") ``` -------------------------------- ### E-step Function for EM Algorithm Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function for the Expectation-step of the (MC)EM algorithm. It requires numerous parameters related to data, model structure, and current estimates. ```r E.step( N, G, D, CnsIndx, OrdIndx, zlimits, mu, Sigma, Y, J, K, norms, nom.ind.Z, patt.indx, pi.vec, model, perc.cut ) ``` -------------------------------- ### Mean and Covariance of Truncated Multivariate Normal Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Calculates the mean and covariance matrix of a truncated multivariate normal distribution. It follows the method proposed by Kan & Robotti (2016) and requires lower and upper thresholds, along with the untruncated distribution's mean and covariance matrix. ```R dtmvnom(a, b, mu, S) ``` -------------------------------- ### Load Byar Prostate Cancer Data Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html This code snippet loads the 'Byar' dataset, which contains mixed-type variables for prostate cancer patients. Use this dataset for practicing or demonstrating clustering on mixed data. ```r Byar ``` -------------------------------- ### Calculate latent data moments (diagonal models) Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function for calculating latent data moments specifically for diagonal covariance models. It requires parameters similar to z.moments but is optimized for diagonal structures. ```R z.moments_diag( D, G, N, CnsIndx, OrdIndx, zlimits, mu, Sigma, Y, J, K, norms, nom.ind.Z ) ``` -------------------------------- ### dtmvnom Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Calculates the mean and covariance matrix of a truncated multivariate normal distribution, following the method proposed by Kan & Robotti (2016). ```APIDOC ## dtmvnom ### Description This function returns the mean and covariance matrix of a truncated multivariate normal distribution. It takes as inputs a vector of lower thresholds and another of upper thresholds along with the mean and covariance matrix of the untruncated distribution. This function follows the method proposed by Kan & Robotti (2016). ### Usage ```R dtmvnom(a, b, mu, S) ``` ### Arguments a | a vector of lower thresholds. ---|--- b | a vector of upper thresholds. mu | the mean of the untruncated distribution. S | the covariance matrix of the untruncated distribution. ### Value Returns a list of two elements. The first element, `tmean`, is the mean of the truncated multivariate normal distribution. The second element, `tvar`, is the covariance matrix of the truncated distribution. ``` -------------------------------- ### Model Based Clustering for Mixed Data Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Fits the clustMD model to a dataset with mixed variable types (continuous, binary, ordinal, nominal). Offers various options for model fitting and convergence. ```R clustMD( X, G, CnsIndx, OrdIndx, Nnorms, MaxIter, model, store.params = FALSE, scale = FALSE, startCL = "hc_mclust", autoStop = FALSE, ma.band = 50, stop.tol = NA ) ``` -------------------------------- ### Transform simulated data to categorical and calculate moments Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function that transforms Monte Carlo simulated latent data into categorical data and calculates the empirical moments of this latent data given the categorical responses. ```R z.nom.diag(Z) ``` -------------------------------- ### Stable computation of the log of a sum Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Computes the log of the sum of elements in a numeric vector using log-scale calculations for numerical stability. ```R stable.probs(s) ``` -------------------------------- ### Calculate threshold parameters for ordinal variables Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Calculates threshold parameters for ordinal variables. This internal function is required for the clustMD function and takes the number of continuous and ordinal variables, the data matrix, and the number of observations as input. ```R perc.cutoffs(CnsIndx, OrdIndx, Y, N) ``` -------------------------------- ### Helper internal function for dtmvnom Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal helper function for the dtmvnom function, used in calculations involving truncated multivariate normal distributions. It computes values based on lower and upper thresholds and the covariance matrix. ```R qfun(a, b, S) ``` -------------------------------- ### Plot Parallel Coordinates for clustMD Output Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Generates a parallel coordinates plot for visualizing cluster results from `clustMD` output. This function adapts the `parcoord` function from the `MASS` library. ```R clustMDparcoord( x, col = 1, xlabels = NULL, lty = 1, var.label = FALSE, xlab = "", ylab = "", ... ) ``` -------------------------------- ### Check if response patterns are equal Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Checks if two numeric vectors are identical. Returns TRUE if they are exactly the same, and FALSE otherwise. Used internally within the clustMD function. ```R patt.equal(x, patt) ``` -------------------------------- ### modal.value Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Calculates the mode (most frequent value) of a given sample vector. Returns the minimum value in case of ties. ```APIDOC ## modal.value ### Description Calculate the mode of a sample ### Usage ```R modal.value(x) ``` ### Arguments x | a vector containing the sample values. ---|--- ### Value The mode of the sample. In the case of a tie, the minimum is returned. ``` -------------------------------- ### clustMD Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Fits a model-based clustering model to a dataset containing a mix of continuous, binary, ordinal, and nominal variables. ```APIDOC ## clustMD ### Description A function that fits the clustMD model to a data set consisting of any combination of continuous, binary, ordinal and nominal variables. ### Usage ``` clustMD( X, G, CnsIndx, OrdIndx, Nnorms, MaxIter, model, store.params = FALSE, scale = FALSE, startCL = "hc_mclust", autoStop = FALSE, ma.band = 50, stop.tol = NA ) ``` ### Arguments `X` | The input data matrix. `G` | number of mixture components. `CnsIndx` | the number of continuous variables. `OrdIndx` | the sum of the number of continuous and ordinal (including binary) variables. `Nnorms` | number of standard normal deviates. `MaxIter` | maximum number of iterations. `model` | the covariance model fitted to the data. `store.params` | logical, whether to store parameters. `scale` | logical, whether to scale the data. `startCL` | method for starting cluster assignments. `autoStop` | logical, whether to use automatic stopping criteria. `ma.band` | bandwidth for moving average. `stop.tol` | tolerance for stopping criterion. ### Value Output required for clustMD function. ``` -------------------------------- ### Calculate outer product of a vector Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Calculates the outer product of a numeric vector with itself. This is an internal utility function. ```R vec.outer(x) ``` -------------------------------- ### clustMDparallel Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Runs multiple clustMD models in parallel, allowing specification of different numbers of components (G) and covariance models. It can automatically detect or be manually set to use a specific number of CPU cores. ```APIDOC ## Run multiple clustMD models in parallel ### Description This function allows the user to run multiple clustMD models in parallel. The inputs are similar to `clustMD()` except `G` is now a vector containing the the numbers of components the user would like to fit and `models` is a vector of strings indicating the covariance models the user would like to fit for each element of G. The user can specify the number of cores to be used or let the function detect the number available. ### Usage ```R clustMDparallel( X, CnsIndx, OrdIndx, G, models, Nnorms, MaxIter, store.params, scale, startCL = "hc_mclust", Ncores = NULL, autoStop = FALSE, ma.band = 50, stop.tol = NA ) ``` ### Arguments `X` | a data matrix where the variables are ordered so that the continuous variables come first, the binary (coded 1 and 2) and ordinal variables (coded 1, 2,...) come second and the nominal variables (coded 1, 2,...) are in last position. `CnsIndx` | the number of continuous variables in the data set. `OrdIndx` | the sum of the number of continuous, binary and ordinal variables in the data set. `G` | a vector containing the numbers of mixture components to be fitted. `models` | a vector of strings indicating which clustMD models are to be fitted. This may be one of: `EII, VII, EEI, VEI, EVI, VVI` or `BD`. `Nnorms` | the number of Monte Carlo samples to be used for the intractable E-step in the presence of nominal data. `MaxIter` | the maximum number of iterations for which the (MC)EM algorithm should run. `store.params` | a logical variable indicating if the parameter estimates at each iteration should be saved and returned by the `clustMD` function. `scale` | a logical variable indicating if the continuous variables should be standardised. `startCL` | a string indicating which clustering method should be used to initialise the (MC)EM algorithm. This may be one of "kmeans" (K means clustering), "hclust" (hierarchical clustering), "mclust" (finite mixture of Gaussian distributions), "hc_mclust" (model-based hierarchical clustering) or "random" (random cluster allocation). `Ncores` | the number of cores the user would like to use. Must be less than or equal to the number of cores available. `autoStop` | a logical argument indicating whether the (MC)EM algorithm should use a stopping criterion to decide if convergence has been reached. Otherwise the algorithm will run for `MaxIter` iterations. If only continuous variables are present the algorithm will use Aitken's acceleration criterion with tolerance `stop.tol`. If categorical variables are present, the stopping criterion is based on a moving average of the approximated log likelihood values. let $t$ denote the current interation. The average of the `ma.band` most recent approximated log likelihood values is compared to the average of another `ma.band` iterations with a lag of 10 iterations. If this difference is less than the tolerance the algorithm will be said to have converged. `ma.band` | the number of iterations to be included in the moving average stopping criterion. `stop.tol` | the tolerance of the (MC)EM stopping criterion. ``` -------------------------------- ### Extract Specific Model Output from clustMDparallel Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Retrieves the output for a specific covariance model and number of clusters from a `clustMDparallel` object. If the requested model is not found, an error is returned. ```R getOutput_clustMDparallel(resParallel, nClus, covModel) ``` -------------------------------- ### clustMD Function Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html The clustMD function fits a model-based clustering algorithm to mixed data types. It supports various covariance models and initialization methods. ```APIDOC ## clustMD Function ### Description Fits a model-based clustering algorithm to mixed data types, supporting various covariance models and initialization methods. ### Arguments - **X** (data matrix) - Required - A data matrix where variables are ordered: continuous first, then binary (coded 1 and 2), ordinal (coded 1, 2, ...), and finally nominal (coded 1, 2, ...). - **G** (integer) - Required - The number of mixture components (clusters) to be fitted. - **CnsIndx** (integer) - Required - The number of continuous variables in the data set. - **OrdIndx** (integer) - Required - The sum of the number of continuous, binary, and ordinal variables in the data set. - **Nnorms** (integer) - Optional - The number of Monte Carlo samples for the E-step in the presence of nominal data. Irrelevant if no nominal variables exist. - **MaxIter** (integer) - Optional - The maximum number of iterations for the (MC)EM algorithm. - **model** (string) - Optional - The covariance model to fit. Options: `EII, VII, EEI, VEI, EVI, VVI, BD`. - **store.params** (logical) - Optional - If TRUE, parameter estimates at each iteration are saved and returned. - **scale** (logical) - Optional - If TRUE, continuous variables are standardized. - **startCL** (string) - Optional - The clustering method for initializing the (MC)EM algorithm. Options: `kmeans`, `hclust`, `mclust`, `hc_mclust`, `random`. - **autoStop** (logical) - Optional - If TRUE, uses a stopping criterion for the (MC)EM algorithm. If FALSE, runs for `MaxIter` iterations. For continuous-only data, uses Aitken's acceleration criterion with `stop.tol`. For mixed data, uses a moving average of log-likelihood values. - **ma.band** (integer) - Optional - The number of iterations for the moving average calculation in the stopping criterion. - **stop.tol** (numeric) - Optional - The tolerance for the (MC)EM stopping criterion. ### Value An object of class `clustMD` containing: - **model** (string) - The covariance model fitted. - **G** (integer) - The number of clusters fitted. - **Y** (matrix) - The observed data matrix. - **cl** (vector) - The cluster assignment for each observation. - **tau** (matrix) - Probabilities of each observation belonging to each cluster. - **means** (matrix) - Cluster means. - **A** (matrix) - Diagonal entries of the A matrix for each cluster. - **Lambda** (matrix) - Volume parameters for each dimension and cluster. - **Sigma** (array) - Covariance matrices for each cluster. - **BIChat** (numeric) - Estimated Bayesian information criterion. - **ICLhat** (numeric) - Estimated integrated classification likelihood criterion. - **paramlist** (list) - If `store.params` is TRUE, contains stored parameter values and likelihoods. - **Varnames** (vector) - Names of the columns of `Y`. - **Varnames_sht** (vector) - Truncated version of `Varnames`. - **likelihood.store** (vector) - Estimated log likelihood at each iteration. ### References McParland, D. and Gormley, I.C. (2016). Model based clustering for mixed data: clustMD. Advances in Data Analysis and Classification, 10 (2):155-169. ### Example ```R data(Byar) # Transformation skewed variables Byar$Size.of.primary.tumour <- sqrt(Byar$Size.of.primary.tumour) Byar$Serum.prostatic.acid.phosphatase <- log(Byar$Serum.prostatic.acid.phosphatase) # Order variables (Continuous, ordinal, nominal) Y <- as.matrix(Byar[, c(1, 2, 5, 6, 8, 9, 10, 11, 3, 4, 12, 7)]) # Start categorical variables at 1 rather than 0 Y[, 9:12] <- Y[, 9:12] + 1 # Standardise continuous variables Y[, 1:8] <- scale(Y[, 1:8]) # Merge categories of EKG variable for efficiency Yekg <- rep(NA, nrow(Y)) Yekg[Y[,12]==1] <- 1 Yekg[(Y[,12]==2)|(Y[,12]==3)|(Y[,12]==4)] <- 2 Yekg[(Y[,12]==5)|(Y[,12]==6)|(Y[,12]==7)] <- 3 Y[, 12] <- Yekg ## Not run: res <- clustMD(X = Y, G = 3, CnsIndx = 8, OrdIndx = 11, Nnorms = 20000, MaxIter = 500, model = "EVI", store.params = FALSE, scale = TRUE, startCL = "kmeans", autoStop= TRUE, ma.band=30, stop.tol=0.0001) ``` ``` -------------------------------- ### clustMDparcoord Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Produces a parallel coordinates plot adapted for `clustMD` output, visualizing cluster assignments and variable distributions. ```APIDOC ## clustMDparcoord ### Description Produces a parallel coordinates plot as `parcoord` in the `MASS` library with some minor adjustments. ### Usage ```R clustMDparcoord( x, col = 1, xlabels = NULL, lty = 1, var.label = FALSE, xlab = "", ylab = "", ... ) ``` ### Arguments x | a matrix or data frame who columns represent variables. Missing values are allowed. ---|--- col | a vector of colours, recycled as necessary for each observation. xlabels | a character vector of variable names for the x axis. lty | a vector of line types, recycled as necessary for each observation. var.label | if TRUE, each variable's axis is labelled with maximum and minimum values. xlab | label for the X axis. ylab | label for the Y axis. ... | further graphics parameters which are passed to `matplot`. ### Value A parallel coordinates plot is drawn with one line for each cluster. ``` -------------------------------- ### clustMDparallel Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Fits a mixture of multivariate normal distributions to data containing continuous, ordinal, and nominal variables. It allows for parallel computation to speed up the fitting process for multiple models. ```APIDOC ## clustMDparallel ### Description Fits a mixture of multivariate normal distributions to data containing continuous, ordinal, and nominal variables. It allows for parallel computation to speed up the fitting process for multiple models. ### Usage ```R clustMDparallel(X, G, CnsIndx, OrdIndx, Nnorms, MaxIter, models, store.params, scale, startCL, autoStop, ma.band, stop.tol) ``` ### Arguments X | A matrix or data frame containing the data to be clustered. Missing values are allowed. ---|--- G | An integer vector specifying the number of clusters to fit. CnsIndx | An integer vector indicating the indices of continuous variables. OrdIndx | An integer vector indicating the indices of ordinal variables. Nnorms | The number of normal distributions to use for approximating the density of each component. MaxIter | The maximum number of iterations for the EM algorithm. models | A character vector specifying the covariance models to fit (e.g., "EVI", "EII", "VII"). store.params | A logical value indicating whether to store the parameters of the fitted models. scale | A logical value indicating whether to scale the continuous variables. startCL | The method to use for initial cluster assignment (e.g., "kmeans"). autoStop | A logical value indicating whether to automatically stop the EM algorithm. ma.band | The bandwidth for the moving average filter used in autoStop. stop.tol | The tolerance for the stopping criterion of the EM algorithm. ### Value An object of class `clustMDparallel` containing the results of the fitted models, including BIC values and detailed model outputs. ``` -------------------------------- ### getOutput_clustMDparallel Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Extracts specific model output from a `clustMDparallel` object based on the number of clusters and covariance model. ```APIDOC ## getOutput_clustMDparallel ### Description This function takes a `clustMDparallel` object, a number of clusters and a covariance model as inputs. It then returns the output corresponding to that model. If the particular model is not contained in the `clustMDparallel` object then the function returns an error. ### Usage ```R getOutput_clustMDparallel(resParallel, nClus, covModel) ``` ### Arguments resParallel | a `clustMDparallel` object. ---|--- nClus | the number of clusters in the desired output. covModel | the covariance model of the desired output. ### Value A `clustMD` object containing the output for the relevant model. ``` -------------------------------- ### Internal function for clustMD covariance model Source: https://cran.r-project.org/web/packages/clustMD/refman/clustMD.html Internal function used to calculate parameters for the clustMD covariance model. Requires specification of latent data dimension, number of mixture components, variables, continuous variables, and categorical variable levels. ```R npars_clustMD(model, D, G, J, CnsIndx, OrdIndx, K) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.