I have calculated 4 standard deviation values for each row of a 4x3 matrix. How to convert these 4 values into a single standard deviation value for the whole matrix?

2 vues (au cours des 30 derniers jours)
a=[2 3 5;12 67 54;3 7 8;14 9 23]
b= std(a,0,2)
  1 commentaire
Rik
Rik le 24 Juin 2023
The standard deviation of a large set can only be estimated from the standard deviations of the parts. Are you sure you want to do that instead of calculating the SD for all values?

Connectez-vous pour commenter.

Réponses (3)

Torsten
Torsten le 24 Juin 2023
Not possible.
Use
std(a(:))
instead.

VBBV
VBBV le 24 Juin 2023
Modifié(e) : VBBV le 24 Juin 2023
a=[2 3 5;12 67 54;3 7 8;14 9 23]
a = 4×3
2 3 5 12 67 54 3 7 8 14 9 23
b = std(a,0,"all")
b = 21.2009
Use the *all* option to get the SD for whole matrix

John D'Errico
John D'Errico le 24 Juin 2023
Modifié(e) : John D'Errico le 24 Juin 2023
You should understand why it is not possible to compute the overall standard deviation, merely from the pieces. This is because a standard deviation does not contain information about the mean. That information has essentially been lost to the world. Dumped in the laundry basket of computing, never to be seen again. ;-)
Let me give an example. Consider a case where we have two groups of numbers. I'll call them X and Y.
X = normrnd(0,2,[1,5])
X = 1×5
0.4428 1.5877 -2.3844 -0.6804 0.3617
Y = normrnd(5,4,[1,5])
Y = 1×5
10.7247 5.8261 5.2775 6.5703 0.6086
We can compute the standard deviation of X and Y. That part is easy.
stdX = std(X)
stdX = 1.4921
stdY = std(Y)
stdY = 3.6080
But if you look at the formula for standard deviation, it first subtracts the mean of the set. I'll write it here as a function handle.
S = @(Z) sqrt(sum((Z - mean(Z)).^2/(numel(Z)-1)))
S = function_handle with value:
@(Z)sqrt(sum((Z-mean(Z)).^2/(numel(Z)-1)))
S(X)
ans = 1.4921
Wow! I got it right! But the problem is, unless you know the original means of the subgroups, you cannot infer what the standard deviation of the aggregate group would be. So you can do this:
std([X,Y])
ans = 4.0697
That is the equivalent to what others have suggested, which is to create one large vector of data from the array, and then compute the global standard deviation.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by