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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by