Standard Normalized Error in x-direction of /ODR fit result from CurveFit

Hello,

I would like to calculate the error in x-direction of a fit result after an /ODR fit.

The general approach would be to calculate the slope in x-direction and multiply it with the weights:

For example for fitting function exp, I calculate the x-slope for a specific x and use this to approximate the error:

variable arg = (x - coefs[2]) / coefs[3]
variable expTerm = exp(-arg^2)
variable slope = coefs[1] * expTerm * (-2 * arg / coefs[3])

variable sigmaX[i] = sqrt((weightX[i]^2) + (yResidual[i]^2 / (slope^2)))

The derivative in x is specific for each fit function. 

Is there a more general way for the Igor Pro integrated fit function to calculate sigmaX from the output of CurveFit?
(Such that I do not need to implement an own function for calculating the slope in x for each integrated fit function)

Best regards,
Michael Huth

kris

Hi Michael,

I assume you are using /ODR=2 or /ODR=3? If so, then you can get the x-residuals as a result from the CurveFit command directly with /XR=wave:

Make/O/N=(numpnts(yData)) xResidualWave= 0   // pre-init to 0
Make/O/N=(numpnts(yData)) yResidualWave= 0   // pre-init to 0

// /I=1 means yErr and xErr are standard deviations (errors).
// If your weight waves instead hold 1/sigma, remove /I=1.
CurveFit/ODR=2 exp_XOffset yData /X=xData /W=yErr /I=1 /XW=xErr /XR=xResidualWave /R=yResidualWave /D

The x-residual wave output from ODR types Explicit Orthogonal Distance Regression (2) or Implicit (3) is the per-point x-shift. i.e. the x-component of the shift from each data point to the curve, obtained without coding a per-function derivative. 

If your sigmaX is meant to combine the input x-uncertainty (/XW) with the x-projection of the y-residual, note that with /ODR=2 or 3 the x-residual (/XR) already gives you the second term directly and correctly: it is the weighting-aware x-shift of each point onto the curve, so it replaces your yResidual/slope approximation. Two caveats: (1) /R (the output y-residual) is evaluated at x + x-residual, not at the original x, so yResidual/slope is only an approximation of the x-residual; and (2) /XR is a signed residual (a displacement), not an uncertainty — it is not itself sigmaX. If you want your original quadrature form with the exact x-projection, combine it with the input x-uncertainty yourself: sigmaX = sqrt(xErr^2 + xResidual^2).

The correct way to calculate the slope to use as a conversion factor to translate uncertainty between the two axes is to differentiate the fitted model. If you ran the CurveFit as I show above, 

Differentiate fit_yData /D=differentiateOutputWave // dy/dx at each data x, any function

// diff output wave may not have the same number of points as original data, so interpolate that slope 
// onto each data x in xData -> one slope per data point
// wave(x) interpolates via x-scaling
Make/O/N=(numpnts(xData)) slopeAtData = differentiateOutputWave(xData[p]) 

But I think what you want is the x-residual wave from CurveFit /XR=wave.

Thanks,

Kris