1 #ifndef JULIAN_DESCRIPTIVESTATISTICS_HPP 2 #define JULIAN_DESCRIPTIVESTATISTICS_HPP 6 #include <boost/assert.hpp> 7 #include <gsl/gsl_statistics.h> 30 inline double mean(
const std::vector<double>& data) {
31 return gsl_stats_mean(&data.front(), 1, data.size());
47 inline double variance(
const std::vector<double>& data) {
48 return gsl_stats_variance(&data.front(), 1, data.size());
63 inline double variance(
const std::vector<double>& data,
const double mean) {
64 return gsl_stats_variance_with_fixed_mean(&data.front(), 1, data.size(),
mean);
80 inline double stdDev(
const std::vector<double>& data) {
81 return gsl_stats_sd(&data.front(), 1, data.size());
96 inline double stdDev(
const std::vector<double>& data,
const double mean) {
97 return gsl_stats_sd_with_fixed_mean(&data.front(), 1, data.size(),
mean);
113 inline double absDev(
const std::vector<double>& data) {
114 return gsl_stats_absdev(&data.front(), 1, data.size());
130 inline double absDev(
const std::vector<double>& data,
const double mean) {
131 return gsl_stats_absdev_m(&data.front(), 1, data.size(),
mean);
145 inline double skew(
const std::vector<double>& data) {
146 return gsl_stats_skew(&data.front(), 1, data.size());
160 inline double kurtosis(
const std::vector<double>& data) {
161 return gsl_stats_kurtosis(&data.front(), 1, data.size());
177 inline double pearsonCorr(
const std::vector<double>& data1,
const std::vector<double>& data2) {
178 BOOST_ASSERT_MSG(data1.size() == data2.size(),
"Data vectors have different sizes.");
179 return gsl_stats_correlation(&data1.front(), 1, &data2.front(), 1, data1.size());
196 inline double spearmanCorr(
const std::vector<double>& data1,
const std::vector<double>& data2) {
197 BOOST_ASSERT_MSG(data1.size() == data2.size(),
"Data vectors have different sizes.");
198 int n = 2 * data1.size();
199 double* t =
new double[n];
200 double corr = gsl_stats_spearman(&data1.front(), 1, &data2.front(), 1, data1.size(),t);
213 inline double max(
const std::vector<double>& data) {
214 return gsl_stats_max(&data.front(), 1, data.size());
225 inline double min(
const std::vector<double>& data) {
226 return gsl_stats_min(&data.front(), 1, data.size());
241 inline double median(
const std::vector<double> data) {
243 std::sort(data_.begin(),data_.end());
244 return gsl_stats_median_from_sorted_data(&data_.front(), 1, data_.size());
261 inline double percentile(
const std::vector<double> data,
const double& q) {
263 std::sort(data_.begin(),data_.end());
264 return gsl_stats_quantile_from_sorted_data(&data_.front(), 1, data_.size(), q);
277 inline double IQR(
const std::vector<double>& data) {
double mean(const std::vector< double > &data)
Function calculates mean.
Definition: descriptiveStatistics.hpp:30
double absDev(const std::vector< double > &data, const double mean)
Function calculates absolute deviation using the provided mean.
Definition: descriptiveStatistics.hpp:130
Definition: cadHoliday.cpp:3
double pearsonCorr(const std::vector< double > &data1, const std::vector< double > &data2)
Function calculates Pearson correlation.
Definition: descriptiveStatistics.hpp:177
double max(const std::vector< double > &data)
Function returns the maximum value.
Definition: descriptiveStatistics.hpp:213
double IQR(const std::vector< double > &data)
Returns interquartile range.
Definition: descriptiveStatistics.hpp:277
double stdDev(const std::vector< double > &data, const double mean)
Function calculates standard deviation using the provided mean.
Definition: descriptiveStatistics.hpp:96
double skew(const std::vector< double > &data)
Function calculates skew.
Definition: descriptiveStatistics.hpp:145
double min(const std::vector< double > &data)
Function returns the minimum value.
Definition: descriptiveStatistics.hpp:225
double spearmanCorr(const std::vector< double > &data1, const std::vector< double > &data2)
Function calculates Spearman correlation.
Definition: descriptiveStatistics.hpp:196
double median(const std::vector< double > data)
Function returns median.
Definition: descriptiveStatistics.hpp:241
double kurtosis(const std::vector< double > &data)
Function calculates normalized kurtosis.
Definition: descriptiveStatistics.hpp:160
double variance(const std::vector< double > &data, const double mean)
Function calculates variance using the provided mean.
Definition: descriptiveStatistics.hpp:63
double percentile(const std::vector< double > data, const double &q)
Function returns a quantile.
Definition: descriptiveStatistics.hpp:261
void descriptiveStatistics(const std::vector< double > &data)
Procedure prints the basic statistical measures.
Definition: descriptiveStatistics.cpp:15