# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Perform linear and nonlinear fits on data with error bars

Contributed by:
Sjoerd Smit

ResourceFunction["FitWithErrors"][LinearModelFit[ performs a LinearModelFit on data with Around values by finding the appropriate Weights option value based on the uncertainties in | |

ResourceFunction["FitWithErrors"][NonlinearModelFit[ performs a NonlinearModelFit on | |

ResourceFunction["FitWithErrors"][ limits the algorithm to |

ResourceFunction["FitWithErrors"] is HoldFirst and inspects the given fit expression to find the correct weights.

The *data* is expected to be a matrix or vector input.

Only symmetric Around values are supported.

Uncertainties in the response variable of the fit are assumed to be Gaussian. The weights are computed as the inverse of the variance. Because of this, all rows of the data need to have non-zero variance.

Uncertainties in the predictor variables are accounted for using the method of Fasano & Vio (see references). This method propagates the uncertainties through the model to obtain the corresponding uncertainties in the responses, which are then converted to weights. The procedure is iterated several times. By default, the number of iterations is limited to 20.

Fit a linear model to some data with errors in the response variable:

In[1]:= |

Out[2]= |

In[3]:= |

Out[3]= |

Fit data with uncertainties in both *x* and *y*:

In[4]:= |

Out[5]= |

In[6]:= |

Out[6]= |

If one of the rows of the input data does not have any uncertainty, it's not possible to calculate the weights for that row and the fit will fail:

In[10]:= |

Out[10]= |

Mixing x errors with y errors does work because it's still possible to compute a weight for each row:

In[11]:= |

Out[11]= |

Only vector and matrix inputs are currently supported:

In[12]:= |

In[13]:= |

Non-symmetric Around values are not supported:

In[14]:= |

Out[14]= |

Wolfram Language 13.0 (December 2021) or above

This work is licensed under a Creative Commons Attribution 4.0 International License