Is it possible to use polyfit in a way that it takes into account the errorbars?
36 ビュー (過去 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!