Learn R Programming

proximetricsR (version 0.6.5)

add_model_metadata: A function for adding model metadata to a spectral_model object

Description

This function has two use cases:

i. If object (being a spectral_model object) is passed to the function, it returns the same object with the specified model metadata added to it.

ii. Otherwise, the function creates a a list of model metadata that can be used as input for the argument metadata of the calibrate function.

Usage

add_model_metadata(object, key = UUIDgenerate(), created, changed,
                   name = c("", NULL), sort_order = 1, tol_min = NULL,
                   tol_max = NULL, decimal_places = 2, unit = "",
                   mahal_limit = 5, corrections = c(bias = 0, slope = 1),
                   limit_min = NULL, limit_max = NULL, target = NULL,
                   wavelength_range = c("Nir", "Vis", "Nir+Vis"),
                   predict_type = "Calibration", arguments = rep("", 4))

Value

Either the spectral_model object with the added property metadata (if object is provided), or the property metadata, which is a named list.

Arguments

object

an optional object of class spectral_model. See details.

key

a string for the key of the model. Defaults to a newly generated key using UUIDgenerate.

created

a string for date and time of the addition of the model to the application. Default is the current date and time of the system. See details for the format in which it has to be provided.

changed

a string for date and time when the model has been changed. Default is the current date and time of the system. See details for the format in which it has to be provided.

name

a vector of character strings of length 2 for the name and alias of the property. If object is given or an object returned by this function is passed to calibrate, defaults to the name of the property (but not the alias). Otherwise, defaults to an empty character.

sort_order

a numeric, indicating the order in which the properties are shown on a ProxiMate device. Defaults to 1.

tol_min

an optional numeric for the minimum error tolerance. Defaults to NULL.

tol_max

an optional numeric for the maximal error tolerance. Defaults to NULL.

decimal_places

a numeric for the decimal precision of the measurements of the property. Defaults to 2.

unit

a string for the units in which the reference values of the property are measured. Defaults to an empty character.

mahal_limit

a numeric for the maximum Mahalanobis distance allowed. Defaults to 5.

corrections

a vector of numerics of length 2 for bias and slope corrections. Defaults to no corrections, i.e. c(0, 1).

limit_min

an optional numeric for the lower limit of the reference values. Defaults to NULL.

limit_max

an optional numeric for the upper limit of the reference values. Defaults to NULL.

target

an optional numeric for the desired predicted reference values. Defaults to NULL.

wavelength_range

a string for the considered wavelength range of the spectrum. Must be one of "Nir" (default), "Vis" or "Nir+Vis".

predict_type

a string for the prediction type of the model. Defaults to "Calibration".

arguments

a vector of maximal length 4. Contains additional arguments to be saved into the metadata. Defaults to a vector of empty characters of length 4.

Author

Claudio Orellano, Leonardo Ramirez-Lopez

Details

This function has two functionalities:

  • If object (being a spectral_model object) is passed to the function, it returns the same object with the specified property metadata added to it.

  • Otherwise, the function creates a a list of property metadata that can be used as the argument metadata of the calibrate function.

The two-fold functionality of this function allows to add metadata during the construction of the model, or after the model-building has been finished. For the former, the model has to be passed in object, and the returned value of this function contains the model including the chosen metadata. In the latter case, the returned value of this function may be passed to the parameter metadata of function calibrate.

A lot of the parameters can be left unchanged and may be adjusted at a later stage of the application development (e.g. in a ProxiMate device).

The parameters created and changed must contain the date (YYYY-MM-DD) and time (HH:MM:SS), seperated by a single "T" (without any spaces). For example, the following code returns the correct format (also, both created and changed default to this value):

gsub(" ", "T", format(Sys.time()))

See Also

calibrate, proximate_write_nax

Examples

Run this code
# \donttest{
data(NIRcannabis)

# Downview Absorbance of CBDA in percentage
downview_metadata <- add_model_metadata(
  name = "CBDA",
  unit = "%",
  arguments = "Example metadata"
)

# Three ways to add metadata to spectral_model object:
# As a direct argument
simple_model <- calibrate(CBDA ~ spc,
  data = NIRcannabis, preprocess = preprocess_recipe(),
  method = fit_plsr(5), control = calibration_control(),
  metadata = downview_metadata
)

# Passing the model to add_model_metadata
simple_model <- add_model_metadata(
  object = simple_model,
  name = "CBDA",
  unit = "%",
  arguments = "Example metadata"
)

# Adding it directly (not recommended)
simple_model$metadata <- downview_metadata
# }

Run the code above in your browser using DataLab