fit_gaussian_nlm: Fit a Gaussian Peak Using Non-Linear Least Squares

Description Usage Arguments Details Value Examples

View source: R/FitFunctions_gaussian_nlm.R

Description

Fit a Gaussian Peak Using Non-Linear Least Squares

Usage

1
fit_gaussian_nlm(x, y, init_mu, init_sigma, init_k)

Arguments

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)

Details

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

Value

a list containing a vector 'fitPeak' containing the y-values of the fitted peak and a list 'nlsResult' containing the data returned from nlm()

Examples

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")

pmbrophy/SummitR documentation built on May 20, 2020, 12:36 a.m.