Peak fitting
Model adjustment
Peak fitting is done with the JuMP framework (https://jump.readthedocs.org/en/latest/). Spectra actually does not provide any peak fitting capacities by itself, but the combination of its functionality with JuMP helps making fitting procedure quite easy. An example is visible in the example section of Spectra.
One goal of Spectra is to promote the use of global optimisation models, where peak parameters are actually calculated from variation in other parameters (chemistry, temperature, etc.), or are shared between several spectra. I will provide very soon an example of such an approach. It can be implemented in a few lines of code with combining Spectra and JuMP, and has the advantage of greatly reducing the errors of the fits.
error calculation with bootstrapping
Error calculation can be done with using bootstrapping. Spectra provides a function that allows generating K new datasetes, by resampling the existing dataset in a non-parametric or parametric way.
Spectra.bootsample
— Function.bootsample(x::Array{Float64}, y::Array{Float64}; boottype::String = "np", ese::Array{Float64} = [0.0])
Inputs
x: Array{Float64}, the x axis. It can have multiple columns.
y: Array{Float64}, the y axis. It can have multiple columns.
Options
boottype: ASCIIString, either "np" or "p", this is the type of bootstrapping performed. "np" performes a non-parametric resampling fo the dataset with replacement. "p" performs a parametric resampling. The data are resample from a gaussian distribution centered on the y values with errors that should be provided in the ese variable.
ese: Array{Float64}, containing the errors affecting the y values that are used during parametric bootstrapping.
Outputs
b_x_f: Array{Float64}, the bootstrapped x values
b_y_f: Array{Float64}, the bootstrapped y values
The bootstrap function can be embedded in a for loop, and will each time produce a different dataset. Performing K times the bootstrapping and fitting each time the model will allow to estimate the error distribution on the peak parameters. This technic has the advantage of making no prior assumption on the probability distribution functions of parameters errors. However, it is much more time consuming that using the covariance matrix.
Spectra.bootperf
— Function.bootperf(params_boot::Array{Float64}; plotting::String = "True", parameter::Int64 = 1, feature::Int64 = 1, histogram_step::Int64 = 100, savefigures::String = "False", save_bootrecord::String = "Boot_record.pdf", save_histogram::String = "Boot_histogram.pdf")
Inputs
params_boot[i,j] or [i,j,k]
array with i the bootstrrap experiment, j the parameter and k the feature being calculated (e.g., a peak during peak fitting)
plotting: String
switch to plotting mode ("True") or not ("False"). If true, parameter and feature must be provided, otherwise an error message is returned.
histogram_step
integer value to control the histogram X axis division.
savefigures: "True" or "False"
explicit, save in the current working directory.
save_bootrecord:
Name for the graphic showing the bootstrap mean and std evolutions, with extension.
save_histogram:
Name for the graphic showing the histogram for the parameter and feature of interest, with extension.
Outputs
std_record, mean_record, the arrays recording how the standard deviation and mean of the parameters as a function of the bootstrap advance.
For further details, see the following references
Efron, B. 1979. “Bootstrap Methods: Another Look at the Jackknife.” The Annals of Statistics 7 (1): 1–26.
Efron, Bradley. 1981. “Nonparametric Estimates of Standard Error: The Jackknife, the Bootstrap and Other Methods.” Biometrika 68 (3): 589–99. doi:10.1093/biomet/68.3.589.
Efron, B., and Tibshirani, R. 1994. An Introduction to the Bootstrap. CRC press.