Regression line that includes x and y errors.

Hi,
I have x and y data set, and each x and y variables have 5% and 10% uncertainty or error, respectively. How I should find a one regresion or best fit line (Best_y = mx + c) for such a dataset? Here is the dataset. Any thoughts? Thanks.

 Accepted Answer

Matt J
Matt J on 20 Feb 2023
Edited: Matt J on 20 Feb 2023
I would recommend linear2dFit() form this FEX download,
fitResult=linear2dFit([x,y]')

4 Comments

Thanks. I tried to run the example code, but got error on this line: xy=linear2dFit.xysim(p1, p2, t, sig). The error is The specified superclass 'conicFit' contains a parse error, cannot be found on MATLAB's search path, or is shadowed by another file with the same name.
I found that I dont have "linear2dFit.xysim" FEX function. I'm missing anything. Thanks.
It sounds to me like you only downloaded linear2dFit. You need to download all the files.
Thanks. It runs now. This is a great function. So, just I understand the linear2dFit function, particularly how the function incorporates the error values. In my case, I need to build an array (xy here) that includes +/-x and +/-y error values.This xy array has x and y values also error dx and dy values too. I believe the function then find a best fit through all these points. Thanks!
Matt J
Matt J on 20 Feb 2023
Edited: Matt J on 20 Feb 2023
Thanks. It runs now. This is a great function
Glad it's working for you, but if it's doing what you need, I'd be much obliged if you'd Accept-click the answer.
particularly how the function incorporates the error values?
The fit is a total least squares fit, so it assumes there are errors in both x and y.

Sign in to comment.

More Answers (0)

Asked:

on 20 Feb 2023

Edited:

on 20 Feb 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!