Is it possible to use polyfit in a way that it takes into account the errorbars?
조회 수: 40 (최근 30일)
이전 댓글 표시
Dear all,
I have a two sets of data that I want to compare. I do so by making a scatterplot of the two and afterwards fit the data with a simple linear regression model. However, for some of the datapoints I assume a large uncertainty that I have already estimated. As far as I understand the polyfit command, it finds a polynomial function that tries to "collect" all the datapoints in the best possible way (in the sense of the smallest squares). I would be interested though in a fit function, that fits best with all the ranges of values I have estimated and not the actual given datapoints. I could not find an answer to that in the documentation and hope someone here can give me a hint?
Thank you very much.
댓글 수: 2
dpb
2018년 7월 17일
Are these estimated errors symmetric around the measured points? If so, the OLS and other estimate will still be around the mean.
Typically, one uses a weighting function to give points with hither error a lower weight in the fit; what's your objective here--almost sounds like you're trying to bias towards an error rather than fit...
As always, showing the data for context would be helpful.
답변 (2개)
John D'Errico
2023년 12월 16일
Different people mean different things when they say error bars. But you also use the word weights, which is a bit more standard. So I'll assume that you have weights for each point.
However polyfit does not allow weights. Other tools, such as fit from the curve fitting toolbox do allow weights, but you need that toolbox. Or if you have the stats toolbox, you could use fitlm. With slightly more effort, you could also use tools like lsqlin (optimization toolbox), or lscov, but they will require you to create appropriate matrices. If you know enough to create the necessary matrices to use those tools, then even backslash will solve the problem.
댓글 수: 0
Douglas Novaes
2023년 12월 16일
MATLAB's fit function provides the capability to account for error bar weights in curve fitting. The fit function, combined with the appropriate fitting type ('poly5' for a 5th-degree polynomial, for instance) and the error model ('Weights', specifying the weights), can be used to fit curves while considering the error bar weights.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!