How to easily propagate the error of a column ?

1 回表示 (過去 30 日間)
Aaron Ashley
Aaron Ashley 2021 年 3 月 11 日
コメント済み: Aaron Ashley 2021 年 3 月 25 日
I am interested in propagating the uncertainty from a table of data. Specifically, I have to deal with some NaN values appearing in my data, so a function that can ignore these would be fantastic.
For instance, let's say I have some values like:
X = [3 1; 4 2; 5 1; NaN NaN; 6 1]
where the first column of numbers are values and the second column of numbers are their uncertainties. Getting the mean is easy because MATLAB can ignore the NaN with the right flag in the mean() function. But is there a built-in MATLAB code to automatically propogate the uncertainties while ignoring the NaN values?
I know I must be overlooking some resource but I'm not sure what search terms to use. I've found resources on using stdev() with the right flag (as with getting the mean), but that is not what I'm after.

採用された回答

Peter Perkins
Peter Perkins 2021 年 3 月 22 日
Aaron, I think that depends on what you mean by "propagate the uncertainties". There is a simple formula for the variance of the mean given the variances of the individual values, and you can use lscov to make that computation, by fitting a constant regression model. But I'm not sure what you have. Among other things, if the individual measurement errors are not independent, then it becomes trickier, because while lscov is happy to handle that case, how do you know the correlations? And of course if the operation you care about is not the mean, then it's a whole different ball game.
Anyways, assuming your second column is something like std deviations, and assuming the measurement errors are independent, and starting from your X
>> X = [3 1; 4 2; 5 1; NaN NaN; 6 1]
X =
3 1
4 2
5 1
NaN NaN
6 1
Then using the notation from the help for lscov:
>> A = [1; 1; 1; 1];
>> b = X([1 2 3 5],1);
>> w = 1 ./ X([1 2 3 5],2).^2;
>> [x,stdx,mse] = lscov(A,b,w)
x =
4.6154
stdx =
0.69939
mse =
1.5897
Here, x is the weighted mean, and stdx is the std error of the weighted mean. But wait, as lscov's help says, it assumes that w is relative weights, not exact variances, so you need to scale the std deviation of the mean by the estimated mse:
>> stdx = stdx / sqrt(mse)
stdx =
0.5547
  1 件のコメント
Aaron Ashley
Aaron Ashley 2021 年 3 月 25 日
Thank you, this is very informative. This does appear to be what I need, in that my measurements are independent of each other.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by