# R Package `mixAK`

## Arnošt Komárek

## This page

Papers related to the package | Supplementary materials and vignettes | Density estimation via normal mixtures (and MCMC) | Multivariate GLMM's with a normal mixture in the distribution of random effects | Supporting functions to further process or visualize results from running NMixMCMC or GLMM_MCMC functions | Univariate distributions | Multivariate distributions | Miscellaneous random number generation | Matrix linear algebra | Basic statistics | Utilities | Datasets |

This package contains a mixture of statistical methods including the MCMC methods to analyze normal mixtures.

This overview provides a sorted list of the functions of the package and links to few more involved examples. Methods implemented in the package could be classified into following areas.

- Density estimation via normal mixtures (and MCMC)
- Multivariate generalized linear mixed models with a normal mixture in the distribution of random effects
- Supporting functions to further process or visualize results from running NMixMCMC or GLMM_MCMC functions
- Univariate distributions
- Multivariate distributions
- Miscellaneous random number generation
- Matrix linear algebra
- Basic statistics
- Utilities
- Datasets

# Papers related to the package

Please, cite either of the following papers if you find the package useful.

- Komárek, A. and Komárková, L. (2014). Capabilities of R package mixAK for clustering based on multivariate continuous and discrete longitudinal data. Journal of Statistical Software, 59(12), 1–38, doi: 10.18637/jss.v059.i12.
  - Paper describing the implementation of the clustering based on multivariate longitudinal data using multivariate generalized linear mixed models with a normal mixture in the distribution of random effects.
- Komárek, A. (2009). A new R package for Bayesian estimation of multivariate normal mixtures allowing for selection of the number of components and interval-censored data. Computational Statistics and Data Analysis, 53(12), 3932–3947, doi: 10.1016/j.csda.2009.05.006.
  - Paper describing the methods related to density estimation via normal mixtures and MCMC.
- Komárek, A. and Komárková, L. (2013). Clustering for multivariate continuous and discrete longitudinal data. The Annals of Applied Statistics, 7(1), 177–200, doi: 10.1214/12-AOAS580.
  - Paper describing the methods related to cluster analysis for multivariate longitudinal or grouped data continuous and discrete data based on multivariate generalized linear mixed models with a normal mixture in the distribution of random effects.
- Komárek, A., Hansen, B. E., Kuiper, E. M. M., van Buuren, H. R., and Lesaffre, E. (2010). Discriminant analysis using a multivariate linear mixed model with a normal mixture in the random effects distribution. Statistics in Medicine, 29(30), 3267–3283, doi: 10.1002/sim.3849.
  - Paper describing the methods related to discriminant analysis for multivariate longitudinal or grouped data continuous data based on multivariate linear mixed models with a normal mixture in the distribution of random effects.

# Supplementary materials and vignettes

- Komarek-NMix-supplement.pdf
  Supplement to Komárek (2009) which includes some technical details not included in the main paper.
- Galaxy.pdf, Galaxy.R
  R example of 1-dimensional density estimation using the RJ-MCMC described in Section 6.1 of Komárek (2009).
- Faithful.pdf, Faithful.R
  R example of 2-dimensional density estimation described in Section 6.2 of Komárek (2009).
- Tandmob.pdf, Tandmob.R
  R example of 6-dimensional density estimation with interval-censored data described in Section 6.3 of Komárek (2009).
- PBCseq.pdf, PBCseq.R
  This is an extended version of a paper Komárek and Komárková (2014) and the related R code.

# 1. Density estimation via normal mixtures (and MCMC)

NMixMCMC | MCMC estimation of (multivariate) normal mixtures with possibly censored data
| There exists a print method for objects of class NMixMCMC.
NMixEM | EM algorithm for a homoscedastic normal mixture
| There exists a print method for objects of class NMixEM.
NMixChainsDerived | Create MCMC chains derived from previously sampled values
NMixPredDA | Discriminant analysis based on MCMC output from the mixture model
NMixPlugDA | Discriminant analysis based on plug-in estimates from the mixture model

# 2. Multivariate generalized linear mixed models with a normal mixture in the distribution of random effects

GLMM_MCMC | MCMC estimation of a (multivariate) generalized linear mixed model with a normal mixture in the distribution of random effects
| There exists a print and fitted method for objects of class GLMM_MCMC.
GLMM_longitDA | Discriminant analysis for longitudinal profiles based on fitted GLMM's

# 3. Supporting functions to further process or visualize results from running NMixMCMC or GLMM_MCMC functions

The following functions are generic with default method and a method for objects of class NMixMCMC and GLMM_MCMC implemented.

NMixRelabel | Re-labeling the MCMC output of the mixture model
NMixSummComp | Summary for the mixture components
tracePlots | Traceplots for selected parameters
NMixPredDensJoint2 | Pairwise bivariate predictive density
| There is also a plot method for objects of class NMixPredDensJoint2.
NMixPlugDensJoint2 | Pairwise bivariate densities: plug-in estimate
| There is also a plot method for objects of class NMixPlugDensJoint2.
NMixPredCondDensJoint2 | Pairwise bivariate conditional predictive densities
| There is also a plot method for objects of class NMixPredCondDensJoint2.
NMixPlugCondDensJoint2 | Pairwise bivariate conditional densities: plug-in estimate
| There is also a plot method for objects of class NMixPlugCondDensJoint2.
NMixPredDensMarg | Marginal (univariate) predictive density
| There is also a plot method for objects of class NMixPredDensMarg.
NMixPlugDensMarg | Marginal (univariate) densities: plug-in estimate
| There is also a plot method for objects of class NMixPlugDensMarg.
NMixPredCDFMarg | Marginal (univariate) predictive cumulative distribution function
| There is also a plot method for objects of class NMixPredCDFMarg.
NMixPredCondDensMarg | Univariate conditional predictive density
| There is also a plot method for objects of class NMixPredCondDensMarg.
NMixPlugCondDensMarg | Univariate conditional densities: plug-in estimate
| There is also a plot method for objects of class NMixPlugCondDensMarg.

Additionally, the following functions are available.

Y2T | Transform fitted distribution of Y=trans(T) into distribution of T
| This is a generic function with default method to transform a fitted distribution of Y = trans(T) into a distribution of T = itrans(Y).
| There are methods for objects of class NMixPredDensMarg, NMixPlugDensMarg, NMixPredCDFMarg, NMixPredDensJoint2, NMixPlugDensJoint2, NMixPredCondDensMarg, NMixPlugCondDensMarg, NMixPredCondDensJoint2, NMixPlugCondDensJoint2.
summaryDiff | Posterior summary statistics for a difference of two quantities

# 4. Univariate distributions

rTNorm | Random number generation from a truncated normal distribution

# 5. Multivariate distributions

dMVN, rMVN, rcMVN | (Log-)density and random number genaration for a multivariate normal distribution
rTMVN | Random number genaration from a truncated multivariate normal distribution
dMVNmixture, dMVNmixture2, rMVNmixture, rMVNmixture2 | (Log-)density and random number genaration for a mixture of (multivariate) normal distributions
dWISHART, rWISHART | (Log-)density and random number genaration for a Wishart distribution
rDirichlet | Random number genaration from a Dirichlet distribution

# 6. Miscellaneous random number generation

rRotationMatrix | Random rotation matrix
rSamplePair | Sample a pair (with replacement)

# 7. Matrix linear algebra

MatMPpinv | Moore-Penrose pseudoinverse of a squared matrix
MatSqrt | Square root of a matrix

# 8. Basic statistics

BLA | Best linear approximation with respect to the mean square error (theoretical linear regression)

# 9. Utilities

getProfiles | Individual longitudinal profiles of a given variable
plotProfiles | Plot individual longitudinal profiles
BsBasis | B-spline basis
generatePermutations | Generate all permutations of (1, ..., K)
SP2Rect | Conversion of a symmetric matrix stored in a packed format (lower triangle only) into a matrix
autolayout | Automatic layout for several plots in one figure
cbplot | Plot a function together with its confidence/credible bands

# 10. Datasets

Acidity | Acidity index of lakes in North-Central Wisconsin
| Acidity index measured in a sample of 155 lakes in North-Central Wisconsin.
Enzyme | Enzymatic activity in the blood
| Enzymatic activity in the blood, for an enzyme involved in the metabolism of carcinogenic substances, among a group of 245 unrelated individuals.
Faithful | Old Faithful Geyser Data
| Waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park, Wyoming, USA, version used in Härdle (1991).
Galaxy | Velocities of distant galaxies
| Velocities of 82 distant galaxies, diverging from our own galaxy.
PBCseq | Mayo Clinic Primary Biliary Cholangitis (Cirrhosis), sequential data
PBC910 | Mayo Clinic Primary Biliary Cholangitis (Cirrhosis), sequential data (subset)
| Subset of PBC data used in Komárek, A. and Komárková, L. (2013) and in Komárek, A. and Komárková, L. (2014).
Tandmob | Signal Tandmobiel data
| Dental (Signal Tandmobiel) data for 4430 6-12 year old children
TandmobEmer | Signal Tandmobiel data - emergence times
| Data derived from Tandmob.