Created
September 11, 2014 18:55
-
-
Save pn11/083d20441f37f73cfa5e to your computer and use it in GitHub Desktop.
ROOTのTMath::RMS() (http://root.cern.ch/root/html/TMath.html#TMath:RMS) はRMSじゃなくて標準偏差を計算してるけど、それが標本標準偏差(?)なのか不偏標準偏差(?)なのか(標本数nで割ってるのかn-1で割ってるのか)調べた。結果、n-1で割ってた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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