|
STK++ 1.0
|
Computation of the univariate Statistics of a Real Variable. More...
#include <STK_Stat_UnivariateReal.h>
Public Member Functions | |
| Univariate (ITContainer1D< Real, TContainer1D > const &V, bool sorted=false) | |
| Default constructor Copy locally the variable V and set dimensions. | |
| Univariate (ITContainer1D< Real, TContainer1D > const &V, ITContainer1D< Real, TContainer1D > const &W, bool sorted=false) | |
| Default constructor for weighted variables. | |
| Univariate (const Univariate &stat) | |
| Copy constructor. | |
| ~Univariate () | |
| destructor. | |
| Univariate & | operator= (const Univariate &stat) |
| Operator = : overwrite the Univariate with stat. | |
| void | setData (ITContainer1D< Real, TContainer1D > const &V, bool sorted=false) |
| Compute the statistics of a new Variable. | |
| void | setData (ITContainer1D< Real, TContainer1D > const &V, ITContainer1D< Real, TContainer1D > const &W, bool sorted=false) |
| Compute the statistics of a new weighted Variable. | |
| const Integer | nbSamples () const |
| get the number of samples | |
| const Integer | nbAvailableSamples () const |
| get the number of available samples (not missing) | |
| const Integer | nbMissingSamples () const |
| get the number of missing samples | |
| const Real | min () const |
| get the min of the variable | |
| const Real | max () const |
| get the max of the variable | |
| const Real | aMax () const |
| get the absolute maximal value | |
| const Real | mean () const |
| get the mean of the variable | |
| const Real | median () const |
| get the median of the variable | |
| const Real | variance () const |
| get the variance of the variable (division by n) | |
| const Real | unbiasedVariance () const |
| get the unbiased Variance of the variable (division by n-1) | |
| const Real | std () const |
| get the standard deviation of the variable | |
| const Real | unbiasedStd () const |
| get the sample standard deviation of the variable | |
| const Real | mad () const |
| get the median absolute deviation of the variable | |
| const Real | kurtosis () const |
| get the kurtosis of the variable | |
| const Real | skewness () const |
| get the skewness of the variable | |
| TContainer1D const & | quartiles () const |
| get the quartiles of the variable (25%) | |
| TContainer1D const & | deciles () const |
| get the deciles of the varibales (10%) | |
| TContainer1D const & | viceciles () const |
| get the viceciles of the variable (5%) | |
| TContainer1D const & | percentiles () const |
| get the percentiles of the variable (1%) | |
Protected Attributes | |
| Integer | nbSamples_ |
| Number of samples. | |
| Integer | nbAvailable_ |
| Number of Available samples. | |
| Integer | nbMiss_ |
| Number of missing samples. | |
| TContainer1D | V_ |
| local copy of the variable | |
| TContainer1D | W_ |
| local copy of the weights | |
| bool | weighted_ |
| Samples are weighted ? | |
| bool | sorted_ |
| Samples are sorted ? | |
| bool | comporder_ |
| Orders Statistics are computed ? | |
| bool | compstat_ |
| Usuals Statistics are computed ? | |
| Real | sumweights_ |
| Sum of the weights. | |
| Real | sum2weights_ |
| Sum of the square of the weights. | |
| Real | min_ |
| Min of the variable. | |
| Real | max_ |
| Max of the variable. | |
| Real | amax_ |
| Absolute maximal value. | |
| Real | mean_ |
| mean of the variable | |
| Real | median_ |
| median of the variable | |
| Real | var_ |
| Variance of the variable (division by n) | |
| Real | uvar_ |
| Unbiased Variance of the variable (division by n-1) | |
| Real | std_ |
| Standard deviation of the variable (n) | |
| Real | ustd_ |
| Sample standard deviation of the variable (n-1) | |
| Real | mad_ |
| absolute deviation of the variable | |
| Real | kurtosis_ |
| kurtosis of the variable | |
| Real | skewness_ |
| Skewness of the variable. | |
| TContainer1D | quartiles_ |
| Quartiles (25%) | |
| TContainer1D | deciles_ |
| Deciles (10%) | |
| TContainer1D | viceciles_ |
| viceciles (5%) | |
| TContainer1D | percentiles_ |
| percentiles (1%) | |
Private Member Functions | |
| void | initializeVariable () |
| Initialize the container in order to discard the missing elements in the non weighted case. | |
| void | initializeVariableAndWeights () |
| Initialize the containers in order to discard the missing elements in the weighted case. | |
| void | compStatistics () |
Compute the usual statistics of the variable:
| |
| void | compWeightedStatistics () |
| Compute the usual weighted statistics of the variable. | |
| void | compOrderStatistics () |
| Compute the Order Statistics of the variable. | |
| void | compQuantiles (TContainer1D &T) |
| Compute the quantiles of the sorted variable V_ and store the result in the array T. | |
Computation of the univariate Statistics of a Real Variable.
This is a specialization of the class Univariate for the type Real.
The template parameter TContainer1D is the type of container used for storing the data : It should derive from ITContainer1D and contain elements of type Real.
This specialization propose also statics methods for computing the (weighted) mean and the (weighted) variance.
Definition at line 62 of file STK_Stat_UnivariateReal.h.
| STK::Stat::Univariate< Real, TContainer1D >::Univariate | ( | ITContainer1D< Real, TContainer1D > const & | V, |
| bool | sorted = false |
||
| ) | [inline] |
Default constructor Copy locally the variable V and set dimensions.
The statistics are then computed.
| V | variable |
| sorted | true if the variable is sorted, false otherwise |
Definition at line 71 of file STK_Stat_UnivariateReal.h.
: nbSamples_(V.size()) , nbAvailable_(V.size()) , nbMiss_(0) , V_(V.asLeaf()) , W_() , weighted_(false) , sorted_(sorted) , comporder_(false) , compstat_(false) , sumweights_(0.) , sum2weights_(0.) , mean_(Arithmetic<Real>::NA()) , median_(Arithmetic<Real>::NA()) , var_(Arithmetic<Real>::NA()) , uvar_(Arithmetic<Real>::NA()) , std_(Arithmetic<Real>::NA()) , ustd_(Arithmetic<Real>::NA()) , mad_(Arithmetic<Real>::NA()) , kurtosis_(Arithmetic<Real>::NA()) , skewness_(Arithmetic<Real>::NA()) , quartiles_(3, Arithmetic<Real>::NA()) , deciles_(9, Arithmetic<Real>::NA()) , viceciles_(19, Arithmetic<Real>::NA()) , percentiles_(99, Arithmetic<Real>::NA()) { initializeVariable(); compOrderStatistics(); compStatistics(); }
| STK::Stat::Univariate< Real, TContainer1D >::Univariate | ( | ITContainer1D< Real, TContainer1D > const & | V, |
| ITContainer1D< Real, TContainer1D > const & | W, | ||
| bool | sorted = false |
||
| ) | [inline] |
Default constructor for weighted variables.
Copy locally the variable V, the weights W and set dimensions. No statistics except min_, max_ and amax_ are calculated at this stage.
| V | variable |
| W | weights |
| sorted | true if the variable is sorted, false otherwise |
Definition at line 110 of file STK_Stat_UnivariateReal.h.
: nbSamples_(V.size()) , nbAvailable_(V.size()) , nbMiss_(0) , V_(V.asLeaf()) , W_(W.asLeaf()) , weighted_(true) , sorted_(sorted) , comporder_(false) , compstat_(false) , sumweights_(0.0) , sum2weights_(0.0) , mean_(Arithmetic<Real>::NA()) , median_(Arithmetic<Real>::NA()) , var_(Arithmetic<Real>::NA()) , uvar_(Arithmetic<Real>::NA()) , std_(Arithmetic<Real>::NA()) , ustd_(Arithmetic<Real>::NA()) , mad_(Arithmetic<Real>::NA()) , kurtosis_(Arithmetic<Real>::NA()) , skewness_(Arithmetic<Real>::NA()) , quartiles_(3) , deciles_(9) , viceciles_(19) , percentiles_(99) { // check weights size if ((V_.range() != W_.range())) { throw std::runtime_error("Univariate<Real, TContainer1D>::Univariate(V, W, sorted) " "V and W have not the same range"); } initializeVariableAndWeights(); compOrderStatistics(); compWeightedStatistics(); }
| STK::Stat::Univariate< Real, TContainer1D >::Univariate | ( | const Univariate< Real, TContainer1D > & | stat | ) | [inline] |
Copy constructor.
| stat | the univariate statistics to copy |
Definition at line 152 of file STK_Stat_UnivariateReal.h.
: nbSamples_(stat.nbSamples_) , nbAvailable_(stat.nbAvailable_) , nbMiss_(stat.nbMiss_) , V_(stat.V_) , W_(stat.W_) , weighted_(stat.weighted_) , sorted_(stat.sorted_) , comporder_(stat.comporder_) , compstat_(stat.compstat_) , sumweights_(stat.sumweights_) , sum2weights_(stat.sum2weights_) , min_(stat.min_) , max_(stat.max_) , amax_(stat.amax_) , mean_(stat.mean_) , median_(stat.median_) , var_(stat.var_) , uvar_(stat.uvar_) , std_(stat.std_) , ustd_(stat.ustd_) , mad_(stat.mad_) , kurtosis_(stat.kurtosis_) , skewness_(stat.skewness_) , quartiles_(stat.quartiles_) , deciles_(stat.deciles_) , viceciles_(stat.viceciles_) , percentiles_(stat.percentiles_) { ;}
| STK::Stat::Univariate< Real, TContainer1D >::~Univariate | ( | ) | [inline] |
| Univariate& STK::Stat::Univariate< Real, TContainer1D >::operator= | ( | const Univariate< Real, TContainer1D > & | stat | ) | [inline] |
Operator = : overwrite the Univariate with stat.
Definition at line 186 of file STK_Stat_UnivariateReal.h.
References STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_, and STK::Stat::Univariate< TYPE, TContainer1D >::nbSamples_.
{
nbSamples_ = stat.nbSamples_;
nbAvailable_ = stat.nbAvailable_;
nbMiss_ = stat.nbMiss_;
V_ = stat.V_;
W_ = stat.W_;
weighted_ = stat.weighted_;
sorted_ = stat.sorted_;
comporder_ = stat.comporder_;
compstat_ = stat.compstat_;
sumweights_ = stat.sumweights_;
sum2weights_ = stat.sum2weights_;
min_ = stat.min_;
max_ = stat.max_;
amax_ = stat.amax_;
mean_ = stat.mean_;
median_ = stat.median_;
var_ = stat.var_;
uvar_ = stat.uvar_;
std_ = stat.std_;
ustd_ = stat.ustd_;
mad_ = stat.mad_;
kurtosis_ = stat.kurtosis_;
skewness_ = stat.skewness_;
quartiles_ = stat.quartiles_;
deciles_ = stat.deciles_;
viceciles_ = stat.viceciles_;
percentiles_ = stat.percentiles_;
return *this;
}
| void STK::Stat::Univariate< Real, TContainer1D >::setData | ( | ITContainer1D< Real, TContainer1D > const & | V, |
| bool | sorted = false |
||
| ) | [inline] |
Compute the statistics of a new Variable.
| V | the variable to set |
| sorted | true if the variable is sorted |
Definition at line 223 of file STK_Stat_UnivariateReal.h.
References STK::IRecursiveTemplate< TContainer1D >::asLeaf(), STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_, STK::Stat::Univariate< TYPE, TContainer1D >::nbSamples_, and STK::ITContainer1D< TYPE, TContainer1D >::size().
{
// initialize dimensions
nbSamples_ = V.size();
nbAvailable_ = V.size();
nbMiss_ = 0;
// set variable and weights
V_ = V.asLeaf();
W_.clear(); // no weights
// initialize data
weighted_ = false;
sorted_ = sorted;
comporder_ = false;
compstat_ = false;
sumweights_ = 0.0;
sum2weights_ = 0.0;
mean_ = Arithmetic<Real>::NA();
median_ = Arithmetic<Real>::NA();
var_ = Arithmetic<Real>::NA();
uvar_ = Arithmetic<Real>::NA();
std_ = Arithmetic<Real>::NA();
ustd_ = Arithmetic<Real>::NA();
mad_ = Arithmetic<Real>::NA();
kurtosis_ = Arithmetic<Real>::NA();
skewness_ = Arithmetic<Real>::NA();
quartiles_ = Arithmetic<Real>::NA();
deciles_ = Arithmetic<Real>::NA();
viceciles_ = Arithmetic<Real>::NA();
percentiles_ = Arithmetic<Real>::NA();
initializeVariable();
compOrderStatistics();
compStatistics();
}
| void STK::Stat::Univariate< Real, TContainer1D >::setData | ( | ITContainer1D< Real, TContainer1D > const & | V, |
| ITContainer1D< Real, TContainer1D > const & | W, | ||
| bool | sorted = false |
||
| ) | [inline] |
Compute the statistics of a new weighted Variable.
| V | the variable to set |
| W | the weights of the variable |
| sorted | true if the variable is sorted |
Definition at line 263 of file STK_Stat_UnivariateReal.h.
References STK::IRecursiveTemplate< TContainer1D >::asLeaf(), STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_, STK::Stat::Univariate< TYPE, TContainer1D >::nbSamples_, STK::ITContainer1D< TYPE, TContainer1D >::range(), and STK::ITContainer1D< TYPE, TContainer1D >::size().
{
// check weights size
if ((V.range() != W.range()))
{ throw std::runtime_error("Univariate<Real>::setData(V, W, sorted) "
"V and W have not the same range");
}
// initialize dimensions
nbSamples_ = V.size();
nbAvailable_ = V.size();
nbMiss_ = 0;
// set variable and weights
V_ = V.asLeaf();
W_ = W.asLeaf();
// initialize data
weighted_ = true;
sorted_ = sorted;
comporder_ = false;
compstat_ = false;
sumweights_ = 0.0;
sum2weights_ = 0.0;
mean_ = Arithmetic<Real>::NA();
median_ = Arithmetic<Real>::NA();
var_ = Arithmetic<Real>::NA();
uvar_ = Arithmetic<Real>::NA();
std_ = Arithmetic<Real>::NA();
ustd_ = Arithmetic<Real>::NA();
mad_ = Arithmetic<Real>::NA();
kurtosis_ = Arithmetic<Real>::NA();
skewness_ = Arithmetic<Real>::NA();
quartiles_ = Arithmetic<Real>::NA();
deciles_ = Arithmetic<Real>::NA();
viceciles_ = Arithmetic<Real>::NA();
percentiles_ = Arithmetic<Real>::NA();
initializeVariableAndWeights();
compOrderStatistics();
compWeightedStatistics();
}
| const Integer STK::Stat::Univariate< Real, TContainer1D >::nbSamples | ( | ) | const [inline] |
get the number of samples
Definition at line 307 of file STK_Stat_UnivariateReal.h.
References STK::Stat::Univariate< TYPE, TContainer1D >::nbSamples_.
{return nbSamples_;}
| const Integer STK::Stat::Univariate< Real, TContainer1D >::nbAvailableSamples | ( | ) | const [inline] |
get the number of available samples (not missing)
Definition at line 309 of file STK_Stat_UnivariateReal.h.
{return nbAvailable_;}
| const Integer STK::Stat::Univariate< Real, TContainer1D >::nbMissingSamples | ( | ) | const [inline] |
get the number of missing samples
Definition at line 311 of file STK_Stat_UnivariateReal.h.
References STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_.
{return nbMiss_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::min | ( | ) | const [inline] |
get the min of the variable
Definition at line 314 of file STK_Stat_UnivariateReal.h.
{return min_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::max | ( | ) | const [inline] |
get the max of the variable
Definition at line 316 of file STK_Stat_UnivariateReal.h.
{return max_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::aMax | ( | ) | const [inline] |
get the absolute maximal value
Definition at line 318 of file STK_Stat_UnivariateReal.h.
{return amax_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::mean | ( | ) | const [inline] |
get the mean of the variable
Definition at line 321 of file STK_Stat_UnivariateReal.h.
{return mean_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::median | ( | ) | const [inline] |
get the median of the variable
Definition at line 323 of file STK_Stat_UnivariateReal.h.
{return median_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::variance | ( | ) | const [inline] |
get the variance of the variable (division by n)
Definition at line 326 of file STK_Stat_UnivariateReal.h.
{return var_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::unbiasedVariance | ( | ) | const [inline] |
get the unbiased Variance of the variable (division by n-1)
Definition at line 328 of file STK_Stat_UnivariateReal.h.
{return uvar_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::std | ( | ) | const [inline] |
get the standard deviation of the variable
Definition at line 330 of file STK_Stat_UnivariateReal.h.
{return std_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::unbiasedStd | ( | ) | const [inline] |
get the sample standard deviation of the variable
Definition at line 332 of file STK_Stat_UnivariateReal.h.
{return ustd_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::mad | ( | ) | const [inline] |
get the median absolute deviation of the variable
Definition at line 334 of file STK_Stat_UnivariateReal.h.
{ return( mad_);}
| const Real STK::Stat::Univariate< Real, TContainer1D >::kurtosis | ( | ) | const [inline] |
get the kurtosis of the variable
Definition at line 337 of file STK_Stat_UnivariateReal.h.
{return kurtosis_;}
| const Real STK::Stat::Univariate< Real, TContainer1D >::skewness | ( | ) | const [inline] |
get the skewness of the variable
Definition at line 339 of file STK_Stat_UnivariateReal.h.
{return skewness_;}
| TContainer1D const& STK::Stat::Univariate< Real, TContainer1D >::quartiles | ( | ) | const [inline] |
get the quartiles of the variable (25%)
Definition at line 342 of file STK_Stat_UnivariateReal.h.
{return quartiles_;}
| TContainer1D const& STK::Stat::Univariate< Real, TContainer1D >::deciles | ( | ) | const [inline] |
get the deciles of the varibales (10%)
Definition at line 344 of file STK_Stat_UnivariateReal.h.
{return deciles_;}
| TContainer1D const& STK::Stat::Univariate< Real, TContainer1D >::viceciles | ( | ) | const [inline] |
get the viceciles of the variable (5%)
Definition at line 346 of file STK_Stat_UnivariateReal.h.
{ return viceciles_;}
| TContainer1D const& STK::Stat::Univariate< Real, TContainer1D >::percentiles | ( | ) | const [inline] |
get the percentiles of the variable (1%)
Definition at line 348 of file STK_Stat_UnivariateReal.h.
{ return percentiles_;}
| void STK::Stat::Univariate< Real, TContainer1D >::initializeVariable | ( | ) | [inline, private] |
Initialize the container in order to discard the missing elements in the non weighted case.
Definition at line 354 of file STK_Stat_UnivariateReal.h.
References STK::abs(), STK::max(), STK::min(), and STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_.
{
// initialize the extreme values
min_ = Arithmetic<Real>::max();
max_ = -Arithmetic<Real>::max();
// discard missing values
for (Integer i=V_.last(); i>=V_.first(); i--)
{
if ( Arithmetic<Real>::isNA(V_[i]) )
{
// if NA
nbAvailable_--; // decrease nbAvailable_
nbMiss_++; // increase nbMiss_
V_.erase(i); // Delete the current row
}
else
{
min_ = STK::min(V_[i], min_); // update min_
max_ = STK::max(V_[i], max_); // update max_
}
}
// all weights are 1/n.
sumweights_ = 1.0;
sum2weights_= 1./(Real)nbAvailable_;
// no samples
if ((nbAvailable_ == 0))
{
min_ = Arithmetic<Real>::NA();
max_ = Arithmetic<Real>::NA();
amax_ = Arithmetic<Real>::NA();
}
else // one or more samples : compute amax
amax_ = STK::max(abs(min_), abs(max_));
}
| void STK::Stat::Univariate< Real, TContainer1D >::initializeVariableAndWeights | ( | ) | [inline, private] |
Initialize the containers in order to discard the missing elements in the weighted case.
Definition at line 393 of file STK_Stat_UnivariateReal.h.
References STK::abs(), STK::max(), STK::min(), and STK::Stat::Univariate< TYPE, TContainer1D >::nbMiss_.
{
// initialize the extreme values
min_ = Arithmetic<Real>::max();
max_ = -Arithmetic<Real>::max();
// discard missing values or values without weights
for (Integer i=V_.last(); i>=V_.first(); i--)
{
if ( Arithmetic<Real>::isNA(V_[i])||Arithmetic<Real>::isNA(W_[i]))
{
V_.erase(i); // Delete the current row
W_.erase(i); // for the weights too
nbAvailable_--; // decrease number of samples
nbMiss_++; // increase number of missing values
}
else
{
min_ = STK::min(V_[i], min_); // update min_
max_ = STK::max(V_[i], max_); // update max_
sumweights_ += (W_[i] = abs((Real)W_[i]));// sum absolute weights
sum2weights_ += W_[i] * W_[i]; // sum squared weights
}
}
// no samples
if ((nbAvailable_ == 0))
{
min_ = Arithmetic<Real>::NA();
max_ = Arithmetic<Real>::NA();
amax_ = Arithmetic<Real>::NA();
}
else // one or more samples : compute amax
amax_ = STK::max(abs(min_), abs(max_));
}
| void STK::Stat::Univariate< Real, TContainer1D >::compStatistics | ( | ) | [inline, private] |
Compute the usual statistics of the variable:
Definition at line 436 of file STK_Stat_UnivariateReal.h.
References STK::abs(), and STK::sum().
{
// If there is no samples
if (nbAvailable_ == 0)
{
mean_ = Arithmetic<Real>::NA();
var_ = Arithmetic<Real>::NA();
uvar_ = Arithmetic<Real>::NA();
std_ = Arithmetic<Real>::NA();
ustd_ = Arithmetic<Real>::NA();
mad_ = Arithmetic<Real>::NA();
kurtosis_ = Arithmetic<Real>::NA();
skewness_ = Arithmetic<Real>::NA();
return;
}
// One observation
if (nbAvailable_ == 1)
{
mean_ = V_.front();
var_ = Arithmetic<Real>::NA();
std_ = 0.0;
ustd_ = Arithmetic<Real>::NA();
mad_ = 0.0;
kurtosis_ = 0.0;
skewness_ = 0.0;
return;
}
// get indexes
const Integer first = V_.first(), last = V_.last();
// get nbAvailable observation in Real
const Real n = (Real)nbAvailable_;
// first pass : compute the mean
// scale the samples for preventing overflows
mean_ = 0.;
{
if (amax_) // if the absolute maximal value is greater than 0
{
// sum samples with scaling
for (Integer i=first; i<=last; i++)
mean_ += V_[i]/amax_;
// divide by the number of available observation
mean_ /= n;
// unscale
mean_ *= amax_;
}
}
// second pass : compute the variance, skewness and kurtosis
// initialize values
Real sum = 0.0, dev1, dev2;
var_ = 0.0;
mad_ = 0.0;
kurtosis_ = 0.0;
skewness_ = 0.0;
for (Integer i=1; i<=nbAvailable_; i++)
{
sum += (dev1 = V_[i]-mean_); // deviation from the mean
var_ += (dev2 = dev1*dev1); // squared deviation
mad_ += abs( dev1 ); // absolute deviation
skewness_ += dev2 * dev1; // cubic deviation
kurtosis_ += dev2 * dev2; // squared squared deviation
}
mad_ *= sum2weights_;
uvar_ = (var_ - sum*sum/n)/(n - 1.);
var_ = (var_ - sum*sum/n)/n;
std_ = sqrt((double)var_);
ustd_ = sqrt((double)uvar_);
// if there is variance
if (var_)
{
skewness_ /= n;
kurtosis_ /= n;
skewness_ /= (var_ * std_);
kurtosis_ /= (var_ * var_);
kurtosis_ -= 3.0;
}
else
{
skewness_ = 0.0;
kurtosis_ = 0.0;
}
// Statistics are computed
compstat_ = true;
}
| void STK::Stat::Univariate< Real, TContainer1D >::compWeightedStatistics | ( | ) | [inline, private] |
Compute the usual weighted statistics of the variable.
Definition at line 523 of file STK_Stat_UnivariateReal.h.
References STK::abs(), and STK::sum().
{
// If there is no samples
if (nbAvailable_ == 0)
{
mean_ = Arithmetic<Real>::NA();
var_ = Arithmetic<Real>::NA();
uvar_ = Arithmetic<Real>::NA();
std_ = Arithmetic<Real>::NA();
ustd_ = Arithmetic<Real>::NA();
mad_ = Arithmetic<Real>::NA();
kurtosis_ = Arithmetic<Real>::NA();
skewness_ = Arithmetic<Real>::NA();
return;
}
// One observation or pathological weights
if ((nbAvailable_ == 1)||(sumweights_*sumweights_ <= sum2weights_))
{
mean_ = V_.front();
var_ = 0.;
uvar_ = Arithmetic<Real>::NA();
std_ = 0.;
ustd_ = Arithmetic<Real>::NA();
mad_ = 0.;
kurtosis_ = 0.;
skewness_ = 0.;
return;
}
// get indexes
const Integer first = V_.first(), last = V_.last();
// first pass : get the mean
// scale the samples for preventing overflows
mean_ = 0.;
if (amax_) // if the maximal value is greater than 0
{
// sum samples
for (Integer i=first; i<=last; i++)
mean_ += (W_[i]*V_[i])/amax_; // compute the mean with scaling
mean_ /= sumweights_; // weight the sum
mean_ *= amax_; // and unscale
}
// second pass : compute the variance, skewness and kurtosis
// initialize some values
Real sum = 0.0, dev1, dev2;
var_ = 0.0;
mad_ = 0.0;
kurtosis_ = 0.0;
skewness_ = 0.0;
for (Integer i=1; i<=nbAvailable_; i++)
{
Real weight = W_[i];
sum += weight * (dev1 = V_[i]-mean_); // deviation from the mean
var_ += weight * (dev2 = dev1*dev1); // squared value
mad_ += weight * abs(dev1); // absolute deviation from mean
skewness_ += weight * dev2 * dev1;
kurtosis_ += weight * dev2 * dev2;
}
mad_ /= sumweights_;
uvar_ = (var_ - sum*sum/sumweights_)/(sumweights_ - sum2weights_/sumweights_);
var_ = (var_ - sum*sum)/(sumweights_);
std_ = sqrt((double)var_);
ustd_ = sqrt((double)uvar_);
// if there is variance
if (var_)
{
skewness_ /= (sumweights_ * var_ * std_);
kurtosis_ /= (sumweights_ * var_ * var_);
kurtosis_ -= 3.0;
}
else
{
skewness_ = 0.0;
kurtosis_ = 0.0;
}
// Stat are computed
compstat_ = true;
}
| void STK::Stat::Univariate< Real, TContainer1D >::compOrderStatistics | ( | ) | [inline, private] |
Compute the Order Statistics of the variable.
Definition at line 603 of file STK_Stat_UnivariateReal.h.
References STK::applySort(), and STK::heapSort().
{
// no samples
if (nbAvailable_ == 0)
{
median_ = Arithmetic<Real>::NA();
quartiles_ = Arithmetic<Real>::NA();
deciles_ = Arithmetic<Real>::NA();
viceciles_ = Arithmetic<Real>::NA();
percentiles_ = Arithmetic<Real>::NA();
return;
}
// One observation
if (nbAvailable_ == 1)
{
median_ = max_;
quartiles_ = max_;
deciles_ = max_;
viceciles_ = max_;
percentiles_ = max_;
return;
}
// sort values
if (!sorted_)
{
// if the Variable is not weighted, we can sort it directly
if (!weighted_) heapSort(V_);
else // otherwise we have to sort V_and W_ using indirection
{
Array1D<Integer> I; // auxiliary Array for indirection
heapSort(I, V_);
applySort(V_, I);
applySort(W_, I);
}
sorted_ = true;
}
// Find the Quantiles of the distribution
compQuantiles(quartiles_);
compQuantiles(deciles_);
compQuantiles(viceciles_);
compQuantiles(percentiles_);
// get the median
median_ = quartiles_[2];
}
| void STK::Stat::Univariate< Real, TContainer1D >::compQuantiles | ( | TContainer1D & | T | ) | [inline, private] |
Compute the quantiles of the sorted variable V_ and store the result in the array T.
The number of quantiles is given by the size of T. For exemple, if T.last() == 9, compQuantiles will return the deciles.
| T | TContainer1Ds of the *tiles |
Definition at line 655 of file STK_Stat_UnivariateReal.h.
References STK::max(), and STK::min().
{
#ifdef STK_DEBUG
if (!sorted_)
{ throw std::runtime_error("Univariate<Real>::comptiles(T) "
"V_ is not sorted");
}
#endif
// in case of
T.shift(1);
// number of quantiles
Integer nt = T.last(), shift = V_.first()-1;
Real n1 = Real(nbAvailable_+1), nt1 = Real(nt+1);
for (Integer k=1; k<=nt; k++)
{
// find index of the k-th quantile
Real find = Real(k)*n1/nt1; // compute the index in Real
Integer tind = STK::max(Integer(1), Integer(find)); // in Integer
Integer tind1 = STK::min(nbAvailable_, tind+1); // next
Real aux = find - Real(tind); // lower ponderation
// nbAvailable_+1 not perfectly divisible ? weighting...
aux ? T[k] = aux * V_[shift+tind] + (1.0-aux)*V_[shift+tind1]
: T[k] = V_[shift+tind];
}
}
Integer STK::Stat::Univariate< Real, TContainer1D >::nbSamples_ [protected] |
Number of samples.
Definition at line 685 of file STK_Stat_UnivariateReal.h.
Integer STK::Stat::Univariate< Real, TContainer1D >::nbAvailable_ [protected] |
Number of Available samples.
Definition at line 686 of file STK_Stat_UnivariateReal.h.
Integer STK::Stat::Univariate< Real, TContainer1D >::nbMiss_ [protected] |
Number of missing samples.
Definition at line 687 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::V_ [protected] |
local copy of the variable
Definition at line 690 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::W_ [protected] |
local copy of the weights
Definition at line 691 of file STK_Stat_UnivariateReal.h.
bool STK::Stat::Univariate< Real, TContainer1D >::weighted_ [protected] |
Samples are weighted ?
Definition at line 694 of file STK_Stat_UnivariateReal.h.
bool STK::Stat::Univariate< Real, TContainer1D >::sorted_ [protected] |
Samples are sorted ?
Definition at line 695 of file STK_Stat_UnivariateReal.h.
bool STK::Stat::Univariate< Real, TContainer1D >::comporder_ [protected] |
Orders Statistics are computed ?
Definition at line 696 of file STK_Stat_UnivariateReal.h.
bool STK::Stat::Univariate< Real, TContainer1D >::compstat_ [protected] |
Usuals Statistics are computed ?
Definition at line 697 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::sumweights_ [protected] |
Sum of the weights.
Definition at line 700 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::sum2weights_ [protected] |
Sum of the square of the weights.
Definition at line 701 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::min_ [protected] |
Min of the variable.
Definition at line 702 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::max_ [protected] |
Max of the variable.
Definition at line 703 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::amax_ [protected] |
Absolute maximal value.
Definition at line 704 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::mean_ [protected] |
mean of the variable
Definition at line 706 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::median_ [protected] |
median of the variable
Definition at line 707 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::var_ [protected] |
Variance of the variable (division by n)
Definition at line 708 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::uvar_ [protected] |
Unbiased Variance of the variable (division by n-1)
Definition at line 709 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::std_ [protected] |
Standard deviation of the variable (n)
Definition at line 710 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::ustd_ [protected] |
Sample standard deviation of the variable (n-1)
Definition at line 711 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::mad_ [protected] |
absolute deviation of the variable
Definition at line 712 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::kurtosis_ [protected] |
kurtosis of the variable
Definition at line 713 of file STK_Stat_UnivariateReal.h.
Real STK::Stat::Univariate< Real, TContainer1D >::skewness_ [protected] |
Skewness of the variable.
Definition at line 714 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::quartiles_ [protected] |
Quartiles (25%)
Definition at line 716 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::deciles_ [protected] |
Deciles (10%)
Definition at line 717 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::viceciles_ [protected] |
viceciles (5%)
Definition at line 718 of file STK_Stat_UnivariateReal.h.
TContainer1D STK::Stat::Univariate< Real, TContainer1D >::percentiles_ [protected] |
percentiles (1%)
Definition at line 719 of file STK_Stat_UnivariateReal.h.