how to calculate the full width at half maximum (FWHM) of error function

1,533 views
Skip to first unread message

G.B.

unread,
Feb 2, 2022, 1:03:44 PM2/2/22
to lmfit-py
I used the StepModel with form='erf',  ‘erf’ is an error function. The fitting results give me the step_sigma as shown below.  Does anyone know how to calculate the FWHM of this "erf" in lmfit? Thanks.

[[Model]]
    (Model(step, prefix='step_', form='erf') + Model(linear, prefix='line_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 63
    # data points      = 2048
    # variables        = 5
    chi-square         = 0.15843966
    reduced chi-square = 7.7552e-05
    Akaike info crit   = -19378.4170
    Bayesian info crit = -19350.2939
[[Variables]]
    line_slope:     -6.0315e-05 +/- 6.7795e-07 (1.12%) (init = 0)
    line_intercept:  0.98634194 +/- 4.4624e-04 (0.05%) (init = 0.05368444)
    step_amplitude: -0.81710209 +/- 8.1135e-04 (0.10%) (init = 0.9396381)
    step_center:     1065.02173 +/- 0.06374482 (0.01%) (init = 1024)
    step_sigma:      13.7122407 +/- 0.12916728 (0.94%) (init = 292.5714)
[[Correlations]] (unreported correlations are < 0.100)
    C(line_slope, step_amplitude)     = -0.874
    C(line_slope, line_intercept)     = -0.792
    C(line_intercept, step_amplitude) =  0.487
    C(step_amplitude, step_sigma)     = -0.206
    C(line_slope, step_sigma)         =  0.178

Matt Newville

unread,
Feb 2, 2022, 2:00:30 PM2/2/22
to lmfit-py
On Wed, Feb 2, 2022 at 12:03 PM G.B. <guib...@gmail.com> wrote:
I used the StepModel with form='erf',  ‘erf’ is an error function. The fitting results give me the step_sigma as shown below.  Does anyone know how to calculate the FWHM of this "erf" in lmfit? Thanks.

I'm not sure what FWHM means for an error function. Its derivative is a Gaussian, IIRC.  I think some people report the span from 10 to 90%, which is almost certainly some factor times sigma.

--Matt

[[Model]]
    (Model(step, prefix='step_', form='erf') + Model(linear, prefix='line_'))
[[Fit Statistics]]
    # fitting method   = leastsq
    # function evals   = 63
    # data points      = 2048
    # variables        = 5
    chi-square         = 0.15843966
    reduced chi-square = 7.7552e-05
    Akaike info crit   = -19378.4170
    Bayesian info crit = -19350.2939
[[Variables]]
    line_slope:     -6.0315e-05 +/- 6.7795e-07 (1.12%) (init = 0)
    line_intercept:  0.98634194 +/- 4.4624e-04 (0.05%) (init = 0.05368444)
    step_amplitude: -0.81710209 +/- 8.1135e-04 (0.10%) (init = 0.9396381)
    step_center:     1065.02173 +/- 0.06374482 (0.01%) (init = 1024)
    step_sigma:      13.7122407 +/- 0.12916728 (0.94%) (init = 292.5714)
[[Correlations]] (unreported correlations are < 0.100)
    C(line_slope, step_amplitude)     = -0.874
    C(line_slope, line_intercept)     = -0.792
    C(line_intercept, step_amplitude) =  0.487
    C(step_amplitude, step_sigma)     = -0.206
    C(line_slope, step_sigma)         =  0.178

--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/d332244c-a06e-422d-a072-dba7c40ce430n%40googlegroups.com.


Laurence Lurio

unread,
Feb 2, 2022, 2:46:37 PM2/2/22
to lmfi...@googlegroups.com
I think you must mean the FWHM of the derivative of the error function, which is almost a gaussian.  For a gaussian y(x) = exp(-x**2)/(2*sigma**2) ) the FWHM is 2.35 sigma or sqrt(8*ln(2))*sigma.  However, the erf function is defined as 2/sqrt(pi)*integral(exp(-t**2), t=0..z).  e.g. exp(-t**2), not  exp(t**2/2), so its derivative differs by a factor of 2 in the exponent from a gaussian.  If we let  t = x/sigma', then we have to redefine sigma' = sigma*sqrt(2), so that the FWHM = sqrt(2)*2.35.  

I'm assuming that lmfit uses the standard definition of the erf function (as defined by scipy.special.erf), but I haven't actually checked that.

Larry Lurio

Matt Newville

unread,
Feb 2, 2022, 10:07:25 PM2/2/22
to lmfit-py
Hi Larry, 

Yes, I believe you're right, that the derivative of erf() will be different from a standard Gaussian with a width that is smaller by sqrt(2) so that FWHM of the derivative of erf would be 

   FWHM/sigma ~= (2.355 / sqrt(2))  ~= 1.665 = 2*sqrt(log(2)) 

Thanks!


 



--
--Matt Newville <newville at cars.uchicago.edu630-327-7411

G.B.

unread,
Feb 2, 2022, 11:42:35 PM2/2/22
to lmfit-py
Hello, thanks both of you. Your answer is really good. I tested, and I'm sure the answer is right. Thanks again.
Reply all
Reply to author
Forward
0 new messages