"분산 계산하기위한 알고리즘"에 대한 위키 백과의 문서 섹션 방법 요소가 귀하의 관찰에 추가하는 경우 분산을 계산하는 방법을 보여줍니다. (표준 편차는 분산의 제곱근입니다.) x n + 1을 더 한다고 가정합니다.xn+1 을 배열에 추가 한 다음
σ2new=σ2old+(xn+1−μnew)(xn+1−μold).
EDIT: Above formula seems to be wrong, see comment.
Now, replacing an element means adding an observation and removing another one; both can be computed with the formula above. However, keep in mind that problems of numerical stability may ensue; the quoted article also proposes numerically stable variants.
To derive the formula by yourself, compute (n−1)(σ2new−σ2old) using the definition of sample variance and substitute μnew by the formula you gave when appropriate. This gives you σ2new−σ2old in the end, and thus a formula for σnew given σold and μold. In my notation, I assume you replace the element xn by x′n:
σ2(n−1)(σ2new−σ2old)===(n−1)−1∑k(xk−μ)2∑k=1n−1((xk−μnew)2−(xk−μold)2)+ ((x′n−μnew)2−(xn−μold)2)∑k=1n−1((xk−μold−n−1(x′n−xn))2−(xk−μold)2)+ ((x′n−μold−n−1(x′n−xn))2−(xn−μold)2)
The xk in the sum transform into something dependent of μold, but you'll have to work the equation a little bit more to derive a neat result. This should give you the general idea.