Learn R Programming

⚠️There's a newer version (0.14.2) of this package.Take me there.

Multivariate Data Analysis Tools

mdatools is an R package for preprocessing, exploring and analysis of multivariate data. The package provides methods mostly common for Chemometrics. It was created for an introductory PhD course on Chemometrics given at Section of Chemical Engineering, Aalborg University. The general idea of the package is to collect most widespread chemometric methods and give a similar "user interface" (or rather API) for using them. So if a user knows how to make a model and visualize results for one method, he or she can easily do this for the others.

For more details and examples read a Bookdown tutorial. The project website, mda.tools, contains additional information about supplementary materials and tools.

You can also take video-lectures from YouTube channel devoted to introductory Chemometric course I give to master students. The lectures explain theory behind basic Chemometric methods but also show how to use them in mdatools.

If you want to cite the package, please use the following: Sergey Kucheryavskiy, mdatools – R package for chemometrics, Chemometrics and Intelligent Laboratory Systems, Volume 198, 2020 (DOI: 10.1016/j.chemolab.2020.103937).

What is new

Latest release (0.14.1, August 2023) is available both from GitHub and CRAN. You can see the full list of changes here. The Bookdown tutorial has been also updated and contains the description of new methods added in the last release.

How to install

The package is available on CRAN, to install it just use:

install.packages("mdatools")

This is the recommended way to install the package. If you have installed it already and just want to update to the newest version, use:

update.packages("mdatools")

If you want to install it directly from GitHub, the easiest way is to install the devtools package first and then run the following command in R:

devtools::install_github("svkucheryavski/mdatools")

Copy Link

Version

Install

install.packages('mdatools')

Monthly Downloads

993

Version

0.14.1

License

MIT + file LICENSE

Last Published

August 12th, 2023

Functions in mdatools (0.14.1)

as.matrix.regres

as.matrix method for regression results
as.matrix.simcamres

as.matrix method for SIMCAM results
as.matrix.classres

as.matrix method for classification results
as.matrix.plsdares

as.matrix method for PLS-DA results
as.matrix.ldecomp

as.matrix method for ldecomp object
carbs

Raman spectra of carbonhydrates
classify.plsda

PLS-DA classification
chisq.prob

Calculate probabilities for distance values using Chi-square distribution
as.matrix.simcares

as.matrix method for SIMCA classification results
as.matrix.regcoeffs

as.matrix method for regression coefficients class
as.matrix.plsres

as.matrix method for PLS results
capitalize

Capitalize text or vector with text values
categorize.pca

Categorize PCA results based on orthogonal and score distances.
constraintAngle

Method for angle constraint
categorize.pls

Categorize data rows based on PLS results and critical limits for total distance.
chisq.crit

Calculates critical limits for distance values using Chi-square distribution
crossval

Generate sequence of indices for cross-validation
confint.regcoeffs

Confidence intervals for regression coefficients
categorize

Categorize PCA results
crossval.getParams

Define parameters based on 'cv' value
classres

Results of classification
classres.getPerformance

Calculation of classification performance parameters
constraintClosure

Method for closure constraint
crossval.str

String with description of cross-validation method
dd.crit

Calculates critical limits for distance values using Data Driven moments approach
ellipse

Create ellipse on the current plot
constraints.list

Shows information about all implemented constraints
constraintUnimod

Method for unimodality constraint
employ.prep

Applies a list with preprocessing methods to a dataset
classmodel.processRefValues

Check reference class values and convert it to a factor if necessary
classify.simca

SIMCA classification
constraintNonNegativity

Method for non-negativity constraint
constraintNorm

Method for normalization constraint
getConfusionMatrix

Confusion matrix for classification results
getProbabilities

Get class belonging probability
constraint

Class for MCR-ALS constraint
getConfusionMatrix.classres

Confusion matrix for classification results
getProbabilities.pca

Probabilities for residual distances
ddmoments.param

Calculates critical limits for distance values using Data Driven moments approach
ddrobust.param

Calculates critical limits for distance values using Data Driven robust approach
crossval.simca

Cross-validation of a SIMCA model
crossval.regmodel

Cross-validation of a regression model
fprintf

Imitation of fprinf() function
getImplementedPrepMethods

Shows a list with implemented preprocessing methods
getDataLabels

Create a vector with labels for plot series
getConvexHull

Compute coordinates of a closed convex hull for data points
getImplementedConstraints

Shows a list with implemented constraints
getVIPScores

VIP scores
getVIPScores.pls

VIP scores for PLS model
hotelling.prob

Calculate probabilities for distance values and given parameters using Hotelling T2 distribution
jm.prob

Calculate probabilities for distance values and given parameters using Hotelling T2 distribution
getMainTitle

Get main title
getPlotColors

Define colors for plot series
getSelectivityRatio

Selectivity ratio
getConfidenceEllipse

Compute confidence ellipse for a set of points
getCalibrationData.simcam

Get calibration data
getLabelsAsValues

Create labels from data values
getSelectivityRatio.pls

Selectivity ratio for PLS model
employ.constraint

Applies constraint to a dataset
getRes

Return list with valid results
getLabelsAsIndices

Create labels as column or row indices
getSelectedComponents

Get selected components
getProbabilities.simca

Probabilities of class belonging for PCA/SIMCA results
getCalibrationData

Calibration data
hotelling.crit

Calculate critical limits for distance values using Hotelling T2 distribution
ldecomp.getDistances

Compute score and residual distances
ldecomp.getLimParams

Compute parameters for critical limits based on calibration results
ldecomp

Class for storing and visualising linear decomposition of dataset (X = TP' + E)
imshow

show image data as an image
mda.getattr

Get data attributes
jm.crit

Calculate critical limits for distance values using Jackson-Mudholkar approach
getPureVariables

Identifies pure variables
mda.inclrows

include/unhide the excluded rows
ipls.forward

Runs the forward iPLS algorithm
ldecomp.plotResiduals

Residuals distance plot for a set of ldecomp objects
mcr

General class for Multivariate Curve Resolution model
mda.subset

A wrapper for subset() method with proper set of attributed
mda.show

Wrapper for show() method
mda.exclrows

Exclude/hide rows in a dataset
mcrals.fcnnls

Fast combinatorial non-negative least squares
getRegcoeffs

Get regression coefficients
getCalibrationData.pca

Returns matrix with original calibration data
mdaplot

Plotting function for a single set of objects
mda.inclcols

Include/unhide the excluded columns
mcrals.nnls

Non-negative least squares
mda.purgeRows

Removes excluded (hidden) rows from data
mdaplot.getXTicks

Prepare xticks for plot
mdaplot.getXTickLabels

Prepare xticklabels for plot
mdaplot.prepareColors

Prepare colors based on palette and opacity value
getVariance.mcr

Compute explained variance for MCR case
getRegcoeffs.regmodel

Regression coefficients for PLS model'
ldecomp.getLimitsCoordinates

Compute coordinates of lines or curves with critical limits
ldecomp.getT2Limits

Compute critical limits for score distances (T2)
ldecomp.getVariances

Compute explained variance
ldecomp.getQLimits

Compute critical limits for orthogonal distances (Q)
mdaplotg.showLegend

Show legend for mdaplotg
mdaplotg.processParam

Check mdaplotg parameters and replicate them if necessary
mcrals

Multivariate curve resolution using Alternating Least Squares
mdaplot.getColors

Color values for plot elements
mda.getexclind

Get indices of excluded rows or columns
mdaplot.getYAxisLim

Calculate limits for y-axis.
mcrals.cal

Identifies pure variables
pellets

Image data
pca.getB

Low-dimensional approximation of data matrix X
pca.mvreplace

Replace missing values in data
mda.t

A wrapper for t() method with proper set of attributes
mdaplot.areColors

Check color values
mdaplot.formatValues

Format vector with numeric values
mda.purge

Removes excluded (hidden) rows and colmns from data
mdaplotyy

Create line plot with double y-axis
mdatools

Package for Multivariate Data Analysis (Chemometrics)
plot.plsres

Overview plot for PLS results
ipls

Variable selection with interval PLS
people

People data
mda.cbind

A wrapper for cbind() method with proper set of attributes
mda.data2im

Convert data matrix to an image
plot.pls

Model overview plot for PLS
plot.simcamres

Model overview plot for SIMCAM results
plot.plsdares

Overview plot for PLS-DA results
plotConvexHull

Add convex hull for groups of points on scatter plot
mda.rbind

A wrapper for rbind() method with proper set of attributes
plot.plsda

Model overview plot for PLS-DA
plotCooman

Cooman's plot
plot.simcam

Model overview plot for SIMCAM
plotContributions

Plot resolved contributions
ipls.backward

Runs the backward iPLS algorithm
mcrpure

Multivariate curve resolution based on pure variables
mda.df2mat

Convert data frame to a matrix
mcrals.ols

Ordinary least squares
pca

Principal Component Analysis
mda.setattr

Set data attributes
mdaplot.getYTickLabels

Prepare yticklabels for plot
plotMisclassified.classres

Misclassified ratio plot for classification results
plot.randtest

Plot for randomization test results
plotLines

Show plot series as set of lines
mdaplot.showColorbar

Plot colorbar
plotPointsShape

Add confidence ellipse or convex hull for group of points
plotMisclassified.classmodel

Misclassified ratio plot for classification model
plot.regcoeffs

Regression coefficients plot
plotPredictions

Predictions plot
plotModelDistance.simcam

Model distance plot for SIMCAM model
plotProbabilities.classres

Plot for class belonging probability
plotDensity

Show plot series as density plot (using hex binning)
plotConfidenceEllipse

Add confidence ellipse for groups of points on scatter plot
plotBiplot.pca

PCA biplot
mda.im2data

Convert image to data matrix
mda.purgeCols

Removes excluded (hidden) colmns from data
plotDiscriminationPower

Discrimination power plot
plotContributions.mcr

Show plot with resolved contributions
plotPerformance

Classification performance plot
plotErrorbars

Show plot series as error bars
plotResiduals.ldecomp

Residual distance plot
plotLoadings

Loadings plot
plotHist.randtest

Histogram plot for randomization test results
plotRMSE.ipls

RMSE development plot
plotPurity

Plot purity values
plotHotellingEllipse

Hotelling ellipse
plotExtreme

Shows extreme plot for SIMCA model
plotModellingPower

Modelling power plot
plotRegressionLine

Add regression line for data points
plotPredictions.regres

Predictions plot for regression results
plotScores.ldecomp

Scores plot
plotRegcoeffs.regmodel

Regression coefficient plot for regression model
plotScores.pca

Scores plot for PCA model
plotPredictions.regmodel

Predictions plot for regression model
mdaplot.plotAxes

Create axes plane
mdaplot.getYTicks

Prepare yticks for plot
plot.regres

Plot method for regression results
plotPurity.mcrpure

Purity values plot
mdaplot.getXAxisLim

Calculate limits for x-axis.
plotCooman.simcamres

Cooman's plot for SIMCAM results
mdaplotg.getLegend

Create and return vector with legend values
pca.svd

Singular Values Decomposition based PCA algorithm
mdaplotg.getXLim

Compute x-axis limits for mdaplotg
plot.pca

Model overview plot for PCA
pca.nipals

NIPALS based PCA algorithm
plotCooman.simcam

Cooman's plot for SIMCAM model
mda.setimbg

Remove background pixels from image data
mdaplot.showLines

Plot lines
mda.exclcols

Exclude/hide columns in a dataset
pcares

Results of PCA decomposition
mdaplotg

Plotting function for several plot series
plot.pcares

Plot method for PCA results object
plot.simca

Model overview plot for SIMCA
plotCumVariance

Variance plot
plotRMSE.regres

RMSE plot for regression results
plotModelDistance

Model distance plot
plotQDoF

Degrees of freedom plot for orthogonal distance (Nh)
plotProbabilities

Plot for class belonging probability
plotT2DoF

Degrees of freedom plot for score distance (Nh)
plotSelectivityRatio

Selectivity ratio plot
pca.cal

PCA model calibration
mdaplotg.getYLim

Compute y-axis limits for mdaplotg
plotSensitivity.classres

Sensitivity plot for classification results
mdaplotg.prepareData

Prepare data for mdaplotg
plot.classres

Plot function for classification results
pinv

Pseudo-inverse matrix
plotXYScores.plsres

XY scores plot for PLS results
plotCumVariance.pca

Cumulative explained variance plot for PCA model
plotSpecificity.classmodel

Specificity plot for classification model
plotRMSE

RMSE plot
plotVIPScores

VIP scores plot
plotResiduals

Residuals plot
plotXVariance

X variance plot
plotSensitivity

Sensitivity plot
plotCumVariance.ldecomp

Cumulative explained variance plot
plotPerformance.classres

Performance plot for classification results
plotPredictions.simcamres

Prediction plot for SIMCAM results
plotRMSE.regmodel

RMSE plot for regression model
plotYResiduals.regmodel

Y residuals plot for regression model
plotExtreme.pca

Extreme plot
plotPerformance.classmodel

Performance plot for classification model
plotHist

Statistic histogram
plotPredictions.simcam

Predictions plot for SIMCAM model
plotSpectra

Plot resolved spectra
plotSpecificity.classres

Specificity plot for classification results
plotXYScores

XY scores plot
plotXVariance.pls

Explained X variance plot for PLS
plotWeights.pls

X loadings plot for PLS
plotXLoadings

X loadings plot
plotCumVariance.mcr

Show plot with cumulative explained variance
pls

Partial Least Squares regression
plotResiduals.pca

Residuals distance plot for PCA model
plotResiduals.regres

Residuals plot for regression results
plotSpecificity

Specificity plot
plotYCumVariance

Y cumulative variance plot
prep.autoscale

Autoscale values
plotXLoadings.pls

X loadings plot for PLS
plotSpectra.mcr

Show plot with resolved spectra
plotSelectivityRatio.pls

Selectivity ratio plot for PLS model
plotScatter

Show plot series as set of points
plotXResiduals

X residuals plot
plotVariance

Variance plot
prep.savgol

Savytzky-Golay filter
plotXResiduals.pls

Residual distance plot for decomposition of X data
plotVIPScores.pls

VIP scores plot for PLS model
plotVariance.pca

Explained variance plot for PCA model
plotVariance.mcr

Show plot with explained variance
plotVariance.ldecomp

Explained variance plot
plot.ipls

Overview plot for iPLS results
print.regcoeffs

print method for regression coefficients class
preparePlotData

Take dataset and prepare them for plot
plotYCumVariance.pls

Cumulative explained Y variance plot for PLS
plotXResiduals.plsres

X residuals plot for PLS results
print.plsda

Print method for PLS-DA model object
plotXYResiduals.plsres

Residual distance plot
pls.getLimitsCoordinates

Compute coordinates of lines or curves with critical limits
plotseries

Create plot series object based on data, plot type and parameters
plotYResiduals

Y residuals plot
print.classres

Print information about classification result object
plotXYResiduals.pls

Residual XY-distance plot
plotYCumVariance.plsres

Explained cumulative Y variance plot for PLS results
plotRMSERatio

Plot for ratio RMSEC/RMSECV vs RMSECV
plotXScores

X scores plot
prep

Class for preprocessing object
pls.cal

PLS model calibration
predict.simcam

SIMCA multiple classes predictions
pls.getxdecomp

Compute object with decomposition of x-values
plotXYScores.pls

XY scores plot for PLS
pls.getxscores

Compute matrix with X-scores
plotXScores.pls

X scores plot for PLS
plotLoadings.pca

Loadings plot for PCA model
plotBars

Show plot series as bars
plotCorr

Correlation plot
plotPredictions.classres

Prediction plot for classification results
pca.run

Runs one of the selected PCA methods
plot.mcr

Plot summary for MCR model
pls.run

Runs selected PLS algorithm
pls.simpls

SIMPLS algorithm
plotScores

Scores plot
plotYResiduals.plsres

Y residuals plot for PLS results
pls.getyscores

Compute and orthogonalize matrix with Y-scores
plotSensitivity.classmodel

Sensitivity plot for classification model
predict.mcrals

MCR ALS predictions
pls.getydecomp

Compute object with decomposition of y-values
prep.list

Shows information about all implemented preprocessing methods.
print.pls

Print method for PLS model object
showPredictions

Predictions
print.randtest

Print method for randtest object
prep.generic

Generic function for preprocessing
splitPlotData

Split dataset to x and y values depending on plot type
summary.mcrpure

Summary method for mcrpure object
plotXScores.plsres

X scores plot for PLS results
showDistanceLimits

Show residual distance limits
print.mcrals

Print method for mcrpure object
prep.snv

Standard Normal Variate transformation
plotBiplot

Biplot
prep.transform

Transformation
regres.bias

Prediction bias
print.regres

print method for regression results object
print.mcrpure

Print method for mcrpure object
splitExcludedData

Split the excluded part of data
summary.pca

Summary method for PCA model object
showPredictions.classres

Show predicted class values
prep.norm

Normalization
prep.msc

Multiplicative Scatter Correction transformation
plotVariance.pls

Variance plot for PLS
plotXYLoadings

X loadings plot
plotXCumVariance

X cumulative variance plot
repmat

Replicate matric x
plotSelection.ipls

iPLS performance plot
plotPredictions.classmodel

Predictions plot for classification model
plotSelection

Selected intervals plot
simcamres

Results of SIMCA multiclass classification
print.regmodel

Print method for PLS model object
showLabels

Show labels on plot
summary.regres

summary method for regression results object
regres.err

Error of prediction
summary.simca

Summary method for SIMCA model object
print.plsres

print method for PLS results object
simcam.getPerformanceStats

Performance statistics for SIMCAM model
print.plsdares

Print method for PLS-DA results object
pls.getZLimits

Compute critical limits for orthogonal distances (Q)
randtest

Randomization test for PLS regression
selratio

Selectivity ratio calculation
summary.pls

Summary method for PLS model object
predict.mcrpure

MCR predictions
plotXVariance.plsres

Explained X variance plot for PLS results
vipscores

VIP scores for PLS model
summary.plsdares

Summary method for PLS-DA results object
plsdares

PLS-DA results
plotYVariance

Y variance plot
regres

Regression results
print.simcamres

Print method for SIMCAM results object
selectCompNum.pca

Select optimal number of components for PCA model
summary.classres

Summary statistics about classification result object
summary.regmodel

Summary method for regression model object
print.simcares

Print method for SIMCA results object
regcoeffs.getStats

Distribution statistics for regression coeffificents
selectCompNum.pls

Select optimal number of components for PLS model
simca

SIMCA one-class classification
plotCorr.randtest

Correlation plot for randomization test results
plotMisclassified

Misclassification ratio plot
plsres

PLS results
simcam

SIMCA multiclass classification
summary.ldecomp

Summary statistics for linear decomposition
pls.getpredictions

Compute predictions for response values
print.pcares

Print method for PCA results object
setDistanceLimits.pls

Compute and set statistical limits for residual distances.
prep.ref2km

Kubelka-Munk transformation
summary.ipls

Summary for iPLS results
prep.alsbasecorr

Baseline correction using asymetric least squares
print.pca

Print method for PCA model object
setDistanceLimits.pca

Compute and set statistical limits for Q and T2 residual distances.
selectCompNum

Select optimal number of components for a model
summary.regcoeffs

Summary method for regcoeffs object
summary.mcrals

Summary method for mcrals object
regres.rmse

RMSE
summary.pcares

Summary method for PCA results object
predict.pca

PCA predictions
predict.pls

PLS predictions
summary.plsda

Summary method for PLS-DA model object
plotDiscriminationPower.simcam

Discrimination power plot for SIMCAM model
regcoeffs

Regression coefficients
setDistanceLimits

Set residual distance limits
regres.r2

Determination coefficient
summary.simcam

Summary method for SIMCAM model object
summary.simcamres

Summary method for SIMCAM results object
plotDistDoF

Degrees of freedom plot for both distances
plotVariance.plsres

Explained X variance plot for PLS results
predict.plsda

PLS-DA predictions
regress.addattrs

Add names and attributes to matrix with statistics
plotRMSERatio.regmodel

RMSECV/RMSEC ratio plot for regression model
prep.varsel

Variable selection
plotPuritySpectra

Plot purity spectra
plotPuritySpectra.mcrpure

Purity spectra plot
prepCalData

Prepares calibration data
pls.simplsold

SIMPLS algorithm (old implementation)
plotRegcoeffs

Regression coefficients plot
plotWeights

Plot for PLS weights
plotXCumVariance.plsres

Explained cumulative X variance plot for PLS results
plotXCumVariance.pls

Cumulative explained X variance plot for PLS
plotYVariance.plsres

Explained Y variance plot for PLS results
plotYVariance.pls

Explained Y variance plot for PLS
plotXYResiduals

Plot for XY-residuals
print.simca

Print method for SIMCA model object
simcares

Results of SIMCA one-class classification
plotXYLoadings.pls

XY loadings plot for PLS
predict.simca

SIMCA predictions
print.ipls

Print method for iPLS
simdata

Spectral data of polyaromatic hydrocarbons mixing
plsda

Partial Least Squares Discriminant Analysis
print.ldecomp

Print method for linear decomposition
regres.slope

Slope
summary.randtest

Summary method for randtest object
unmix.mcrpure

Unmix spectral data using pure variables estimated before
summary.plsres

summary method for PLS results object
print.simcam

Print method for SIMCAM model object
summary.simcares

Summary method for SIMCA results object