---
title: "An introduction to the proximetricsR package"
author: 
 - name: Leonardo Ramirez-Lopez and Claudio Orellano
   email: ramirez-lopez.l@buchi.com
   affiliation: Data Science Department, BUCHILabortechnik AG, Flawil, Switzerland
date: today
clean: true
bibliography: ["proximetricsR.bib"]
biblio-style: "apalike"
link-citations: true
format:
  html:
    toc: true
    toc-depth: 3
    toc-location: left
    number-sections: true
    code-overflow: wrap
    smooth-scroll: true
    html-math-method: mathjax
vignette: >
  %\VignetteIndexEntry{An introduction to the proximetricsR package}
  %\VignetteEncoding{UTF-8}
  %\VignetteEngine{quarto::html}
---


```{r}
#| label: setup
#| include: false
old_options <- options(digits = 3)
```

# Overview

`proximetricsR` is an `R` package for building and updating near-infrared (NIR) applications for the [ProxiMate](https://www.buchi.com/en/products/instruments/proximate) and [ProxiScout](https://www.buchi.com/de/produkte/instrumente/proxiscout) series of NIR sensors manufactured by BUCHI Labortechnik AG.

# Background: NIR spectroscopy and applications

Near-infrared (NIR) spectroscopy is a well-established technology in food, feed, and environmental research and industry. NIR instruments typically measure either the light reflected by a matrix or the light transmitted through it. These measurements are used to infer how much light is absorbed by the matrix at different NIR wavelengths. Absorbance is largely determined by the chemical and physical composition of the matrix and by the concentration of its components.

Empirical models can therefore be built to describe the relationship between NIR spectra and properties of interest. For example, the protein content of a wheat sample can be predicted by applying a pre-calibrated NIR model to the spectrum measured from that sample. Quantitative NIR models are usually matrix- and property-specific. These models can be viewed as functions that translate spectral data into meaningful information:

$$
\hat{y} = f(x; \theta)
$$

where (\hat{y}) is the predicted response, (x) is the spectral data, and (\theta) represents the parameters of the function.

In this document, the term **NIR application** refers to a set of predictive functions or models used to predict one or more properties of a given matrix. The NIR application, (A), for a matrix with (n) response variables or properties can be described as:

$$
A = {f_1, \ldots, f_n}
$$

# Application workflows for ProxiMate and ProxiScout

ProxiMate and ProxiScout applications consist of predictive models and the metadata required for deployment on the corresponding device.

ProxiMate applications are conventionally developed with **NIRWise PLUS**, the compiled-executable software offered by BUCHI. ProxiScout applications are conventionally developed using the **Modeller** environment together with an additional third-party proprietary software component requiring paid licenses.

# Scope of `proximetricsR`

The aim of `proximetricsR` is to provide a transparent and flexible `R`-based workflow for calibrating predictive NIR models and generating application files for ProxiMate and ProxiScout devices. Users with a basic understanding of `R` can use the package to programmatically build and/or update NIR applications while benefiting from the broader `R` ecosystem and open-source workflows.

The files generated by `proximetricsR` are designed to follow the expected application structure for both ProxiMate and ProxiScout devices. The package does not introduce changes or improvements to these output file structures.

```{r cleanup, include = FALSE}
options(old_options)
```
