I’m looking for a way to do curve fitting where the data has error both on x and y. I’ve read up on physics forums about errors-in-variables fitting, but I’d like to know if there are already any functionalities that julia provides to make this sort of regression.

Specifically, my problem is to try and fit a curve for the reflectance of an Electromagnetic Wave(red laser) which s-polarized(TE mode). The theoretical curve depends on the angle of incidence \theta_i and the relative index of refraction n, with a formula that is given by the Fresnel equation:

R_s = |\Gamma^{\text{TE}}|^2 = \left| \frac{\sqrt{n^2 - \sin^2(\theta_i)} - \cos \theta_i}{\sqrt{n^2 - \sin^2(\theta_i)} + \cos \theta_i} \right|^2

There’s also the problem that, if n<1, there might be total internal reflection, so the curve will be discontinuous at the critical angle \theta_L (image taken from wikipedia):

This is the experimental data, with x and y uncertainties:

Currently, my solution was to just ignore the uncertainties and use Optim.jl, but I’d like to know if there’s a better way, preferably accounting for the uncertainties.