Calculate standard deviation given frequency counts rather than sample
Mostrar comentarios más antiguos
Given a sample x
x = [1 1 1 1 2 2 2 3 3 3 3 4 5 6 6];
it is trivial to calculate the standard deviation:
s = std(x);
Suppose instead of x, I have the an array with the frequency counts of x:
A = [4 1;
3 2;
4 3;
1 4;
1 5;
2 6];
What's an elegant way to calculate the standard deviation, without needing to reconstruct x along the way?
Respuesta aceptada
Más respuestas (1)
mu = (A(:,1).*A(:,2)) ./ sum(A(:,1));
std =sqrt(sum(A(:,1).*(A(:,2)-mu).^2)) ./(sum(A(:,1))-1));
2 comentarios
the cyclist
el 27 de Ag. de 2013
Iain
el 27 de Ag. de 2013
Yup, I'm missing a sum here or there:
mu = sum(A(:,1).*A(:,2)) ./ sum(A(:,1));
Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!