|
STK++ 1.0
|
Computation of the bivariate Statistics of two Variables. More...
#include <STK_Stat_BivariateRealReal.h>

Public Member Functions | |
| Bivariate (ITContainer1D< Real, TContainer1D > const &X, ITContainer1D< Real, TContainer1D > const &Y) | |
| Default constructor. | |
| Bivariate (ITContainer1D< Real, TContainer1D > const &X, ITContainer1D< Real, TContainer1D > const &Y, TContainer1D const &W) | |
| Default constructor. | |
| Bivariate (Bivariate< Real, Real, TContainer1D > const &stat) | |
| Copy constructor. | |
| virtual | ~Bivariate () |
| virtual destructor. | |
| Bivariate & | operator= (Bivariate< Real, Real, TContainer1D > const &stat) |
| Operator = : overwrite the BivariateRealReal with stat. | |
| void | setData (ITContainer1D< Real, TContainer1D > const &X, ITContainer1D< Real, TContainer1D > const &Y) |
| set a new data sets | |
| void | setData (ITContainer1D< Real, TContainer1D > const &X, ITContainer1D< Real, TContainer1D > const &Y, TContainer1D const &W) |
| set a new data sets | |
| Univariate< Real, TContainer1D > const & | xStat () const |
| get statistics of the first variable | |
| Univariate< Real, TContainer1D > const & | yStat () const |
| get statistics of the first variable | |
| Real const & | covariance () const |
| get covariance between the variables | |
| Real const & | correlation () const |
| get correlation between the variables | |
| Real const & | unbiasedCovariance () const |
| get the unbiased covariance between the variables | |
| Real const & | unbiasedCorrelation () const |
| get the unbiased correlation between the variables | |
Protected Member Functions | |
| void | compCovariance () |
| compute the covariance | |
| void | compWeightedCovariance () |
| compute the weighted covariance | |
Protected Attributes | |
| TContainer1D | X_ |
| reference on the X data set. | |
| TContainer1D | Y_ |
| reference on the Y data set. | |
| TContainer1D | W_ |
| local copy of the weights | |
| Univariate< Real, TContainer1D > | xStat_ |
| Statistics of the X variable. | |
| Univariate< Real, TContainer1D > | yStat_ |
| Statistics of the Y variable. | |
| Real | cov_ |
| covariance between X and Y | |
| Real | ucov_ |
| unbiased covariance between X and Y | |
| Real | cor_ |
| correlation between X and Y | |
| Real | ucor_ |
| unbiased correlation between X and Y | |
| Real | sumWeights_ |
| Sum of the weights. | |
| Real | sum2Weights_ |
| Sum of the square of the weights. | |
Computation of the bivariate Statistics of two Variables.
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 specialized class compute the Real univariate descriptive statistics of X and Y and the covariance between X and Y.
The covariance between X and Y will be computed using the formula
Definition at line 68 of file STK_Stat_BivariateRealReal.h.
| STK::Stat::Bivariate< Real, Real, TContainer1D >::Bivariate | ( | ITContainer1D< Real, TContainer1D > const & | X, |
| ITContainer1D< Real, TContainer1D > const & | Y | ||
| ) | [inline] |
Default constructor.
Copy locally the vectors X and Y and compute the univariate and bivariate statistics.
| X | the first variable |
| Y | the second variable |
Definition at line 76 of file STK_Stat_BivariateRealReal.h.
: X_(X.asLeaf()) , Y_(Y.asLeaf()) , W_() , xStat_(X) , yStat_(Y) , cov_(0.) , ucov_(0.) , cor_(0.) , ucor_(0.) , sumWeights_(0.0) , sum2Weights_(0.0) { compCovariance(); }
| STK::Stat::Bivariate< Real, Real, TContainer1D >::Bivariate | ( | ITContainer1D< Real, TContainer1D > const & | X, |
| ITContainer1D< Real, TContainer1D > const & | Y, | ||
| TContainer1D const & | W | ||
| ) | [inline] |
Default constructor.
Compute the univariate statistics of the two variables. The
| X | the first variable |
| Y | the second variable |
| W | the weights |
Definition at line 100 of file STK_Stat_BivariateRealReal.h.
: X_(X.asLeaf()) , Y_(Y.asLeaf()) , W_(W) , xStat_(X, W) , yStat_(Y, W) , cov_(0.) , ucov_(0.) , cor_(0.) , ucor_(0.) , sumWeights_(0.0) , sum2Weights_(0.0) { compWeightedCovariance(); }
| STK::Stat::Bivariate< Real, Real, TContainer1D >::Bivariate | ( | Bivariate< Real, Real, TContainer1D > const & | stat | ) | [inline] |
Copy constructor.
| stat | the statistics to copy |
Definition at line 121 of file STK_Stat_BivariateRealReal.h.
: xStat_(stat.xStat_) , yStat_(stat.yStat_) , cov_(stat.cov_) , ucov_(stat.ucov_) , cor_(stat.cor_) , ucor_(stat.ucor_) , sumWeights_(stat.nweight_) , sum2Weights_(stat.nweight2_) { }
| virtual STK::Stat::Bivariate< Real, Real, TContainer1D >::~Bivariate | ( | ) | [inline, virtual] |
| Bivariate& STK::Stat::Bivariate< Real, Real, TContainer1D >::operator= | ( | Bivariate< Real, Real, TContainer1D > const & | stat | ) | [inline] |
Operator = : overwrite the BivariateRealReal with stat.
| stat | the statistics to copy |
Definition at line 139 of file STK_Stat_BivariateRealReal.h.
References cor_, cov_, ucor_, ucov_, W_, xStat_, STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_, yStat_, and STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
| void STK::Stat::Bivariate< Real, Real, TContainer1D >::setData | ( | ITContainer1D< Real, TContainer1D > const & | X, |
| ITContainer1D< Real, TContainer1D > const & | Y | ||
| ) | [inline] |
set a new data sets
| X | the first variable |
| Y | the second variable |
Definition at line 155 of file STK_Stat_BivariateRealReal.h.
References STK::IRecursiveTemplate< TContainer1D >::asLeaf(), STK::Stat::Univariate< TYPE, TContainer1D >::setData(), STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_, and STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
{
X_ = X.asLeaf();
Y_ = Y.asLeaf();
W_.clear();
xStat_.setData(X);
yStat_.setData(Y);
compCovariance();
}

| void STK::Stat::Bivariate< Real, Real, TContainer1D >::setData | ( | ITContainer1D< Real, TContainer1D > const & | X, |
| ITContainer1D< Real, TContainer1D > const & | Y, | ||
| TContainer1D const & | W | ||
| ) | [inline] |
set a new data sets
| X | the first variable |
| Y | the second variable |
| W | the weights to apply |
Definition at line 172 of file STK_Stat_BivariateRealReal.h.
References STK::IRecursiveTemplate< TContainer1D >::asLeaf(), STK::Stat::Univariate< TYPE, TContainer1D >::setData(), STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_, and STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
{
X_ = X.asLeaf();
Y_ = Y.asLeaf();
W_ = W;
xStat_.setData(X, W);
yStat_.setData(Y, W);
compWeightedCovariance();
}

| Univariate<Real, TContainer1D> const& STK::Stat::Bivariate< Real, Real, TContainer1D >::xStat | ( | ) | const [inline] |
get statistics of the first variable
Definition at line 188 of file STK_Stat_BivariateRealReal.h.
References STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_.
{return xStat_;}
| Univariate<Real, TContainer1D> const& STK::Stat::Bivariate< Real, Real, TContainer1D >::yStat | ( | ) | const [inline] |
get statistics of the first variable
Definition at line 192 of file STK_Stat_BivariateRealReal.h.
References STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
{return yStat_;}
| Real const& STK::Stat::Bivariate< Real, Real, TContainer1D >::covariance | ( | ) | const [inline] |
get covariance between the variables
Definition at line 196 of file STK_Stat_BivariateRealReal.h.
{ return cov_;}
| Real const& STK::Stat::Bivariate< Real, Real, TContainer1D >::correlation | ( | ) | const [inline] |
get correlation between the variables
Definition at line 200 of file STK_Stat_BivariateRealReal.h.
{ return cor_;}
| Real const& STK::Stat::Bivariate< Real, Real, TContainer1D >::unbiasedCovariance | ( | ) | const [inline] |
get the unbiased covariance between the variables
Definition at line 204 of file STK_Stat_BivariateRealReal.h.
{ return ucov_;}
| Real const& STK::Stat::Bivariate< Real, Real, TContainer1D >::unbiasedCorrelation | ( | ) | const [inline] |
get the unbiased correlation between the variables
Definition at line 208 of file STK_Stat_BivariateRealReal.h.
{ return ucor_;}
| void STK::Stat::Bivariate< Real, Real, TContainer1D >::compCovariance | ( | ) | [inline, protected] |
compute the covariance
Definition at line 235 of file STK_Stat_BivariateRealReal.h.
References STK::Range::first(), STK::Range::inf(), STK::Range::last(), STK::Range::size(), STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_, and STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
{
// get dimensions
Range com = STK::Range::inf(X_.range(),Y_.range());
const Integer first = com.first(), last = com.last();
Integer nobs = com.size();
// get means
Real xMean = xStat_.mean(), yMean= yStat_.mean();
// compute covariance
Real xsum = 0.0, ysum = 0.0, xdev, ydev;
cov_ = 0.;
for (Integer i=first; i<=last; i++)
{
if (Arithmetic<Real>::isFinite(X_[i]) && Arithmetic<Real>::isFinite(Y_[i]))
{
xsum += (xdev = X_[i] - xMean); // deviation from the mean
ysum += (ydev = Y_[i] - yMean); // deviation from the mean
cov_ += (xdev*ydev); // squared value
}
else nobs--;
}
if (nobs > 1)
{
ucov_ = (cov_ - (xsum*ysum)/(Real)nobs)/(Real)(nobs -1);
ucor_ = ucov_/(xStat_.unbiasedStd()*yStat_.unbiasedStd());
cov_ = (cov_ - (xsum*ysum)/(Real)nobs)/(Real)(nobs);
cor_ = cov_/(xStat_.std()*yStat_.std());
}
else
{
if (nobs == 1)
{
cov_ = 0.;
cor_ = 0.;
ucov_ = Arithmetic<Real>::NA();
ucor_ = Arithmetic<Real>::NA();
}
// no observations
cov_ = Arithmetic<Real>::NA();
cor_ = Arithmetic<Real>::NA();
ucov_ = Arithmetic<Real>::NA();
ucor_ = Arithmetic<Real>::NA();
}
}

| void STK::Stat::Bivariate< Real, Real, TContainer1D >::compWeightedCovariance | ( | ) | [inline, protected] |
compute the weighted covariance
Definition at line 281 of file STK_Stat_BivariateRealReal.h.
References STK::abs(), STK::Range::first(), STK::Range::inf(), STK::Range::last(), STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::xStat_, and STK::Stat::Bivariate< XTYPE, YTYPE, TContainer1D >::yStat_.
{
// get dimensions
Range com = STK::Range::inf(X_.range(),Y_.range());
Integer first = com.first(), last = com.last();
// get means
Real xMean = xStat_.mean(), yMean= yStat_.mean();
// compute covariance
Real xsum = 0.0, ysum = 0.0, xdev, ydev;
sumWeights_ = 0.0;
sum2Weights_ = 0.0;
// sum
cov_ = 0.0;
for (Integer i=first; i<=last; i++)
{
if (Arithmetic<Real>::isFinite(X_[i]) && Arithmetic<Real>::isFinite(Y_[i]))
{
xsum += (xdev = X_[i] - xMean); // deviation from the mean
ysum += (ydev = Y_[i] - yMean); // deviation from the mean
Real Wi = abs((Real)W_[i]);
cov_ += Wi * (xdev*ydev); // cross product
sumWeights_ += Wi; // sum absolute weights
sum2Weights_ += Wi * Wi; // sum squared weights
}
}
// not pathological weights
if (sumWeights_*sumWeights_ > sum2Weights_)
{
ucov_ = (cov_ - xsum*ysum/sumWeights_)/(sumWeights_ - sum2Weights_/sumWeights_);
ucor_ = ucov_/(xStat_.unbiasedStd()*yStat_.unbiasedStd());
cov_ = (cov_ - xsum*ysum)/(sumWeights_);
cor_ = cov_/(xStat_.std()*yStat_.std());
}
else
{
if (sumWeights_) // if sum of the weights is not 0
{
cov_ = 0.;
cor_ = 0.;
ucov_ = Arithmetic<Real>::NA();
ucor_ = Arithmetic<Real>::NA();
}
// no weigths
cov_ = Arithmetic<Real>::NA();
cor_ = Arithmetic<Real>::NA();
ucov_ = Arithmetic<Real>::NA();
ucor_ = Arithmetic<Real>::NA();
}
}

TContainer1D STK::Stat::Bivariate< Real, Real, TContainer1D >::X_ [protected] |
reference on the X data set.
Definition at line 212 of file STK_Stat_BivariateRealReal.h.
TContainer1D STK::Stat::Bivariate< Real, Real, TContainer1D >::Y_ [protected] |
reference on the Y data set.
Definition at line 214 of file STK_Stat_BivariateRealReal.h.
TContainer1D STK::Stat::Bivariate< Real, Real, TContainer1D >::W_ [protected] |
local copy of the weights
Definition at line 216 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Univariate<Real, TContainer1D> STK::Stat::Bivariate< Real, Real, TContainer1D >::xStat_ [protected] |
Statistics of the X variable.
Definition at line 218 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Univariate<Real, TContainer1D> STK::Stat::Bivariate< Real, Real, TContainer1D >::yStat_ [protected] |
Statistics of the Y variable.
Definition at line 220 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::cov_ [protected] |
covariance between X and Y
Definition at line 222 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::ucov_ [protected] |
unbiased covariance between X and Y
Definition at line 224 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::cor_ [protected] |
correlation between X and Y
Definition at line 226 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::ucor_ [protected] |
unbiased correlation between X and Y
Definition at line 228 of file STK_Stat_BivariateRealReal.h.
Referenced by operator=().
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::sumWeights_ [protected] |
Sum of the weights.
Definition at line 230 of file STK_Stat_BivariateRealReal.h.
Real STK::Stat::Bivariate< Real, Real, TContainer1D >::sum2Weights_ [protected] |
Sum of the square of the weights.
Definition at line 232 of file STK_Stat_BivariateRealReal.h.