関数calculate_weighted_stddev マニュアル

(The documentation of function calculate_weighted_stddev)

Last Update: 2025/8/7


◆機能・用途(Purpose)

実数値配列\(d_1,\cdots,d_N\)の重み付き標準偏差(重みの総和を分母とするもの) \[\begin{equation} \sigma_d=\sqrt{\frac{\sum_{i=1}^Nw_i\left(d_i-\bar{d}\right)^2} {\sum_{i=1}^Nw_i}} \label{eq.stddev} \end{equation}\] を計算する。ここで\(w_i\)は\(i\)番目のデータの重みを表し、 \(\bar{d}\)は\(d_1,\cdots,d_N\)の重み付き平均 \[\begin{equation} \bar{d}=\frac{\sum_{i=1}^Nw_id_i}{\sum_{i=1}^Nw_i} \label{eq.average} \end{equation}\] である。
Calculate the weighted standard deviation (eq. \ref{eq.stddev}) of the components of an array of real numbers \(d_1,\cdots,d_N\), where the sum of the weights is used for the denominator; \(w_i\) is the weight of \(i\)th data and \(\bar{d}\) is the weighted average (eq. \ref{eq.average}) of \(d_1,\cdots,d_N\).


◆形式(Format)

#include <statistics.h>
inline double calculate_weighted_stddev
(const int N,const double ∗d,const double ∗w, const double average)


◆引数(Arguments)

N データサンプル数\(N\)。
The number of data samples \(N\).
d 実数値\(d_1,\cdots,d_N\)を並べた配列。
An array composed of the real numbers \(d_1,\cdots,d_N\).
w 各データの重み\(w_1,\cdots,w_N\)を並べた配列。
An array composed of the weights \(w_1,\cdots,w_N\) of individual data.
average \(d_1,\cdots,d_N\)の重み付き平均。
A weighted average of \(d_1,\cdots,d_N\).


◆戻り値(Return value)

(\ref{eq.stddev})式で計算した重み付き標準偏差。
The weighted standard deviation calculated with eq. (\ref{eq.stddev}).


◆使用例(Example)

const int N=5;
const double d[]={1.2,3.4,5.6,7.8,9.0};
const double w[]={1.0,1.0,2.0,0.5,1.0};
double a=calculate_average(N,d);
double sigma=calculate_weighted_stddev(N,d,w,a);


◆使用上の注意(Important note)

この関数では 第4引数で与えた平均値が正しいかどうかのチェックは行われない ので、間違いを防ぐために上の使用例のように 必ず関数calculate_weighted_averageで得た戻り値をそのまま与えること。
No check is conducted for the average given by the 4th argument. To avoid wrong calculation, make sure to use the return value of function calculate_weighted_average for the 4th argument of this function, as the example above.


◆検証(Validation)

上の「使用例」の計算をこの関数を用いて行い、 正しい結果(2.606920)が得られることを確認した。
A calculation of the “Example” above using this function yielded a correct result (2.606920).