# Fitting in mathematica when dealing with non-gaussian noise and errors on the data points

When you have just a single additive error term with a known distributional form, you should avoid thinking about "weights" (except for some distributions where using weights and least squares gives you good starting values for troublesome datasets and models).

For the example you give using maximum likelihood is pretty straightforward. If you have some knowledge about the parameters of interest that can be characterized with a probability distribution, then a Bayesian approach would be your best bet.

Here is a maximum likelihood approach:

```
(* Define function *)
f[A_, ν0_, t_] := A Sin[2 π ν0 t]
(* Generate some data *)
f0 = 10;
Amax = 1;
dt = 0.005;
t0 = 0;
tf = 0.4;
σRayleigh = 4;
SeedRandom[12345];
RayleighNoisedData = Table[{t, f[Amax, f0, t] +
RandomVariate[RayleighDistribution[σRayleigh]]}, {t, t0, tf, dt}];
(* Find log of the likelihood and maximize it *)
logL = LogLikelihood[RayleighDistribution[σ], (#[[2]] - f[A, ν0, #[[1]]]) & /@ RayleighNoisedData];
sol = FindMaximum[{logL[[1, 1, 1]], σ > 0}, {{A, Amax}, {ν0, f0}, {σ, σRayleigh}}]
(* {-176.659, {A -> 0.790322, ν0 -> 10.3217, σ -> 3.83458}} *)
(* Plot results *)
Show[ListPlot[RayleighNoisedData],
Plot[{f[A, ν0, t] /. {A -> Amax, ν0 -> f0},
f[A, ν0, t] /. sol[[2]]}, {t, t0, tf},
PlotLegends -> {"True", "Estimated"}], PlotRange -> All]
```

In this case there's just no need for symmetric or asymmetric error bands on the data points. If there is sampling/measurement error in addition to the random deviations from the underlying curve, then you need to use software that accounts for multiple error sources (i.e., mixed models). *Mathematica* does not yet offer mixed model functions (although one can obtain estimates of mixed model parameters with *Mathematica*, there are no higher level functions equivalent to `NonlinearModelFit`

to do so).

(I've left off error bars (symmetric and/or asymmetric) because I don't see that they help in interpretation in this case. Also, I've not included essential confidence bands around the estimated curve because I've run out of time tonight.)