Description Usage Arguments Details Value Examples
View source: R/FitFunctions_gaussian_nlm.R
Fit a Gaussian Peak Using Non-Linear Least Squares
1 | fit_gaussian_nlm(x, y, init_mu, init_sigma, init_k)
|
x |
values of the x-axis |
y |
values of the y-axis |
init_mu |
initial guess of mu (the peak center) |
init_sigma |
initial guess of sigma (the standard deviation) |
init_k |
initial guess of k (the peak height) |
Implementation uses the nls() function to fit a gaussian peak to experimental data using the nl2sol algorithm from the Port library - see ?nls() and https://people.sc.fsu.edu/~jburkardt/f_src/minpack/minpack.html
a list containing a vector 'fitPeak' containing the y-values of the fitted peak and a list 'nlsResult' containing the data returned from nlm()
1 2 3 4 5 | xVec <- seq(from = 1, to = 100, by = 0.1)
gauss <- func_gaussian(x = xVec, mu = 10, sigma = 1, probDensity = FALSE, k = 10)
gauss <- gauss + rnorm(n = length(gauss), mean = 0, sd = 1)
fit <- fit_gaussian_nlm(x = xVec, y = gauss, init_mu = 9, init_sigma = 0.5, init_k = 3)
plot(x = xVec, y = gauss); points(x = xVec, y = fit$fitPeak, col = "red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.