# Task view: Chemometrics and Computational Physics

Last updated on 2019-05-19 by Katharine Mullen

Chemometrics and computational physics are concerned with the analysis of data arising in chemistry and physics experiments, as well as the simulation of physico-chemico systems. Many of the functions in base R are useful for these ends.

The book Chemometrics with R by Ron Wehrens, ISBN: 978-3-642-17840-5, Springer, 2011, provides an introduction to multivariate statistics in the life sciences, as well as coverage of several specific topics from the area of chemometrics; the examples in the book are possible to reproduce using the package ChemometricsWithR.

The book Modern Statistical Methods for Astronomy With R Applications by Eric D. Feigelson and G. Jogesh Babu, ISBN-13: 9780521767279, Cambridge, 2012, provides an introduction to statistics for astronomers and an overview of the foremost methods being used in astrostatistical analysis, illustrated by examples in R.

The book by Kurt Varmuza and Peter Filzmoser, Introduction to Multivariate Statistical Analysis in Chemometrics, ISBN 978-1-420-05947-2, CRC Press, 2009, is associated with the package chemometrics.

A special issue of R News with a focus on R in Chemistry was published in August 2006. A special volume of Journal of Statistical Software (JSS) dedicated to oscopy and Chemometrics in R was published in January 2007.

Please let us knowif we have omitted something of importance, or if a new package or function should be mentioned here.

Linear Regression Models

• Linear models can be fitted (via OLS) with `lm()` (from stats). A least squares solution for `x` in `Ax = b` can also be computed as `qr.coef(qr(A), b)`.
• The package nnls provides a means of constraining `x` to non-negative or non-positive values; the package bvls allows other bounds on `x` to be applied.
• Functions for isotonic regression are available in the package Iso, and are useful to determine the unimodal vector that is closest to a given vector `x` under least squares criteria.
• Heteroskedastic linear models can be fit using the `gls()` function of the nlme package.

Nonlinear Regression Models

• The `nls()` function (from stats) as well as the package minpack.lm allow the solution of nonlinear least squares problems.
• Correlated and/or unequal variances can be modeled using the `gnls()` function of the nlme package and by nlreg.

Curve Resolution

• The PTAk package provides functions for Principal Tensor Analysis on k modes. The package includes also some other multiway methods: PCAn (Tucker-n) and PARAFAC/CANDECOMP.
• Multivariate curve resolution alternating least squares (MCR-ALS) is implemented in the package ALS.
• The alsace package provides MCR-ALS support for Liquid chromatography with PhotoDiode Array Detection (LC-DAD) data with many injections, with features for peak alignment and identification.
• The package drc provides functions for the analysis of one or multiple non-linear curves with focus on models for concentration-response, dose-response and time-response data.

Partial Least Squares

• The package pls implements Partial Least Squares Regression (PLSR) and Principal Component Regression (PCR).
• The package lspls implements the least squares-partial least squares (LS-PLS) method.
• Penalized Partial Least Squares is implemented in the ppls package.
• Sparse PLS is implemented in the package spls package.
• The gpls package implements generalized partial least squares, based on the Iteratively ReWeighted Least Squares (IRWLS) method of Brian Marx.
• Package plspm contains, in addition to the usual functions for PLS regression, also functions for path modeling.
• The package enpls implements ensemble partial least squares, a framework for measuring feature importance, outlier detection, and ensemble modeling based on (sparse) partial least squares regressions.

Principal Component Analysis

• Principal component analysis (PCA) is in the package stats as functions `princomp()`. Some graphical PCA representations can be found in the psy package.
• The homals package provides nonlinear PCA and, by defining sets, nonlinear canonical correlation analysis (models of the Gifi-family).
• A desired number of robust principal components can be computed with the pcaPP package. The package elasticnet is applicable to sparse PCA. The package fpca can be applied to restricted MLE for functional PCA.
• See the Multivariate task view for further packages dealing with PCA and other projection methods.

Factor Analysis

• Factor analysis (FA) is in the package stats as functions `factanal()`; see Psychometrics task view for details on extensions.

Compositional Data Analysis

• The package compositions provides functions for the consistent analysis of compositional data (e.g. portions of substances) and positive numbers (e.g. concentrations). See also the book, Analyzing Compositional Data with R by K. Gerald von den Boogaart und Raimon Tolosana-Delgado, ISBN: 978-3-642-36808-0, Springer, 2013.

Independent Component Analysis

• Independent component analysis (ICA) can be computed using fastICA.

Clustering

• The Cluster task view provides a list of packages that can be used for clustering problems.

Variable Selection

• Stepwise variable selection for linear models, using AIC, is available in function `step()`; package leaps implements leaps-and-bounds variable selection, by default using Mallow's Cp. stepPlr provides stepwise variable selection for penalized logistic regression.
• Variable selection based on evolutionary algorithms is available in package and subselect. The latter also provides simulated annealing and leaps-and-bounds algorithms, as well as local refinements.
• Package varSelRF provides variable selection methods for random forests. Cross-validation-based variable selection using Wilcoxon rank sum tests is available in package WilcoxCV, focused on binary classification in microarrays. Package clustvarsel implements variable selection for model-based clustering.
• The BioMark package implements two meta-methods for variable selection: stability selection (applying a primary selection method like a t-test, VIP value or PLSDA regression coefficient) to different subsets of the data, and higher criticism, which provides a data-driven choice of significance cutoffs in statistical testing.

Self-Organizing Maps

• The kohonen package implements self-organizing maps as well as some extensions for supervised pattern recognition and data fusion. The som package provides functions for self-organizing maps.

Differential Equations

Metrology

• The units package attaches unit metadata to vectors, matrices and arrays, providing automatic propagation, conversion, derivation and simplification of units.
• The errors attaches uncertainty metadata to vectors, matrices and arrays, providing automatic propagation and reporting.
• The constants package provides values of the fundamental physical constants based on values reported by the Committee on Data for Science and Technology (CODATA), an interdisciplinary committee of the International Council for Science.
• NISTunits also provides values of the fundamental physical constants. The values it contains are based on the values reported by the National Institute of Standards and Technology, (NIST).
• The measurements contains tools to make working with physical measurements easier, such as functions to convert between metric and imperial units, or to calculate a dimension's unknown value from other dimensions' measurements.
• The metRology package provides support for metrology applications, including measurement uncertainty estimation and inter-laboratory metrology comparison studies.
• The ATmet package provides functions for smart sampling and sensitivity analysis for metrology applications, including computationally expensive problems.

Calibration

• The investr package facilitates calibration/inverse estimation with linear and nonlinear regression models.
• The chemCal package provides functions for plotting linear calibration functions and estimating standard errors for measurements.
• The nlreg package is useful for nonlinear calibration models.
• The package represent calculates the 'representativity' of two multidimensional datasets, which involves comparison of the similarity of principal component analysis loading patterns, variance-covariance matrix structures, and data set centroid locations.

Cellular Automata

• The simecol package includes functions for cellular automata modeling.

Thermodynamics

• The CHNOSZ package provides functions for calculating the standard Gibbs energies and other thermodynamic properties, and chemical affinities of reactions between species contained in a thermodynamic database.

Interfaces to External Libraries

Spectroscopy

• The spectralAnalysis package allows users to pre-process, visualize and analyze spectroscopy data. Non-negative matrix factorization analysis is included.
• The hyperSpec packages allows analysis of hyperspectral data, i.e., spectra plus further information such as spatial information, time, concentrations, etc. Such data are frequently encountered in the analysis of Raman, IR, NIR, UV/VIS, NMR, etc., spectroscopic data sets.
• The ChemoSpec package collects user-friendly functions for plotting spectra (NMR, IR, etc) and carrying top-down exploratory data analysis, such as HCA, PCA and model-based clustering.
• The Chathurga/HyperChemoBridge interconverts ChemoSpec and hyperSpec objects
• The speaq package implements the hierarchical Cluster-based Peak Alignment (CluPA) and may be used for aligning NMR spectra.
• Software for the book by Donald B. Percival and Andrew T. Walden, Spectral Analysis for Physical Applications, ISBN 978-0-521-43541-3, Cambridge University Press, 1993, is found in the package sapa.
• The package TIMP provides a problem solving environment for fitting separable nonlinear models in physics and chemistry applications, and has been extensively applied to time-resolved spectroscopy data.
• The package prospectr provides functions for pretreatment and sample selection of visible and near infrared diffuse reflectance spectra.
• The resemble includes functions for spectral dissimilarity analysis and memory-based learning (a.k.a. local modeling) for non-linear modeling in spectral datasets.
• The package ChemoSpec2D allows exploratory chemometrics of 2D spectroscopic data sets such as COSY (correlated spectroscopy) and HSQC (heteronuclear single quantum coherence) 2D NMR (nuclear magnetic resonance) spectra.

Mass Spectrometry

• The MSnbase defines infrastructure for mass spectrometry-based proteomics data handling, plotting, processing and quantification.
• The MALDIquant provides tools for quantitative analysis of MALDI-TOF mass spectrometry data, with support for baseline correction, peak detection and plotting of mass spectra.
• The MALDIrppa provides methods for quality control and robust pre-processing and analysis of MALDI mass spectrometry data.
• The OrgMassSpecR package is for organic/biological mass spectrometry, with a focus on graphical display, quantification using stable isotope dilution, and protein hydrogen/deuterium exchange experiments.
• The FTICRMS package provides functions for Analyzing Fourier Transform-Ion Cyclotron ed Resonance Mass Spectrometry Data.
• The titan provides a GUI to analyze mass spectrometric data on the relative abundance of two substances from a titration series.
• The Bioconductor packages MassSpecWavelet, PROcess, and xcms are designed for the analysis of mass spectrometry data.
• The RAMClustR package offers post-processing (feature clustering) of the xcms package's output in support of metabolite annotation.
• The apLCMS package is designed for the processing of LC/MS based metabolomics data.
• The xMSanalyzer package allows merging apLCMS sample processing results from multiple sets of parameter settings, among other features.
• The MSPrep package is for post-processing of metabolomic data, including summarization of replicates, filtering, imputation, and normalization.
• The metaMS package is an MS-based metabolomics data processing and compound annotation pipeline.

Functional Magnetic Resonance Imaging

• Functions for I/O, visualization and analysis of functional Magnetic Resonance Imaging (fMRI) datasets stored in the ANALYZE or NIFTI format are available in the package AnalyzeFMRI. The package fmri contains functions to analyze fMRI data using adaptive smoothing procedures.

• Functions for visualization and analysis of Fluorescence Lifetime Imaging Microscopy (FLIM) datasets are available in the package TIMP.

Fluorescence Excitation-Emission Matrix (EEM)

• The EEM reads raw EEM data and prepares it for further analysis.

Carbon Dating

• The package Bchron creates chronologies based on radiocarbon and non-radiocarbon dated depths.

Astronomy and astrophysics

• The astrodatR package collects 19 datasets from contemporary astronomy research, many of which are described in the aforementioned textbook ‘Modern Statistical Methods for Astronomy with R Applications’.
• The astrolibR package presents an R interface to low-level utilities and codes from the Interactive Data Language (IDL) Astronomy Users Library.
• The CRAC collects R functions for cosmological research, with its main functions being similar to the python library, cosmolopy.
• The RobPer package calculates periodograms based on (robustly) fitting periodic functions to light curves.
• The package snapshot contains functions for reading and writing N-body snapshots from the GADGET code for cosmological N-body/SPH simulations.
• The package UPMASK performs unsupervised photometric membership assignment in stellar clusters using, e.g., photometry and spatial positions.
• The solaR package provides functions to determine the movement of the sun from the earth and to determine incident solar radiation.
• The FITSio package provides utilities to read and write files in the FITS (Flexible Image Transport System) format, a standard format in astronomy.
• The stellaR package manages and displays stellar tracks and isochrones from the Pisa low-mass database.
• The astroFns provides miscellaneous astronomy functions, utilities, and data.
• The cosmoFns contains standard expressions for distances, times, luminosities, and other quantities useful in observational cosmology, including molecular line observations.
• The astro package provides tools for astronomy; functions provided may be grouped into 4 main areas: cosmology, FITS file manipulation, the Sersic function and general (plotting and scripting) tools.
• The celestial package includes a number of common astronomy conversion routines, particularly the HMS and degrees schemes.
• The SCEPtER package is used to estimate stellar mass and radius given observational data of effective temperature, [Fe/H], and astroseismic parameters.
• The lira package performs Bayesian linear regression and forecasting in Astronomy, accounting for all kinds of errors and correlations in the data.
• The astrochron package contains routines for astronomical time scale construction, time series analysis, time scale development, and paleoclimate analysis.
• The SPADAR package provides functions to create all-sky grid plots of widely used astronomical coordinate systems (equatorial, ecliptic, galactic) and scatter plots of data on any of these systems, including on-the-fly system conversion.
• The SCEPtERbinary allows for estimating the stellar age for double-lined detached binary systems, adopted from the effective temperature, the metallicity [Fe/H], the mass, and the radius of the two stars.
• The Astrostatistics and Astroinformatics Portal is an R-centric collection of information regarding statistical analysis in astronomy.
• Hans Werner Borchers has a page on Astronomy modules and links for R, Python, and Julia.

Optics and Scattering Approximations

• The planar package provides code to simulate reflection and transmission at a multilayer planar interface.
• The dielectric package defines some physical constants and dielectric functions commonly used in optics and plasmonics.

Energy Modeling

• The solaR package provides functions to simulate and model systems involved in the capture and use of solar energy, including photovoltaics.

Positron Emission Tomography

• The PET package implements different analytic/direct and iterative reconstruction methods for positron emission tomography (PET) data.

Water and Soil Chemistry

• The AquaEnv package is a toolbox for aquatic chemical modelling focused on (ocean) acidification and CO2 air-water exchange.
• See the Environmetrics task view for further related packages related to water and soil chemistry.

Titration Curves

• The titrationCurves package provides functions to plot acid/base, complexation, redox, and precipitation titration curves.

Electrochemistry

• The eChem package provides functions to simulate voltammetry, chronoamperometry and chronocoulometry experiments, which may be useful in courses in analytical chemistry.

## Packages

### ALS — 0.0.6

Multivariate Curve Resolution Alternating Least Squares (MCR-ALS)

### AnalyzeFMRI — 1.1-18

Functions for Analysis of fMRI Datasets Stored in the ANALYZE or NIFTI Format

### AquaEnv — 1.0-4

Integrated Development Toolbox for Aquatic Chemical Model Generation

### astro — 1.2

Astronomy Functions, Tools and Routines

### astrochron — 0.9

A Computational Tool for Astrochronology

### astrodatR — 0.1

Astronomical Data

### astrolibR — 0.1

Astronomy Users Library

### astroFns — 4.1-0

Astronomy: time and position functions, misc. utilities

### Bchron — 4.3.0

Radiocarbon Dating, Age-Depth Modelling, Relative Sea Level Rate Estimation, and Non-Parametric Phase Modelling

### BioMark — 0.4.5

Find Biomarkers in Two-Class Discrimination Problems

### bvls — 1.4

The Stark-Parker algorithm for bounded-variable least squares

### celestial — 1.4.6

Collection of Common Astronomical Conversion Routines and Functions

### cosmoFns — 1.0-1

Functions for cosmological distances, times, luminosities, etc.

### CHNOSZ — 1.3.2

Thermodynamic Calculations and Diagrams for Geochemistry

### chemCal — 0.2.1

Calibration Functions for Analytical Chemistry

### chemometrics — 1.4.2

Multivariate Statistical Analysis in Chemometrics

### ChemometricsWithR — 0.1.13

Chemometrics with R - Multivariate Data Analysis in the Natural Sciences and Life Sciences

### ChemoSpec — 5.0.229

Exploratory Chemometrics for Spectroscopy

### ChemoSpec2D — 0.2.19

Exploratory Chemometrics for 2D Spectroscopy

### clustvarsel — 2.3.3

Variable Selection for Gaussian Model-Based Clustering

### compositions — 1.40-2

Compositional Data Analysis

### constants — 0.0.2

Reference on Constants, Units and Uncertainty

### CRAC — 1.0

Cosmology R Analysis Code

### dielectric — 0.2.3

Defines some physical constants and dielectric functions commonly used in optics, plasmonics.

### drc — 3.0-1

Analysis of Dose-Response Curves

### eChem — 1.0.0

Simulations for Electrochemistry Experiments

### EEM — 1.1.1

Read and Preprocess Fluorescence Excitation-Emission Matrix (EEM) Data

### elasticnet — 1.1.1

Elastic-Net for Sparse Estimation and Sparse PCA

### enpls — 6.1

Ensemble Partial Least Squares Regression

### errors — 0.3.2

Uncertainty Propagation for R Vectors

### fastICA — 1.2-1

FastICA Algorithms to Perform ICA and Projection Pursuit

### fingerprint — 3.5.7

Functions to Operate on Binary Fingerprint Data

### fmri — 1.9

Analysis of fMRI Experiments

### fpca — 0.2-1

Restricted MLE for Functional Principal Components Analysis

### FITSio — 2.1-0

FITS (Flexible Image Transport System) Utilities

### FTICRMS — 0.8

Programs for Analyzing Fourier Transform-Ion Cyclotron Resonance Mass Spectrometry Data

### homals — 1.0-8

Gifi Methods for Optimal Scaling

### hyperSpec — 0.99-20180627

Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...)

### investr — 1.4.0

Inverse Estimation/Calibration Functions

### Iso — 0.0-17

Functions to Perform Isotonic Regression

### kohonen — 3.0.8

Supervised and Unsupervised Self-Organising Maps

### leaps — 3.0

Regression Subset Selection

### lira — 2.0.1

LInear Regression in Astronomy

LS-PLS Models

### MALDIquant — 1.19.3

Quantitative Analysis of Mass Spectrometry Data

### MALDIrppa — 1.0.1-2

MALDI Mass Spectrometry Data Robust Pre-Processing and Analysis

### measurements — 1.3.0

Tools for Units of Measurement

### metRology — 0.9-28-1

Support for Metrological Applications

### minpack.lm — 1.2-1

R Interface to the Levenberg-Marquardt Nonlinear Least-Squares Algorithm Found in MINPACK, Plus Support for Bounds

### NISTunits — 1.0.1

Fundamental Physical Constants and Unit Conversions from NIST

### nlme — 3.1-140

Linear and Nonlinear Mixed Effects Models

### nlreg — 1.2-2.2

Higher Order Inference for Nonlinear Heteroscedastic Models

### OrgMassSpecR — 0.5-3

Organic Mass Spectrometry

### nnls — 1.4

The Lawson-Hanson algorithm for non-negative least squares (NNLS)

### pcaPP — 1.9-73

Robust PCA by Projection Pursuit

### PET — 0.5.1

Simulation and Reconstruction of PET Images

### planar — 1.6

Multilayer Optics

### pls — 2.7-1

Partial Least Squares and Principal Component Regression

### plspm — 0.4.9

Tools for Partial Least Squares Path Modeling (PLS-PM)

### ppls — 1.6-1.1

Penalized Partial Least Squares

### prospectr — 0.1.3

Miscellaneous functions for processing and sample selection of vis-NIR diffuse reflectance data

### psy — 1.1

Various procedures used in psychometry

### PTAk — 1.3-34

Principal Tensor Analysis on k Modes

### RAMClustR — 1.0.6

Mass Spectrometry Metabolomics Feature Clustering and Interpretation

### rcdk — 3.4.7.1

Interface to the 'CDK' Libraries

### rcdklibs — 2.0

The CDK Libraries Packaged for R

### represent — 1.0

Determine the representativity of two multidimensional data sets

### resemble — 1.2.2

Regression and Similarity Evaluation for Memory-Based Learning in Spectral Chemometrics

### RobPer — 1.2.2

Robust Periodogram and Periodicity Detection Methods

### rpubchem — 1.5.10

An Interface to the PubChem Collection

### sapa — 2.0-2

Spectral Analysis for Physical Applications

### simecol — 0.8-12

Simulation of Ecological (and Other) Dynamic Systems

### SCEPtER — 0.2-1

Stellar CharactEristics Pisa Estimation gRid

### SCEPtERbinary — 0.1-1

Stellar CharactEristics Pisa Estimation gRid for Binary Systems

### som — 0.3-5.1

Self-Organizing Map

Spherical Projections of Astronomical Data

### spectralAnalysis — 3.12.0

Pre-Process, Visualize and Analyse Process Analytical Data, by Spectral Data Measurements Made During a Chemical Process

### snapshot — 0.1.2

Gadget N-body cosmological simulation code snapshot I/O utilities

### speaq — 2.6.0

Tools for Nuclear Magnetic Resonance (NMR) Spectra Alignment, Peak Based Processing, Quantitative Analysis and Visualizations

### spls — 2.2-3

Sparse Partial Least Squares (SPLS) Regression and Classification

### stellaR — 0.3-3

stellar evolution tracks and isochrones

### stepPlr — 0.93

L2 Penalized Logistic Regression with Stepwise Variable Selection

### subselect — 0.14

Selecting Variable Subsets

### titrationCurves — 0.1.0

Acid/Base, Complexation, Redox, and Precipitation Titration Curves

### TIMP — 1.13.2

Fitting Separable Nonlinear Models in Spectroscopy and Microscopy

### units — 0.6-3

Measurement Units for R Vectors

Unsupervised Photometric Membership Assignment in Stellar Clusters

### titan — 1.0-16

Titration analysis for mass spectrometry data

### varSelRF — 0.7-8

Variable Selection using Random Forests

### webchem — 0.4.0

Chemical Information from the Web

### WilcoxCV — 1.0-2

Wilcoxon-based variable selection in cross-validation