Skip to content

Instantly share code, notes, and snippets.

@pn11
Created Sep 11, 2014
Embed
What would you like to do?
ROOTのTMath::RMS() (http://root.cern.ch/root/html/TMath.html#TMath:RMS) はRMSじゃなくて標準偏差を計算してるけど、それが標本標準偏差(?)なのか不偏標準偏差(?)なのか(標本数nで割ってるのかn-1で割ってるのか)調べた。結果、n-1で割ってた。
{
const int ndata = 10000;
double data[ndata];
TRandom *gaus = new TRandom();
for (int idata = 0; idata < ndata; idata++){
data[idata] = gaus->Gaus(0., 1.);
}
double rms_root = TMath::RMS(ndata, data);
double var_my = 0;
for (int idata = 0; idata < ndata; idata++){
var_my += pow( (data[idata] - TMath::Mean(ndata, data)), 2.0);
}
var_my /= double(ndata - 1);
double rms_my = sqrt(var_my);
cout << "RMS (standard deviation) by ROOT is " << rms_root << endl;
cout << "RMS (unbiased standard deviation) in my calculation is " << rms_my << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment