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.13.0) 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 from CRAN by usual installing procedure. However, due to restrictions in CRAN politics regarding number of submissions (one in 3-4 month), mostly major releases will be published there (with 2-3 weeks delay after GitHub release as more thorough testing is needed). You can download a zip-file with source package and install it using the install.packages command, e.g. if the downloaded file is mdatools_0.13.0.tar.gz and it is located in a current working directory, just run the following:

install.packages("mdatools_0.13.0.tar.gz")

If you have devtools package installed, the following command will install the current developer version from the master branch of GitHub repository (do not forget to load the devtools package first):

install_github("svkucheryavski/mdatools")

Copy Link

Version

Install

install.packages('mdatools')

Monthly Downloads

1,171

Version

0.13.0

License

MIT + file LICENSE

Maintainer

Sergey Kucheryavskiy

Last Published

July 14th, 2022

Functions in mdatools (0.13.0)

as.matrix.regcoeffs

as.matrix method for regression coefficients class
carbs

Raman spectra of carbonhydrates
as.matrix.ldecomp

as.matrix method for ldecomp object
as.matrix.plsdares

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

as.matrix method for regression results
as.matrix.plsres

as.matrix method for PLS results
as.matrix.classres

as.matrix method for classification results
as.matrix.simcamres

as.matrix method for SIMCAM results
capitalize

Capitalize text or vector with text values
categorize.pls

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

Results of classification
classres.getPerformance

Calculation of classification performance parameters
classify.plsda

PLS-DA classification
chisq.prob

Calculate probabilities for distance values using Chi-square distribution
getMainTitle

Get main title
getLabelsAsValues

Create labels from data values
crossval.getParams

Define parameters based on 'cv' value
categorize

Categorize PCA results
crossval

Generate sequence of indices for cross-validation
categorize.pca

Categorize PCA results based on orthogonal and score distances.
as.matrix.simcares

as.matrix method for SIMCA classification results
confint.regcoeffs

Confidence intervals for regression coefficients
constraint

Class for MCR-ALS constraint
classify.simca

SIMCA classification
constraintUnimod

Method for unimodality constraint
ddmoments.param

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

Define colors for plot series
getConfusionMatrix.classres

Confusion matrix for classification results
classmodel.processRefValues

Check reference class values and convert it to a factor if necessary
constraints.list

Shows information about all implemented constraints
getConvexHull

Compute coordinates of a closed convex hull for data points
ddrobust.param

Calculates critical limits for distance values using Data Driven robust approach
chisq.crit

Calculates critical limits for distance values using Chi-square distribution
ldecomp.getDistances

Compute score and residual distances
getProbabilities

Get class belonging probability
getImplementedConstraints

Shows a list with implemented constraints
getSelectivityRatio.pls

Selectivity ratio for PLS model
dd.crit

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

Selectivity ratio
getDataLabels

Create a vector with labels for plot series
crossval.str

String with description of cross-validation method
ldecomp.plotResiduals

Residuals distance plot for a set of ldecomp objects
constraintNorm

Method for normalization constraint
constraintNonNegativity

Method for non-negativity constraint
ellipse

Create ellipse on the current plot
employ.constraint

Applies constraint to a dataset
constraintAngle

Method for angle constraint
getPureVariables

Identifies pure variables
fprintf

Imitation of fprinf() function
getRes

Return list with valid results
eye

Create the identity matrix
employ.prep

Applies a list with preprocessing methods to a dataset
getR

Creates rotation matrix to map a set vectors base1 to a set of vectors base2.
getCalibrationData

Calibration data
ldecomp.getLimParams

Compute parameters for critical limits based on calibration results
ldecomp.getLimitsCoordinates

Compute coordinates of lines or curves with critical limits
mcr

General class for Multivariate Curve Resolution model
getConfidenceEllipse

Compute confidence ellipse for a set of points
mcrals.fcnnls

Fast combinatorial non-negative least squares
mda.setattr

Set data attributes
ipls

Variable selection with interval PLS
getSelectedComponents

Get selected components
pca.nipals

NIPALS based PCA algorithm
mda.setimbg

Remove background pixels from image data
ipls.backward

Runs the backward iPLS algorithm
mcrals.nnls

Non-negative least squares
getConfusionMatrix

Confusion matrix for classification results
mda.getexclind

Get indices of excluded rows or columns
constraintClosure

Method for closure constraint
ldecomp.getQLimits

Compute critical limits for orthogonal distances (Q)
mda.cbind

A wrapper for cbind() method with proper set of attributes
mcrals.ols

Ordinary least squares
getRegcoeffs

Get regression coefficients
imshow

show image data as an image
getRegcoeffs.regmodel

Regression coefficients for PLS model'
hotelling.prob

Calculate probabilities for distance values and given parameters using Hotelling T2 distribution
mda.data2im

Convert data matrix to an image
mdaplot.areColors

Check color values
getImplementedPrepMethods

Shows a list with implemented preprocessing methods
crossval.regmodel

Cross-validation of a regression model
mdaplot.formatValues

Format vector with numeric values
pca.run

Runs one of the selected PCA methods
plotConfidenceEllipse

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

Singular Values Decomposition based PCA algorithm
pcares

Results of PCA decomposition
plotCumVariance.mcr

Show plot with cumulative explained variance
plotCumVariance.ldecomp

Cumulative explained variance plot
plotContributions

Plot resolved contributions
getVariance.mcr

Compute explained variance for MCR case
getLabelsAsIndices

Create labels as column or row indices
mcrpure

Multivariate curve resolution based on pure variables
hotelling.crit

Calculate critical limits for distance values using Hotelling T2 distribution
plotHotellingEllipse

Hotelling ellipse
jm.crit

Calculate critical limits for distance values using Jackson-Mudholkar approach
ldecomp.getVariances

Compute explained variance
ipls.forward

Runs the forward iPLS algorithm
mda.df2mat

Convert data frame to a matrix
ldecomp.getT2Limits

Compute critical limits for score distances (T2)
mda.exclcols

Exclude/hide columns in a dataset
plotMisclassified.classres

Misclassified ratio plot for classification results
plotModelDistance

Model distance plot
plotLines

Show plot series as set of lines
plotPredictions.regres

Predictions plot for regression results
mda.im2data

Convert image to data matrix
mda.purge

Removes excluded (hidden) rows and colmns from data
plotResiduals.ldecomp

Residual distance plot
plotPuritySpectra.mcrpure

Purity spectra plot
plotPredictions.simcam

Predictions plot for SIMCAM model
plotQDoF

Degrees of freedom plot for orthogonal distance (Nh)
mda.inclcols

Include/unhide the excluded columns
mdaplot.getColors

Color values for plot elements
mdaplot.getXAxisLim

Calculate limits for x-axis.
mda.inclrows

include/unhide the excluded rows
mda.purgeCols

Removes excluded (hidden) colmns from data
mdaplot.getYAxisLim

Calculate limits for y-axis.
mda.show

Wrapper for show() method
mda.subset

A wrapper for subset() method with proper set of attributed
plotResiduals.pca

Residuals distance plot for PCA model
mdaplot.prepareColors

Prepare colors based on palette and opacity value
crossval.simca

Cross-validation of a SIMCA model
mdaplot

Plotting function for a single set of objects
mdaplot.getYTicks

Prepare yticks for plot
mda.t

A wrapper for t() method with proper set of attributes
plotSensitivity.classmodel

Sensitivity plot for classification model
plot.mcr

Plot summary for MCR model
mdaplot.showColorbar

Plot colorbar
pca

Principal Component Analysis
pca.cal

PCA model calibration
plot.pca

Model overview plot for PCA
plot.pcares

Plot method for PCA results object
mdaplotg.getYLim

Compute y-axis limits for mdaplotg
plotSpectra

Plot resolved spectra
plotSpecificity.classres

Specificity plot for classification results
plotSensitivity.classres

Sensitivity plot for classification results
getProbabilities.pca

Probabilities for residual distances
getCalibrationData.pca

Returns matrix with original calibration data
getCalibrationData.simcam

Get calibration data
getProbabilities.simca

Probabilities of class belonging for PCA/SIMCA results
mdaplot.plotAxes

Create axes plane
plotRMSE.regres

RMSE plot for regression results
plotRMSE.regmodel

RMSE plot for regression model
plotProbabilities.classres

Plot for class belonging probability
plotPurity

Plot purity values
plot.pls

Model overview plot for PLS
mdaplotg.getXLim

Compute x-axis limits for mdaplotg
mdaplot.getYTickLabels

Prepare yticklabels for plot
pca.getB

Low-dimensional approximation of data matrix X
mdaplotg.getLegend

Create and return vector with legend values
pca.mvreplace

Replace missing values in data
plot.plsres

Overview plot for PLS results
mdaplotyy

Create line plot with double y-axis
plotXYLoadings.pls

XY loadings plot for PLS
plot.randtest

Plot for randomization test results
plotXYLoadings

X loadings plot
plotYCumVariance

Y cumulative variance plot
getVIPScores.pls

VIP scores for PLS model
getVIPScores

VIP scores
plotSelectivityRatio.pls

Selectivity ratio plot for PLS model
plotXCumVariance

X cumulative variance plot
plotSensitivity

Sensitivity plot
jm.prob

Calculate probabilities for distance values and given parameters using Hotelling T2 distribution
plotXCumVariance.pls

Cumulative explained X variance plot for PLS
plotCooman.simcam

Cooman's plot for SIMCAM model
plotCooman

Cooman's plot
plotCorr.randtest

Correlation plot for randomization test results
predict.simca

SIMCA predictions
plotYVariance.plsres

Explained Y variance plot for PLS results
plotYCumVariance.pls

Cumulative explained Y variance plot for PLS
plotseries

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

Multivariate curve resolution using Alternating Least Squares
ldecomp

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

Variance plot
predict.simcam

SIMCA multiple classes predictions
plotXVariance

X variance plot
plotXScores.plsres

X scores plot for PLS results
plotXYScores.pls

XY scores plot for PLS
mda.getattr

Get data attributes
mcrals.cal

Identifies pure variables
mda.exclrows

Exclude/hide rows in a dataset
mda.rbind

A wrapper for rbind() method with proper set of attributes
mda.purgeRows

Removes excluded (hidden) rows from data
mdaplotg.prepareData

Prepare data for mdaplotg
plot.classres

Plot function for classification results
mdatools

Package for Multivariate Data Analysis (Chemometrics)
people

People data
pinv

Pseudo-inverse matrix
plot.ipls

Overview plot for iPLS results
mdaplot.getXTickLabels

Prepare xticklabels for plot
plotLoadings.pca

Loadings plot for PCA model
plotModelDistance.simcam

Model distance plot for SIMCAM model
plotLoadings

Loadings plot
plotModellingPower

Modelling power plot
plotPuritySpectra

Plot purity spectra
plotProbabilities

Plot for class belonging probability
plotPredictions.simcamres

Prediction plot for SIMCAM results
plotPurity.mcrpure

Purity values plot
plotXYScores.plsres

XY scores plot for PLS results
plotYVariance

Y variance plot
plot.regcoeffs

Regression coefficients plot
plot.regres

Plot method for regression results
plotYVariance.pls

Explained Y variance plot for PLS
plot.plsdares

Overview plot for PLS-DA results
plot.plsda

Model overview plot for PLS-DA
plotBiplot.pca

PCA biplot
plotBiplot

Biplot
plotDiscriminationPower

Discrimination power plot
plotBars

Show plot series as bars
plotCumVariance.pca

Cumulative explained variance plot for PCA model
plot.simcamres

Model overview plot for SIMCAM results
plotDensity

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

Statistic histogram
plotDiscriminationPower.simcam

Discrimination power plot for SIMCAM model
plotErrorbars

Show plot series as error bars
plotDistDoF

Degrees of freedom plot for both distances
mdaplot.getXTicks

Prepare xticks for plot
mdaplotg

Plotting function for several plot series
mdaplot.showLines

Plot lines
plotResiduals

Residuals plot
plotRegressionLine

Add regression line for data points
print.mcrals

Print method for mcrpure object
print.ldecomp

Print method for linear decomposition
print.plsda

Print method for PLS-DA model object
pls.simpls

SIMPLS algorithm
print.plsdares

Print method for PLS-DA results object
regres

Regression results
regres.bias

Prediction bias
rotationMatrixToX1

Creates a rotation matrix to map a vector x to [1 0 0 ... 0]
plotPerformance

Classification performance plot
plotPerformance.classmodel

Performance plot for classification model
prep.autoscale

Autoscale values
print.simcam

Print method for SIMCAM model object
prep.generic

Generic function for preprocessing
pls.simplsold

SIMPLS algorithm (old implementation)
print.simcamres

Print method for SIMCAM results object
selectCompNum

Select optimal number of components for a model
mdaplotg.showLegend

Show legend for mdaplotg
mdaplotg.processParam

Check mdaplotg parameters and replicate them if necessary
pcv

Compute matrix with pseudo-validation set
regcoeffs

Regression coefficients
pellets

Image data
plotVariance

Variance plot
plotVariance.plsres

Explained X variance plot for PLS results
plotVariance.pls

Variance plot for PLS
plotVariance.ldecomp

Explained variance plot
plot.simca

Model overview plot for SIMCA
plotHist.randtest

Histogram plot for randomization test results
summary.ipls

Summary for iPLS results
simcares

Results of SIMCA one-class classification
simdata

Spectral data of polyaromatic hydrocarbons mixing
summary.classres

Summary statistics about classification result object
plotPredictions.classres

Prediction plot for classification results
pls.cal

PLS model calibration
plotXVariance.plsres

Explained X variance plot for PLS results
plotXVariance.pls

Explained X variance plot for PLS
pls

Partial Least Squares regression
plsda

Partial Least Squares Discriminant Analysis
plotPerformance.classres

Performance plot for classification results
plotPredictions.regmodel

Predictions plot for regression model
plotRMSE.ipls

RMSE development plot
plotRMSE

RMSE plot
plotPointsShape

Add confidence ellipse or convex hull for group of points
plot.simcam

Model overview plot for SIMCAM
plotPredictions.classmodel

Predictions plot for classification model
plotPredictions

Predictions plot
summary.plsda

Summary method for PLS-DA model object
summary.plsdares

Summary method for PLS-DA results object
plsdares

PLS-DA results
regcoeffs.getStats

Distribution statistics for regression coeffificents
plotContributions.mcr

Show plot with resolved contributions
plotConvexHull

Add convex hull for groups of points on scatter plot
plsres

PLS results
plotResiduals.regres

Residuals plot for regression results
plotCooman.simcamres

Cooman's plot for SIMCAM results
plotSpecificity

Specificity plot
plotScatter

Show plot series as set of points
simcam.getPerformanceStats

Performance statistics for SIMCAM model
plotRegcoeffs.regmodel

Regression coefficient plot for regression model
plotSelectivityRatio

Selectivity ratio plot
plotSelection.ipls

iPLS performance plot
plotRegcoeffs

Regression coefficients plot
plotVariance.mcr

Show plot with explained variance
plotYCumVariance.plsres

Explained cumulative Y variance plot for PLS results
plotWeights

Plot for PLS weights
plotVariance.pca

Explained variance plot for PCA model
plotWeights.pls

X loadings plot for PLS
plotSpecificity.classmodel

Specificity plot for classification model
plotYResiduals

Y residuals plot
plotSpectra.mcr

Show plot with resolved spectra
plotYResiduals.regmodel

Y residuals plot for regression model
plotYResiduals.plsres

Y residuals plot for PLS results
pls.getyscores

Compute and orthogonalize matrix with Y-scores
predict.pls

PLS predictions
plotT2DoF

Degrees of freedom plot for score distance (Nh)
pls.run

Runs selected PLS algorithm
plotXLoadings.pls

X loadings plot for PLS
prep.list

Shows information about all implemented preprocessing methods.
predict.plsda

PLS-DA predictions
simcamres

Results of SIMCA multiclass classification
plotXResiduals

X residuals plot
prep.msc

Multiplicative Scatter Correction transformation
print.mcrpure

Print method for mcrpure object
print.pca

Print method for PCA model object
print.regcoeffs

print method for regression coefficients class
print.regmodel

Print method for PLS model object
summary.mcrpure

Summary method for mcrpure object
predict.mcrals

MCR ALS predictions
plotXScores

X scores plot
summary.pca

Summary method for PCA model object
plotXScores.pls

X scores plot for PLS
plotXYResiduals

Plot for XY-residuals
vipscores

VIP scores for PLS model
summary.randtest

Summary method for randtest object
summary.plsres

summary method for PLS results object
prep.transform

Transformation
plotExtreme

Shows extreme plot for SIMCA model
plotExtreme.pca

Extreme plot
plotCorr

Correlation plot
plotMisclassified.classmodel

Misclassified ratio plot for classification model
plotMisclassified

Misclassification ratio plot
regres.err

Error of prediction
pls.getxdecomp

Compute object with decomposition of x-values
pls.getpredictions

Compute predictions for response values
plotXYResiduals.pls

Residual XY-distance plot
prep

Class for preprocessing object
prep.alsbasecorr

Baseline correction using asymetric least squares
plotRMSERatio

Plot for ratio RMSEC/RMSECV vs RMSECV
prep.snv

Standard Normal Variate transformation
prep.savgol

Savytzky-Golay filter
prep.varsel

Variable selection
print.classres

Print information about classification result object
regres.r2

Determination coefficient
plotRMSERatio.regmodel

RMSECV/RMSEC ratio plot for regression model
selectCompNum.pca

Select optimal number of components for PCA model
preparePlotData

Take dataset and prepare them for plot
print.plsres

print method for PLS results object
prepCalData

Prepares calibration data
print.ipls

Print method for iPLS
print.randtest

Print method for randtest object
selectCompNum.pls

Select optimal number of components for PLS model
summary.regres

summary method for regression results object
summary.simca

Summary method for SIMCA model object
setDistanceLimits.pls

Compute and set statistical limits for residual distances.
setDistanceLimits.pca

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

Scores plot
print.simcares

Print method for SIMCA results object
randtest

Randomization test for PLS regression
selratio

Selectivity ratio calculation
showDistanceLimits

Show residual distance limits
showLabels

Show labels on plot
plotScores.ldecomp

Scores plot
plotScores.pca

Scores plot for PCA model
summary.ldecomp

Summary statistics for linear decomposition
summary.simcares

Summary method for SIMCA results object
summary.mcrals

Summary method for mcrals object
setDistanceLimits

Set residual distance limits
plotSelection

Selected intervals plot
plotXLoadings

X loadings plot
plotXResiduals.plsres

X residuals plot for PLS results
plotVIPScores.pls

VIP scores plot for PLS model
plotXCumVariance.plsres

Explained cumulative X variance plot for PLS results
plotXResiduals.pls

Residual distance plot for decomposition of X data
plotVIPScores

VIP scores plot
plotXYScores

XY scores plot
plotXYResiduals.plsres

Residual distance plot
simca

SIMCA one-class classification
simcam

SIMCA multiclass classification
summary.pcares

Summary method for PCA results object
summary.pls

Summary method for PLS model object
unmix.mcrpure

Unmix spectral data using pure variables estimated before
summary.regcoeffs

Summary method for regcoeffs object
pls.getLimitsCoordinates

Compute coordinates of lines or curves with critical limits
summary.regmodel

Summary method for regression model object
pls.getxscores

Compute matrix with X-scores
pls.getZLimits

Compute critical limits for orthogonal distances (Q)
pls.getydecomp

Compute object with decomposition of y-values
predict.mcrpure

MCR predictions
predict.pca

PCA predictions
prep.norm

Normalization
prep.ref2km

Kubelka-Munk transformation
print.simca

Print method for SIMCA model object
print.regres

print method for regression results object
print.pcares

Print method for PCA results object
print.pls

Print method for PLS model object
regres.rmse

RMSE
regres.slope

Slope
regress.addattrs

Add names and attributes to matrix with statistics
repmat

Replicate matric x
showPredictions

Predictions
showPredictions.classres

Show predicted class values
splitExcludedData

Split the excluded part of data
summary.simcamres

Summary method for SIMCAM results object
splitPlotData

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

Summary method for SIMCAM model object