elco_xrf_correct_elements: Heuristic function to correct XRF element contents of samples...

View source: R/elco_xrf_correct_elements.R

elco_xrf_correct_elementsR Documentation

Heuristic function to correct XRF element contents of samples measured with sample masses smaller than used for the instrument calibration.

Description

elco_xrf_correct_elements is a heuristic function to correct measured element contents of samples during XRF analysis. Elements for which to perform a correction can be selected. Only batch processing of files is possible. The correction is based on a reference calibration data set where five different samples have been measured with four different masses (500 mg, the current reference with which the instrument is calibrated, 300, 250, and 200 mg). For each measured element and measurement, the ratio of the element content measured with mass x and the element content measured with reference mass (500 mg) are divided. Deviations from 1 are due to measurement noise and effects of mass differences on the recorded signal. The correction targets the latter, but also propagates uncertainty about the former. The computed ratios are modeled with a linear mixed model, where there is a random intercept for each sample and the sample mass is treated as factor. Sample mass is treated as factor because the variance is not homogeneous between different masses (a future version might include a procedure where the variance is also modeled in dependence of the sample mass). A consequence is that the correction procedure currently can only be applied to values measured with sample masses as used in the calibration data set. The regression models assume a Gamma distribution since all computed ratios are ≥0. The models are fit with rstanarm() (rstanarm::stan_glmer()) using default priors. From the models' predictive distributions, the predicted correction factors are sampled and its mean and standard deviation stored. During correction, the measured value to correct and a sample mass are given. elco_xrf_correct_elements searches the respective correction factor and its standard deviation and multiplies it with the measured value. The quantities::quantities() package is used to propagate the uncertainty in the correction factor into the corrected value.

Usage

elco_xrf_correct_elements(
  x,
  element = NULL,
  sample_mass,
  xrf_calibration = NULL
)

Arguments

x

An object of class data.frame.

element

A character vector representing the chemical elements for which to correct the mass fraction values. This must be one in xrf_calibration$el_symbol(). Can alternatively be set to NULL to correct all chemical elements possible.

sample_mass

A vector of class units::units() with an element for each row in x and "mg" as measurement unit.

xrf_calibration

A data frame which stores correction factors for combinations of chemical elements and sample masses, with a row for each element and sample mass and three columns:

el_symbol

A character vector with the chemical element symbol which the correction factor in correction_factor applies.

sample_mass

A character vector with the sample mass [mg] for which the correction factor in correction_factor applies.

correction_factor

A quantities::quantities() vector with the correction factors.

Alternatively, xrf_calibration can be set to NULL. In this case, the built-in xrf_calibration() is used. Check beforehand if this set of calibration factors is appropriate!

Value

x with corrected element content values.

Note

Currently, the calibration procedure is rather crude and not based on a large amount of samples. This causes relative large uncertainties.


henningte/elco documentation built on May 21, 2022, 6:56 p.m.