fitCurve: Curve fitting using minpack.lm

Description Usage Arguments Value Examples

View source: R/curveFit_utils.R

Description

Fit different curve models using minpack. Fitting parameters can be passed or guessed.

Usage

1
fitCurve(x, y, curveModel = "skewedGaussian", params = "guess")

Arguments

x

(numeric) x values (e.g. retention time)

y

(numeric) y observed values (e.g. spectra intensity)

curveModel

(str) name of the curve model to fit (currently skewedGaussian)

params

(list or str) either 'guess' for automated parametrisation or list of initial parameters ($init_params), lower parameter bounds ($lower_bounds) and upper parameter bounds ($upper_bounds)

Value

A 'peakPantheR_curveFit': a list of fitted curve parameters, fitStatus from nls.lm$info and curve shape name curveModel. fitStatus=0 unsuccessful completion: improper input parameters, fitStatus=1 successful completion: first convergence test is successful, fitStatus=2 successful completion: second convergence test is successful, fitStatus=3 successful completion: both convergence test are successful, fitStatus=4 questionable completion: third convergence test is successful but should be carefully examined (maximizers and saddle points might satisfy), fitStatus=5 unsuccessful completion: excessive number of function evaluations/iterations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## Not run: 
## x is retention time, y corresponding intensity
input_x  <- c(3362.102, 3363.667, 3365.232, 3366.797, 3368.362, 3369.927, 3371.492, 3373.057,
             3374.622, 3376.187, 3377.752, 3379.317, 3380.882, 3382.447, 3384.012, 3385.577,
             3387.142, 3388.707, 3390.272, 3391.837, 3393.402, 3394.966, 3396.531, 3398.096,
             3399.661, 3401.226, 3402.791, 3404.356, 3405.921, 3407.486, 3409.051)
input_y  <- c(51048, 81568, 138288, 233920, 376448, 557288, 753216, 938048, 1091840, 1196992,
              1261056, 1308992, 1362752, 1406592, 1431360, 1432896, 1407808, 1345344, 1268480,
              1198592, 1126848, 1036544, 937600, 849792, 771456, 692416, 614528, 546088, 492752,
              446464, 400632)

## Fit
fitted_curve <- fitCurve(input_x, input_y, curveModel='skewedGaussian', params='guess')

## Returns the optimal fitting parameters
fitted_curve
#
# $amplitude
# [1] 275371.1
# 
# $center
# [1] 3382.577
# 
# $sigma
# [1] 0.07904697
# 
# $gamma
# [1] 0.001147647
# 
# $fitStatus
# [1] 2
# 
# $curveModel
# [1] "skewedGaussian"
#
# attr(,"class")
# [1] "peakPantheR_curveFit"

## End(Not run)

peakPantheR documentation built on May 1, 2019, 10:53 p.m.