statcpp
C++17 Header-Only Statistics Library
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
statcpp Namespace Reference

Namespaces

namespace  detail
 Internal helper functions.
 

Classes

struct  aggregation_result
 Aggregation result per group. More...
 
struct  ancova_result
 Structure storing ANCOVA (Analysis of Covariance) results. More...
 
struct  anova_row
 Structure representing a row in the ANOVA table. More...
 
struct  bootstrap_result
 Structure to store bootstrap estimation results. More...
 
struct  complete_case_result
 Complete case analysis result. More...
 
struct  confidence_interval
 Structure to store confidence interval results. More...
 
struct  contingency_table_result
 Contingency table (cross-tabulation) result. More...
 
struct  cv_result
 Structure to store cross-validation results. More...
 
struct  dendrogram_node
 Dendrogram node. More...
 
struct  five_number_summary_result
 Five-number summary result. More...
 
struct  frequency_entry
 Frequency table entry. More...
 
struct  frequency_table_result
 Frequency table result. More...
 
struct  glm_residuals
 GLM residuals structure. More...
 
struct  glm_result
 GLM result structure. More...
 
struct  group_result
 Grouping result. More...
 
struct  hazard_rate_result
 Hazard rate result. More...
 
struct  is_random_engine
 Type trait to determine if a type is a random engine. More...
 
struct  is_random_engine< std::knuth_b >
 Specialization for std::knuth_b. More...
 
struct  is_random_engine< std::minstd_rand >
 Specialization for std::minstd_rand. More...
 
struct  is_random_engine< std::minstd_rand0 >
 Specialization for std::minstd_rand0. More...
 
struct  is_random_engine< std::mt19937 >
 Specialization for std::mt19937. More...
 
struct  is_random_engine< std::mt19937_64 >
 Specialization for std::mt19937_64. More...
 
struct  is_random_engine< std::ranlux24 >
 Specialization for std::ranlux24. More...
 
struct  is_random_engine< std::ranlux24_base >
 Specialization for std::ranlux24_base. More...
 
struct  is_random_engine< std::ranlux48 >
 Specialization for std::ranlux48. More...
 
struct  is_random_engine< std::ranlux48_base >
 Specialization for std::ranlux48_base. More...
 
struct  kaplan_meier_result
 Kaplan-Meier estimation result. More...
 
struct  kmeans_result
 K-means clustering result. More...
 
struct  label_encoding_result
 Label encoding result. More...
 
struct  logrank_result
 Log-rank test result. More...
 
struct  mcar_test_result
 Little's MCAR test result. More...
 
struct  missing_pattern_info
 Missing pattern information. More...
 
struct  multiple_imputation_result
 Multiple imputation result. More...
 
struct  multiple_regression_result
 Structure to store multiple regression analysis results. More...
 
struct  odds_ratio_result
 Odds ratio result. More...
 
struct  one_way_anova_result
 Structure storing one-way ANOVA results. More...
 
struct  outlier_detection_result
 Outlier detection result. More...
 
struct  pca_result
 PCA result. More...
 
struct  permutation_result
 Structure to store permutation test results. More...
 
struct  posthoc_comparison
 Structure storing individual pairwise comparison result in post-hoc tests. More...
 
struct  posthoc_result
 Structure storing post-hoc comparison results. More...
 
struct  power_result
 Power analysis result. More...
 
struct  prediction_interval
 Structure to store prediction interval results. More...
 
struct  quartile_result
 Quartile result. More...
 
struct  regularized_regression_result
 Structure to store regularized regression results. More...
 
struct  relative_risk_result
 Relative risk result. More...
 
struct  residual_diagnostics
 Structure to store residual diagnostics results. More...
 
struct  risk_difference_result
 Risk difference result. More...
 
struct  sensitivity_analysis_result
 Sensitivity analysis result (single parameter) More...
 
struct  simple_regression_result
 Structure to store simple regression analysis results. More...
 
struct  test_result
 Structure to store statistical test results. More...
 
struct  tipping_point_result
 Tipping point analysis result. More...
 
struct  two_way_anova_result
 Structure storing two-way ANOVA results. More...
 
struct  validation_result
 Data validation result. More...
 

Typedefs

using default_random_engine = std::mt19937_64
 Default random engine type (Mersenne Twister 64-bit version)
 

Enumerations

enum class  linkage_type { single , complete , average , ward }
 Linkage types. More...
 
enum class  effect_size_magnitude { negligible , small , medium , large }
 Enumeration for effect size magnitude. More...
 
enum class  link_function {
  identity , logit , probit , log ,
  inverse , cloglog
}
 Link function types. More...
 
enum class  distribution_family { gaussian , binomial , poisson , gamma_family }
 Distribution family. More...
 
enum class  missing_mechanism { mcar , mar , mnar , unknown }
 Missing mechanism types. More...
 
enum class  alternative_hypothesis { two_sided , less , greater }
 Enumeration representing the type of alternative hypothesis. More...
 

Functions

one_way_anova_result one_way_anova (const std::vector< std::vector< double > > &groups)
 Perform one-way analysis of variance.
 
two_way_anova_result two_way_anova (const std::vector< std::vector< std::vector< double > > > &data)
 Perform two-way analysis of variance (with replication)
 
posthoc_result tukey_hsd (const one_way_anova_result &anova_result, const std::vector< std::vector< double > > &groups, double alpha=0.05)
 Perform Tukey's Honestly Significant Difference (HSD) test.
 
posthoc_result bonferroni_posthoc (const one_way_anova_result &anova_result, double alpha=0.05)
 Perform Bonferroni method for multiple comparisons.
 
posthoc_result dunnett_posthoc (const one_way_anova_result &anova_result, std::size_t control_group=0, double alpha=0.05)
 Perform Dunnett's test for multiple comparisons against a control group.
 
posthoc_result scheffe_posthoc (const one_way_anova_result &anova_result, double alpha=0.05)
 Perform Scheffe's method for multiple comparisons.
 
ancova_result one_way_ancova (const std::vector< std::vector< std::pair< double, double > > > &groups)
 Perform one-way analysis of covariance.
 
double eta_squared (const one_way_anova_result &result)
 Calculate Eta-squared for one-way ANOVA.
 
double partial_eta_squared_a (const two_way_anova_result &result)
 Calculate Partial eta-squared for factor A in two-way ANOVA.
 
double partial_eta_squared_b (const two_way_anova_result &result)
 Calculate Partial eta-squared for factor B in two-way ANOVA.
 
double partial_eta_squared_interaction (const two_way_anova_result &result)
 Calculate Partial eta-squared for interaction in two-way ANOVA.
 
double omega_squared (const one_way_anova_result &result)
 Calculate Omega-squared for one-way ANOVA.
 
double cohens_f (const one_way_anova_result &result)
 Calculate Cohen's f for one-way ANOVA.
 
template<typename Iterator >
auto sum (Iterator first, Iterator last)
 Sum.
 
template<typename Iterator , typename Projection >
auto sum (Iterator first, Iterator last, Projection proj)
 Sum of projected values using a lambda expression.
 
template<typename Iterator >
std::size_t count (Iterator first, Iterator last)
 Data count.
 
template<typename Iterator >
double mean (Iterator first, Iterator last)
 Arithmetic mean.
 
template<typename Iterator , typename Projection >
double mean (Iterator first, Iterator last, Projection proj)
 Arithmetic mean of projected values using a lambda expression.
 
template<typename Iterator >
double median (Iterator first, Iterator last)
 Median (accepts a sorted range)
 
template<typename Iterator , typename Projection >
double median (Iterator first, Iterator last, Projection proj)
 Median of projected values using a lambda expression (projection results must be in sorted order)
 
template<typename Iterator >
auto mode (Iterator first, Iterator last)
 Mode (returns the smallest value when there are multiple modes: guarantees deterministic behavior)
 
template<typename Iterator , typename Projection >
auto mode (Iterator first, Iterator last, Projection proj)
 Mode of projected values using a lambda expression.
 
template<typename Iterator >
auto modes (Iterator first, Iterator last) -> std::vector< typename std::iterator_traits< Iterator >::value_type >
 Returns all modes (returns a vector sorted in ascending order)
 
template<typename Iterator , typename Projection >
auto modes (Iterator first, Iterator last, Projection proj) -> std::vector< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type > >
 Returns all modes of projected values using a lambda expression.
 
template<typename Iterator >
double geometric_mean (Iterator first, Iterator last)
 Geometric mean.
 
template<typename Iterator , typename Projection >
double geometric_mean (Iterator first, Iterator last, Projection proj)
 Geometric mean of projected values using a lambda expression.
 
template<typename Iterator >
double harmonic_mean (Iterator first, Iterator last)
 Harmonic mean.
 
template<typename Iterator , typename Projection >
double harmonic_mean (Iterator first, Iterator last, Projection proj)
 Harmonic mean of projected values using a lambda expression.
 
template<typename Iterator >
double trimmed_mean (Iterator first, Iterator last, double proportion)
 Trimmed mean (accepts a sorted range. proportion: exclusion ratio per side, 0.0 to less than 0.5)
 
template<typename Iterator , typename Projection >
double trimmed_mean (Iterator first, Iterator last, double proportion, Projection proj)
 Trimmed mean of projected values using a lambda expression (projection results must be in sorted order)
 
template<typename Iterator , typename WeightIterator >
double weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted mean.
 
template<typename Iterator , typename WeightIterator >
double weighted_mean (Iterator first, Iterator last, WeightIterator weight_first)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted mean (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_mean (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 
template<typename T1 , typename T2 >
double logarithmic_mean (T1 a, T2 b)
 Logarithmic Mean.
 
template<typename Iterator , typename WeightIterator >
double weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted harmonic mean (safe range version)
 
template<typename Iterator , typename WeightIterator >
double weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted harmonic mean.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted harmonic mean (safe range version with projection)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_harmonic_mean (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted harmonic mean (projection version)
 
template<typename Iterator >
std::size_t argmin (Iterator first, Iterator last)
 Returns the index of the minimum value.
 
template<typename Iterator , typename Projection >
std::size_t argmin (Iterator first, Iterator last, Projection proj)
 Returns the index of the minimum value (projection version)
 
template<typename Iterator >
std::size_t argmax (Iterator first, Iterator last)
 Returns the index of the maximum value.
 
template<typename Iterator , typename Projection >
std::size_t argmax (Iterator first, Iterator last, Projection proj)
 Returns the index of the maximum value (projection version)
 
contingency_table_result contingency_table (const std::vector< std::size_t > &row_data, const std::vector< std::size_t > &col_data)
 Create a contingency table.
 
odds_ratio_result odds_ratio (const std::vector< std::vector< std::size_t > > &table)
 Calculate odds ratio from a 2x2 contingency table.
 
odds_ratio_result odds_ratio (std::size_t a, std::size_t b, std::size_t c, std::size_t d)
 Calculate odds ratio from a 2x2 contingency table (specifying cell values directly)
 
relative_risk_result relative_risk (const std::vector< std::vector< std::size_t > > &table)
 Calculate relative risk (risk ratio) from a 2x2 contingency table.
 
relative_risk_result relative_risk (std::size_t a, std::size_t b, std::size_t c, std::size_t d)
 Calculate relative risk from a 2x2 contingency table (specifying cell values directly)
 
risk_difference_result risk_difference (const std::vector< std::vector< std::size_t > > &table)
 Calculate risk difference from a 2x2 contingency table.
 
risk_difference_result risk_difference (std::size_t a, std::size_t b, std::size_t c, std::size_t d)
 Calculate risk difference from a 2x2 contingency table (specifying cell values directly)
 
double number_needed_to_treat (const std::vector< std::vector< std::size_t > > &table)
 Calculate Number Needed to Treat (NNT)
 
double euclidean_distance (const std::vector< double > &a, const std::vector< double > &b)
 Euclidean distance.
 
double manhattan_distance (const std::vector< double > &a, const std::vector< double > &b)
 Manhattan distance.
 
std::vector< std::vector< double > > kmeans_plusplus_init (const std::vector< std::vector< double > > &data, std::size_t k)
 K-means++ initialization.
 
kmeans_result kmeans (const std::vector< std::vector< double > > &data, std::size_t k, std::size_t max_iter=100, double tol=1e-6)
 K-means clustering.
 
std::vector< dendrogram_nodehierarchical_clustering (const std::vector< std::vector< double > > &data, linkage_type linkage=linkage_type::single)
 Hierarchical clustering.
 
std::vector< std::size_t > cut_dendrogram (const std::vector< dendrogram_node > &dendrogram, std::size_t n_data, std::size_t k)
 Extract k clusters from dendrogram.
 
double silhouette_score (const std::vector< std::vector< double > > &data, const std::vector< std::size_t > &labels)
 Calculate silhouette score.
 
double uniform_pdf (double x, double a=0.0, double b=1.0)
 Uniform distribution probability density function (PDF)
 
double uniform_cdf (double x, double a=0.0, double b=1.0)
 Uniform distribution cumulative distribution function (CDF)
 
double uniform_quantile (double p, double a=0.0, double b=1.0)
 Uniform distribution quantile function (inverse CDF)
 
template<typename Engine = default_random_engine>
double uniform_rand (double a, double b, Engine &engine)
 Uniform distribution random number generation.
 
double uniform_rand (double a=0.0, double b=1.0)
 Uniform distribution random number generation (using default engine)
 
double normal_pdf (double x, double mu=0.0, double sigma=1.0)
 Normal distribution probability density function (PDF)
 
double normal_cdf (double x, double mu=0.0, double sigma=1.0)
 Normal distribution cumulative distribution function (CDF)
 
double normal_quantile (double p, double mu=0.0, double sigma=1.0)
 Normal distribution quantile function (inverse CDF, percent point function)
 
template<typename Engine = default_random_engine>
double normal_rand (double mu, double sigma, Engine &engine)
 Normal distribution random number generation.
 
double normal_rand (double mu=0.0, double sigma=1.0)
 Normal distribution random number generation (using default engine)
 
double exponential_pdf (double x, double lambda=1.0)
 Exponential distribution probability density function (PDF)
 
double exponential_cdf (double x, double lambda=1.0)
 Exponential distribution cumulative distribution function (CDF)
 
double exponential_quantile (double p, double lambda=1.0)
 Exponential distribution quantile function.
 
template<typename Engine = default_random_engine>
double exponential_rand (double lambda, Engine &engine)
 Exponential distribution random number generation.
 
double exponential_rand (double lambda=1.0)
 Exponential distribution random number generation (using default engine)
 
double gamma_pdf (double x, double shape, double rate=1.0)
 Gamma distribution probability density function (PDF)
 
double gamma_cdf (double x, double shape, double rate=1.0)
 Gamma distribution cumulative distribution function (CDF)
 
double gamma_quantile (double p, double shape, double rate=1.0)
 Gamma distribution quantile function.
 
template<typename Engine = default_random_engine>
double gamma_rand (double shape, double rate, Engine &engine)
 Gamma distribution random number generation.
 
double gamma_rand (double shape, double rate=1.0)
 Gamma distribution random number generation (using default engine)
 
double beta_pdf (double x, double alpha, double beta_param)
 Beta distribution probability density function (PDF)
 
double beta_cdf (double x, double alpha, double beta_param)
 Beta distribution cumulative distribution function (CDF)
 
double beta_quantile (double p, double alpha, double beta_param)
 Beta distribution quantile function.
 
template<typename Engine = default_random_engine>
double beta_rand (double alpha, double beta_param, Engine &engine)
 Beta distribution random number generation (using gamma variates)
 
double beta_rand (double alpha, double beta_param)
 Beta distribution random number generation (using default engine)
 
double chisq_pdf (double x, double df)
 Chi-square distribution probability density function (PDF)
 
double chisq_cdf (double x, double df)
 Chi-square distribution cumulative distribution function (CDF)
 
double chisq_quantile (double p, double df)
 Chi-square distribution quantile function.
 
template<typename Engine = default_random_engine>
double chisq_rand (double df, Engine &engine)
 Chi-square distribution random number generation.
 
double chisq_rand (double df)
 Chi-square distribution random number generation (using default engine)
 
double t_pdf (double x, double df)
 t-distribution probability density function (PDF)
 
double t_cdf (double x, double df)
 t-distribution cumulative distribution function (CDF)
 
double t_quantile (double p, double df)
 t-distribution quantile function (Newton-Raphson method)
 
template<typename Engine = default_random_engine>
double t_rand (double df, Engine &engine)
 t-distribution random number generation
 
double t_rand (double df)
 t-distribution random number generation (using default engine)
 
double f_pdf (double x, double df1, double df2)
 F-distribution probability density function (PDF)
 
double f_cdf (double x, double df1, double df2)
 F-distribution cumulative distribution function (CDF)
 
double f_quantile (double p, double df1, double df2)
 F-distribution quantile function (Newton-Raphson method)
 
template<typename Engine = default_random_engine>
double f_rand (double df1, double df2, Engine &engine)
 F-distribution random number generation.
 
double f_rand (double df1, double df2)
 F-distribution random number generation (using default engine)
 
double lognormal_pdf (double x, double mu=0.0, double sigma=1.0)
 Log-normal distribution probability density function (PDF)
 
double lognormal_cdf (double x, double mu=0.0, double sigma=1.0)
 Log-normal distribution cumulative distribution function (CDF)
 
double lognormal_quantile (double p, double mu=0.0, double sigma=1.0)
 Log-normal distribution quantile function.
 
template<typename Engine = default_random_engine>
double lognormal_rand (double mu, double sigma, Engine &engine)
 Log-normal distribution random number generation.
 
double lognormal_rand (double mu=0.0, double sigma=1.0)
 Log-normal distribution random number generation (using default engine)
 
double weibull_pdf (double x, double shape, double scale=1.0)
 Weibull distribution probability density function (PDF)
 
double weibull_cdf (double x, double shape, double scale=1.0)
 Weibull distribution cumulative distribution function (CDF)
 
double weibull_quantile (double p, double shape, double scale=1.0)
 Weibull distribution quantile function.
 
template<typename Engine = default_random_engine>
double weibull_rand (double shape, double scale, Engine &engine)
 Weibull distribution random number generation.
 
double weibull_rand (double shape, double scale=1.0)
 Weibull distribution random number generation (using default engine)
 
double studentized_range_cdf (double q, double k, double df)
 CDF of the studentized range distribution.
 
double studentized_range_quantile (double p, double k, double df)
 Quantile function of the studentized range distribution.
 
template<typename Iterator1 , typename Iterator2 >
double population_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Population covariance.
 
template<typename Iterator1 , typename Iterator2 >
double population_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double mean_x, double mean_y)
 Population covariance with precomputed means.
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double population_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Population covariance (projection version)
 
template<typename Iterator1 , typename Iterator2 >
double sample_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Sample covariance (unbiased covariance)
 
template<typename Iterator1 , typename Iterator2 >
double sample_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double mean_x, double mean_y)
 Sample covariance with precomputed means.
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double sample_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Sample covariance (projection version)
 
template<typename Iterator1 , typename Iterator2 >
double covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Covariance (alias for sample_covariance)
 
template<typename Iterator1 , typename Iterator2 >
double covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double mean_x, double mean_y)
 Covariance with precomputed means (alias for sample_covariance)
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Covariance (projection version, alias for sample_covariance)
 
template<typename Iterator1 , typename Iterator2 >
double pearson_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Pearson correlation coefficient.
 
template<typename Iterator1 , typename Iterator2 >
double pearson_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double mean_x, double mean_y)
 Pearson correlation coefficient with precomputed means.
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double pearson_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Pearson correlation coefficient (projection version)
 
template<typename Iterator1 , typename Iterator2 >
double spearman_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Spearman's rank correlation coefficient.
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double spearman_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Spearman's rank correlation coefficient (projection version)
 
template<typename Iterator1 , typename Iterator2 >
double kendall_tau (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Kendall's rank correlation coefficient (tau-b)
 
template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double kendall_tau (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Projection1 proj1, Projection2 proj2)
 Kendall's rank correlation coefficient (projection version)
 
template<typename Iterator1 , typename Iterator2 , typename WeightIterator >
double weighted_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, WeightIterator weight_first)
 Weighted covariance.
 
template<typename Iterator1 , typename Iterator2 , typename WeightIterator , typename Projection1 , typename Projection2 >
double weighted_covariance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, WeightIterator weight_first, Projection1 proj1, Projection2 proj2)
 Weighted covariance (projection version)
 
bool is_na (double x)
 Check if a value is NA.
 
template<typename T >
std::vector< std::vector< T > > dropna (const std::vector< std::vector< T > > &data)
 Drop rows containing NA.
 
template<typename T >
std::vector< T > dropna (const std::vector< T > &data)
 Drop NA from a 1-dimensional vector.
 
template<typename T >
std::vector< T > fillna (const std::vector< T > &data, T fill_value)
 Fill NA with a specified value.
 
std::vector< double > fillna_mean (const std::vector< double > &data)
 Fill NA with mean.
 
std::vector< double > fillna_median (const std::vector< double > &data)
 Fill NA with median.
 
std::vector< double > fillna_ffill (const std::vector< double > &data)
 Fill NA with forward fill.
 
std::vector< double > fillna_bfill (const std::vector< double > &data)
 Fill NA with backward fill.
 
std::vector< double > fillna_interpolate (const std::vector< double > &data)
 Fill NA with linear interpolation.
 
template<typename T , typename Predicate >
std::vector< T > filter (const std::vector< T > &data, Predicate pred)
 Filter elements that match a condition.
 
template<typename T , typename Predicate >
std::vector< std::vector< T > > filter_rows (const std::vector< std::vector< T > > &data, Predicate pred)
 Filter rows that match a condition (2-dimensional)
 
template<typename T >
std::vector< T > filter_range (const std::vector< T > &data, T min_val, T max_val)
 Filter values within a range.
 
std::vector< double > log_transform (const std::vector< double > &data)
 Logarithmic transformation (natural logarithm)
 
std::vector< double > log1p_transform (const std::vector< double > &data)
 Logarithmic transformation (log1p: log(1 + x))
 
std::vector< double > sqrt_transform (const std::vector< double > &data)
 Square root transformation.
 
std::vector< double > boxcox_transform (const std::vector< double > &data, double lambda)
 Box-Cox transformation.
 
std::vector< double > rank_transform (const std::vector< double > &data)
 Rank transformation.
 
template<typename K , typename V >
group_result< K, V > group_by (const std::vector< K > &keys, const std::vector< V > &values)
 Group by.
 
template<typename K >
aggregation_result< K > group_mean (const std::vector< K > &keys, const std::vector< double > &values)
 Mean per group.
 
template<typename K >
aggregation_result< K > group_sum (const std::vector< K > &keys, const std::vector< double > &values)
 Sum per group.
 
template<typename K >
aggregation_result< K > group_count (const std::vector< K > &keys, const std::vector< double > &values)
 Count per group.
 
template<typename T >
std::vector< T > sort_values (const std::vector< T > &data, bool ascending=true)
 Return a sorted vector (ascending)
 
template<typename T >
std::vector< std::size_t > argsort (const std::vector< T > &data, bool ascending=true)
 Return indices in sorted order.
 
template<typename T >
std::vector< T > sample_with_replacement (const std::vector< T > &data, std::size_t n)
 Random sampling (with replacement)
 
template<typename T >
std::vector< T > sample_without_replacement (const std::vector< T > &data, std::size_t n)
 Random sampling (without replacement)
 
template<typename K , typename V >
std::vector< V > stratified_sample (const std::vector< K > &strata, const std::vector< V > &data, double sample_ratio)
 Stratified sampling.
 
template<typename T >
std::vector< T > drop_duplicates (const std::vector< T > &data)
 Drop duplicates.
 
template<typename T >
std::map< T, std::size_t > value_counts (const std::vector< T > &data)
 Count duplicates.
 
template<typename T >
std::vector< T > get_duplicates (const std::vector< T > &data)
 Get duplicate values.
 
std::vector< double > rolling_mean (const std::vector< double > &data, std::size_t window)
 Moving average.
 
std::vector< double > rolling_std (const std::vector< double > &data, std::size_t window)
 Moving standard deviation.
 
std::vector< double > rolling_min (const std::vector< double > &data, std::size_t window)
 Moving minimum.
 
std::vector< double > rolling_max (const std::vector< double > &data, std::size_t window)
 Moving maximum.
 
std::vector< double > rolling_sum (const std::vector< double > &data, std::size_t window)
 Moving sum.
 
template<typename T >
label_encoding_result< T > label_encode (const std::vector< T > &data)
 Label encoding.
 
template<typename T >
std::vector< std::vector< double > > one_hot_encode (const std::vector< T > &data)
 One-hot encoding.
 
std::vector< std::size_t > bin_equal_width (const std::vector< double > &data, std::size_t n_bins)
 Binning (equal width)
 
std::vector< std::size_t > bin_equal_freq (const std::vector< double > &data, std::size_t n_bins)
 Binning (equal frequency)
 
validation_result validate_data (const std::vector< double > &data, bool allow_missing=false, bool allow_infinite=false, bool allow_negative=true)
 Data validation.
 
bool validate_range (const std::vector< double > &data, double min_val=-std::numeric_limits< double >::infinity(), double max_val=std::numeric_limits< double >::infinity())
 Range validation.
 
double log_factorial (std::uint64_t n)
 Calculate log factorial.
 
double log_binomial_coef (std::uint64_t n, std::uint64_t k)
 Calculate log binomial coefficient.
 
double binomial_coef (std::uint64_t n, std::uint64_t k)
 Calculate binomial coefficient.
 
double binomial_pmf (std::uint64_t k, std::uint64_t n, double p)
 Binomial distribution probability mass function (PMF)
 
double binomial_cdf (std::uint64_t k, std::uint64_t n, double p)
 Binomial distribution cumulative distribution function (CDF)
 
std::uint64_t binomial_quantile (double prob, std::uint64_t n, double p)
 Binomial distribution quantile function.
 
template<typename Engine = default_random_engine>
std::uint64_t binomial_rand (std::uint64_t n, double p, Engine &engine)
 Binomial distribution random number generation.
 
std::uint64_t binomial_rand (std::uint64_t n, double p)
 Binomial distribution random number generation (using default engine)
 
double poisson_pmf (std::uint64_t k, double lambda)
 Poisson distribution probability mass function (PMF)
 
double poisson_cdf (std::uint64_t k, double lambda)
 Poisson distribution cumulative distribution function (CDF)
 
std::uint64_t poisson_quantile (double p, double lambda)
 Poisson distribution quantile function.
 
template<typename Engine = default_random_engine>
std::uint64_t poisson_rand (double lambda, Engine &engine)
 Poisson distribution random number generation.
 
std::uint64_t poisson_rand (double lambda)
 Poisson distribution random number generation (using default engine)
 
double geometric_pmf (std::uint64_t k, double p)
 Geometric distribution probability mass function (PMF)
 
double geometric_cdf (std::uint64_t k, double p)
 Geometric distribution cumulative distribution function (CDF)
 
std::uint64_t geometric_quantile (double prob, double p)
 Geometric distribution quantile function (inverse CDF)
 
template<typename Engine = default_random_engine>
std::uint64_t geometric_rand (double p, Engine &engine)
 Geometric distribution random number generation.
 
std::uint64_t geometric_rand (double p)
 Geometric distribution random number generation (using default engine)
 
double hypergeom_pmf (std::uint64_t k, std::uint64_t N, std::uint64_t K, std::uint64_t n)
 Hypergeometric distribution probability mass function (PMF)
 
double hypergeom_cdf (std::uint64_t k, std::uint64_t N, std::uint64_t K, std::uint64_t n)
 Hypergeometric distribution cumulative distribution function (CDF)
 
std::uint64_t hypergeom_quantile (double p, std::uint64_t N, std::uint64_t K, std::uint64_t n)
 Hypergeometric distribution quantile function (inverse CDF)
 
template<typename Engine = default_random_engine>
std::uint64_t hypergeom_rand (std::uint64_t N, std::uint64_t K, std::uint64_t n, Engine &engine)
 Hypergeometric distribution random number generation.
 
std::uint64_t hypergeom_rand (std::uint64_t N, std::uint64_t K, std::uint64_t n)
 Hypergeometric distribution random number generation (using default engine)
 
double nbinom_pmf (std::uint64_t k, double r, double p)
 Negative binomial distribution probability mass function (PMF)
 
double nbinom_cdf (std::uint64_t k, double r, double p)
 Negative binomial distribution cumulative distribution function (CDF)
 
std::uint64_t nbinom_quantile (double prob, double r, double p)
 Negative binomial distribution quantile function (inverse CDF)
 
template<typename Engine = default_random_engine>
std::uint64_t nbinom_rand (double r, double p, Engine &engine)
 Negative binomial distribution random number generation.
 
std::uint64_t nbinom_rand (double r, double p)
 Negative binomial distribution random number generation (using default engine)
 
double bernoulli_pmf (std::uint64_t k, double p)
 Bernoulli distribution probability mass function (PMF)
 
double bernoulli_cdf (std::uint64_t k, double p)
 Bernoulli distribution cumulative distribution function (CDF)
 
std::uint64_t bernoulli_quantile (double prob, double p)
 Bernoulli distribution quantile function.
 
template<typename Engine = default_random_engine>
std::uint64_t bernoulli_rand (double p, Engine &engine)
 Bernoulli distribution random number generation.
 
std::uint64_t bernoulli_rand (double p)
 Bernoulli distribution random number generation (using default engine)
 
double discrete_uniform_pmf (std::int64_t k, std::int64_t a, std::int64_t b)
 Discrete uniform distribution probability mass function (PMF)
 
double discrete_uniform_cdf (std::int64_t k, std::int64_t a, std::int64_t b)
 Discrete uniform distribution cumulative distribution function (CDF)
 
std::int64_t discrete_uniform_quantile (double p, std::int64_t a, std::int64_t b)
 Discrete uniform distribution quantile function.
 
template<typename Engine = default_random_engine>
std::int64_t discrete_uniform_rand (std::int64_t a, std::int64_t b, Engine &engine)
 Discrete uniform distribution random number generation.
 
std::int64_t discrete_uniform_rand (std::int64_t a, std::int64_t b)
 Discrete uniform distribution random number generation (using default engine)
 
template<typename Iterator >
double range (Iterator first, Iterator last)
 Range (maximum - minimum)
 
template<typename Iterator , typename Projection >
double range (Iterator first, Iterator last, Projection proj)
 Range of projected values using a lambda expression.
 
template<typename Iterator >
double var (Iterator first, Iterator last, std::size_t ddof=0)
 Variance (ddof = Delta Degrees of Freedom)
 
template<typename Iterator >
double var (Iterator first, Iterator last, double precomputed_mean, std::size_t ddof)
 Variance using precomputed mean (with ddof)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double var (Iterator first, Iterator last, Projection proj, std::size_t ddof=0)
 Variance of projected values using a lambda expression (with ddof)
 
template<typename Iterator , typename Projection >
double var (Iterator first, Iterator last, Projection proj, double precomputed_mean, std::size_t ddof)
 Variance of projected values using precomputed mean (with ddof)
 
template<typename Iterator >
double population_variance (Iterator first, Iterator last)
 Population variance.
 
template<typename Iterator >
double population_variance (Iterator first, Iterator last, double precomputed_mean)
 Population variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double population_variance (Iterator first, Iterator last, Projection proj)
 Population variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double population_variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Population variance of projected values using precomputed mean.
 
template<typename Iterator >
double sample_variance (Iterator first, Iterator last)
 Sample variance (unbiased variance)
 
template<typename Iterator >
double sample_variance (Iterator first, Iterator last, double precomputed_mean)
 Sample variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double sample_variance (Iterator first, Iterator last, Projection proj)
 Sample variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double sample_variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Sample variance of projected values using precomputed mean.
 
template<typename Iterator >
double variance (Iterator first, Iterator last)
 Variance (alias for sample_variance)
 
template<typename Iterator >
double variance (Iterator first, Iterator last, double precomputed_mean)
 Variance using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double variance (Iterator first, Iterator last, Projection proj)
 Variance of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double variance (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Variance of projected values using precomputed mean.
 
template<typename Iterator >
double stdev (Iterator first, Iterator last, std::size_t ddof=0)
 Standard deviation (ddof = Delta Degrees of Freedom)
 
template<typename Iterator >
double stdev (Iterator first, Iterator last, double precomputed_mean, std::size_t ddof)
 Standard deviation using precomputed mean (with ddof)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double stdev (Iterator first, Iterator last, Projection proj, std::size_t ddof=0)
 Standard deviation of projected values using a lambda expression (with ddof)
 
template<typename Iterator , typename Projection >
double stdev (Iterator first, Iterator last, Projection proj, double precomputed_mean, std::size_t ddof)
 Standard deviation of projected values using precomputed mean (with ddof)
 
template<typename Iterator >
double population_stddev (Iterator first, Iterator last)
 Population standard deviation.
 
template<typename Iterator >
double population_stddev (Iterator first, Iterator last, double precomputed_mean)
 Population standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double population_stddev (Iterator first, Iterator last, Projection proj)
 Population standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double population_stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Population standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double sample_stddev (Iterator first, Iterator last)
 Sample standard deviation.
 
template<typename Iterator >
double sample_stddev (Iterator first, Iterator last, double precomputed_mean)
 Sample standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double sample_stddev (Iterator first, Iterator last, Projection proj)
 Sample standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double sample_stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Sample standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double stddev (Iterator first, Iterator last)
 Standard deviation (alias for sample_stddev)
 
template<typename Iterator >
double stddev (Iterator first, Iterator last, double precomputed_mean)
 Standard deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double stddev (Iterator first, Iterator last, Projection proj)
 Standard deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double stddev (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Standard deviation of projected values using precomputed mean.
 
template<typename Iterator >
double coefficient_of_variation (Iterator first, Iterator last)
 Coefficient of variation.
 
template<typename Iterator >
double coefficient_of_variation (Iterator first, Iterator last, double precomputed_mean)
 Coefficient of variation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double coefficient_of_variation (Iterator first, Iterator last, Projection proj)
 Coefficient of variation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double coefficient_of_variation (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Coefficient of variation of projected values using precomputed mean.
 
template<typename Iterator >
double iqr (Iterator first, Iterator last)
 Interquartile range (accepts a sorted range)
 
template<typename Iterator , typename Projection >
double iqr (Iterator first, Iterator last, Projection proj)
 Interquartile range of projected values (projection results must be in sorted order)
 
template<typename Iterator >
double mean_absolute_deviation (Iterator first, Iterator last)
 Mean absolute deviation.
 
template<typename Iterator >
double mean_absolute_deviation (Iterator first, Iterator last, double precomputed_mean)
 Mean absolute deviation using precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double mean_absolute_deviation (Iterator first, Iterator last, Projection proj)
 Mean absolute deviation of projected values using a lambda expression.
 
template<typename Iterator , typename Projection >
double mean_absolute_deviation (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Mean absolute deviation of projected values using precomputed mean.
 
template<typename Iterator , typename WeightIterator >
double weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted variance (reliability weights / analytic weights)
 
template<typename Iterator , typename WeightIterator >
double weighted_variance (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted variance (reliability weights / analytic weights)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted variance (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_variance (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted variance (projection version)
 
template<typename Iterator , typename WeightIterator >
double weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted standard deviation.
 
template<typename Iterator , typename WeightIterator >
double weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted standard deviation.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted standard deviation (projection version)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_stddev (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted standard deviation (projection version)
 
template<typename Iterator >
double geometric_stddev (Iterator first, Iterator last)
 Geometric standard deviation.
 
template<typename Iterator , typename Projection >
double geometric_stddev (Iterator first, Iterator last, Projection proj)
 Geometric standard deviation (projection version)
 
template<typename Iterator1 , typename Iterator2 >
double euclidean_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Euclidean distance (L2 norm)
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double euclidean_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Proj1 proj1, Proj2 proj2)
 Euclidean distance with projection.
 
template<typename Iterator1 , typename Iterator2 >
double manhattan_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Manhattan distance (L1 norm, taxicab distance)
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double manhattan_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Proj1 proj1, Proj2 proj2)
 Manhattan distance with projection.
 
template<typename Iterator1 , typename Iterator2 >
double cosine_similarity (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Cosine similarity.
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double cosine_similarity (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Proj1 proj1, Proj2 proj2)
 Cosine similarity with projection.
 
template<typename Iterator1 , typename Iterator2 >
double cosine_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Cosine distance.
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double cosine_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Proj1 proj1, Proj2 proj2)
 Cosine distance with projection.
 
double mahalanobis_distance (const std::vector< double > &x, const std::vector< double > &mean, const std::vector< std::vector< double > > &cov_matrix)
 Mahalanobis distance.
 
template<typename Iterator1 , typename Iterator2 >
double minkowski_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double p)
 Minkowski distance (generalized Lp distance)
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double minkowski_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double p, Proj1 proj1, Proj2 proj2)
 Minkowski distance with projection.
 
template<typename Iterator1 , typename Iterator2 >
double chebyshev_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Chebyshev distance (L∞ norm, maximum metric)
 
template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double chebyshev_distance (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Proj1 proj1, Proj2 proj2)
 Chebyshev distance with projection.
 
template<typename Iterator >
double cohens_d (Iterator first, Iterator last, double mu0, double sigma)
 Cohen's d (one-sample, known population standard deviation)
 
template<typename Iterator >
double cohens_d (Iterator first, Iterator last, double mu0)
 Cohen's d (one-sample, using sample standard deviation)
 
template<typename Iterator1 , typename Iterator2 >
double cohens_d_two_sample (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Cohen's d (two-sample, pooled standard deviation)
 
double hedges_correction_factor (double df)
 Hedges' bias correction factor J.
 
template<typename Iterator >
double hedges_g (Iterator first, Iterator last, double mu0)
 Hedges' g (one-sample)
 
template<typename Iterator1 , typename Iterator2 >
double hedges_g_two_sample (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 Hedges' g (two-sample)
 
template<typename Iterator1 , typename Iterator2 >
double glass_delta (Iterator1 control_first, Iterator1 control_last, Iterator2 treatment_first, Iterator2 treatment_last)
 Glass's Delta (using control group's standard deviation)
 
double t_to_r (double t, double df)
 Convert t-value to correlation coefficient.
 
double d_to_r (double d)
 Convert Cohen's d to correlation coefficient.
 
double r_to_d (double r)
 Convert correlation coefficient to Cohen's d.
 
double eta_squared (double ss_effect, double ss_total)
 Calculate eta-squared from F-test.
 
double partial_eta_squared (double f, double df1, double df2)
 Calculate partial eta-squared from F-test.
 
double omega_squared (double ss_effect, double ss_total, double ms_error, double df_effect)
 Omega-squared.
 
double cohens_h (double p1, double p2)
 Cohen's h (effect size for difference between two proportions)
 
double odds_ratio (double a, double b, double c, double d)
 Odds ratio.
 
double risk_ratio (double a, double b, double c, double d)
 Relative risk (risk ratio)
 
effect_size_magnitude interpret_cohens_d (double d)
 Interpret Cohen's d.
 
effect_size_magnitude interpret_correlation (double r)
 Interpret correlation coefficient.
 
effect_size_magnitude interpret_eta_squared (double eta2)
 Interpret eta-squared.
 
template<typename Iterator >
double standard_error (Iterator first, Iterator last)
 Calculate standard error of the mean.
 
template<typename Iterator , typename Projection >
double standard_error (Iterator first, Iterator last, Projection proj)
 Calculate standard error of the mean (projection version)
 
template<typename Iterator >
double standard_error (Iterator first, Iterator last, double precomputed_stddev)
 Calculate standard error of the mean (using precomputed standard deviation)
 
template<typename Iterator >
confidence_interval ci_mean (Iterator first, Iterator last, double confidence=0.95)
 Calculate confidence interval for mean (t-distribution based)
 
template<typename Iterator , typename Projection >
confidence_interval ci_mean (Iterator first, Iterator last, double confidence, Projection proj)
 Calculate confidence interval for mean (projection version)
 
template<typename Iterator >
confidence_interval ci_mean_z (Iterator first, Iterator last, double sigma, double confidence=0.95)
 Calculate confidence interval for mean (z-distribution based, known variance)
 
confidence_interval ci_proportion (std::size_t successes, std::size_t trials, double confidence=0.95)
 Calculate confidence interval for proportion (Wald method)
 
confidence_interval ci_proportion_wilson (std::size_t successes, std::size_t trials, double confidence=0.95)
 Calculate confidence interval for proportion (Wilson method, recommended)
 
template<typename Iterator >
confidence_interval ci_variance (Iterator first, Iterator last, double confidence=0.95)
 Calculate confidence interval for variance (chi-square distribution based)
 
template<typename Iterator1 , typename Iterator2 >
confidence_interval ci_mean_diff (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double confidence=0.95)
 Calculate confidence interval for difference of two-sample means (independent samples, pooled variance)
 
template<typename Iterator1 , typename Iterator2 >
confidence_interval ci_mean_diff_welch (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double confidence=0.95)
 Calculate confidence interval for difference of two-sample means (Welch method, not assuming equal variances)
 
template<typename Iterator >
double margin_of_error_mean (Iterator first, Iterator last, double confidence=0.95)
 Calculate margin of error for mean.
 
template<typename Iterator , typename Projection >
double margin_of_error_mean (Iterator first, Iterator last, double confidence, Projection proj)
 Calculate margin of error for mean (projection version)
 
double margin_of_error_proportion (std::size_t successes, std::size_t n, double confidence=0.95)
 Calculate margin of error for proportion.
 
double margin_of_error_proportion_worst_case (std::size_t n, double confidence=0.95)
 Calculate worst-case margin of error for proportion.
 
std::size_t sample_size_for_moe_proportion (double margin_of_error, double confidence_level=0.95, double p_estimate=0.5)
 Calculate sample size for proportion estimation.
 
std::size_t sample_size_for_moe_mean (double margin_of_error, double sigma, double confidence_level=0.95)
 Calculate sample size for mean estimation (known population standard deviation)
 
template<typename Iterator1 , typename Iterator2 >
confidence_interval ci_mean_diff_pooled (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double confidence=0.95)
 Calculate confidence interval for two-sample mean difference (assuming equal variances)
 
confidence_interval ci_proportion_diff (std::size_t successes1, std::size_t n1, std::size_t successes2, std::size_t n2, double confidence=0.95)
 Calculate confidence interval for two-sample proportion difference.
 
template<typename Iterator >
auto frequency_table (Iterator first, Iterator last) -> frequency_table_result< typename std::iterator_traits< Iterator >::value_type >
 Create frequency table (returned with sorted keys)
 
template<typename Iterator , typename Projection >
auto frequency_table (Iterator first, Iterator last, Projection proj) -> frequency_table_result< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type > >
 Frequency table with projection.
 
template<typename Iterator >
auto frequency_count (Iterator first, Iterator last) -> std::unordered_map< typename std::iterator_traits< Iterator >::value_type, std::size_t >
 Return frequency for each value (unordered_map version, fast)
 
template<typename Iterator , typename Projection >
auto frequency_count (Iterator first, Iterator last, Projection proj) -> std::unordered_map< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type >, std::size_t >
 Frequency count with projection.
 
template<typename Iterator >
auto relative_frequency (Iterator first, Iterator last) -> std::unordered_map< typename std::iterator_traits< Iterator >::value_type, double >
 Return relative frequency for each value.
 
template<typename Iterator , typename Projection >
auto relative_frequency (Iterator first, Iterator last, Projection proj) -> std::unordered_map< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type >, double >
 Relative frequency with projection.
 
template<typename Iterator >
auto cumulative_frequency (Iterator first, Iterator last) -> std::vector< std::pair< typename std::iterator_traits< Iterator >::value_type, std::size_t > >
 Return cumulative frequency (for sorted values)
 
template<typename Iterator , typename Projection >
auto cumulative_frequency (Iterator first, Iterator last, Projection proj) -> std::vector< std::pair< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type >, std::size_t > >
 Cumulative frequency with projection.
 
template<typename Iterator >
auto cumulative_relative_frequency (Iterator first, Iterator last) -> std::vector< std::pair< typename std::iterator_traits< Iterator >::value_type, double > >
 Return cumulative relative frequency (for sorted values)
 
template<typename Iterator , typename Projection >
auto cumulative_relative_frequency (Iterator first, Iterator last, Projection proj) -> std::vector< std::pair< std::invoke_result_t< Projection, typename std::iterator_traits< Iterator >::value_type >, double > >
 Cumulative relative frequency with projection.
 
glm_result glm_fit (const std::vector< std::vector< double > > &X, const std::vector< double > &y, distribution_family family=distribution_family::gaussian, link_function link=link_function::identity, std::size_t max_iter=100, double tol=1e-8)
 Fit a generalized linear model.
 
glm_result logistic_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y, std::size_t max_iter=100, double tol=1e-8)
 Logistic regression.
 
double predict_probability (const glm_result &model, const std::vector< double > &x)
 Probability prediction with logistic regression.
 
std::vector< double > odds_ratios (const glm_result &model)
 Calculate odds ratios.
 
std::vector< std::pair< double, double > > odds_ratios_ci (const glm_result &model, double confidence=0.95)
 Confidence intervals for odds ratios.
 
glm_result poisson_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y, std::size_t max_iter=100, double tol=1e-8)
 Poisson regression.
 
double predict_count (const glm_result &model, const std::vector< double > &x)
 Expected count prediction with Poisson regression.
 
std::vector< double > incidence_rate_ratios (const glm_result &model)
 Calculate Incidence Rate Ratios.
 
glm_residuals compute_glm_residuals (const glm_result &model, const std::vector< std::vector< double > > &X, const std::vector< double > &y)
 Calculate GLM residuals.
 
double overdispersion_test (const glm_result &model, const std::vector< std::vector< double > > &X, const std::vector< double > &y)
 Overdispersion test (for Poisson regression)
 
double pseudo_r_squared_mcfadden (const glm_result &model)
 McFadden's pseudo R-squared.
 
double pseudo_r_squared_nagelkerke (const glm_result &model, const std::vector< double > &y, std::size_t n)
 Nagelkerke's pseudo R-squared.
 
template<typename IteratorX , typename IteratorY >
simple_regression_result simple_linear_regression (IteratorX x_first, IteratorX x_last, IteratorY y_first, IteratorY y_last)
 Perform simple linear regression.
 
multiple_regression_result multiple_linear_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y)
 Perform multiple linear regression.
 
double predict (const simple_regression_result &model, double x)
 Make prediction using simple regression model.
 
double predict (const multiple_regression_result &model, const std::vector< double > &x)
 Make prediction using multiple regression model.
 
template<typename IteratorX >
prediction_interval prediction_interval_simple (const simple_regression_result &model, IteratorX x_first, IteratorX x_last, double x_new, double confidence=0.95)
 Calculate prediction interval for simple regression model.
 
template<typename IteratorX >
prediction_interval confidence_interval_mean (const simple_regression_result &model, IteratorX x_first, IteratorX x_last, double x_new, double confidence=0.95)
 Calculate confidence interval for mean of simple regression model.
 
template<typename IteratorX , typename IteratorY >
residual_diagnostics compute_residual_diagnostics (const simple_regression_result &model, IteratorX x_first, IteratorX x_last, IteratorY y_first, IteratorY y_last)
 Perform residual diagnostics for simple regression model.
 
residual_diagnostics compute_residual_diagnostics (const multiple_regression_result &model, const std::vector< std::vector< double > > &X, const std::vector< double > &y)
 Perform residual diagnostics for multiple regression model.
 
std::vector< double > compute_vif (const std::vector< std::vector< double > > &X)
 Calculate VIF (Variance Inflation Factor) for each predictor.
 
double correlation_matrix_determinant (const std::vector< std::vector< double > > &X)
 Calculate determinant of correlation matrix.
 
double multicollinearity_score (const std::vector< std::vector< double > > &X)
 Calculate multicollinearity score.
 
template<typename IteratorY , typename IteratorPred >
double r_squared (IteratorY y_first, IteratorY y_last, IteratorPred pred_first, IteratorPred pred_last)
 Calculate coefficient of determination from observed and predicted values.
 
template<typename IteratorY , typename IteratorPred >
double adjusted_r_squared (IteratorY y_first, IteratorY y_last, IteratorPred pred_first, IteratorPred pred_last, std::size_t num_predictors)
 Calculate adjusted coefficient of determination.
 
missing_pattern_info analyze_missing_patterns (const std::vector< std::vector< double > > &data)
 Analyze missing patterns.
 
std::vector< std::vector< double > > create_missing_indicator (const std::vector< std::vector< double > > &data)
 Create missing indicator variables.
 
mcar_test_result test_mcar_simple (const std::vector< std::vector< double > > &data)
 Little's MCAR test (simplified version)
 
missing_mechanism diagnose_missing_mechanism (const std::vector< std::vector< double > > &data)
 Simple diagnosis of missing mechanism.
 
std::vector< double > impute_conditional_mean (const std::vector< std::vector< double > > &data, std::size_t target_col, const std::vector< std::size_t > &predictor_cols)
 Single imputation by conditional mean.
 
multiple_imputation_result multiple_imputation_pmm (const std::vector< std::vector< double > > &data, std::size_t m=5, unsigned int seed=0)
 Multiple imputation (PMM: Predictive Mean Matching)
 
multiple_imputation_result multiple_imputation_bootstrap (const std::vector< std::vector< double > > &data, std::size_t m=5, unsigned int seed=0)
 Multiple imputation (simplified Bootstrap EM method)
 
sensitivity_analysis_result sensitivity_analysis_pattern_mixture (const std::vector< double > &data, const std::vector< double > &delta_values)
 Sensitivity analysis using pattern mixture model.
 
sensitivity_analysis_result sensitivity_analysis_selection_model (const std::vector< double > &data, const std::vector< double > &phi_values)
 Sensitivity analysis using selection model.
 
tipping_point_result find_tipping_point (const std::vector< double > &data, double threshold=0.0, double delta_min=-5.0, double delta_max=5.0, std::size_t n_points=100)
 Tipping point analysis.
 
complete_case_result extract_complete_cases (const std::vector< std::vector< double > > &data)
 Extract complete cases.
 
std::vector< std::vector< double > > correlation_matrix_pairwise (const std::vector< std::vector< double > > &data)
 Correlation matrix using available case analysis (pairwise deletion)
 
double aic (double log_likelihood, std::size_t k)
 Calculate AIC (Akaike Information Criterion)
 
double aic_linear (const simple_regression_result &model, std::size_t n)
 Calculate AIC from simple regression model.
 
double aic_linear (const multiple_regression_result &model, std::size_t n)
 Calculate AIC from multiple regression model.
 
double aicc (double log_likelihood, std::size_t n, std::size_t k)
 Calculate AICc (corrected AIC)
 
double bic (double log_likelihood, std::size_t n, std::size_t k)
 Calculate BIC (Bayesian Information Criterion)
 
double bic_linear (const simple_regression_result &model, std::size_t n)
 Calculate BIC from simple regression model.
 
double bic_linear (const multiple_regression_result &model, std::size_t n)
 Calculate BIC from multiple regression model.
 
template<typename IteratorX , typename IteratorY >
double press_statistic (IteratorX x_first, IteratorX x_last, IteratorY y_first, IteratorY y_last, const simple_regression_result &model)
 Calculate PRESS statistic.
 
std::vector< std::vector< std::size_t > > create_cv_folds (std::size_t n, std::size_t k, bool shuffle=true)
 Generate indices for k-fold cross-validation.
 
cv_result cross_validate_linear (const std::vector< std::vector< double > > &X, const std::vector< double > &y, std::size_t k=5)
 Perform k-fold cross-validation for multiple regression model.
 
cv_result loocv_linear (const std::vector< std::vector< double > > &X, const std::vector< double > &y)
 Perform leave-one-out cross-validation.
 
regularized_regression_result ridge_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y, double lambda, bool standardize=true, std::size_t max_iter=1000, double tol=1e-6)
 Perform Ridge regression (L2 regularization)
 
regularized_regression_result lasso_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y, double lambda, bool standardize=true, std::size_t max_iter=1000, double tol=1e-6)
 Perform Lasso regression (L1 regularization)
 
regularized_regression_result elastic_net_regression (const std::vector< std::vector< double > > &X, const std::vector< double > &y, double lambda, double alpha=0.5, bool standardize=true, std::size_t max_iter=1000, double tol=1e-6)
 Perform Elastic Net regression (L1 + L2 regularization)
 
std::pair< double, std::vector< double > > cv_ridge (const std::vector< std::vector< double > > &X, const std::vector< double > &y, const std::vector< double > &lambda_grid, std::size_t k=5)
 Select optimal lambda for Ridge regression using cross-validation.
 
std::pair< double, std::vector< double > > cv_lasso (const std::vector< std::vector< double > > &X, const std::vector< double > &y, const std::vector< double > &lambda_grid, std::size_t k=5)
 Select optimal lambda for Lasso regression using cross-validation.
 
std::vector< double > generate_lambda_grid (const std::vector< std::vector< double > > &X, const std::vector< double > &y, std::size_t n_lambda=100, double lambda_min_ratio=0.0001)
 Automatically generate lambda grid for regularized regression.
 
std::vector< std::vector< double > > covariance_matrix (const std::vector< std::vector< double > > &data)
 Calculate sample covariance matrix.
 
std::vector< std::vector< double > > correlation_matrix (const std::vector< std::vector< double > > &data)
 Calculate Pearson correlation matrix.
 
std::vector< std::vector< double > > standardize (const std::vector< std::vector< double > > &data)
 Z-score standardization.
 
std::vector< std::vector< double > > min_max_scale (const std::vector< std::vector< double > > &data)
 Min-Max normalization (0-1 scaling)
 
std::pair< double, std::vector< double > > power_iteration (const std::vector< std::vector< double > > &matrix, std::size_t max_iter=1000, double tol=1e-10)
 Find largest eigenvalue and eigenvector using power iteration.
 
pca_result pca (const std::vector< std::vector< double > > &data, std::size_t n_components)
 Principal Component Analysis.
 
std::vector< std::vector< double > > pca_transform (const std::vector< std::vector< double > > &data, const pca_result &pca)
 Project data onto principal component space.
 
template<typename Iterator >
std::vector< double > compute_ranks_with_ties (Iterator first, Iterator last)
 Compute ranks with tie handling.
 
std::vector< std::size_t > compute_tie_groups (const std::vector< double > &sorted_values)
 Compute tie group sizes from sorted data.
 
template<typename Iterator >
test_result shapiro_wilk_test (Iterator first, Iterator last)
 Perform Shapiro-Wilk test.
 
template<typename Iterator >
test_result lilliefors_test (Iterator first, Iterator last)
 Perform Lilliefors test for normality.
 
template<typename Iterator >
test_result ks_test_normal (Iterator first, Iterator last)
 Perform Kolmogorov-Smirnov test for normality (deprecated)
 
test_result levene_test (const std::vector< std::vector< double > > &groups)
 Perform Levene test (homogeneity of variance test)
 
test_result bartlett_test (const std::vector< std::vector< double > > &groups)
 Perform Bartlett test (homogeneity of variance test)
 
template<typename Iterator >
test_result wilcoxon_signed_rank_test (Iterator first, Iterator last, double mu0=0.0, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Perform Wilcoxon signed-rank test (one-sample)
 
template<typename Iterator1 , typename Iterator2 >
test_result mann_whitney_u_test (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, alternative_hypothesis alt=alternative_hypothesis::two_sided, bool correct=true)
 Perform Mann-Whitney U test (two-sample)
 
test_result kruskal_wallis_test (const std::vector< std::vector< double > > &groups)
 Perform Kruskal-Wallis test (k-sample)
 
test_result fisher_exact_test (std::uint64_t a, std::uint64_t b, std::uint64_t c, std::uint64_t d, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Perform Fisher's exact test (2x2 contingency table)
 
bool approx_equal (double a, double b, double rel_tol=default_rel_tol, double abs_tol=default_abs_tol)
 Check if two floating-point numbers are approximately equal.
 
bool is_zero (double x, double tol=default_abs_tol)
 Check if a value is close to zero.
 
bool is_finite (double x)
 Check if a value is finite (not infinity or NaN)
 
template<typename Iterator >
bool all_finite (Iterator first, Iterator last)
 Check if all values in a range are finite.
 
bool has_converged_abs (double x_new, double x_old, double tol=1e-6)
 Check for convergence based on absolute change.
 
bool has_converged_rel (double x_new, double x_old, double tol=1e-6)
 Check for convergence based on relative change.
 
bool has_converged (double x_new, double x_old, double abs_tol=1e-8, double rel_tol=1e-6)
 Check for convergence using combined absolute and relative criteria.
 
double log1p_safe (double x)
 Safely compute log(1 + x) for small x.
 
double expm1_safe (double x)
 Safely compute exp(x) - 1 for small x.
 
double clamp (double x, double min_val, double max_val)
 Clamp a value to a range [min_val, max_val].
 
bool in_range (double x, double min_val, double max_val)
 Check if a value is in range [min_val, max_val].
 
double relative_error (double x, double x_ref)
 Compute the relative error between two values.
 
double safe_divide (double numerator, double denominator, double default_value=std::numeric_limits< double >::quiet_NaN())
 Safe division with check for division by zero.
 
template<typename Iterator >
double kahan_sum (Iterator first, Iterator last)
 Compute sum with Kahan summation algorithm.
 
template<typename Iterator , typename Proj >
double kahan_sum (Iterator first, Iterator last, Proj proj)
 Compute sum with Kahan summation algorithm (with projection)
 
template<typename Iterator1 , typename Iterator2 >
bool approx_equal_range (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double rel_tol=default_rel_tol, double abs_tol=default_abs_tol)
 Check if two ranges are approximately equal element-wise.
 
template<typename Iterator >
double interpolate_at (Iterator first, std::size_t n, double p)
 Linear interpolation at position.
 
template<typename Iterator , typename Projection >
double interpolate_at (Iterator first, std::size_t n, double p, Projection proj)
 Linear interpolation at position with projection.
 
template<typename Iterator >
auto minimum (Iterator first, Iterator last)
 Return minimum value.
 
template<typename Iterator , typename Projection >
auto minimum (Iterator first, Iterator last, Projection proj)
 Return minimum value with projection.
 
template<typename Iterator >
auto maximum (Iterator first, Iterator last)
 Return maximum value.
 
template<typename Iterator , typename Projection >
auto maximum (Iterator first, Iterator last, Projection proj)
 Return maximum value with projection.
 
template<typename Iterator >
quartile_result quartiles (Iterator first, Iterator last)
 Return quartiles.
 
template<typename Iterator , typename Projection >
quartile_result quartiles (Iterator first, Iterator last, Projection proj)
 Return quartiles with projection.
 
template<typename Iterator >
double percentile (Iterator first, Iterator last, double p)
 Return percentile.
 
template<typename Iterator , typename Projection >
double percentile (Iterator first, Iterator last, double p, Projection proj)
 Return percentile with projection.
 
template<typename Iterator >
five_number_summary_result five_number_summary (Iterator first, Iterator last)
 Return five-number summary.
 
template<typename Iterator , typename Projection >
five_number_summary_result five_number_summary (Iterator first, Iterator last, Projection proj)
 Return five-number summary with projection.
 
template<typename Iterator , typename WeightIterator >
double weighted_median (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last)
 Weighted median (safe overload)
 
template<typename Iterator , typename WeightIterator >
double weighted_median (Iterator first, Iterator last, WeightIterator weight_first)
 Weighted median.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_median (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, Projection proj)
 Weighted median with projection (safe overload)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_median (Iterator first, Iterator last, WeightIterator weight_first, Projection proj)
 Weighted median with projection.
 
template<typename Iterator , typename WeightIterator >
double weighted_percentile (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, double p)
 Weighted percentile (safe overload)
 
template<typename Iterator , typename WeightIterator >
double weighted_percentile (Iterator first, Iterator last, WeightIterator weight_first, double p)
 Weighted percentile.
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_percentile (Iterator first, Iterator last, WeightIterator weight_first, WeightIterator weight_last, double p, Projection proj)
 Weighted percentile with projection (safe overload)
 
template<typename Iterator , typename WeightIterator , typename Projection >
double weighted_percentile (Iterator first, Iterator last, WeightIterator weight_first, double p, Projection proj)
 Weighted percentile with projection.
 
template<typename Iterator >
test_result z_test (Iterator first, Iterator last, double mu0, double sigma, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 One-sample z-test (known variance)
 
test_result z_test_proportion (std::size_t successes, std::size_t trials, double p0, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 One-sample proportion z-test.
 
test_result z_test_proportion_two_sample (std::size_t successes1, std::size_t trials1, std::size_t successes2, std::size_t trials2, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Two-sample proportion z-test.
 
template<typename Iterator >
test_result t_test (Iterator first, Iterator last, double mu0, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 One-sample t-test.
 
template<typename Iterator1 , typename Iterator2 >
test_result t_test_two_sample (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Two-sample t-test (independent samples, pooled variance)
 
template<typename Iterator1 , typename Iterator2 >
test_result t_test_welch (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Two-sample t-test (Welch's method)
 
template<typename Iterator1 , typename Iterator2 >
test_result t_test_paired (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 Paired t-test.
 
template<typename Iterator1 , typename Iterator2 >
test_result chisq_test_gof (Iterator1 observed_first, Iterator1 observed_last, Iterator2 expected_first, Iterator2 expected_last)
 Chi-square goodness of fit test.
 
template<typename Iterator >
test_result chisq_test_gof_uniform (Iterator observed_first, Iterator observed_last)
 Chi-square goodness of fit test (uniform expected frequencies)
 
test_result chisq_test_independence (const std::vector< std::vector< double > > &contingency_table)
 Chi-square test for independence.
 
template<typename Iterator1 , typename Iterator2 >
test_result f_test (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, alternative_hypothesis alt=alternative_hypothesis::two_sided)
 F-test (variance comparison)
 
std::vector< double > bonferroni_correction (const std::vector< double > &p_values)
 Bonferroni correction.
 
std::vector< double > benjamini_hochberg_correction (const std::vector< double > &p_values)
 Benjamini-Hochberg correction (FDR control)
 
std::vector< double > holm_correction (const std::vector< double > &p_values)
 Holm correction (step-down Bonferroni method)
 
double power_t_test_one_sample (double effect_size, std::size_t n, double alpha=0.05, const std::string &alternative="two.sided")
 Calculate power for one-sample t-test.
 
std::size_t sample_size_t_test_one_sample (double effect_size, double power=0.80, double alpha=0.05, const std::string &alternative="two.sided")
 Calculate required sample size for one-sample t-test.
 
double power_t_test_two_sample (double effect_size, std::size_t n1, std::size_t n2, double alpha=0.05, const std::string &alternative="two.sided")
 Calculate power for two-sample t-test.
 
std::size_t sample_size_t_test_two_sample (double effect_size, double power=0.80, double alpha=0.05, double ratio=1.0, const std::string &alternative="two.sided")
 Calculate required sample size for two-sample t-test (per group)
 
double power_prop_test (double p1, double p2, std::size_t n, double alpha=0.05, const std::string &alternative="two.sided")
 Calculate power for two-sample proportion test.
 
std::size_t sample_size_prop_test (double p1, double p2, double power=0.80, double alpha=0.05, const std::string &alternative="two.sided")
 Calculate required sample size for two-sample proportion test.
 
power_result power_analysis_t_one_sample (double effect_size, std::size_t n, double alpha=0.05, const std::string &alternative="two.sided")
 Power analysis for one-sample t-test (calculate power)
 
power_result power_analysis_t_one_sample_n (double effect_size, double power=0.80, double alpha=0.05, const std::string &alternative="two.sided")
 Power analysis for one-sample t-test (calculate sample size)
 
double power_t_test_one_sample (double effect_size, std::size_t n, double alpha, alternative_hypothesis alt)
 Calculate power for one-sample t-test (enum overload)
 
std::size_t sample_size_t_test_one_sample (double effect_size, double power, double alpha, alternative_hypothesis alt)
 Calculate required sample size for one-sample t-test (enum overload)
 
double power_t_test_two_sample (double effect_size, std::size_t n1, std::size_t n2, double alpha, alternative_hypothesis alt)
 Calculate power for two-sample t-test (enum overload)
 
std::size_t sample_size_t_test_two_sample (double effect_size, double power, double alpha, double ratio, alternative_hypothesis alt)
 Calculate required sample size for two-sample t-test (enum overload)
 
double power_prop_test (double p1, double p2, std::size_t n, double alpha, alternative_hypothesis alt)
 Calculate power for two-sample proportion test (enum overload)
 
std::size_t sample_size_prop_test (double p1, double p2, double power, double alpha, alternative_hypothesis alt)
 Calculate required sample size for two-sample proportion test (enum overload)
 
power_result power_analysis_t_one_sample (double effect_size, std::size_t n, double alpha, alternative_hypothesis alt)
 Power analysis for one-sample t-test (enum overload, returning struct)
 
power_result power_analysis_t_one_sample_n (double effect_size, double power, double alpha, alternative_hypothesis alt)
 Power analysis for one-sample t-test, sample size (enum overload, returning struct)
 
default_random_engineget_random_engine ()
 Singleton accessor for global random engine.
 
void set_seed (std::uint64_t seed)
 Set the seed of the random engine.
 
void randomize_seed ()
 Randomly reset the random engine seed.
 
template<typename Iterator , typename Engine = default_random_engine>
std::vector< typename std::iterator_traits< Iterator >::value_type > bootstrap_sample (Iterator first, Iterator last, Engine &engine)
 Generate a single bootstrap sample.
 
template<typename Iterator >
std::vector< typename std::iterator_traits< Iterator >::value_type > bootstrap_sample (Iterator first, Iterator last)
 Generate a single bootstrap sample (using default random engine)
 
template<typename Iterator , typename Statistic , typename Engine = default_random_engine>
bootstrap_result bootstrap (Iterator first, Iterator last, Statistic stat_func, std::size_t n_bootstrap=1000, double confidence=0.95, Engine &engine=get_random_engine())
 Perform general bootstrap estimation.
 
template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result bootstrap_mean (Iterator first, Iterator last, std::size_t n_bootstrap=1000, double confidence=0.95, Engine &engine=get_random_engine())
 Perform bootstrap estimation of the mean.
 
template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result bootstrap_median (Iterator first, Iterator last, std::size_t n_bootstrap=1000, double confidence=0.95, Engine &engine=get_random_engine())
 Perform bootstrap estimation of the median.
 
template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result bootstrap_stddev (Iterator first, Iterator last, std::size_t n_bootstrap=1000, double confidence=0.95, Engine &engine=get_random_engine())
 Perform bootstrap estimation of the standard deviation.
 
template<typename Iterator , typename Statistic , typename Engine = default_random_engine>
bootstrap_result bootstrap_bca (Iterator first, Iterator last, Statistic stat_func, std::size_t n_bootstrap=1000, double confidence=0.95, Engine &engine=get_random_engine())
 Compute BCa (bias-corrected and accelerated) bootstrap confidence interval.
 
template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result permutation_test_two_sample (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, std::size_t n_permutations=10000, Engine &engine=get_random_engine())
 Perform two-sample permutation test (test of difference in means)
 
template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result permutation_test_paired (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, std::size_t n_permutations=10000, Engine &engine=get_random_engine())
 Perform paired permutation test.
 
template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result permutation_test_correlation (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, std::size_t n_permutations=10000, Engine &engine=get_random_engine())
 Perform permutation test for correlation.
 
template<typename Iterator >
double mad (Iterator first, Iterator last)
 Median Absolute Deviation (MAD)
 
template<typename Iterator >
double mad_scaled (Iterator first, Iterator last)
 Scaled MAD for normal distribution.
 
template<typename Iterator >
outlier_detection_result detect_outliers_iqr (Iterator first, Iterator last, double k=1.5)
 Outlier detection using IQR method (Tukey's Fences)
 
template<typename Iterator >
outlier_detection_result detect_outliers_zscore (Iterator first, Iterator last, double threshold=3.0)
 Outlier detection using Z-score.
 
template<typename Iterator >
outlier_detection_result detect_outliers_modified_zscore (Iterator first, Iterator last, double threshold=3.5)
 Outlier detection using Modified Z-score.
 
template<typename Iterator >
std::vector< double > winsorize (Iterator first, Iterator last, double limits=0.05)
 Winsorization.
 
std::vector< double > cooks_distance (const std::vector< double > &residuals, const std::vector< double > &hat_values, double mse, std::size_t p)
 Calculate Cook's Distance.
 
std::vector< double > dffits (const std::vector< double > &residuals, const std::vector< double > &hat_values, double mse)
 Calculate DFFITS.
 
template<typename Iterator >
double hodges_lehmann (Iterator first, Iterator last)
 Hodges-Lehmann estimator.
 
template<typename Iterator >
double biweight_midvariance (Iterator first, Iterator last, double c=9.0)
 Biweight Midvariance.
 
template<typename Iterator >
double population_skewness (Iterator first, Iterator last)
 Calculate population skewness (Fisher's definition)
 
template<typename Iterator >
double population_skewness (Iterator first, Iterator last, double precomputed_mean)
 Calculate population skewness with precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double population_skewness (Iterator first, Iterator last, Projection proj)
 Calculate population skewness with projection.
 
template<typename Iterator , typename Projection >
double population_skewness (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate population skewness with projection and precomputed mean.
 
template<typename Iterator >
double sample_skewness (Iterator first, Iterator last)
 Calculate sample skewness (bias-corrected version)
 
template<typename Iterator >
double sample_skewness (Iterator first, Iterator last, double precomputed_mean)
 Calculate sample skewness with precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double sample_skewness (Iterator first, Iterator last, Projection proj)
 Calculate sample skewness with projection.
 
template<typename Iterator , typename Projection >
double sample_skewness (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate sample skewness with projection and precomputed mean.
 
template<typename Iterator >
double skewness (Iterator first, Iterator last)
 Calculate skewness (alias for sample_skewness)
 
template<typename Iterator >
double skewness (Iterator first, Iterator last, double precomputed_mean)
 Calculate skewness (precomputed mean version)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double skewness (Iterator first, Iterator last, Projection proj)
 Calculate skewness (projection version)
 
template<typename Iterator , typename Projection >
double skewness (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate skewness (projection version, precomputed mean)
 
template<typename Iterator >
double population_kurtosis (Iterator first, Iterator last)
 Calculate population kurtosis (Excess Kurtosis)
 
template<typename Iterator >
double population_kurtosis (Iterator first, Iterator last, double precomputed_mean)
 Calculate population kurtosis with precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double population_kurtosis (Iterator first, Iterator last, Projection proj)
 Calculate population kurtosis with projection.
 
template<typename Iterator , typename Projection >
double population_kurtosis (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate population kurtosis with projection and precomputed mean.
 
template<typename Iterator >
double sample_kurtosis (Iterator first, Iterator last)
 Calculate sample kurtosis (bias-corrected version)
 
template<typename Iterator >
double sample_kurtosis (Iterator first, Iterator last, double precomputed_mean)
 Calculate sample kurtosis with precomputed mean.
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double sample_kurtosis (Iterator first, Iterator last, Projection proj)
 Calculate sample kurtosis with projection.
 
template<typename Iterator , typename Projection >
double sample_kurtosis (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate sample kurtosis with projection and precomputed mean.
 
template<typename Iterator >
double kurtosis (Iterator first, Iterator last)
 Calculate kurtosis (alias for sample_kurtosis)
 
template<typename Iterator >
double kurtosis (Iterator first, Iterator last, double precomputed_mean)
 Calculate kurtosis (precomputed mean version)
 
template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double kurtosis (Iterator first, Iterator last, Projection proj)
 Calculate kurtosis (projection version)
 
template<typename Iterator , typename Projection >
double kurtosis (Iterator first, Iterator last, Projection proj, double precomputed_mean)
 Calculate kurtosis (projection version, precomputed mean)
 
double lgamma_impl (double x)
 Internal log-gamma function implementation.
 
double lgamma (double x)
 Log-gamma function.
 
double tgamma (double x)
 Gamma function.
 
double beta (double a, double b)
 Beta function.
 
double lbeta (double a, double b)
 Log-beta function.
 
double betainc_impl (double a, double b, double x, int recursion_depth)
 Internal regularized incomplete beta function.
 
double betainc (double a, double b, double x)
 Regularized incomplete beta function.
 
double betaincinv (double a, double b, double p)
 Inverse regularized incomplete beta function.
 
double erf (double x)
 Error function.
 
double erfc (double x)
 Complementary error function.
 
double norm_cdf (double x)
 Standard normal CDF.
 
double norm_quantile (double p)
 Standard normal quantile function.
 
double gammainc_lower (double a, double x)
 Lower regularized incomplete gamma function.
 
double gammainc_upper (double a, double x)
 Upper regularized incomplete gamma function.
 
double gammainc_lower_inv (double a, double p)
 Inverse lower regularized incomplete gamma function.
 
kaplan_meier_result kaplan_meier (const std::vector< double > &times, const std::vector< bool > &events)
 Estimate Kaplan-Meier survival curve.
 
logrank_result logrank_test (const std::vector< double > &times1, const std::vector< bool > &events1, const std::vector< double > &times2, const std::vector< bool > &events2)
 Log-rank test (comparison of two survival curves)
 
double median_survival_time (const kaplan_meier_result &km)
 Calculate median survival time.
 
hazard_rate_result nelson_aalen (const std::vector< double > &times, const std::vector< bool > &events)
 Nelson-Aalen cumulative hazard estimation.
 
template<typename Iterator >
double autocorrelation (Iterator first, Iterator last, std::size_t lag)
 Calculate autocorrelation coefficient (lag k)
 
template<typename Iterator >
std::vector< double > acf (Iterator first, Iterator last, std::size_t max_lag)
 Calculate autocorrelation function (ACF) (from lag 0 to max_lag)
 
template<typename Iterator >
std::vector< double > pacf (Iterator first, Iterator last, std::size_t max_lag)
 Calculate partial autocorrelation function (PACF) (Durbin-Levinson algorithm)
 
template<typename Iterator1 , typename Iterator2 >
double mae (Iterator1 first1, Iterator1 last1, Iterator2 first2)
 Mean Absolute Error (MAE)
 
template<typename Iterator1 , typename Iterator2 >
double mse (Iterator1 first1, Iterator1 last1, Iterator2 first2)
 Mean Squared Error (MSE)
 
template<typename Iterator1 , typename Iterator2 >
double rmse (Iterator1 first1, Iterator1 last1, Iterator2 first2)
 Root Mean Squared Error (RMSE)
 
template<typename Iterator1 , typename Iterator2 >
double mape (Iterator1 first1, Iterator1 last1, Iterator2 first2)
 Mean Absolute Percentage Error (MAPE)
 
template<typename Iterator >
std::vector< double > moving_average (Iterator first, Iterator last, std::size_t window)
 Simple moving average.
 
template<typename Iterator >
std::vector< double > exponential_moving_average (Iterator first, Iterator last, double alpha)
 Exponential moving average.
 
template<typename Iterator >
std::vector< double > diff (Iterator first, Iterator last, std::size_t order=1)
 Difference series (first-order or d-th order differencing)
 
template<typename Iterator >
std::vector< double > seasonal_diff (Iterator first, Iterator last, std::size_t period)
 Seasonal differencing.
 
template<typename Iterator >
std::vector< double > lag (Iterator first, Iterator last, std::size_t k)
 Generate lag series.
 

Variables

constexpr double NA = std::numeric_limits<double>::quiet_NaN()
 Constant representing NA (NaN)
 
constexpr double epsilon = std::numeric_limits<double>::epsilon()
 Machine epsilon for double precision.
 
constexpr double default_rel_tol = 1e-9
 Default relative tolerance for floating-point comparisons.
 
constexpr double default_abs_tol = 1e-12
 Default absolute tolerance for floating-point comparisons.
 
template<typename T >
constexpr bool is_random_engine_v = is_random_engine<T>::value
 Variable template version of is_random_engine.
 
constexpr double pi = 3.14159265358979323846
 Pi constant.
 
constexpr double sqrt_2 = 1.41421356237309504880
 Square root of 2.
 
constexpr double sqrt_2_pi = 2.50662827463100050242
 Square root of 2*pi.
 
constexpr double log_sqrt_2_pi = 0.91893853320467274178
 Natural logarithm of sqrt(2*pi)
 

Typedef Documentation

◆ default_random_engine

using statcpp::default_random_engine = typedef std::mt19937_64

Default random engine type (Mersenne Twister 64-bit version)

Definition at line 21 of file random_engine.hpp.

Enumeration Type Documentation

◆ alternative_hypothesis

Enumeration representing the type of alternative hypothesis.

Specifies the direction of the alternative hypothesis in statistical tests.

Enumerator
two_sided 

Two-sided test.

less 

One-sided test (less than)

greater 

One-sided test (greater than)

Definition at line 34 of file parametric_tests.hpp.

◆ distribution_family

enum class statcpp::distribution_family
strong

Distribution family.

Specifies the probability distribution family to use in generalized linear models.

Enumerator
gaussian 

Gaussian (normal) distribution.

binomial 

Binomial distribution.

poisson 

Poisson distribution.

gamma_family 

Gamma distribution (gamma_family because gamma is a reserved word)

Definition at line 49 of file glm.hpp.

◆ effect_size_magnitude

enum class statcpp::effect_size_magnitude
strong

Enumeration for effect size magnitude.

Enumerator
negligible 

Negligible.

small 

Small.

medium 

Medium.

large 

Large.

Definition at line 426 of file effect_size.hpp.

◆ link_function

enum class statcpp::link_function
strong

Link function types.

Specifies the link function to use in generalized linear models.

Enumerator
identity 

Identity link (linear regression)

logit 

Logit link (logistic regression)

probit 

Probit link.

log 

Log link (Poisson regression)

inverse 

Inverse link (Gamma regression)

cloglog 

Complementary log-log link.

Definition at line 35 of file glm.hpp.

◆ linkage_type

enum class statcpp::linkage_type
strong

Linkage types.

Enumerator
single 

Single linkage.

complete 

Complete linkage.

average 

Average linkage.

ward 

Ward's method.

Definition at line 273 of file clustering.hpp.

◆ missing_mechanism

enum class statcpp::missing_mechanism
strong

Missing mechanism types.

Enumeration for classifying the mechanism of missing data.

  • MCAR: Missing occurs completely at random
  • MAR: Missing depends on observed variables
  • MNAR: Missing depends on the missing value itself
Enumerator
mcar 

Missing Completely At Random.

mar 

Missing At Random.

mnar 

Missing Not At Random.

unknown 

Cannot be determined.

Definition at line 46 of file missing_data.hpp.

Function Documentation

◆ acf()

template<typename Iterator >
std::vector< double > statcpp::acf ( Iterator  first,
Iterator  last,
std::size_t  max_lag 
)

Calculate autocorrelation function (ACF) (from lag 0 to max_lag)

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
max_lagMaximum lag
Returns
Vector of autocorrelation coefficients
Exceptions
std::invalid_argumentIf range is empty

Definition at line 97 of file time_series.hpp.

◆ adjusted_r_squared()

template<typename IteratorY , typename IteratorPred >
double statcpp::adjusted_r_squared ( IteratorY  y_first,
IteratorY  y_last,
IteratorPred  pred_first,
IteratorPred  pred_last,
std::size_t  num_predictors 
)

Calculate adjusted coefficient of determination.

Coefficient of determination adjusted for overfitting due to number of predictors. Adjusted R^2 = 1 - (1 - R^2) * (n - 1) / (n - p - 1)

Template Parameters
IteratorYIterator type for observed values
IteratorPredIterator type for predicted values
Parameters
y_firstBeginning iterator for observed values
y_lastEnding iterator for observed values
pred_firstBeginning iterator for predicted values
pred_lastEnding iterator for predicted values
num_predictorsNumber of predictors (excluding intercept)
Returns
double Adjusted coefficient of determination
Exceptions
std::invalid_argumentIf y and predictions have different lengths
std::invalid_argumentIf number of observations is not greater than number of predictors + 1

Definition at line 1177 of file linear_regression.hpp.

◆ aic()

double statcpp::aic ( double  log_likelihood,
std::size_t  k 
)
inline

Calculate AIC (Akaike Information Criterion)

Calculates the Akaike Information Criterion. Smaller values indicate better models.

Parameters
log_likelihoodLog-likelihood
kNumber of parameters
Returns
AIC value

Definition at line 41 of file model_selection.hpp.

◆ aic_linear() [1/2]

double statcpp::aic_linear ( const multiple_regression_result model,
std::size_t  n 
)
inline

Calculate AIC from multiple regression model.

Calculates log-likelihood from multiple regression result and computes AIC.

Parameters
modelMultiple regression result
nSample size
Returns
AIC value

Definition at line 76 of file model_selection.hpp.

◆ aic_linear() [2/2]

double statcpp::aic_linear ( const simple_regression_result model,
std::size_t  n 
)
inline

Calculate AIC from simple regression model.

Calculates log-likelihood from simple regression result and computes AIC.

Parameters
modelSimple regression result
nSample size
Returns
AIC value

Definition at line 55 of file model_selection.hpp.

◆ aicc()

double statcpp::aicc ( double  log_likelihood,
std::size_t  n,
std::size_t  k 
)
inline

Calculate AICc (corrected AIC)

Calculates the corrected AIC for small samples. Used when sample size is small relative to number of parameters.

Parameters
log_likelihoodLog-likelihood
nSample size
kNumber of parameters
Returns
AICc value
Exceptions
std::invalid_argumentIf n <= k + 1

Definition at line 99 of file model_selection.hpp.

◆ all_finite()

template<typename Iterator >
bool statcpp::all_finite ( Iterator  first,
Iterator  last 
)

Check if all values in a range are finite.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning of sequence
lastEnd of sequence
Returns
true if all values are finite

Definition at line 102 of file numerical_utils.hpp.

◆ analyze_missing_patterns()

missing_pattern_info statcpp::analyze_missing_patterns ( const std::vector< std::vector< double > > &  data)
inline

Analyze missing patterns.

Analyzes missing patterns in a dataset, calculating missing rate per variable, overall missing rate, and types and frequencies of missing patterns.

Parameters
data2D data for analysis (rows: observations, columns: variables)
Returns
missing_pattern_info Missing pattern information
Exceptions
std::invalid_argumentIf data is empty or row sizes are inconsistent

Definition at line 92 of file missing_data.hpp.

◆ approx_equal()

bool statcpp::approx_equal ( double  a,
double  b,
double  rel_tol = default_rel_tol,
double  abs_tol = default_abs_tol 
)
inline

Check if two floating-point numbers are approximately equal.

Uses both relative and absolute tolerance: |a - b| <= max(rel_tol * max(|a|, |b|), abs_tol)

Parameters
aFirst value
bSecond value
rel_tolRelative tolerance (default: 1e-9)
abs_tolAbsolute tolerance (default: 1e-12)
Returns
true if values are approximately equal

Definition at line 43 of file numerical_utils.hpp.

◆ approx_equal_range()

template<typename Iterator1 , typename Iterator2 >
bool statcpp::approx_equal_range ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  rel_tol = default_rel_tol,
double  abs_tol = default_abs_tol 
)

Check if two ranges are approximately equal element-wise.

Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
rel_tolRelative tolerance (default: 1e-9)
abs_tolAbsolute tolerance (default: 1e-12)
Returns
true if all corresponding elements are approximately equal

Definition at line 314 of file numerical_utils.hpp.

◆ argmax() [1/2]

template<typename Iterator >
std::size_t statcpp::argmax ( Iterator  first,
Iterator  last 
)

Returns the index of the maximum value.

Returns the index of the element with the maximum value in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Index of the maximum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 1149 of file basic_statistics.hpp.

◆ argmax() [2/2]

template<typename Iterator , typename Projection >
std::size_t statcpp::argmax ( Iterator  first,
Iterator  last,
Projection  proj 
)

Returns the index of the maximum value (projection version)

Returns the index of the element whose projected value is maximum.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Index of the maximum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 1174 of file basic_statistics.hpp.

◆ argmin() [1/2]

template<typename Iterator >
std::size_t statcpp::argmin ( Iterator  first,
Iterator  last 
)

Returns the index of the minimum value.

Returns the index of the element with the minimum value in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Index of the minimum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 1097 of file basic_statistics.hpp.

◆ argmin() [2/2]

template<typename Iterator , typename Projection >
std::size_t statcpp::argmin ( Iterator  first,
Iterator  last,
Projection  proj 
)

Returns the index of the minimum value (projection version)

Returns the index of the element whose projected value is minimum.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Index of the minimum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 1122 of file basic_statistics.hpp.

◆ argsort()

template<typename T >
std::vector< std::size_t > statcpp::argsort ( const std::vector< T > &  data,
bool  ascending = true 
)

Return indices in sorted order.

Template Parameters
TData type
Parameters
dataData vector
ascendingtrue for ascending, false for descending
Returns
Indices in sorted order

Definition at line 598 of file data_wrangling.hpp.

◆ autocorrelation()

template<typename Iterator >
double statcpp::autocorrelation ( Iterator  first,
Iterator  last,
std::size_t  lag 
)

Calculate autocorrelation coefficient (lag k)

Calculates the autocorrelation coefficient at the specified lag for time series data.

Note
About normalization: This implementation normalizes by the variance of all data following Box-Jenkins (1976): rho(k) = gamma(k) / gamma(0) where gamma(k) = (1/n) * sum((x_t - mu)(x_{t+k} - mu)) is the autocovariance.

The denominator always uses gamma(0) (variance of all data), so rho(0) = 1 and |rho(k)| <= 1 is guaranteed for all lags. This is the same method as R's acf() and Python statsmodels.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
lagLag (time difference)
Returns
Autocorrelation coefficient [-1, 1]
Exceptions
std::invalid_argumentIf range is empty, lag is >= data length, or variance is zero

Definition at line 45 of file time_series.hpp.

◆ bartlett_test()

test_result statcpp::bartlett_test ( const std::vector< std::vector< double > > &  groups)
inline

Perform Bartlett test (homogeneity of variance test)

Tests whether variances are equal across multiple groups. Based on likelihood ratio test assuming normal distribution. For data that may not follow normal distribution, Levene test is recommended.

Parameters
groupsVector of vectors containing data for each group
Returns
test_result Test result containing chi-square statistic, p-value, and degrees of freedom
Exceptions
std::invalid_argumentIf there are fewer than 2 groups
std::invalid_argumentIf any group has fewer than 2 elements
std::invalid_argumentIf any group has zero or negative variance
Note
Null hypothesis: All groups have equal variance
Sensitive to departures from normality; use levene_test if normality is questionable

Definition at line 482 of file nonparametric_tests.hpp.

◆ benjamini_hochberg_correction()

std::vector< double > statcpp::benjamini_hochberg_correction ( const std::vector< double > &  p_values)
inline

Benjamini-Hochberg correction (FDR control)

Corrects p-values for multiple testing using the Benjamini-Hochberg method. Performs step-up correction to control the false discovery rate (FDR).

Parameters
p_valuesVector of original p-values
Returns
std::vector<double> Vector of corrected p-values

Definition at line 711 of file parametric_tests.hpp.

◆ bernoulli_cdf()

double statcpp::bernoulli_cdf ( std::uint64_t  k,
double  p 
)
inline

Bernoulli distribution cumulative distribution function (CDF)

Parameters
kUpper bound
pProbability of success
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 768 of file discrete_distributions.hpp.

◆ bernoulli_pmf()

double statcpp::bernoulli_pmf ( std::uint64_t  k,
double  p 
)
inline

Bernoulli distribution probability mass function (PMF)

P(X = k) = p^k * (1-p)^(1-k) for k ∈ {0, 1}

Parameters
kOutcome (0 or 1)
pProbability of success
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 746 of file discrete_distributions.hpp.

◆ bernoulli_quantile()

std::uint64_t statcpp::bernoulli_quantile ( double  prob,
double  p 
)
inline

Bernoulli distribution quantile function.

Parameters
probCumulative probability
pProbability of success
Returns
Smallest k such that P(X <= k) >= prob

Definition at line 787 of file discrete_distributions.hpp.

◆ bernoulli_rand() [1/2]

std::uint64_t statcpp::bernoulli_rand ( double  p)
inline

Bernoulli distribution random number generation (using default engine)

Parameters
pProbability of success
Returns
Generated random number (0 or 1)

Definition at line 824 of file discrete_distributions.hpp.

◆ bernoulli_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::bernoulli_rand ( double  p,
Engine &  engine 
)

Bernoulli distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
pProbability of success
engineRandom engine
Returns
Generated random number (0 or 1)
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 809 of file discrete_distributions.hpp.

◆ beta()

double statcpp::beta ( double  a,
double  b 
)
inline

Beta function.

Computes the beta function B(a, b) = Gamma(a) * Gamma(b) / Gamma(a + b).

Parameters
aFirst parameter (must be positive)
bSecond parameter (must be positive)
Returns
B(a, b)
Exceptions
std::domain_errorIf a or b is non-positive

Definition at line 148 of file special_functions.hpp.

◆ beta_cdf()

double statcpp::beta_cdf ( double  x,
double  alpha,
double  beta_param 
)
inline

Beta distribution cumulative distribution function (CDF)

F(x) = I_x(alpha, beta) (regularized incomplete beta function)

Parameters
xRandom variable value
alphaShape parameter alpha
beta_paramShape parameter beta
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf alpha <= 0 or beta_param <= 0

Definition at line 493 of file continuous_distributions.hpp.

◆ beta_pdf()

double statcpp::beta_pdf ( double  x,
double  alpha,
double  beta_param 
)
inline

Beta distribution probability density function (PDF)

f(x) = x^(alpha-1) * (1-x)^(beta-1) / B(alpha, beta) for 0 < x < 1

Parameters
xRandom variable value
alphaShape parameter alpha
beta_paramShape parameter beta
Returns
Probability density
Exceptions
std::invalid_argumentIf alpha <= 0 or beta_param <= 0

Definition at line 459 of file continuous_distributions.hpp.

◆ beta_quantile()

double statcpp::beta_quantile ( double  p,
double  alpha,
double  beta_param 
)
inline

Beta distribution quantile function.

Parameters
pProbability (0 <= p <= 1)
alphaShape parameter alpha
beta_paramShape parameter beta
Returns
Quantile
Exceptions
std::invalid_argumentIf alpha <= 0, beta_param <= 0, or p is outside [0, 1]

Definition at line 516 of file continuous_distributions.hpp.

◆ beta_rand() [1/2]

double statcpp::beta_rand ( double  alpha,
double  beta_param 
)
inline

Beta distribution random number generation (using default engine)

Parameters
alphaShape parameter alpha
beta_paramShape parameter beta
Returns
Random number following beta distribution

Definition at line 574 of file continuous_distributions.hpp.

◆ beta_rand() [2/2]

template<typename Engine = default_random_engine>
double statcpp::beta_rand ( double  alpha,
double  beta_param,
Engine &  engine 
)

Beta distribution random number generation (using gamma variates)

Template Parameters
EngineRandom engine type
Parameters
alphaShape parameter alpha
beta_paramShape parameter beta
engineRandom engine
Returns
Random number following beta distribution
Exceptions
std::invalid_argumentIf alpha <= 0 or beta_param <= 0

Definition at line 544 of file continuous_distributions.hpp.

◆ betainc()

double statcpp::betainc ( double  a,
double  b,
double  x 
)
inline

Regularized incomplete beta function.

Computes the regularized incomplete beta function I_x(a, b).

Parameters
aFirst parameter (must be positive)
bSecond parameter (must be positive)
xUpper limit of integration (must be in [0, 1])
Returns
I_x(a, b)
Exceptions
std::domain_errorIf parameters are invalid
Note
Used for computing CDFs of beta, F, and t distributions.

Definition at line 264 of file special_functions.hpp.

◆ betainc_impl()

double statcpp::betainc_impl ( double  a,
double  b,
double  x,
int  recursion_depth 
)
inline

Internal regularized incomplete beta function.

Computes the regularized incomplete beta function I_x(a, b) using continued fraction expansion.

Parameters
aFirst parameter
bSecond parameter
xUpper limit of integration (must be in [0, 1])
recursion_depthRecursion depth for tracking
Returns
I_x(a, b)
Exceptions
std::runtime_errorIf recursion depth is exceeded
Note
Reference: Numerical Recipes, Press et al.
Uses Lentz's algorithm

Definition at line 189 of file special_functions.hpp.

◆ betaincinv()

double statcpp::betaincinv ( double  a,
double  b,
double  p 
)
inline

Inverse regularized incomplete beta function.

Computes x such that I_x(a, b) = p (quantile function).

Parameters
aFirst parameter (must be positive)
bSecond parameter (must be positive)
pProbability value (must be in [0, 1])
Returns
x such that I_x(a, b) = p
Exceptions
std::domain_errorIf parameters are invalid
Note
Uses Newton-Raphson iteration

Definition at line 291 of file special_functions.hpp.

◆ bic()

double statcpp::bic ( double  log_likelihood,
std::size_t  n,
std::size_t  k 
)
inline

Calculate BIC (Bayesian Information Criterion)

Calculates the Bayesian Information Criterion (Schwarz criterion). Penalizes complex models more heavily than AIC.

Parameters
log_likelihoodLog-likelihood
nSample size
kNumber of parameters
Returns
BIC value

Definition at line 122 of file model_selection.hpp.

◆ bic_linear() [1/2]

double statcpp::bic_linear ( const multiple_regression_result model,
std::size_t  n 
)
inline

Calculate BIC from multiple regression model.

Calculates log-likelihood from multiple regression result and computes BIC.

Parameters
modelMultiple regression result
nSample size
Returns
BIC value

Definition at line 155 of file model_selection.hpp.

◆ bic_linear() [2/2]

double statcpp::bic_linear ( const simple_regression_result model,
std::size_t  n 
)
inline

Calculate BIC from simple regression model.

Calculates log-likelihood from simple regression result and computes BIC.

Parameters
modelSimple regression result
nSample size
Returns
BIC value

Definition at line 136 of file model_selection.hpp.

◆ bin_equal_freq()

std::vector< std::size_t > statcpp::bin_equal_freq ( const std::vector< double > &  data,
std::size_t  n_bins 
)
inline

Binning (equal frequency)

Parameters
dataData vector
n_binsNumber of bins
Returns
Vector of bin numbers

Definition at line 1058 of file data_wrangling.hpp.

◆ bin_equal_width()

std::vector< std::size_t > statcpp::bin_equal_width ( const std::vector< double > &  data,
std::size_t  n_bins 
)
inline

Binning (equal width)

Parameters
dataData vector
n_binsNumber of bins
Returns
Vector of bin numbers

Definition at line 1021 of file data_wrangling.hpp.

◆ binomial_cdf()

double statcpp::binomial_cdf ( std::uint64_t  k,
std::uint64_t  n,
double  p 
)
inline

Binomial distribution cumulative distribution function (CDF)

Calculates P(X <= k).

Parameters
kUpper bound of number of successes
nNumber of trials
pProbability of success in each trial
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 111 of file discrete_distributions.hpp.

◆ binomial_coef()

double statcpp::binomial_coef ( std::uint64_t  n,
std::uint64_t  k 
)
inline

Calculate binomial coefficient.

Calculates C(n, k) = n! / (k! * (n-k)!)

Parameters
nTotal number of elements
kNumber of elements to choose
Returns
Value of C(n, k)

Definition at line 65 of file discrete_distributions.hpp.

◆ binomial_pmf()

double statcpp::binomial_pmf ( std::uint64_t  k,
std::uint64_t  n,
double  p 
)
inline

Binomial distribution probability mass function (PMF)

P(X = k) = C(n, k) * p^k * (1-p)^(n-k)

Parameters
kNumber of successes
nNumber of trials
pProbability of success in each trial
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 86 of file discrete_distributions.hpp.

◆ binomial_quantile()

std::uint64_t statcpp::binomial_quantile ( double  prob,
std::uint64_t  n,
double  p 
)
inline

Binomial distribution quantile function.

Returns the smallest k such that P(X <= k) >= prob.

Parameters
probProbability value
nNumber of trials
pProbability of success in each trial
Returns
Quantile
Exceptions
std::invalid_argumentIf prob or p is in an invalid range

Definition at line 134 of file discrete_distributions.hpp.

◆ binomial_rand() [1/2]

std::uint64_t statcpp::binomial_rand ( std::uint64_t  n,
double  p 
)
inline

Binomial distribution random number generation (using default engine)

Parameters
nNumber of trials
pProbability of success in each trial
Returns
Generated random number

Definition at line 188 of file discrete_distributions.hpp.

◆ binomial_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::binomial_rand ( std::uint64_t  n,
double  p,
Engine &  engine 
)

Binomial distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
nNumber of trials
pProbability of success in each trial
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf p is outside [0, 1]

Definition at line 172 of file discrete_distributions.hpp.

◆ biweight_midvariance()

template<typename Iterator >
double statcpp::biweight_midvariance ( Iterator  first,
Iterator  last,
double  c = 9.0 
)

Biweight Midvariance.

Calculates the Biweight Midvariance, a robust variance estimator.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
cTuning constant (default: 9.0)
Returns
Biweight midvariance
Exceptions
std::invalid_argumentIf range has less than 2 elements
Note
A variance estimator less affected by outliers.

Definition at line 517 of file robust.hpp.

◆ bonferroni_correction()

std::vector< double > statcpp::bonferroni_correction ( const std::vector< double > &  p_values)
inline

Bonferroni correction.

Corrects p-values for multiple testing using the Bonferroni method. Each p-value is multiplied by the number of tests, capped at 1.

Parameters
p_valuesVector of original p-values
Returns
std::vector<double> Vector of corrected p-values

Definition at line 690 of file parametric_tests.hpp.

◆ bonferroni_posthoc()

posthoc_result statcpp::bonferroni_posthoc ( const one_way_anova_result anova_result,
double  alpha = 0.05 
)
inline

Perform Bonferroni method for multiple comparisons.

Performs multiple comparisons among all pairs of groups with Bonferroni correction as a post-hoc test following one-way ANOVA.

Parameters
anova_resultResult from one-way ANOVA
alphaSignificance level (default: 0.05)
Returns
posthoc_result Post-hoc comparison results
Exceptions
std::invalid_argumentIf alpha is outside the range (0, 1)

Definition at line 444 of file anova.hpp.

◆ bootstrap()

template<typename Iterator , typename Statistic , typename Engine = default_random_engine>
bootstrap_result statcpp::bootstrap ( Iterator  first,
Iterator  last,
Statistic  stat_func,
std::size_t  n_bootstrap = 1000,
double  confidence = 0.95,
Engine &  engine = get_random_engine() 
)

Perform general bootstrap estimation.

Applies the bootstrap method to any statistical function and computes the estimated statistic, standard error, percentile confidence interval, and bias.

Percentile confidence interval calculation:

  • Lower index: floor(alpha/2 * B)
  • Upper index: floor((1 - alpha/2) * B) - 1
  • Where alpha = 1 - confidence, B = n_bootstrap
Note
The percentile method is the simplest confidence interval calculation method. For more accurate confidence intervals, use bootstrap_bca().
Template Parameters
IteratorInput iterator type
StatisticStatistical function type (function taking iterator pair and returning double)
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
stat_funcFunction object that computes the statistic
n_bootstrapNumber of bootstrap iterations (default: 1000)
confidenceConfidence level (default: 0.95)
engineReference to random engine
Returns
bootstrap_result structure containing bootstrap estimation results
Exceptions
std::invalid_argumentIf confidence is outside (0, 1)
std::invalid_argumentIf number of input elements is less than 2

Definition at line 139 of file resampling.hpp.

◆ bootstrap_bca()

template<typename Iterator , typename Statistic , typename Engine = default_random_engine>
bootstrap_result statcpp::bootstrap_bca ( Iterator  first,
Iterator  last,
Statistic  stat_func,
std::size_t  n_bootstrap = 1000,
double  confidence = 0.95,
Engine &  engine = get_random_engine() 
)

Compute BCa (bias-corrected and accelerated) bootstrap confidence interval.

Implements the BCa method which provides more accurate confidence intervals than the standard percentile method. Uses jackknife to estimate the acceleration factor and applies bias correction.

Template Parameters
IteratorInput iterator type
StatisticStatistical function type (function taking iterator pair and returning double)
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
stat_funcFunction object that computes the statistic
n_bootstrapNumber of bootstrap iterations (default: 1000)
confidenceConfidence level (default: 0.95)
engineReference to random engine
Returns
bootstrap_result structure containing bootstrap estimation results
Exceptions
std::invalid_argumentIf confidence is outside (0, 1)
std::invalid_argumentIf number of input elements is less than 3

Definition at line 310 of file resampling.hpp.

◆ bootstrap_mean()

template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result statcpp::bootstrap_mean ( Iterator  first,
Iterator  last,
std::size_t  n_bootstrap = 1000,
double  confidence = 0.95,
Engine &  engine = get_random_engine() 
)

Perform bootstrap estimation of the mean.

Applies the bootstrap method to the sample mean and computes standard error and confidence interval.

Template Parameters
IteratorInput iterator type
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
n_bootstrapNumber of bootstrap iterations (default: 1000)
confidenceConfidence level (default: 0.95)
engineReference to random engine
Returns
bootstrap_result structure containing bootstrap estimation results
Exceptions
std::invalid_argumentIf confidence is outside (0, 1)
std::invalid_argumentIf number of input elements is less than 2

Definition at line 221 of file resampling.hpp.

◆ bootstrap_median()

template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result statcpp::bootstrap_median ( Iterator  first,
Iterator  last,
std::size_t  n_bootstrap = 1000,
double  confidence = 0.95,
Engine &  engine = get_random_engine() 
)

Perform bootstrap estimation of the median.

Applies the bootstrap method to the sample median and computes standard error and confidence interval.

Template Parameters
IteratorInput iterator type
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
n_bootstrapNumber of bootstrap iterations (default: 1000)
confidenceConfidence level (default: 0.95)
engineReference to random engine
Returns
bootstrap_result structure containing bootstrap estimation results
Exceptions
std::invalid_argumentIf confidence is outside (0, 1)
std::invalid_argumentIf number of input elements is less than 2

Definition at line 247 of file resampling.hpp.

◆ bootstrap_sample() [1/2]

template<typename Iterator >
std::vector< typename std::iterator_traits< Iterator >::value_type > statcpp::bootstrap_sample ( Iterator  first,
Iterator  last 
)

Generate a single bootstrap sample (using default random engine)

Generates a bootstrap sample using the global default random engine.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
Returns
Bootstrap sample obtained by sampling with replacement
Exceptions
std::invalid_argumentIf input range is empty

Definition at line 102 of file resampling.hpp.

◆ bootstrap_sample() [2/2]

template<typename Iterator , typename Engine = default_random_engine>
std::vector< typename std::iterator_traits< Iterator >::value_type > statcpp::bootstrap_sample ( Iterator  first,
Iterator  last,
Engine &  engine 
)

Generate a single bootstrap sample.

Generates a bootstrap sample of the same size as the original sample by sampling with replacement from the given data.

Template Parameters
IteratorInput iterator type
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
engineReference to random engine
Returns
Bootstrap sample obtained by sampling with replacement
Exceptions
std::invalid_argumentIf input range is empty

Definition at line 69 of file resampling.hpp.

◆ bootstrap_stddev()

template<typename Iterator , typename Engine = default_random_engine>
bootstrap_result statcpp::bootstrap_stddev ( Iterator  first,
Iterator  last,
std::size_t  n_bootstrap = 1000,
double  confidence = 0.95,
Engine &  engine = get_random_engine() 
)

Perform bootstrap estimation of the standard deviation.

Applies the bootstrap method to the sample standard deviation and computes standard error and confidence interval.

Template Parameters
IteratorInput iterator type
EngineRandom engine type (default: default_random_engine)
Parameters
firstBeginning iterator of input range
lastEnd iterator of input range
n_bootstrapNumber of bootstrap iterations (default: 1000)
confidenceConfidence level (default: 0.95)
engineReference to random engine
Returns
bootstrap_result structure containing bootstrap estimation results
Exceptions
std::invalid_argumentIf confidence is outside (0, 1)
std::invalid_argumentIf number of input elements is less than 2

Definition at line 277 of file resampling.hpp.

◆ boxcox_transform()

std::vector< double > statcpp::boxcox_transform ( const std::vector< double > &  data,
double  lambda 
)
inline

Box-Cox transformation.

When lambda = 0, performs logarithmic transformation

Parameters
dataData vector
lambdaTransformation parameter
Returns
Box-Cox transformed data (values <= 0 become NA)

Definition at line 390 of file data_wrangling.hpp.

◆ chebyshev_distance() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::chebyshev_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Chebyshev distance (L∞ norm, maximum metric)

Computes the maximum absolute difference: d(x, y) = max(|x_i - y_i|)

Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
Returns
Chebyshev distance
Exceptions
std::invalid_argumentif sequences have different lengths

Definition at line 487 of file distance_metrics.hpp.

◆ chebyshev_distance() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::chebyshev_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Proj1  proj1,
Proj2  proj2 
)

Chebyshev distance with projection.

Definition at line 520 of file distance_metrics.hpp.

◆ chisq_cdf()

double statcpp::chisq_cdf ( double  x,
double  df 
)
inline

Chi-square distribution cumulative distribution function (CDF)

Chi-square distribution is a special case of gamma distribution: chi^2(df) = Gamma(df/2, 1/2) This implementation uses the regularized incomplete gamma function: F(x; df) = gamma(df/2, x/2) / Gamma(df/2) = P(df/2, x/2)

Parameters
xRandom variable value
dfDegrees of freedom
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 613 of file continuous_distributions.hpp.

◆ chisq_pdf()

double statcpp::chisq_pdf ( double  x,
double  df 
)
inline

Chi-square distribution probability density function (PDF)

Special case of gamma distribution (shape = df/2, rate = 1/2)

Parameters
xRandom variable value
dfDegrees of freedom
Returns
Probability density
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 593 of file continuous_distributions.hpp.

◆ chisq_quantile()

double statcpp::chisq_quantile ( double  p,
double  df 
)
inline

Chi-square distribution quantile function.

Parameters
pProbability (0 <= p <= 1)
dfDegrees of freedom
Returns
Quantile
Exceptions
std::invalid_argumentIf df <= 0 or p is outside [0, 1]

Definition at line 629 of file continuous_distributions.hpp.

◆ chisq_rand() [1/2]

double statcpp::chisq_rand ( double  df)
inline

Chi-square distribution random number generation (using default engine)

Parameters
dfDegrees of freedom
Returns
Random number following chi-square distribution

Definition at line 661 of file continuous_distributions.hpp.

◆ chisq_rand() [2/2]

template<typename Engine = default_random_engine>
double statcpp::chisq_rand ( double  df,
Engine &  engine 
)

Chi-square distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
dfDegrees of freedom
engineRandom engine
Returns
Random number following chi-square distribution
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 647 of file continuous_distributions.hpp.

◆ chisq_test_gof()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::chisq_test_gof ( Iterator1  observed_first,
Iterator1  observed_last,
Iterator2  expected_first,
Iterator2  expected_last 
)

Chi-square goodness of fit test.

Tests whether observed frequencies match expected frequencies.

Template Parameters
Iterator1Input iterator type for observed frequencies
Iterator2Input iterator type for expected frequencies
Parameters
observed_firstBeginning iterator of observed frequencies
observed_lastEnd iterator of observed frequencies
expected_firstBeginning iterator of expected frequencies
expected_lastEnd iterator of expected frequencies
Returns
test_result Test result (chi-square statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf observed and expected lengths differ, fewer than 2 categories, or expected frequency is non-positive

Definition at line 464 of file parametric_tests.hpp.

◆ chisq_test_gof_uniform()

template<typename Iterator >
test_result statcpp::chisq_test_gof_uniform ( Iterator  observed_first,
Iterator  observed_last 
)

Chi-square goodness of fit test (uniform expected frequencies)

Tests whether observed frequencies follow a uniform distribution.

Template Parameters
IteratorInput iterator type for observed frequencies
Parameters
observed_firstBeginning iterator of observed frequencies
observed_lastEnd iterator of observed frequencies
Returns
test_result Test result (chi-square statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf fewer than 2 categories

Definition at line 513 of file parametric_tests.hpp.

◆ chisq_test_independence()

test_result statcpp::chisq_test_independence ( const std::vector< std::vector< double > > &  contingency_table)
inline

Chi-square test for independence.

Tests independence of two variables based on a contingency table.

Parameters
contingency_tableContingency table (2D array in row-major order)
Returns
test_result Test result (chi-square statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf rows or columns are less than 2, column counts are inconsistent, negative values exist, or table is empty

Definition at line 556 of file parametric_tests.hpp.

◆ ci_mean() [1/2]

template<typename Iterator , typename Projection >
confidence_interval statcpp::ci_mean ( Iterator  first,
Iterator  last,
double  confidence,
Projection  proj 
)

Calculate confidence interval for mean (projection version)

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
confidenceConfidence level
projProjection function
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or there are fewer than 2 elements

Definition at line 155 of file estimation.hpp.

◆ ci_mean() [2/2]

template<typename Iterator >
confidence_interval statcpp::ci_mean ( Iterator  first,
Iterator  last,
double  confidence = 0.95 
)

Calculate confidence interval for mean (t-distribution based)

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or there are fewer than 2 elements

Definition at line 119 of file estimation.hpp.

◆ ci_mean_diff()

template<typename Iterator1 , typename Iterator2 >
confidence_interval statcpp::ci_mean_diff ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  confidence = 0.95 
)

Calculate confidence interval for difference of two-sample means (independent samples, pooled variance)

Calculates the confidence interval for the difference of two-sample means assuming equal variances.

Template Parameters
Iterator1First iterator type
Iterator2Second iterator type
Parameters
first1Beginning iterator of first data range
last1Ending iterator of first data range
first2Beginning iterator of second data range
last2Ending iterator of second data range
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or either sample has fewer than 2 elements

Definition at line 354 of file estimation.hpp.

◆ ci_mean_diff_pooled()

template<typename Iterator1 , typename Iterator2 >
confidence_interval statcpp::ci_mean_diff_pooled ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  confidence = 0.95 
)

Calculate confidence interval for two-sample mean difference (assuming equal variances)

Template Parameters
Iterator1First iterator type
Iterator2Second iterator type
Parameters
first1Beginning iterator of first data range
last1Ending iterator of first data range
first2Beginning iterator of second data range
last2Ending iterator of second data range
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or either sample has fewer than 2 elements

Definition at line 669 of file estimation.hpp.

◆ ci_mean_diff_welch()

template<typename Iterator1 , typename Iterator2 >
confidence_interval statcpp::ci_mean_diff_welch ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  confidence = 0.95 
)

Calculate confidence interval for difference of two-sample means (Welch method, not assuming equal variances)

Calculates the confidence interval for the difference of two-sample means without assuming equal variances (Welch-Satterthwaite method).

Template Parameters
Iterator1First iterator type
Iterator2Second iterator type
Parameters
first1Beginning iterator of first data range
last1Ending iterator of first data range
first2Beginning iterator of second data range
last2Ending iterator of second data range
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1), either sample has fewer than 2 elements, or both variances are zero

Definition at line 405 of file estimation.hpp.

◆ ci_mean_z()

template<typename Iterator >
confidence_interval statcpp::ci_mean_z ( Iterator  first,
Iterator  last,
double  sigma,
double  confidence = 0.95 
)

Calculate confidence interval for mean (z-distribution based, known variance)

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
sigmaKnown population standard deviation
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1), sigma is not positive, or the range is empty

Definition at line 194 of file estimation.hpp.

◆ ci_proportion()

confidence_interval statcpp::ci_proportion ( std::size_t  successes,
std::size_t  trials,
double  confidence = 0.95 
)
inline

Calculate confidence interval for proportion (Wald method)

Parameters
successesNumber of successes
trialsNumber of trials
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1), trials is 0, or successes exceeds trials

Definition at line 232 of file estimation.hpp.

◆ ci_proportion_diff()

confidence_interval statcpp::ci_proportion_diff ( std::size_t  successes1,
std::size_t  n1,
std::size_t  successes2,
std::size_t  n2,
double  confidence = 0.95 
)
inline

Calculate confidence interval for two-sample proportion difference.

Parameters
successes1Number of successes in first sample
n1First sample size
successes2Number of successes in second sample
n2Second sample size
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 692 of file estimation.hpp.

◆ ci_proportion_wilson()

confidence_interval statcpp::ci_proportion_wilson ( std::size_t  successes,
std::size_t  trials,
double  confidence = 0.95 
)
inline

Calculate confidence interval for proportion (Wilson method, recommended)

The Wilson method has better properties than the Wald method, especially for small samples or extreme proportions.

Parameters
successesNumber of successes
trialsNumber of trials
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1), trials is 0, or successes exceeds trials

Definition at line 269 of file estimation.hpp.

◆ ci_variance()

template<typename Iterator >
confidence_interval statcpp::ci_variance ( Iterator  first,
Iterator  last,
double  confidence = 0.95 
)

Calculate confidence interval for variance (chi-square distribution based)

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
confidenceConfidence level (default: 0.95)
Returns
Confidence interval
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or there are fewer than 2 elements

Definition at line 310 of file estimation.hpp.

◆ clamp()

double statcpp::clamp ( double  x,
double  min_val,
double  max_val 
)
inline

Clamp a value to a range [min_val, max_val].

Parameters
xValue to clamp
min_valMinimum value
max_valMaximum value
Returns
Clamped value
Exceptions
std::invalid_argumentif min_val > max_val

Definition at line 199 of file numerical_utils.hpp.

◆ coefficient_of_variation() [1/4]

template<typename Iterator >
double statcpp::coefficient_of_variation ( Iterator  first,
Iterator  last 
)

Coefficient of variation.

Computes the standard deviation divided by the mean (returned as a ratio; multiply by 100 for percentage). Useful for measuring relative variability of data.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Coefficient of variation (ratio)
Exceptions
std::invalid_argumentIf range is empty, has fewer than 2 elements, or mean is zero

Definition at line 832 of file dispersion_spread.hpp.

◆ coefficient_of_variation() [2/4]

template<typename Iterator >
double statcpp::coefficient_of_variation ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Coefficient of variation using precomputed mean.

Computes coefficient of variation when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Coefficient of variation (ratio)
Exceptions
std::invalid_argumentIf range is empty, has fewer than 2 elements, or mean is zero

Definition at line 861 of file dispersion_spread.hpp.

◆ coefficient_of_variation() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::coefficient_of_variation ( Iterator  first,
Iterator  last,
Projection  proj 
)

Coefficient of variation of projected values using a lambda expression.

Computes the coefficient of variation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Coefficient of variation of projected values (ratio)
Exceptions
std::invalid_argumentIf range is empty, has fewer than 2 elements, or mean is zero

Definition at line 893 of file dispersion_spread.hpp.

◆ coefficient_of_variation() [4/4]

template<typename Iterator , typename Projection >
double statcpp::coefficient_of_variation ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Coefficient of variation of projected values using precomputed mean.

Computes coefficient of variation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Coefficient of variation of projected values (ratio)
Exceptions
std::invalid_argumentIf range is empty, has fewer than 2 elements, or mean is zero

Definition at line 924 of file dispersion_spread.hpp.

◆ cohens_d() [1/2]

template<typename Iterator >
double statcpp::cohens_d ( Iterator  first,
Iterator  last,
double  mu0 
)

Cohen's d (one-sample, using sample standard deviation)

Calculates the standardized mean difference using the sample standard deviation.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnding iterator
mu0Population mean to compare against
Returns
Cohen's d
Exceptions
std::invalid_argumentIf there are fewer than 2 elements or variance is zero

Definition at line 63 of file effect_size.hpp.

◆ cohens_d() [2/2]

template<typename Iterator >
double statcpp::cohens_d ( Iterator  first,
Iterator  last,
double  mu0,
double  sigma 
)

Cohen's d (one-sample, known population standard deviation)

Calculates the standardized mean difference. Used when the population standard deviation is known.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnding iterator
mu0Population mean to compare against
sigmaPopulation standard deviation
Returns
Cohen's d
Exceptions
std::invalid_argumentIf the range is empty or sigma is not positive

Definition at line 35 of file effect_size.hpp.

◆ cohens_d_two_sample()

template<typename Iterator1 , typename Iterator2 >
double statcpp::cohens_d_two_sample ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Cohen's d (two-sample, pooled standard deviation)

Calculates the standardized mean difference between two groups. Uses pooled standard deviation.

Template Parameters
Iterator1RandomAccessIterator type for first sample
Iterator2RandomAccessIterator type for second sample
Parameters
first1Beginning iterator of first sample
last1Ending iterator of first sample
first2Beginning iterator of second sample
last2Ending iterator of second sample
Returns
Cohen's d
Exceptions
std::invalid_argumentIf either sample has fewer than 2 elements or pooled variance is zero

Definition at line 96 of file effect_size.hpp.

◆ cohens_f()

double statcpp::cohens_f ( const one_way_anova_result result)
inline

Calculate Cohen's f for one-way ANOVA.

Standardized effect size measure where 0.10 indicates small, 0.25 indicates medium, and 0.40 indicates large effect.

Parameters
resultResult from one-way ANOVA
Returns
double Cohen's f value (infinity if eta_squared equals 1.0)

Definition at line 922 of file anova.hpp.

◆ cohens_h()

double statcpp::cohens_h ( double  p1,
double  p2 
)
inline

Cohen's h (effect size for difference between two proportions)

Calculates the effect size representing the difference between two proportions.

Parameters
p1Proportion in first group
p2Proportion in second group
Returns
Cohen's h
Exceptions
std::invalid_argumentIf proportions are outside [0, 1] range

Definition at line 355 of file effect_size.hpp.

◆ compute_glm_residuals()

glm_residuals statcpp::compute_glm_residuals ( const glm_result model,
const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y 
)
inline

Calculate GLM residuals.

Calculates various types of residuals from a fitted GLM model.

Parameters
modelFitted GLM model
XPredictor matrix
yResponse variable vector
Returns
Structure containing various residuals
Exceptions
std::invalid_argumentIf X and Y sizes don't match

Definition at line 890 of file glm.hpp.

◆ compute_ranks_with_ties()

template<typename Iterator >
std::vector< double > statcpp::compute_ranks_with_ties ( Iterator  first,
Iterator  last 
)

Compute ranks with tie handling.

Assigns ranks to input data. Elements with the same value are assigned average ranks.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of range
lastEnding iterator of range
Returns
std::vector<double> Vector of ranks corresponding to each element
Note
Returns an empty vector if an empty range is passed.

Definition at line 56 of file nonparametric_tests.hpp.

◆ compute_residual_diagnostics() [1/2]

residual_diagnostics statcpp::compute_residual_diagnostics ( const multiple_regression_result model,
const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y 
)
inline

Perform residual diagnostics for multiple regression model.

Calculates residuals, standardized residuals, studentized residuals, leverage values, Cook's distance, and Durbin-Watson statistic.

Parameters
modelMultiple regression analysis results
XPredictor matrix
yResponse variable vector
Returns
residual_diagnostics Residual diagnostics results
Exceptions
std::invalid_argumentIf X and y have different lengths

Definition at line 879 of file linear_regression.hpp.

◆ compute_residual_diagnostics() [2/2]

template<typename IteratorX , typename IteratorY >
residual_diagnostics statcpp::compute_residual_diagnostics ( const simple_regression_result model,
IteratorX  x_first,
IteratorX  x_last,
IteratorY  y_first,
IteratorY  y_last 
)

Perform residual diagnostics for simple regression model.

Calculates residuals, standardized residuals, studentized residuals, leverage values, Cook's distance, and Durbin-Watson statistic.

Template Parameters
IteratorXIterator type for predictor variable
IteratorYIterator type for response variable
Parameters
modelSimple regression analysis results
x_firstBeginning iterator for predictor variable
x_lastEnding iterator for predictor variable
y_firstBeginning iterator for response variable
y_lastEnding iterator for response variable
Returns
residual_diagnostics Residual diagnostics results
Exceptions
std::invalid_argumentIf x and y have different lengths

Definition at line 798 of file linear_regression.hpp.

◆ compute_tie_groups()

std::vector< std::size_t > statcpp::compute_tie_groups ( const std::vector< double > &  sorted_values)
inline

Compute tie group sizes from sorted data.

Returns a vector of tie group sizes t_j, where each t_j > 1 represents a group of tied values. Used for tie corrections in nonparametric tests.

Parameters
sorted_valuesSorted vector of values
Returns
std::vector<std::size_t> Vector of tie group sizes (only groups with t > 1)

Definition at line 101 of file nonparametric_tests.hpp.

◆ compute_vif()

std::vector< double > statcpp::compute_vif ( const std::vector< std::vector< double > > &  X)
inline

Calculate VIF (Variance Inflation Factor) for each predictor.

VIF is an indicator of multicollinearity, showing the degree to which each predictor is explained by other predictors. Generally VIF > 10 suggests a multicollinearity problem.

Parameters
XPredictor matrix (n x p)
Returns
std::vector<double> VIF for each predictor
Exceptions
std::invalid_argumentIf there are fewer than 3 observations
std::invalid_argumentIf there are fewer than 2 predictors

Definition at line 976 of file linear_regression.hpp.

◆ confidence_interval_mean()

template<typename IteratorX >
prediction_interval statcpp::confidence_interval_mean ( const simple_regression_result model,
IteratorX  x_first,
IteratorX  x_last,
double  x_new,
double  confidence = 0.95 
)

Calculate confidence interval for mean of simple regression model.

Calculates the confidence interval for the mean response at a specific x value. The confidence interval shows the probability that the true regression line is within this interval.

Template Parameters
IteratorXIterator type for predictor variable
Parameters
modelSimple regression analysis results
x_firstBeginning iterator for original predictor variable data
x_lastEnding iterator for original predictor variable data
x_newx value of the point to predict
confidenceConfidence level (default: 0.95)
Returns
prediction_interval Predicted value and confidence interval
Exceptions
std::invalid_argumentIf confidence is outside (0, 1) range

Definition at line 744 of file linear_regression.hpp.

◆ contingency_table()

contingency_table_result statcpp::contingency_table ( const std::vector< std::size_t > &  row_data,
const std::vector< std::size_t > &  col_data 
)
inline

Create a contingency table.

Creates a contingency table (cross-tabulation) from two categorical variables.

Parameters
row_dataRow category values (integers starting from 0)
col_dataColumn category values (integers starting from 0)
Returns
Contingency table result
Exceptions
std::invalid_argumentIf data lengths do not match or if data is empty

Definition at line 42 of file categorical.hpp.

◆ cooks_distance()

std::vector< double > statcpp::cooks_distance ( const std::vector< double > &  residuals,
const std::vector< double > &  hat_values,
double  mse,
std::size_t  p 
)
inline

Calculate Cook's Distance.

Calculates Cook's Distance to detect influential observations in linear regression.

Parameters
residualsResiduals
hat_valuesLeverage values (hat values)
mseMean squared error
pNumber of parameters (including intercept)
Returns
Cook's distances
Exceptions
std::invalid_argumentIf parameters are invalid
Note
D_i > 1 indicates the observation is influential.
D_i > 4/n is also sometimes used as a threshold.

Definition at line 363 of file robust.hpp.

◆ correlation_matrix()

std::vector< std::vector< double > > statcpp::correlation_matrix ( const std::vector< std::vector< double > > &  data)
inline

Calculate Pearson correlation matrix.

Calculates the correlation matrix for multivariate data. Standardizes the covariance matrix to obtain correlation coefficients.

Parameters
dataMatrix data (rows=observations, columns=variables)
Returns
Correlation matrix (p x p)
Exceptions
std::invalid_argumentIf data is empty, rows have different column counts, there are fewer than 2 observations, or any variable has zero variance

Definition at line 89 of file multivariate.hpp.

◆ correlation_matrix_determinant()

double statcpp::correlation_matrix_determinant ( const std::vector< std::vector< double > > &  X)
inline

Calculate determinant of correlation matrix.

Used for multicollinearity diagnostics. det(R) close to 0 indicates strong multicollinearity, det(R) = 1 indicates no correlation between variables.

Parameters
XPredictor matrix (n x p)
Returns
double Determinant of correlation matrix
Exceptions
std::invalid_argumentIf there are fewer than 2 observations
std::invalid_argumentIf there are fewer than 2 or more than 3 predictors (only 2 or 3 supported)

Definition at line 1035 of file linear_regression.hpp.

◆ correlation_matrix_pairwise()

std::vector< std::vector< double > > statcpp::correlation_matrix_pairwise ( const std::vector< std::vector< double > > &  data)
inline

Correlation matrix using available case analysis (pairwise deletion)

Calculates correlation coefficients using only cases where both variables are observed for each pair of variables. Also called pairwise deletion.

Parameters
dataInput data (rows: observations, columns: variables)
Returns
std::vector<std::vector<double>> Correlation matrix (NA if insufficient observations)

Definition at line 1100 of file missing_data.hpp.

◆ cosine_distance() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::cosine_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Cosine distance.

Defined as: distance = 1 - similarity Returns a value in [0, 2], where 0 means identical direction

Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
Returns
Cosine distance

Definition at line 288 of file distance_metrics.hpp.

◆ cosine_distance() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::cosine_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Proj1  proj1,
Proj2  proj2 
)

Cosine distance with projection.

Definition at line 298 of file distance_metrics.hpp.

◆ cosine_similarity() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::cosine_similarity ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Cosine similarity.

Computes the cosine of the angle between two vectors: similarity(x, y) = (x · y) / (||x|| * ||y||)

Returns a value in [-1, 1]:

  • 1: vectors point in the same direction
  • 0: vectors are orthogonal
  • -1: vectors point in opposite directions
Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
Returns
Cosine similarity
Exceptions
std::invalid_argumentif sequences have different lengths or if either vector has zero norm

Definition at line 190 of file distance_metrics.hpp.

◆ cosine_similarity() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::cosine_similarity ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Proj1  proj1,
Proj2  proj2 
)

Cosine similarity with projection.

Definition at line 233 of file distance_metrics.hpp.

◆ count()

template<typename Iterator >
std::size_t statcpp::count ( Iterator  first,
Iterator  last 
)

Data count.

Returns the number of elements in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Number of elements

Definition at line 91 of file basic_statistics.hpp.

◆ covariance() [1/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Covariance (alias for sample_covariance)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Sample covariance

Definition at line 303 of file correlation_covariance.hpp.

◆ covariance() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  mean_x,
double  mean_y 
)

Covariance with precomputed means (alias for sample_covariance)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
mean_xMean of the first data
mean_yMean of the second data
Returns
Sample covariance

Definition at line 323 of file correlation_covariance.hpp.

◆ covariance() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Covariance (projection version, alias for sample_covariance)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Sample covariance

Definition at line 346 of file correlation_covariance.hpp.

◆ covariance_matrix()

std::vector< std::vector< double > > statcpp::covariance_matrix ( const std::vector< std::vector< double > > &  data)
inline

Calculate sample covariance matrix.

Calculates the covariance matrix for multivariate data. Data is passed with rows=observations and columns=variables.

Parameters
dataMatrix data (rows=observations, columns=variables)
Returns
Covariance matrix (p x p)
Exceptions
std::invalid_argumentIf data is empty, rows have different column counts, or there are fewer than 2 observations

Definition at line 37 of file multivariate.hpp.

◆ create_cv_folds()

std::vector< std::vector< std::size_t > > statcpp::create_cv_folds ( std::size_t  n,
std::size_t  k,
bool  shuffle = true 
)
inline

Generate indices for k-fold cross-validation.

Generates indices for splitting data into k folds.

Parameters
nData size
kNumber of folds
shuffleWhether to shuffle (default: true)
Returns
Vector of indices belonging to each fold
Exceptions
std::invalid_argumentIf k is less than 2 or k exceeds n

Definition at line 250 of file model_selection.hpp.

◆ create_missing_indicator()

std::vector< std::vector< double > > statcpp::create_missing_indicator ( const std::vector< std::vector< double > > &  data)
inline

Create missing indicator variables.

Creates an indicator variable matrix where each element is 1.0 if missing and 0.0 if observed.

Parameters
dataInput data (rows: observations, columns: variables)
Returns
std::vector<std::vector<double>> Missing indicator matrix (1 = missing, 0 = observed)

Definition at line 179 of file missing_data.hpp.

◆ cross_validate_linear()

cv_result statcpp::cross_validate_linear ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
std::size_t  k = 5 
)
inline

Perform k-fold cross-validation for multiple regression model.

Splits data into specified number of folds and evaluates model prediction performance through cross-validation.

Parameters
XPredictor matrix (each row is one sample)
yResponse variable vector
kNumber of folds (default: 5)
Returns
Cross-validation result
Exceptions
std::invalid_argumentIf X and y have different sizes

Definition at line 294 of file model_selection.hpp.

◆ cumulative_frequency() [1/2]

template<typename Iterator >
auto statcpp::cumulative_frequency ( Iterator  first,
Iterator  last 
) -> std::vector<std::pair<typename std::iterator_traits<Iterator>::value_type, std::size_t>>

Return cumulative frequency (for sorted values)

Calculates the cumulative frequency up to each value. Results are sorted in ascending order by value.

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator
lastEnding iterator
Returns
Vector of (value, cumulative frequency) pairs

Definition at line 305 of file frequency_distribution.hpp.

◆ cumulative_frequency() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::cumulative_frequency ( Iterator  first,
Iterator  last,
Projection  proj 
) -> std::vector<std::pair<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>, std::size_t>>

Cumulative frequency with projection.

Returns the cumulative frequency of results after applying a projection function to each element. Results are sorted in ascending order by value.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator
lastEnding iterator
projProjection function
Returns
Vector of (value, cumulative frequency) pairs

Definition at line 346 of file frequency_distribution.hpp.

◆ cumulative_relative_frequency() [1/2]

template<typename Iterator >
auto statcpp::cumulative_relative_frequency ( Iterator  first,
Iterator  last 
) -> std::vector<std::pair<typename std::iterator_traits<Iterator>::value_type, double>>

Return cumulative relative frequency (for sorted values)

Calculates the cumulative relative frequency up to each value. Results are sorted in ascending order by value.

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator
lastEnding iterator
Returns
Vector of (value, cumulative relative frequency) pairs

Definition at line 390 of file frequency_distribution.hpp.

◆ cumulative_relative_frequency() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::cumulative_relative_frequency ( Iterator  first,
Iterator  last,
Projection  proj 
) -> std::vector<std::pair<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>, double>>

Cumulative relative frequency with projection.

Returns the cumulative relative frequency of results after applying a projection function to each element. Results are sorted in ascending order by value.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator
lastEnding iterator
projProjection function
Returns
Vector of (value, cumulative relative frequency) pairs

Definition at line 427 of file frequency_distribution.hpp.

◆ cut_dendrogram()

std::vector< std::size_t > statcpp::cut_dendrogram ( const std::vector< dendrogram_node > &  dendrogram,
std::size_t  n_data,
std::size_t  k 
)
inline

Extract k clusters from dendrogram.

Cuts the dendrogram to extract k clusters.

Parameters
dendrogramDendrogram
n_dataNumber of data points
kNumber of clusters
Returns
Cluster labels
Exceptions
std::invalid_argumentIf k is invalid

Definition at line 425 of file clustering.hpp.

◆ cv_lasso()

std::pair< double, std::vector< double > > statcpp::cv_lasso ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
const std::vector< double > &  lambda_grid,
std::size_t  k = 5 
)
inline

Select optimal lambda for Lasso regression using cross-validation.

Performs k-fold cross-validation for a grid of lambda values and selects the lambda with minimum cross-validation error.

Parameters
XPredictor matrix (each row is one sample)
yResponse variable vector
lambda_gridVector of lambda values to evaluate
kNumber of folds (default: 5)
Returns
Pair of optimal lambda and cross-validation errors for each lambda

Definition at line 905 of file model_selection.hpp.

◆ cv_ridge()

std::pair< double, std::vector< double > > statcpp::cv_ridge ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
const std::vector< double > &  lambda_grid,
std::size_t  k = 5 
)
inline

Select optimal lambda for Ridge regression using cross-validation.

Performs k-fold cross-validation for a grid of lambda values and selects the lambda with minimum cross-validation error.

Parameters
XPredictor matrix (each row is one sample)
yResponse variable vector
lambda_gridVector of lambda values to evaluate
kNumber of folds (default: 5)
Returns
Pair of optimal lambda and cross-validation errors for each lambda

Definition at line 837 of file model_selection.hpp.

◆ d_to_r()

double statcpp::d_to_r ( double  d)
inline

Convert Cohen's d to correlation coefficient.

Parameters
dCohen's d
Returns
Correlation coefficient

Definition at line 260 of file effect_size.hpp.

◆ detect_outliers_iqr()

template<typename Iterator >
outlier_detection_result statcpp::detect_outliers_iqr ( Iterator  first,
Iterator  last,
double  k = 1.5 
)

Outlier detection using IQR method (Tukey's Fences)

Detects outliers using the interquartile range (Tukey's Fences).

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
kFence multiplier (default: 1.5, use 3.0 for extreme outliers)
Returns
Outlier detection result
Exceptions
std::invalid_argumentIf range is empty
Note
Standard box plots use k=1.5.

Definition at line 130 of file robust.hpp.

◆ detect_outliers_modified_zscore()

template<typename Iterator >
outlier_detection_result statcpp::detect_outliers_modified_zscore ( Iterator  first,
Iterator  last,
double  threshold = 3.5 
)

Outlier detection using Modified Z-score.

Detects outliers using MAD-based Modified Z-score (more robust).

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
thresholdModified Z-score threshold (default: 3.5)
Returns
Outlier detection result
Exceptions
std::invalid_argumentIf range is empty or MAD is zero
Note
More robust than standard Z-score. Less affected by outliers.

Definition at line 239 of file robust.hpp.

◆ detect_outliers_zscore()

template<typename Iterator >
outlier_detection_result statcpp::detect_outliers_zscore ( Iterator  first,
Iterator  last,
double  threshold = 3.0 
)

Outlier detection using Z-score.

Detects outliers using Z-score (standardized values).

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
thresholdZ-score threshold (default: 3.0)
Returns
Outlier detection result
Exceptions
std::invalid_argumentIf range has less than 2 elements or standard deviation is zero
Note
Assumes normal distribution. Sensitive to outliers.

Definition at line 190 of file robust.hpp.

◆ dffits()

std::vector< double > statcpp::dffits ( const std::vector< double > &  residuals,
const std::vector< double > &  hat_values,
double  mse 
)
inline

Calculate DFFITS.

Calculates DFFITS to measure the influence of each observation on predicted values.

Parameters
residualsResiduals
hat_valuesLeverage values (hat values)
mseMean squared error
Returns
DFFITS values
Exceptions
std::invalid_argumentIf parameters are invalid
Note
|DFFITS_i| > 2*sqrt(p/n) indicates the observation is influential.

Definition at line 418 of file robust.hpp.

◆ diagnose_missing_mechanism()

missing_mechanism statcpp::diagnose_missing_mechanism ( const std::vector< std::vector< double > > &  data)
inline

Simple diagnosis of missing mechanism.

Diagnoses the missing mechanism (MCAR, MAR, MNAR) of the data. Internally performs Little's MCAR test and estimates the missing mechanism based on the result.

Note
Distinguishing between MAR and MNAR is difficult with observed data alone, so if MCAR is rejected, it is conservatively classified as MAR.
Parameters
data2D data for diagnosis (rows: observations, columns: variables)
Returns
missing_mechanism Estimated missing mechanism

Definition at line 330 of file missing_data.hpp.

◆ diff()

template<typename Iterator >
std::vector< double > statcpp::diff ( Iterator  first,
Iterator  last,
std::size_t  order = 1 
)

Difference series (first-order or d-th order differencing)

Calculates the difference of time series data.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
orderDifferencing order (default: 1)
Returns
Vector of differenced series
Exceptions
std::invalid_argumentIf data is insufficient for the differencing order

Definition at line 417 of file time_series.hpp.

◆ discrete_uniform_cdf()

double statcpp::discrete_uniform_cdf ( std::int64_t  k,
std::int64_t  a,
std::int64_t  b 
)
inline

Discrete uniform distribution cumulative distribution function (CDF)

Parameters
kUpper bound
aLower bound (inclusive)
bUpper bound (inclusive)
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf a > b

Definition at line 864 of file discrete_distributions.hpp.

◆ discrete_uniform_pmf()

double statcpp::discrete_uniform_pmf ( std::int64_t  k,
std::int64_t  a,
std::int64_t  b 
)
inline

Discrete uniform distribution probability mass function (PMF)

P(X = k) = 1 / (b - a + 1) for a <= k <= b

Parameters
kValue
aLower bound (inclusive)
bUpper bound (inclusive)
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf a > b

Definition at line 844 of file discrete_distributions.hpp.

◆ discrete_uniform_quantile()

std::int64_t statcpp::discrete_uniform_quantile ( double  p,
std::int64_t  a,
std::int64_t  b 
)
inline

Discrete uniform distribution quantile function.

Parameters
pCumulative probability
aLower bound (inclusive)
bUpper bound (inclusive)
Returns
Smallest k such that P(X <= k) >= p
Exceptions
std::invalid_argumentIf a > b or p is outside [0, 1]

Definition at line 887 of file discrete_distributions.hpp.

◆ discrete_uniform_rand() [1/2]

std::int64_t statcpp::discrete_uniform_rand ( std::int64_t  a,
std::int64_t  b 
)
inline

Discrete uniform distribution random number generation (using default engine)

Parameters
aLower bound (inclusive)
bUpper bound (inclusive)
Returns
Generated random number

Definition at line 929 of file discrete_distributions.hpp.

◆ discrete_uniform_rand() [2/2]

template<typename Engine = default_random_engine>
std::int64_t statcpp::discrete_uniform_rand ( std::int64_t  a,
std::int64_t  b,
Engine &  engine 
)

Discrete uniform distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
aLower bound (inclusive)
bUpper bound (inclusive)
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf a > b

Definition at line 913 of file discrete_distributions.hpp.

◆ drop_duplicates()

template<typename T >
std::vector< T > statcpp::drop_duplicates ( const std::vector< T > &  data)

Drop duplicates.

Template Parameters
TData type
Parameters
dataData vector
Returns
Data with duplicates removed

Definition at line 723 of file data_wrangling.hpp.

◆ dropna() [1/2]

template<typename T >
std::vector< std::vector< T > > statcpp::dropna ( const std::vector< std::vector< T > > &  data)

Drop rows containing NA.

Template Parameters
TData type
Parameters
data2-dimensional data
Returns
Data containing only rows without NA

Definition at line 56 of file data_wrangling.hpp.

◆ dropna() [2/2]

template<typename T >
std::vector< T > statcpp::dropna ( const std::vector< T > &  data)

Drop NA from a 1-dimensional vector.

Template Parameters
TData type
Parameters
data1-dimensional data
Returns
Data without NA

Definition at line 85 of file data_wrangling.hpp.

◆ dunnett_posthoc()

posthoc_result statcpp::dunnett_posthoc ( const one_way_anova_result anova_result,
std::size_t  control_group = 0,
double  alpha = 0.05 
)
inline

Perform Dunnett's test for multiple comparisons against a control group.

Performs comparisons between a specified control group and all other groups as a post-hoc test following one-way ANOVA. Uses Bonferroni approximation.

Parameters
anova_resultResult from one-way ANOVA
control_groupIndex of the control group (default: 0)
alphaSignificance level (default: 0.05)
Returns
posthoc_result Post-hoc comparison results
Exceptions
std::invalid_argumentIf alpha is outside the range (0, 1)
std::invalid_argumentIf control_group is an invalid index

Definition at line 514 of file anova.hpp.

◆ elastic_net_regression()

regularized_regression_result statcpp::elastic_net_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
double  lambda,
double  alpha = 0.5,
bool  standardize = true,
std::size_t  max_iter = 1000,
double  tol = 1e-6 
)
inline

Perform Elastic Net regression (L1 + L2 regularization)

Solves Elastic Net regression using coordinate descent. Combines L1 and L2 penalties, achieving both Lasso's variable selection and Ridge's stability.

Parameters
XPredictor matrix (each row is one sample, no intercept column)
yResponse variable vector
lambdaRegularization parameter (>= 0)
alphaL1 penalty ratio (0 = Ridge, 1 = Lasso, default: 0.5)
standardizeWhether to standardize data (default: true)
max_iterMaximum number of iterations (default: 1000)
tolConvergence tolerance (default: 1e-6)
Returns
Regularized regression result
Exceptions
std::invalid_argumentIf lambda is negative, alpha is outside [0,1], data is empty, or X and y have different sizes

Definition at line 708 of file model_selection.hpp.

◆ erf()

double statcpp::erf ( double  x)
inline

Error function.

Computes the error function erf(x).

Parameters
xArgument
Returns
erf(x)
Note
Reference: Abramowitz and Stegun, 7.1.26
Uses Horner's method approximation

Definition at line 364 of file special_functions.hpp.

◆ erfc()

double statcpp::erfc ( double  x)
inline

Complementary error function.

Computes the complementary error function erfc(x) = 1 - erf(x).

Parameters
xArgument
Returns
erfc(x)

Definition at line 377 of file special_functions.hpp.

◆ eta_squared() [1/2]

double statcpp::eta_squared ( const one_way_anova_result result)
inline

Calculate Eta-squared for one-way ANOVA.

Effect size measure indicating the proportion of total variation accounted for by between-group variation.

Parameters
resultResult from one-way ANOVA
Returns
double Eta-squared value (range 0 to 1)

Definition at line 828 of file anova.hpp.

◆ eta_squared() [2/2]

double statcpp::eta_squared ( double  ss_effect,
double  ss_total 
)
inline

Calculate eta-squared from F-test.

Calculates the effect size from the sum of squares for effect and total.

Parameters
ss_effectSum of squares for effect
ss_totalTotal sum of squares
Returns
Eta-squared
Exceptions
std::invalid_argumentIf ss_total is not positive

Definition at line 296 of file effect_size.hpp.

◆ euclidean_distance() [1/3]

double statcpp::euclidean_distance ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
inline

Euclidean distance.

Computes the Euclidean distance between two vectors.

Parameters
aFirst vector
bSecond vector
Returns
Euclidean distance
Exceptions
std::invalid_argumentIf vector dimensions mismatch

Definition at line 39 of file clustering.hpp.

◆ euclidean_distance() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::euclidean_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Euclidean distance (L2 norm)

Computes the Euclidean distance between two points in n-dimensional space: d(x, y) = sqrt(sum((x_i - y_i)^2))

Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
Returns
Euclidean distance
Exceptions
std::invalid_argumentif sequences have different lengths

Definition at line 31 of file distance_metrics.hpp.

◆ euclidean_distance() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::euclidean_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Proj1  proj1,
Proj2  proj2 
)

Euclidean distance with projection.

Definition at line 62 of file distance_metrics.hpp.

◆ expm1_safe()

double statcpp::expm1_safe ( double  x)
inline

Safely compute exp(x) - 1 for small x.

Uses std::expm1 which is more accurate than exp(x) - 1 for small x

Parameters
xInput value
Returns
exp(x) - 1

Definition at line 185 of file numerical_utils.hpp.

◆ exponential_cdf()

double statcpp::exponential_cdf ( double  x,
double  lambda = 1.0 
)
inline

Exponential distribution cumulative distribution function (CDF)

F(x) = 1 - exp(-lambda*x)

Parameters
xRandom variable value
lambdaRate parameter (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf lambda <= 0

Definition at line 263 of file continuous_distributions.hpp.

◆ exponential_moving_average()

template<typename Iterator >
std::vector< double > statcpp::exponential_moving_average ( Iterator  first,
Iterator  last,
double  alpha 
)

Exponential moving average.

Calculates the exponential moving average using smoothing parameter alpha.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
alphaSmoothing parameter (0 < alpha <= 1)
Returns
Vector of exponential moving averages
Exceptions
std::invalid_argumentIf range is empty or alpha is outside (0, 1]

Definition at line 374 of file time_series.hpp.

◆ exponential_pdf()

double statcpp::exponential_pdf ( double  x,
double  lambda = 1.0 
)
inline

Exponential distribution probability density function (PDF)

f(x) = lambda * exp(-lambda*x) for x >= 0

Parameters
xRandom variable value
lambdaRate parameter (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf lambda <= 0

Definition at line 244 of file continuous_distributions.hpp.

◆ exponential_quantile()

double statcpp::exponential_quantile ( double  p,
double  lambda = 1.0 
)
inline

Exponential distribution quantile function.

Q(p) = -ln(1-p) / lambda

Parameters
pProbability (0 <= p < 1)
lambdaRate parameter (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf lambda <= 0 or p is outside [0, 1)

Definition at line 282 of file continuous_distributions.hpp.

◆ exponential_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::exponential_rand ( double  lambda,
Engine &  engine 
)

Exponential distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
lambdaRate parameter
engineRandom engine
Returns
Random number following exponential distribution
Exceptions
std::invalid_argumentIf lambda <= 0

Definition at line 304 of file continuous_distributions.hpp.

◆ exponential_rand() [2/2]

double statcpp::exponential_rand ( double  lambda = 1.0)
inline

Exponential distribution random number generation (using default engine)

Parameters
lambdaRate parameter (default: 1.0)
Returns
Random number following exponential distribution

Definition at line 319 of file continuous_distributions.hpp.

◆ extract_complete_cases()

complete_case_result statcpp::extract_complete_cases ( const std::vector< std::vector< double > > &  data)
inline

Extract complete cases.

Extracts only rows without missing values (complete cases) from the dataset. This is also called listwise deletion.

Parameters
dataInput data (rows: observations, columns: variables)
Returns
complete_case_result Complete case analysis result

Definition at line 1063 of file missing_data.hpp.

◆ f_cdf()

double statcpp::f_cdf ( double  x,
double  df1,
double  df2 
)
inline

F-distribution cumulative distribution function (CDF)

Computed using the incomplete beta function. F(x) = I_{d1*x/(d1*x + d2)}(d1/2, d2/2)

Parameters
xRandom variable value
df1First degrees of freedom
df2Second degrees of freedom
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf df1 <= 0 or df2 <= 0

Definition at line 862 of file continuous_distributions.hpp.

◆ f_pdf()

double statcpp::f_pdf ( double  x,
double  df1,
double  df2 
)
inline

F-distribution probability density function (PDF)

f(x) = sqrt((d1*x)^d1 * d2^d2 / (d1*x + d2)^(d1+d2)) / (x * B(d1/2, d2/2))

Parameters
xRandom variable value
df1First degrees of freedom
df2Second degrees of freedom
Returns
Probability density
Exceptions
std::invalid_argumentIf df1 <= 0 or df2 <= 0

Definition at line 832 of file continuous_distributions.hpp.

◆ f_quantile()

double statcpp::f_quantile ( double  p,
double  df1,
double  df2 
)
inline

F-distribution quantile function (Newton-Raphson method)

Parameters
pProbability (0 <= p <= 1)
df1First degrees of freedom
df2Second degrees of freedom
Returns
Quantile
Exceptions
std::invalid_argumentIf df1 <= 0, df2 <= 0, or p is outside [0, 1]
Note
Uses Newton-Raphson iteration with tolerance eps = 1e-10 and maximum 50 iterations. If the iteration does not converge within the maximum number of iterations, the best approximation so far is returned (no exception is thrown). For interior points (0 < p < 1), the result is a finite value. Boundary values p = 0 or p = 1 may return +/-infinity as per the distribution definition. In practice, convergence is achieved for all typical input ranges.

Definition at line 893 of file continuous_distributions.hpp.

◆ f_rand() [1/2]

double statcpp::f_rand ( double  df1,
double  df2 
)
inline

F-distribution random number generation (using default engine)

Parameters
df1First degrees of freedom
df2Second degrees of freedom
Returns
Random number following F-distribution

Definition at line 976 of file continuous_distributions.hpp.

◆ f_rand() [2/2]

template<typename Engine = default_random_engine>
double statcpp::f_rand ( double  df1,
double  df2,
Engine &  engine 
)

F-distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
df1First degrees of freedom
df2Second degrees of freedom
engineRandom engine
Returns
Random number following F-distribution
Exceptions
std::invalid_argumentIf df1 <= 0 or df2 <= 0

Definition at line 957 of file continuous_distributions.hpp.

◆ f_test()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::f_test ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

F-test (variance comparison)

Tests whether the variances of two samples are equal.

Template Parameters
Iterator1Input iterator type for first sample
Iterator2Input iterator type for second sample
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (F-statistic, p-value, df=df1, df2=df2)
Exceptions
std::invalid_argumentIf either sample has less than 2 elements or second sample variance is zero

Definition at line 634 of file parametric_tests.hpp.

◆ fillna()

template<typename T >
std::vector< T > statcpp::fillna ( const std::vector< T > &  data,
fill_value 
)

Fill NA with a specified value.

Template Parameters
TData type
Parameters
dataData vector
fill_valueValue to fill
Returns
Data with NA filled

Definition at line 110 of file data_wrangling.hpp.

◆ fillna_bfill()

std::vector< double > statcpp::fillna_bfill ( const std::vector< double > &  data)
inline

Fill NA with backward fill.

Parameters
dataData vector
Returns
Data with NA filled with backward values

Definition at line 196 of file data_wrangling.hpp.

◆ fillna_ffill()

std::vector< double > statcpp::fillna_ffill ( const std::vector< double > &  data)
inline

Fill NA with forward fill.

Parameters
dataData vector
Returns
Data with NA filled with forward values

Definition at line 176 of file data_wrangling.hpp.

◆ fillna_interpolate()

std::vector< double > statcpp::fillna_interpolate ( const std::vector< double > &  data)
inline

Fill NA with linear interpolation.

Parameters
dataData vector
Returns
Data with NA filled with linear interpolation

Definition at line 216 of file data_wrangling.hpp.

◆ fillna_mean()

std::vector< double > statcpp::fillna_mean ( const std::vector< double > &  data)
inline

Fill NA with mean.

Parameters
dataData vector
Returns
Data with NA filled with mean

Definition at line 128 of file data_wrangling.hpp.

◆ fillna_median()

std::vector< double > statcpp::fillna_median ( const std::vector< double > &  data)
inline

Fill NA with median.

Parameters
dataData vector
Returns
Data with NA filled with median

Definition at line 152 of file data_wrangling.hpp.

◆ filter()

template<typename T , typename Predicate >
std::vector< T > statcpp::filter ( const std::vector< T > &  data,
Predicate  pred 
)

Filter elements that match a condition.

Template Parameters
TData type
PredicatePredicate type
Parameters
dataData vector
predPredicate function
Returns
Vector of elements satisfying the condition

Definition at line 266 of file data_wrangling.hpp.

◆ filter_range()

template<typename T >
std::vector< T > statcpp::filter_range ( const std::vector< T > &  data,
min_val,
max_val 
)

Filter values within a range.

Template Parameters
TData type
Parameters
dataData vector
min_valMinimum value
max_valMaximum value
Returns
Vector of values within the range

Definition at line 310 of file data_wrangling.hpp.

◆ filter_rows()

template<typename T , typename Predicate >
std::vector< std::vector< T > > statcpp::filter_rows ( const std::vector< std::vector< T > > &  data,
Predicate  pred 
)

Filter rows that match a condition (2-dimensional)

Template Parameters
TData type
PredicatePredicate type
Parameters
data2-dimensional data
predPredicate function
Returns
Data containing only rows satisfying the condition

Definition at line 288 of file data_wrangling.hpp.

◆ find_tipping_point()

tipping_point_result statcpp::find_tipping_point ( const std::vector< double > &  data,
double  threshold = 0.0,
double  delta_min = -5.0,
double  delta_max = 5.0,
std::size_t  n_points = 100 
)
inline

Tipping point analysis.

Searches for the critical point (tipping point) where the estimated mean crosses the specified threshold. This allows assessment of how extreme the MNAR assumption must be to change conclusions.

Parameters
data1D data for analysis
thresholdThreshold (e.g., null hypothesis value)
delta_minMinimum delta value to search (default: -5.0)
delta_maxMaximum delta value to search (default: 5.0)
n_pointsNumber of search points (default: 100)
Returns
tipping_point_result Tipping point analysis result

Definition at line 985 of file missing_data.hpp.

◆ fisher_exact_test()

test_result statcpp::fisher_exact_test ( std::uint64_t  a,
std::uint64_t  b,
std::uint64_t  c,
std::uint64_t  d,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)
inline

Perform Fisher's exact test (2x2 contingency table)

Tests whether row and column variables are independent in a 2x2 contingency table. Uses exact probability calculation based on hypergeometric distribution, applicable even when expected frequencies are small.

Contingency table format:

| Col1 | Col2 | Row Total
Row1 | a | b | a+b
Row2 | c | d | c+d
Col | a+c | b+d | n
Parameters
aFrequency of cell (1,1)
bFrequency of cell (1,2)
cFrequency of cell (2,1)
dFrequency of cell (2,2)
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result containing odds ratio, p-value, and degrees of freedom (NaN)
Note
Null hypothesis: Row and column variables are independent (odds ratio = 1)
For two-sided test, sums probabilities of all tables with probability less than or equal to observed
If b or c is zero, odds ratio is infinity

Definition at line 925 of file nonparametric_tests.hpp.

◆ five_number_summary() [1/2]

template<typename Iterator >
five_number_summary_result statcpp::five_number_summary ( Iterator  first,
Iterator  last 
)

Return five-number summary.

Calculates five-number summary (min, Q1, median, Q3, max) from sorted range.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
Returns
Five-number summary
Exceptions
std::invalid_argumentIf range is empty
Note
Provides basic statistics needed for box plot visualization.

Definition at line 340 of file order_statistics.hpp.

◆ five_number_summary() [2/2]

template<typename Iterator , typename Projection >
five_number_summary_result statcpp::five_number_summary ( Iterator  first,
Iterator  last,
Projection  proj 
)

Return five-number summary with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
projProjection function
Returns
Five-number summary
Exceptions
std::invalid_argumentIf range is empty

Definition at line 373 of file order_statistics.hpp.

◆ frequency_count() [1/2]

template<typename Iterator >
auto statcpp::frequency_count ( Iterator  first,
Iterator  last 
) -> std::unordered_map<typename std::iterator_traits<Iterator>::value_type, std::size_t>

Return frequency for each value (unordered_map version, fast)

Counts the number of occurrences of each value. Sort order is not guaranteed, but operates faster.

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator
lastEnding iterator
Returns
Map of values and their frequencies

Definition at line 178 of file frequency_distribution.hpp.

◆ frequency_count() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::frequency_count ( Iterator  first,
Iterator  last,
Projection  proj 
) -> std::unordered_map<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>, std::size_t>

Frequency count with projection.

Returns the frequency of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator
lastEnding iterator
projProjection function
Returns
Map of values and their frequencies

Definition at line 203 of file frequency_distribution.hpp.

◆ frequency_table() [1/2]

template<typename Iterator >
auto statcpp::frequency_table ( Iterator  first,
Iterator  last 
) -> frequency_table_result<typename std::iterator_traits<Iterator>::value_type>

Create frequency table (returned with sorted keys)

Calculates frequency, relative frequency, cumulative frequency, and cumulative relative frequency for each value. Results are sorted in ascending order by key.

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator
lastEnding iterator
Returns
Frequency table result

Definition at line 74 of file frequency_distribution.hpp.

◆ frequency_table() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::frequency_table ( Iterator  first,
Iterator  last,
Projection  proj 
) -> frequency_table_result<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>>

Frequency table with projection.

Creates a frequency table of the results after applying a projection function to each element. Results are sorted in ascending order by key.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator
lastEnding iterator
projProjection function
Returns
Frequency table result

Definition at line 125 of file frequency_distribution.hpp.

◆ gamma_cdf()

double statcpp::gamma_cdf ( double  x,
double  shape,
double  rate = 1.0 
)
inline

Gamma distribution cumulative distribution function (CDF)

F(x) = P(alpha, beta*x) (regularized lower incomplete gamma function)

Parameters
xRandom variable value
shapeShape parameter alpha
rateRate parameter beta (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf shape <= 0 or rate <= 0

Definition at line 369 of file continuous_distributions.hpp.

◆ gamma_pdf()

double statcpp::gamma_pdf ( double  x,
double  shape,
double  rate = 1.0 
)
inline

Gamma distribution probability density function (PDF)

f(x) = (beta^alpha / Gamma(alpha)) * x^(alpha-1) * exp(-beta*x) for x > 0 Parameters: shape = alpha (k), rate = beta (1/theta)

Parameters
xRandom variable value
shapeShape parameter alpha
rateRate parameter beta (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf shape <= 0 or rate <= 0

Definition at line 340 of file continuous_distributions.hpp.

◆ gamma_quantile()

double statcpp::gamma_quantile ( double  p,
double  shape,
double  rate = 1.0 
)
inline

Gamma distribution quantile function.

Parameters
pProbability (0 <= p <= 1)
shapeShape parameter alpha
rateRate parameter beta (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf shape <= 0, rate <= 0, or p is outside [0, 1]

Definition at line 391 of file continuous_distributions.hpp.

◆ gamma_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::gamma_rand ( double  shape,
double  rate,
Engine &  engine 
)

Gamma distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
shapeShape parameter alpha
rateRate parameter beta
engineRandom engine
Returns
Random number following gamma distribution
Exceptions
std::invalid_argumentIf shape <= 0 or rate <= 0

Definition at line 419 of file continuous_distributions.hpp.

◆ gamma_rand() [2/2]

double statcpp::gamma_rand ( double  shape,
double  rate = 1.0 
)
inline

Gamma distribution random number generation (using default engine)

Parameters
shapeShape parameter alpha
rateRate parameter beta (default: 1.0)
Returns
Random number following gamma distribution

Definition at line 439 of file continuous_distributions.hpp.

◆ gammainc_lower()

double statcpp::gammainc_lower ( double  a,
double  x 
)
inline

Lower regularized incomplete gamma function.

Computes the lower regularized incomplete gamma function P(a, x) = gamma(a, x) / Gamma(a).

Parameters
aShape parameter (must be positive)
xUpper limit of integration (must be non-negative)
Returns
P(a, x)
Exceptions
std::domain_errorIf parameters are invalid
Note
Uses series expansion for x < a + 1, continued fraction for x >= a + 1

Definition at line 490 of file special_functions.hpp.

◆ gammainc_lower_inv()

double statcpp::gammainc_lower_inv ( double  a,
double  p 
)
inline

Inverse lower regularized incomplete gamma function.

Computes x such that P(a, x) = p.

Parameters
aShape parameter (must be positive)
pProbability value (must be in [0, 1])
Returns
x such that P(a, x) = p
Exceptions
std::domain_errorIf parameters are invalid
Note
Uses Newton-Raphson iteration
Uses Wilson-Hilferty approximation for initial guess when a > 1

Definition at line 573 of file special_functions.hpp.

◆ gammainc_upper()

double statcpp::gammainc_upper ( double  a,
double  x 
)
inline

Upper regularized incomplete gamma function.

Computes the upper regularized incomplete gamma function Q(a, x) = Gamma(a, x) / Gamma(a) = 1 - P(a, x).

Parameters
aShape parameter (must be positive)
xLower limit of integration (must be non-negative)
Returns
Q(a, x)
Exceptions
std::domain_errorIf parameters are invalid

Definition at line 555 of file special_functions.hpp.

◆ generate_lambda_grid()

std::vector< double > statcpp::generate_lambda_grid ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
std::size_t  n_lambda = 100,
double  lambda_min_ratio = 0.0001 
)
inline

Automatically generate lambda grid for regularized regression.

Calculates maximum lambda based on data and generates a grid of lambda values on a logarithmic scale.

Parameters
XPredictor matrix (each row is one sample)
yResponse variable vector
n_lambdaGrid size (default: 100)
lambda_min_ratioRatio of lambda_min to lambda_max (default: 0.0001)
Returns
Vector of lambda values equally spaced on logarithmic scale

Definition at line 972 of file model_selection.hpp.

◆ geometric_cdf()

double statcpp::geometric_cdf ( std::uint64_t  k,
double  p 
)
inline

Geometric distribution cumulative distribution function (CDF)

P(X <= k) = 1 - (1-p)^(k+1)

Parameters
kUpper bound of number of failures
pProbability of success in each trial
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf p is outside (0, 1]

Definition at line 346 of file discrete_distributions.hpp.

◆ geometric_mean() [1/2]

template<typename Iterator >
double statcpp::geometric_mean ( Iterator  first,
Iterator  last 
)

Geometric mean.

Computes the geometric mean of elements in the range. All values must be positive.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Geometric mean
Exceptions
std::invalid_argumentIf range is empty or if a value is zero or negative

Definition at line 449 of file basic_statistics.hpp.

◆ geometric_mean() [2/2]

template<typename Iterator , typename Projection >
double statcpp::geometric_mean ( Iterator  first,
Iterator  last,
Projection  proj 
)

Geometric mean of projected values using a lambda expression.

Computes the geometric mean of the results after applying a projection function to each element. All values must be positive.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Geometric mean of projected values
Exceptions
std::invalid_argumentIf range is empty or if a value is zero or negative

Definition at line 480 of file basic_statistics.hpp.

◆ geometric_pmf()

double statcpp::geometric_pmf ( std::uint64_t  k,
double  p 
)
inline

Geometric distribution probability mass function (PMF)

P(X = k) = (1-p)^k * p X = Number of failures before first success (support: k = 0, 1, 2, ...)

Parameters
kNumber of failures
pProbability of success in each trial
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf p is outside (0, 1]

Definition at line 326 of file discrete_distributions.hpp.

◆ geometric_quantile()

std::uint64_t statcpp::geometric_quantile ( double  prob,
double  p 
)
inline

Geometric distribution quantile function (inverse CDF)

Parameters
probCumulative probability
pProbability of success in each trial
Returns
Smallest k such that P(X <= k) >= prob
Exceptions
std::invalid_argumentIf prob is outside [0, 1] or p is outside (0, 1]

Definition at line 364 of file discrete_distributions.hpp.

◆ geometric_rand() [1/2]

std::uint64_t statcpp::geometric_rand ( double  p)
inline

Geometric distribution random number generation (using default engine)

Parameters
pProbability of success in each trial
Returns
Generated random number

Definition at line 408 of file discrete_distributions.hpp.

◆ geometric_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::geometric_rand ( double  p,
Engine &  engine 
)

Geometric distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
pProbability of success in each trial
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf p is outside (0, 1]

Definition at line 393 of file discrete_distributions.hpp.

◆ geometric_stddev() [1/2]

template<typename Iterator >
double statcpp::geometric_stddev ( Iterator  first,
Iterator  last 
)

Geometric standard deviation.

Computes the exponential of the standard deviation of log-transformed data. GSD = exp(sigma_ln) where sigma_ln is the standard deviation of ln(x) Useful for measuring dispersion of data following a log-normal distribution.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Geometric standard deviation
Exceptions
std::invalid_argumentIf the range is empty or values are non-positive

Definition at line 1515 of file dispersion_spread.hpp.

◆ geometric_stddev() [2/2]

template<typename Iterator , typename Projection >
double statcpp::geometric_stddev ( Iterator  first,
Iterator  last,
Projection  proj 
)

Geometric standard deviation (projection version)

Computes the geometric standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Geometric standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty or values are non-positive

Definition at line 1552 of file dispersion_spread.hpp.

◆ get_duplicates()

template<typename T >
std::vector< T > statcpp::get_duplicates ( const std::vector< T > &  data)

Get duplicate values.

Template Parameters
TData type
Parameters
dataData vector
Returns
Vector of duplicate values

Definition at line 760 of file data_wrangling.hpp.

◆ get_random_engine()

default_random_engine & statcpp::get_random_engine ( )
inline

Singleton accessor for global random engine.

Returns a thread-local random engine. Each thread can generate independent random sequences, making it thread-safe.

Returns
Reference to thread-local random engine

Definition at line 31 of file random_engine.hpp.

◆ glass_delta()

template<typename Iterator1 , typename Iterator2 >
double statcpp::glass_delta ( Iterator1  control_first,
Iterator1  control_last,
Iterator2  treatment_first,
Iterator2  treatment_last 
)

Glass's Delta (using control group's standard deviation)

Calculates the effect size using only the control group's standard deviation. Useful when the variances of the experimental and control groups differ substantially.

Template Parameters
Iterator1RandomAccessIterator type for control group
Iterator2RandomAccessIterator type for treatment group
Parameters
control_firstBeginning iterator of control group
control_lastEnding iterator of control group
treatment_firstBeginning iterator of treatment group
treatment_lastEnding iterator of treatment group
Returns
Glass's Delta
Exceptions
std::invalid_argumentIf control group has fewer than 2 elements, treatment group is empty, or control group has zero variance

Definition at line 214 of file effect_size.hpp.

◆ glm_fit()

glm_result statcpp::glm_fit ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
distribution_family  family = distribution_family::gaussian,
link_function  link = link_function::identity,
std::size_t  max_iter = 100,
double  tol = 1e-8 
)
inline

Fit a generalized linear model.

Estimates parameters of a generalized linear model using the IRLS (Iteratively Reweighted Least Squares) algorithm.

Parameters
XPredictor matrix (intercept is added automatically)
yResponse variable vector
familyDistribution family (default: gaussian)
linkLink function (default: identity)
max_iterMaximum number of iterations (default: 100)
tolConvergence tolerance (default: 1e-8)
Returns
GLM estimation results
Exceptions
std::invalid_argumentIf data is empty, X and Y sizes don't match, number of predictors is inconsistent, or number of observations is not greater than number of predictors
Note
If the IRLS algorithm does not converge within max_iter iterations, converged is set to false and coefficient_se, z_statistics, and p_values may contain NaN values. NaN indicates that the corresponding estimate is undefined due to numerical issues (not a bug). Always check glm_result::converged before using these fields.

Definition at line 401 of file glm.hpp.

◆ group_by()

template<typename K , typename V >
group_result< K, V > statcpp::group_by ( const std::vector< K > &  keys,
const std::vector< V > &  values 
)

Group by.

Template Parameters
KKey type
VValue type
Parameters
keysVector of keys
valuesVector of values
Returns
Grouping result

Definition at line 494 of file data_wrangling.hpp.

◆ group_count()

template<typename K >
aggregation_result< K > statcpp::group_count ( const std::vector< K > &  keys,
const std::vector< double > &  values 
)

Count per group.

Template Parameters
KKey type
Parameters
keysVector of keys
valuesVector of values
Returns
Element count for each group

Definition at line 555 of file data_wrangling.hpp.

◆ group_mean()

template<typename K >
aggregation_result< K > statcpp::group_mean ( const std::vector< K > &  keys,
const std::vector< double > &  values 
)

Mean per group.

Template Parameters
KKey type
Parameters
keysVector of keys
valuesVector of values
Returns
Mean value for each group

Definition at line 515 of file data_wrangling.hpp.

◆ group_sum()

template<typename K >
aggregation_result< K > statcpp::group_sum ( const std::vector< K > &  keys,
const std::vector< double > &  values 
)

Sum per group.

Template Parameters
KKey type
Parameters
keysVector of keys
valuesVector of values
Returns
Sum for each group

Definition at line 535 of file data_wrangling.hpp.

◆ harmonic_mean() [1/2]

template<typename Iterator >
double statcpp::harmonic_mean ( Iterator  first,
Iterator  last 
)

Harmonic mean.

Computes the harmonic mean of elements in the range. All values must be non-zero.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Harmonic mean
Exceptions
std::invalid_argumentIf range is empty or if a value is zero
Note
The current zero-detection threshold uses std::numeric_limits<double>::min() (smallest positive normal double, ~2.2e-308). This catches subnormals and zero, but users working with intentionally small positive values near this threshold should be aware of potential false rejections. A future version may allow a user-specified threshold.

Definition at line 519 of file basic_statistics.hpp.

◆ harmonic_mean() [2/2]

template<typename Iterator , typename Projection >
double statcpp::harmonic_mean ( Iterator  first,
Iterator  last,
Projection  proj 
)

Harmonic mean of projected values using a lambda expression.

Computes the harmonic mean of the results after applying a projection function to each element. All values must be non-zero.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Harmonic mean of projected values
Exceptions
std::invalid_argumentIf range is empty or if a value is zero

Definition at line 555 of file basic_statistics.hpp.

◆ has_converged()

bool statcpp::has_converged ( double  x_new,
double  x_old,
double  abs_tol = 1e-8,
double  rel_tol = 1e-6 
)
inline

Check for convergence using combined absolute and relative criteria.

Convergence criterion: |x_new - x_old| <= abs_tol + rel_tol * |x_old|

Parameters
x_newNew value
x_oldOld value
abs_tolAbsolute tolerance (default: 1e-8)
rel_tolRelative tolerance (default: 1e-6)
Returns
true if converged

Definition at line 156 of file numerical_utils.hpp.

◆ has_converged_abs()

bool statcpp::has_converged_abs ( double  x_new,
double  x_old,
double  tol = 1e-6 
)
inline

Check for convergence based on absolute change.

Convergence criterion: |x_new - x_old| <= tol

Parameters
x_newNew value
x_oldOld value
tolTolerance (default: 1e-6)
Returns
true if converged

Definition at line 122 of file numerical_utils.hpp.

◆ has_converged_rel()

bool statcpp::has_converged_rel ( double  x_new,
double  x_old,
double  tol = 1e-6 
)
inline

Check for convergence based on relative change.

Convergence criterion: |x_new - x_old| / max(|x_old|, eps) <= tol

Parameters
x_newNew value
x_oldOld value
tolTolerance (default: 1e-6)
Returns
true if converged

Definition at line 138 of file numerical_utils.hpp.

◆ hedges_correction_factor()

double statcpp::hedges_correction_factor ( double  df)
inline

Hedges' bias correction factor J.

Calculates the correction factor for small sample size bias.

Parameters
dfDegrees of freedom
Returns
Bias correction factor

Definition at line 133 of file effect_size.hpp.

◆ hedges_g()

template<typename Iterator >
double statcpp::hedges_g ( Iterator  first,
Iterator  last,
double  mu0 
)

Hedges' g (one-sample)

Calculates bias-corrected Cohen's d.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnding iterator
mu0Population mean to compare against
Returns
Hedges' g
Exceptions
std::invalid_argumentIf there are fewer than 2 elements

Definition at line 152 of file effect_size.hpp.

◆ hedges_g_two_sample()

template<typename Iterator1 , typename Iterator2 >
double statcpp::hedges_g_two_sample ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Hedges' g (two-sample)

Calculates bias-corrected standardized mean difference between two groups.

Template Parameters
Iterator1RandomAccessIterator type for first sample
Iterator2RandomAccessIterator type for second sample
Parameters
first1Beginning iterator of first sample
last1Ending iterator of first sample
first2Beginning iterator of second sample
last2Ending iterator of second sample
Returns
Hedges' g
Exceptions
std::invalid_argumentIf either sample has fewer than 2 elements

Definition at line 179 of file effect_size.hpp.

◆ hierarchical_clustering()

std::vector< dendrogram_node > statcpp::hierarchical_clustering ( const std::vector< std::vector< double > > &  data,
linkage_type  linkage = linkage_type::single 
)
inline

Hierarchical clustering.

Performs hierarchical clustering and generates a dendrogram.

Parameters
dataVector of data points
linkageLinkage type (default: single)
Returns
Dendrogram
Exceptions
std::invalid_argumentIf data is empty
Note
Has O(n^3) time complexity. Not suitable for large datasets.

Definition at line 302 of file clustering.hpp.

◆ hodges_lehmann()

template<typename Iterator >
double statcpp::hodges_lehmann ( Iterator  first,
Iterator  last 
)

Hodges-Lehmann estimator.

Calculates the median of all pairwise averages (Walsh average).

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
Returns
Hodges-Lehmann estimate
Exceptions
std::invalid_argumentIf range is empty
Note
A robust location estimator. Less affected by outliers.

Definition at line 475 of file robust.hpp.

◆ holm_correction()

std::vector< double > statcpp::holm_correction ( const std::vector< double > &  p_values)
inline

Holm correction (step-down Bonferroni method)

Corrects p-values for multiple testing using the Holm method. A step-down version of Bonferroni correction with higher power.

Parameters
p_valuesVector of original p-values
Returns
std::vector<double> Vector of corrected p-values

Definition at line 751 of file parametric_tests.hpp.

◆ hypergeom_cdf()

double statcpp::hypergeom_cdf ( std::uint64_t  k,
std::uint64_t  N,
std::uint64_t  K,
std::uint64_t  n 
)
inline

Hypergeometric distribution cumulative distribution function (CDF)

Calculates P(X <= k).

Parameters
kUpper bound of success draws
NPopulation size
KNumber of success states in population
nNumber of draws
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 460 of file discrete_distributions.hpp.

◆ hypergeom_pmf()

double statcpp::hypergeom_pmf ( std::uint64_t  k,
std::uint64_t  N,
std::uint64_t  K,
std::uint64_t  n 
)
inline

Hypergeometric distribution probability mass function (PMF)

P(X = k) = C(K, k) * C(N-K, n-k) / C(N, n)

Parameters
kNumber of success draws
NPopulation size
KNumber of success states in population
nNumber of draws
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf parameters are invalid (K > N or n > N)

Definition at line 429 of file discrete_distributions.hpp.

◆ hypergeom_quantile()

std::uint64_t statcpp::hypergeom_quantile ( double  p,
std::uint64_t  N,
std::uint64_t  K,
std::uint64_t  n 
)
inline

Hypergeometric distribution quantile function (inverse CDF)

Parameters
pCumulative probability
NPopulation size
KNumber of success states in population
nNumber of draws
Returns
Smallest k such that P(X <= k) >= p
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 491 of file discrete_distributions.hpp.

◆ hypergeom_rand() [1/2]

std::uint64_t statcpp::hypergeom_rand ( std::uint64_t  N,
std::uint64_t  K,
std::uint64_t  n 
)
inline

Hypergeometric distribution random number generation (using default engine)

Parameters
NPopulation size
KNumber of success states in population
nNumber of draws
Returns
Generated random number

Definition at line 568 of file discrete_distributions.hpp.

◆ hypergeom_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::hypergeom_rand ( std::uint64_t  N,
std::uint64_t  K,
std::uint64_t  n,
Engine &  engine 
)

Hypergeometric distribution random number generation.

Uses direct sampling method (suitable for moderate n).

Template Parameters
EngineRandom engine type
Parameters
NPopulation size
KNumber of success states in population
nNumber of draws
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 532 of file discrete_distributions.hpp.

◆ impute_conditional_mean()

std::vector< double > statcpp::impute_conditional_mean ( const std::vector< std::vector< double > > &  data,
std::size_t  target_col,
const std::vector< std::size_t > &  predictor_cols 
)
inline

Single imputation by conditional mean.

Imputes missing values with conditional mean using simple linear regression with predictor variables.

Parameters
dataInput data (rows: observations, columns: variables)
target_colColumn index for imputation target
predictor_colsColumn indices for predictor variables
Returns
std::vector<double> Values of target_col after imputation

Definition at line 375 of file missing_data.hpp.

◆ in_range()

bool statcpp::in_range ( double  x,
double  min_val,
double  max_val 
)
inline

Check if a value is in range [min_val, max_val].

Parameters
xValue to check
min_valMinimum value
max_valMaximum value
Returns
true if min_val <= x <= max_val

Definition at line 215 of file numerical_utils.hpp.

◆ incidence_rate_ratios()

std::vector< double > statcpp::incidence_rate_ratios ( const glm_result model)
inline

Calculate Incidence Rate Ratios.

Calculates incidence rate ratios from Poisson regression model coefficients.

Parameters
modelFitted Poisson regression model
Returns
Vector of incidence rate ratios for each predictor (excluding intercept)
Exceptions
std::invalid_argumentIf model is not Poisson regression

Definition at line 850 of file glm.hpp.

◆ interpolate_at() [1/2]

template<typename Iterator >
double statcpp::interpolate_at ( Iterator  first,
std::size_t  n,
double  p 
)

Linear interpolation at position.

Decomposes position p * (n-1) into integer part lo and fractional part frac, then performs linear interpolation.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of sorted range
nNumber of elements
pPosition (0.0 to 1.0)
Returns
Interpolated value
Note
Assumes sorted range.

Definition at line 66 of file order_statistics.hpp.

◆ interpolate_at() [2/2]

template<typename Iterator , typename Projection >
double statcpp::interpolate_at ( Iterator  first,
std::size_t  n,
double  p,
Projection  proj 
)

Linear interpolation at position with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of sorted range
nNumber of elements
pPosition (0.0 to 1.0)
projProjection function
Returns
Interpolated value

Definition at line 96 of file order_statistics.hpp.

◆ interpret_cohens_d()

effect_size_magnitude statcpp::interpret_cohens_d ( double  d)
inline

Interpret Cohen's d.

Determines the magnitude of effect size based on Cohen (1988) criteria.

Parameters
dCohen's d
Returns
Effect size magnitude

Definition at line 441 of file effect_size.hpp.

◆ interpret_correlation()

effect_size_magnitude statcpp::interpret_correlation ( double  r)
inline

Interpret correlation coefficient.

Determines the strength of correlation based on Cohen (1988) criteria.

Parameters
rCorrelation coefficient
Returns
Effect size magnitude

Definition at line 458 of file effect_size.hpp.

◆ interpret_eta_squared()

effect_size_magnitude statcpp::interpret_eta_squared ( double  eta2)
inline

Interpret eta-squared.

Determines the magnitude of effect size based on Cohen (1988) criteria.

Parameters
eta2Eta-squared
Returns
Effect size magnitude

Definition at line 475 of file effect_size.hpp.

◆ iqr() [1/2]

template<typename Iterator >
double statcpp::iqr ( Iterator  first,
Iterator  last 
)

Interquartile range (accepts a sorted range)

Computes the difference between the third and first quartiles. Useful for measuring the spread of the middle 50% of the data.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Interquartile range (Q3 - Q1)
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 956 of file dispersion_spread.hpp.

◆ iqr() [2/2]

template<typename Iterator , typename Projection >
double statcpp::iqr ( Iterator  first,
Iterator  last,
Projection  proj 
)

Interquartile range of projected values (projection results must be in sorted order)

Computes the interquartile range of results after applying a projection function to each element. Assumes projection results are in sorted order.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Interquartile range of projected values (Q3 - Q1)
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 982 of file dispersion_spread.hpp.

◆ is_finite()

bool statcpp::is_finite ( double  x)
inline

Check if a value is finite (not infinity or NaN)

Parameters
xValue to check
Returns
true if x is finite

Definition at line 88 of file numerical_utils.hpp.

◆ is_na()

bool statcpp::is_na ( double  x)
inline

Check if a value is NA.

Parameters
xValue to check
Returns
true if NA, false otherwise

Definition at line 45 of file data_wrangling.hpp.

◆ is_zero()

bool statcpp::is_zero ( double  x,
double  tol = default_abs_tol 
)
inline

Check if a value is close to zero.

Parameters
xValue to check
tolTolerance (default: 1e-12)
Returns
true if |x| <= tol

Definition at line 77 of file numerical_utils.hpp.

◆ kahan_sum() [1/2]

template<typename Iterator >
double statcpp::kahan_sum ( Iterator  first,
Iterator  last 
)

Compute sum with Kahan summation algorithm.

Kahan summation reduces numerical error in summing a sequence of floating-point numbers. More accurate than naive summation for large sequences or when values vary widely in magnitude.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning of sequence
lastEnd of sequence
Returns
Sum of elements using Kahan algorithm

Definition at line 264 of file numerical_utils.hpp.

◆ kahan_sum() [2/2]

template<typename Iterator , typename Proj >
double statcpp::kahan_sum ( Iterator  first,
Iterator  last,
Proj  proj 
)

Compute sum with Kahan summation algorithm (with projection)

Definition at line 284 of file numerical_utils.hpp.

◆ kaplan_meier()

kaplan_meier_result statcpp::kaplan_meier ( const std::vector< double > &  times,
const std::vector< bool > &  events 
)
inline

Estimate Kaplan-Meier survival curve.

Estimates the survival curve from survival time data including censored observations. Calculates standard errors using Greenwood's formula and provides 95% confidence intervals.

Parameters
timesVector of observation times
eventsEvent occurrence flags (true = event occurred, false = censored)
Returns
Kaplan-Meier estimation result
Exceptions
std::invalid_argumentIf times and events have different sizes or data is empty

Definition at line 54 of file survival.hpp.

◆ kendall_tau() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::kendall_tau ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Kendall's rank correlation coefficient (tau-b)

Computes Kendall's rank correlation coefficient (tau-b) of two variables. This version accounts for ties. tau_b = (concordant - discordant) / sqrt((n0 - tie_x) * (n0 - tie_y))

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Kendall's tau-b (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 735 of file correlation_covariance.hpp.

◆ kendall_tau() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::kendall_tau ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Kendall's rank correlation coefficient (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Kendall's tau-b (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 829 of file correlation_covariance.hpp.

◆ kmeans()

kmeans_result statcpp::kmeans ( const std::vector< std::vector< double > > &  data,
std::size_t  k,
std::size_t  max_iter = 100,
double  tol = 1e-6 
)
inline

K-means clustering.

Performs clustering using the K-means algorithm.

Parameters
dataVector of data points
kNumber of clusters
max_iterMaximum number of iterations (default: 100)
tolConvergence tolerance (default: 1e-6)
Returns
Clustering result
Exceptions
std::invalid_argumentIf data is empty, k is 0, or k exceeds number of data points

Definition at line 168 of file clustering.hpp.

◆ kmeans_plusplus_init()

std::vector< std::vector< double > > statcpp::kmeans_plusplus_init ( const std::vector< std::vector< double > > &  data,
std::size_t  k 
)
inline

K-means++ initialization.

Selects initial cluster centroids using the K-means++ algorithm.

Parameters
dataVector of data points
kNumber of clusters
Returns
Initial cluster centroids
Note
Arthur & Vassilvitskii (2007) "k-means++: the advantages of careful seeding"

Definition at line 101 of file clustering.hpp.

◆ kruskal_wallis_test()

test_result statcpp::kruskal_wallis_test ( const std::vector< std::vector< double > > &  groups)
inline

Perform Kruskal-Wallis test (k-sample)

Tests whether three or more independent samples come from the same distribution. The nonparametric version of one-way ANOVA that does not assume normal distribution. Uses chi-square approximation for p-value calculation.

Parameters
groupsVector of vectors containing data for each group
Returns
test_result Test result containing H statistic, p-value, and degrees of freedom (k-1)
Exceptions
std::invalid_argumentIf there are fewer than 2 groups
std::invalid_argumentIf any group is empty
Note
Null hypothesis: All groups are drawn from the same distribution
Larger H statistic indicates greater differences between groups

Definition at line 805 of file nonparametric_tests.hpp.

◆ ks_test_normal()

template<typename Iterator >
test_result statcpp::ks_test_normal ( Iterator  first,
Iterator  last 
)

Perform Kolmogorov-Smirnov test for normality (deprecated)

Deprecated:
Use lilliefors_test() instead. This function will be removed in a future version. The implementation is actually a Lilliefors test (parameters estimated from data), not a standard KS test with known parameters.

Definition at line 372 of file nonparametric_tests.hpp.

◆ kurtosis() [1/4]

template<typename Iterator >
double statcpp::kurtosis ( Iterator  first,
Iterator  last 
)

Calculate kurtosis (alias for sample_kurtosis)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Sample kurtosis value

Definition at line 635 of file shape_of_distribution.hpp.

◆ kurtosis() [2/4]

template<typename Iterator >
double statcpp::kurtosis ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate kurtosis (precomputed mean version)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Sample kurtosis value

Definition at line 650 of file shape_of_distribution.hpp.

◆ kurtosis() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::kurtosis ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate kurtosis (projection version)

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Sample kurtosis value

Definition at line 669 of file shape_of_distribution.hpp.

◆ kurtosis() [4/4]

template<typename Iterator , typename Projection >
double statcpp::kurtosis ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate kurtosis (projection version, precomputed mean)

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample kurtosis value

Definition at line 686 of file shape_of_distribution.hpp.

◆ label_encode()

template<typename T >
label_encoding_result< T > statcpp::label_encode ( const std::vector< T > &  data)

Label encoding.

Template Parameters
TData type
Parameters
dataData vector
Returns
Label encoding result

Definition at line 969 of file data_wrangling.hpp.

◆ lag()

template<typename Iterator >
std::vector< double > statcpp::lag ( Iterator  first,
Iterator  last,
std::size_t  k 
)

Generate lag series.

Creates a lag series from time series data.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
kLag
Returns
Vector of lag series
Exceptions
std::invalid_argumentIf lag exceeds data length

Definition at line 499 of file time_series.hpp.

◆ lasso_regression()

regularized_regression_result statcpp::lasso_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
double  lambda,
bool  standardize = true,
std::size_t  max_iter = 1000,
double  tol = 1e-6 
)
inline

Perform Lasso regression (L1 regularization)

Solves Lasso regression using coordinate descent. L1 penalty shrinks some coefficients exactly to zero, performing variable selection.

Parameters
XPredictor matrix (each row is one sample, no intercept column)
yResponse variable vector
lambdaRegularization parameter (>= 0)
standardizeWhether to standardize data (default: true)
max_iterMaximum number of iterations (default: 1000)
tolConvergence tolerance (default: 1e-6)
Returns
Regularized regression result
Exceptions
std::invalid_argumentIf lambda is negative, data is empty, or X and y have different sizes

Definition at line 582 of file model_selection.hpp.

◆ lbeta()

double statcpp::lbeta ( double  a,
double  b 
)
inline

Log-beta function.

Computes the natural logarithm of the beta function.

Parameters
aFirst parameter (must be positive)
bSecond parameter (must be positive)
Returns
log(B(a, b))
Exceptions
std::domain_errorIf a or b is non-positive

Definition at line 166 of file special_functions.hpp.

◆ levene_test()

test_result statcpp::levene_test ( const std::vector< std::vector< double > > &  groups)
inline

Perform Levene test (homogeneity of variance test)

Tests whether variances are equal across multiple groups. Uses the median-based Brown-Forsythe version, which is robust to departures from normality.

Parameters
groupsVector of vectors containing data for each group
Returns
test_result Test result containing F statistic, p-value, and degrees of freedom
Exceptions
std::invalid_argumentIf there are fewer than 2 groups
std::invalid_argumentIf any group has fewer than 2 elements
Note
Null hypothesis: All groups have equal variance
Larger F statistic indicates greater heterogeneity of variance

Definition at line 397 of file nonparametric_tests.hpp.

◆ lgamma()

double statcpp::lgamma ( double  x)
inline

Log-gamma function.

Computes the natural logarithm of the gamma function.

Parameters
xArgument
Returns
log(Gamma(x))
Exceptions
std::domain_errorIf x is a non-positive integer

Definition at line 100 of file special_functions.hpp.

◆ lgamma_impl()

double statcpp::lgamma_impl ( double  x)
inline

Internal log-gamma function implementation.

Calculates log(Gamma(x)) using Lanczos approximation.

Parameters
xArgument (must be positive or non-integer if negative)
Returns
log(Gamma(x))
Exceptions
std::domain_errorIf x is a non-positive integer
Note
Reference: Numerical Recipes, Press et al.
Uses Lanczos coefficients for g=7

Definition at line 57 of file special_functions.hpp.

◆ lilliefors_test()

template<typename Iterator >
test_result statcpp::lilliefors_test ( Iterator  first,
Iterator  last 
)

Perform Lilliefors test for normality.

Tests whether data follows a normal distribution. This is a Lilliefors test (not a standard KS test): parameters (mean, variance) are estimated from data, and the Lilliefors correction is applied to the p-value.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of range
lastEnding iterator of range
Returns
test_result Test result containing D statistic, p-value, and sample size
Exceptions
std::invalid_argumentIf there are fewer than 2 elements
std::invalid_argumentIf variance is zero
Note
Null hypothesis: Data follows a normal distribution
Larger D statistic indicates greater deviation from normal distribution
The current implementation uses an asymptotic approximation formula. Future versions may adopt more precise critical values (e.g., Dallal & Wilkinson 1986).
The Lilliefors asymptotic approximation may be imprecise for small samples (n < 20) or in extreme tail regions (very small p-values). For small samples, consider using the Shapiro-Wilk test as an alternative.

Definition at line 312 of file nonparametric_tests.hpp.

◆ log1p_safe()

double statcpp::log1p_safe ( double  x)
inline

Safely compute log(1 + x) for small x.

Uses std::log1p which is more accurate than log(1 + x) for small x

Parameters
xInput value
Returns
log(1 + x)

Definition at line 172 of file numerical_utils.hpp.

◆ log1p_transform()

std::vector< double > statcpp::log1p_transform ( const std::vector< double > &  data)
inline

Logarithmic transformation (log1p: log(1 + x))

Parameters
dataData vector
Returns
log1p-transformed data (values < -1 become NA)

Definition at line 346 of file data_wrangling.hpp.

◆ log_binomial_coef()

double statcpp::log_binomial_coef ( std::uint64_t  n,
std::uint64_t  k 
)
inline

Calculate log binomial coefficient.

Calculates log(C(n, k)) = log(n! / (k! * (n-k)!))

Parameters
nTotal number of elements
kNumber of elements to choose
Returns
Value of log(C(n, k))

Definition at line 49 of file discrete_distributions.hpp.

◆ log_factorial()

double statcpp::log_factorial ( std::uint64_t  n)
inline

Calculate log factorial.

Parameters
nNon-negative integer
Returns
Value of log(n!)

Definition at line 34 of file discrete_distributions.hpp.

◆ log_transform()

std::vector< double > statcpp::log_transform ( const std::vector< double > &  data)
inline

Logarithmic transformation (natural logarithm)

Parameters
dataData vector
Returns
Log-transformed data (values <= 0 become NA)

Definition at line 326 of file data_wrangling.hpp.

◆ logarithmic_mean()

template<typename T1 , typename T2 >
double statcpp::logarithmic_mean ( T1  a,
T2  b 
)

Logarithmic Mean.

Computes the logarithmic mean of two positive values. LM(a, b) = (b - a) / (ln(b) - ln(a)) for a != b LM(a, a) = a

Template Parameters
T1Type of first argument
T2Type of second argument
Parameters
aFirst value
bSecond value
Returns
Logarithmic mean
Exceptions
std::invalid_argumentIf arguments are not positive

Definition at line 845 of file basic_statistics.hpp.

◆ logistic_regression()

glm_result statcpp::logistic_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
std::size_t  max_iter = 100,
double  tol = 1e-8 
)
inline

Logistic regression.

Fits a generalized linear model using binomial distribution and logit link function.

Parameters
XPredictor matrix (intercept is added automatically)
yResponse variable vector (range 0 to 1)
max_iterMaximum number of iterations (default: 100)
tolConvergence tolerance (default: 1e-8)
Returns
GLM estimation results
Exceptions
std::invalid_argumentIf y is outside [0,1] range or X contains an intercept column

Definition at line 675 of file glm.hpp.

◆ lognormal_cdf()

double statcpp::lognormal_cdf ( double  x,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Log-normal distribution cumulative distribution function (CDF)

F(x) = Phi((ln(x) - mu) / sigma)

Parameters
xRandom variable value
muLog-mean (default: 0.0)
sigmaLog-standard deviation (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 1020 of file continuous_distributions.hpp.

◆ lognormal_pdf()

double statcpp::lognormal_pdf ( double  x,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Log-normal distribution probability density function (PDF)

f(x) = (1 / (x * sigma * sqrt(2*pi))) * exp(-(ln(x) - mu)^2 / (2*sigma^2))

Parameters
xRandom variable value
muLog-mean (default: 0.0)
sigmaLog-standard deviation (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 996 of file continuous_distributions.hpp.

◆ lognormal_quantile()

double statcpp::lognormal_quantile ( double  p,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Log-normal distribution quantile function.

Q(p) = exp(mu + sigma * Phi^(-1)(p))

Parameters
pProbability (0 < p < 1)
muLog-mean (default: 0.0)
sigmaLog-standard deviation (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf sigma <= 0 or p is outside (0, 1)

Definition at line 1043 of file continuous_distributions.hpp.

◆ lognormal_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::lognormal_rand ( double  mu,
double  sigma,
Engine &  engine 
)

Log-normal distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
muLog-mean
sigmaLog-standard deviation
engineRandom engine
Returns
Random number following log-normal distribution
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 1067 of file continuous_distributions.hpp.

◆ lognormal_rand() [2/2]

double statcpp::lognormal_rand ( double  mu = 0.0,
double  sigma = 1.0 
)
inline

Log-normal distribution random number generation (using default engine)

Parameters
muLog-mean (default: 0.0)
sigmaLog-standard deviation (default: 1.0)
Returns
Random number following log-normal distribution

Definition at line 1083 of file continuous_distributions.hpp.

◆ logrank_test()

logrank_result statcpp::logrank_test ( const std::vector< double > &  times1,
const std::vector< bool > &  events1,
const std::vector< double > &  times2,
const std::vector< bool > &  events2 
)
inline

Log-rank test (comparison of two survival curves)

Tests whether the survival curves of two groups are equal. A nonparametric test that considers the risk set at each time point.

Parameters
times1Observation times for group 1
events1Event occurrence flags for group 1
times2Observation times for group 2
events2Event occurrence flags for group 2
Returns
Log-rank test result
Exceptions
std::invalid_argumentIf times and events sizes don't match or data is empty

Definition at line 184 of file survival.hpp.

◆ loocv_linear()

cv_result statcpp::loocv_linear ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y 
)
inline

Perform leave-one-out cross-validation.

Performs cross-validation using each sample as test data one at a time.

Parameters
XPredictor matrix (each row is one sample)
yResponse variable vector
Returns
Cross-validation result

Definition at line 366 of file model_selection.hpp.

◆ mad()

template<typename Iterator >
double statcpp::mad ( Iterator  first,
Iterator  last 
)

Median Absolute Deviation (MAD)

Computes the median of absolute deviations from the median.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
Returns
MAD value
Exceptions
std::invalid_argumentIf range is empty
Note
Used as a robust estimator of variance.

Definition at line 42 of file robust.hpp.

◆ mad_scaled()

template<typename Iterator >
double statcpp::mad_scaled ( Iterator  first,
Iterator  last 
)

Scaled MAD for normal distribution.

Computes MAD scaled to estimate standard deviation for normal distribution.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
Returns
Scaled MAD value
Exceptions
std::invalid_argumentIf range is empty
Note
Scale factor derivation: For standard normal N(0,1), the median of absolute deviations |X - 0| = |X| is the inverse of the normal quantile function at 0.75, approximately 0.6745. Therefore, to use MAD as an estimator of standard deviation sigma: sigma = MAD / 0.6745 = MAD * 1.4826

This factor is exact only when the data follows a normal distribution. For non-normal distributions, the standard deviation estimate using this factor is an approximation.

Definition at line 93 of file robust.hpp.

◆ mae()

template<typename Iterator1 , typename Iterator2 >
double statcpp::mae ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2 
)

Mean Absolute Error (MAE)

Calculates the mean absolute error between actual and predicted values.

Template Parameters
Iterator1RandomAccessIterator type for actual values
Iterator2RandomAccessIterator type for predicted values
Parameters
first1Beginning iterator of actual values
last1End iterator of actual values
first2Beginning iterator of predicted values
Returns
MAE
Exceptions
std::invalid_argumentIf range is empty

Definition at line 207 of file time_series.hpp.

◆ mahalanobis_distance()

double statcpp::mahalanobis_distance ( const std::vector< double > &  x,
const std::vector< double > &  mean,
const std::vector< std::vector< double > > &  cov_matrix 
)
inline

Mahalanobis distance.

Computes the Mahalanobis distance between a point and a distribution. This accounts for correlations in the data and is scale-invariant.

For a point x and a distribution with mean μ and covariance matrix Σ: d(x, μ) = sqrt((x - μ)ᵀ Σ⁻¹ (x - μ))

Current implementation supports 2-dimensional data only.

Parameters
xPoint to measure distance from
meanMean of the distribution
cov_matrixCovariance matrix (2x2)
Returns
Mahalanobis distance
Exceptions
std::invalid_argumentif dimensions mismatch or covariance matrix is singular

Definition at line 322 of file distance_metrics.hpp.

◆ manhattan_distance() [1/3]

double statcpp::manhattan_distance ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
inline

Manhattan distance.

Computes the Manhattan distance between two vectors.

Parameters
aFirst vector
bSecond vector
Returns
Manhattan distance
Exceptions
std::invalid_argumentIf vector dimensions mismatch

Definition at line 63 of file clustering.hpp.

◆ manhattan_distance() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::manhattan_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Manhattan distance (L1 norm, taxicab distance)

Computes the Manhattan distance between two points: d(x, y) = sum(|x_i - y_i|)

Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
Returns
Manhattan distance
Exceptions
std::invalid_argumentif sequences have different lengths

Definition at line 108 of file distance_metrics.hpp.

◆ manhattan_distance() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::manhattan_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Proj1  proj1,
Proj2  proj2 
)

Manhattan distance with projection.

Definition at line 139 of file distance_metrics.hpp.

◆ mann_whitney_u_test()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::mann_whitney_u_test ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided,
bool  correct = true 
)

Perform Mann-Whitney U test (two-sample)

Tests whether two independent samples come from the same distribution. Also known as Wilcoxon rank-sum test, a nonparametric test that does not assume normal distribution. Uses normal approximation for p-value calculation.

Template Parameters
Iterator1Iterator type for first sample
Iterator2Iterator type for second sample
Parameters
first1Beginning iterator of first sample
last1Ending iterator of first sample
first2Beginning iterator of second sample
last2Ending iterator of second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result containing U1 statistic, p-value, and total sample size
Exceptions
std::invalid_argumentIf either sample has fewer than 2 elements
Note
Null hypothesis: Two samples are drawn from the same distribution
U1 is calculated from the rank sum of the first sample

Definition at line 672 of file nonparametric_tests.hpp.

◆ mape()

template<typename Iterator1 , typename Iterator2 >
double statcpp::mape ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2 
)

Mean Absolute Percentage Error (MAPE)

Calculates the mean absolute percentage error between actual and predicted values.

Template Parameters
Iterator1RandomAccessIterator type for actual values
Iterator2RandomAccessIterator type for predicted values
Parameters
first1Beginning iterator of actual values
last1End iterator of actual values
first2Beginning iterator of predicted values
Returns
MAPE (percentage)
Exceptions
std::invalid_argumentIf range is empty or all actual values are zero

Definition at line 285 of file time_series.hpp.

◆ margin_of_error_mean() [1/2]

template<typename Iterator , typename Projection >
double statcpp::margin_of_error_mean ( Iterator  first,
Iterator  last,
double  confidence,
Projection  proj 
)

Calculate margin of error for mean (projection version)

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
confidenceConfidence level
projProjection function
Returns
Margin of error
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or there are fewer than 2 elements

Definition at line 499 of file estimation.hpp.

◆ margin_of_error_mean() [2/2]

template<typename Iterator >
double statcpp::margin_of_error_mean ( Iterator  first,
Iterator  last,
double  confidence = 0.95 
)

Calculate margin of error for mean.

MoE = t_{alpha/2, df} * SE

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
confidenceConfidence level (default: 0.95)
Returns
Margin of error
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or there are fewer than 2 elements

Definition at line 467 of file estimation.hpp.

◆ margin_of_error_proportion()

double statcpp::margin_of_error_proportion ( std::size_t  successes,
std::size_t  n,
double  confidence = 0.95 
)
inline

Calculate margin of error for proportion.

MoE = z_{alpha/2} * sqrt(p(1-p)/n)

Parameters
successesNumber of successes
nSample size
confidenceConfidence level (default: 0.95)
Returns
Margin of error
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1), n is 0, or successes exceeds n

Definition at line 529 of file estimation.hpp.

◆ margin_of_error_proportion_worst_case()

double statcpp::margin_of_error_proportion_worst_case ( std::size_t  n,
double  confidence = 0.95 
)
inline

Calculate worst-case margin of error for proportion.

Maximum at p=0.5: MoE = z_{alpha/2} * 0.5/sqrt(n)

Parameters
nSample size
confidenceConfidence level (default: 0.95)
Returns
Margin of error
Exceptions
std::invalid_argumentIf confidence level is outside (0, 1) or n is 0

Definition at line 560 of file estimation.hpp.

◆ maximum() [1/2]

template<typename Iterator >
auto statcpp::maximum ( Iterator  first,
Iterator  last 
)

Return maximum value.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
Returns
Maximum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 177 of file order_statistics.hpp.

◆ maximum() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::maximum ( Iterator  first,
Iterator  last,
Projection  proj 
)

Return maximum value with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
projProjection function
Returns
Maximum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 197 of file order_statistics.hpp.

◆ mean() [1/2]

template<typename Iterator >
double statcpp::mean ( Iterator  first,
Iterator  last 
)

Arithmetic mean.

Computes the arithmetic mean of elements in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Arithmetic mean
Exceptions
std::invalid_argumentIf range is empty

Definition at line 112 of file basic_statistics.hpp.

◆ mean() [2/2]

template<typename Iterator , typename Projection >
double statcpp::mean ( Iterator  first,
Iterator  last,
Projection  proj 
)

Arithmetic mean of projected values using a lambda expression.

Computes the arithmetic mean of the results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Arithmetic mean of projected values
Exceptions
std::invalid_argumentIf range is empty

Definition at line 139 of file basic_statistics.hpp.

◆ mean_absolute_deviation() [1/4]

template<typename Iterator >
double statcpp::mean_absolute_deviation ( Iterator  first,
Iterator  last 
)

Mean absolute deviation.

Computes the mean of absolute deviations from the mean. A measure of dispersion less sensitive to outliers than variance.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Mean absolute deviation
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 1010 of file dispersion_spread.hpp.

◆ mean_absolute_deviation() [2/4]

template<typename Iterator >
double statcpp::mean_absolute_deviation ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Mean absolute deviation using precomputed mean.

Computes mean absolute deviation when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Mean absolute deviation
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 1037 of file dispersion_spread.hpp.

◆ mean_absolute_deviation() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::mean_absolute_deviation ( Iterator  first,
Iterator  last,
Projection  proj 
)

Mean absolute deviation of projected values using a lambda expression.

Computes the mean absolute deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Mean absolute deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 1067 of file dispersion_spread.hpp.

◆ mean_absolute_deviation() [4/4]

template<typename Iterator , typename Projection >
double statcpp::mean_absolute_deviation ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Mean absolute deviation of projected values using precomputed mean.

Computes mean absolute deviation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Mean absolute deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 1096 of file dispersion_spread.hpp.

◆ median() [1/2]

template<typename Iterator >
double statcpp::median ( Iterator  first,
Iterator  last 
)

Median (accepts a sorted range)

Computes the median of a sorted range. Returns the average of the two middle values if the number of elements is even.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Median
Exceptions
std::invalid_argumentIf range is empty

Definition at line 169 of file basic_statistics.hpp.

◆ median() [2/2]

template<typename Iterator , typename Projection >
double statcpp::median ( Iterator  first,
Iterator  last,
Projection  proj 
)

Median of projected values using a lambda expression (projection results must be in sorted order)

Computes the median of the results after applying a projection function to each element. Assumes that projection results are sorted.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Median of projected values
Exceptions
std::invalid_argumentIf range is empty

Definition at line 204 of file basic_statistics.hpp.

◆ median_survival_time()

double statcpp::median_survival_time ( const kaplan_meier_result km)
inline

Calculate median survival time.

Returns the time at which survival probability reaches 50%. Returns NaN if 50% is not reached.

Parameters
kmKaplan-Meier estimation result
Returns
Median survival time (NaN if 50% is not reached)

Definition at line 286 of file survival.hpp.

◆ min_max_scale()

std::vector< std::vector< double > > statcpp::min_max_scale ( const std::vector< std::vector< double > > &  data)
inline

Min-Max normalization (0-1 scaling)

Scales each variable to the [0, 1] range. Data is passed with rows=observations and columns=variables.

Parameters
dataMatrix data (rows=observations, columns=variables)
Returns
Scaled data
Exceptions
std::invalid_argumentIf data is empty, rows have different column counts, or any variable has zero range

Definition at line 198 of file multivariate.hpp.

◆ minimum() [1/2]

template<typename Iterator >
auto statcpp::minimum ( Iterator  first,
Iterator  last 
)

Return minimum value.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
Returns
Minimum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 128 of file order_statistics.hpp.

◆ minimum() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::minimum ( Iterator  first,
Iterator  last,
Projection  proj 
)

Return minimum value with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
projProjection function
Returns
Minimum value
Exceptions
std::invalid_argumentIf range is empty

Definition at line 148 of file order_statistics.hpp.

◆ minkowski_distance() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::minkowski_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  p 
)

Minkowski distance (generalized Lp distance)

Computes the Minkowski distance with parameter p: d(x, y) = (sum(|x_i - y_i|^p))^(1/p)

Special cases:

  • p = 1: Manhattan distance
  • p = 2: Euclidean distance
  • p → ∞: Chebyshev distance (max |x_i - y_i|)
Template Parameters
Iterator1RandomAccessIterator type for first sequence
Iterator2RandomAccessIterator type for second sequence
Parameters
first1Beginning of first sequence
last1End of first sequence
first2Beginning of second sequence
last2End of second sequence
pThe order of the Minkowski distance (must be >= 1)
Returns
Minkowski distance
Exceptions
std::invalid_argumentif sequences have different lengths or p < 1

Definition at line 401 of file distance_metrics.hpp.

◆ minkowski_distance() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Proj1 , typename Proj2 >
double statcpp::minkowski_distance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  p,
Proj1  proj1,
Proj2  proj2 
)

Minkowski distance with projection.

Definition at line 437 of file distance_metrics.hpp.

◆ mode() [1/2]

template<typename Iterator >
auto statcpp::mode ( Iterator  first,
Iterator  last 
)

Mode (returns the smallest value when there are multiple modes: guarantees deterministic behavior)

Returns the most frequent value in the range. When there are multiple modes, returns the smallest value.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Mode
Exceptions
std::invalid_argumentIf range is empty

Definition at line 242 of file basic_statistics.hpp.

◆ mode() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::mode ( Iterator  first,
Iterator  last,
Projection  proj 
)

Mode of projected values using a lambda expression.

Returns the most frequent value after applying a projection function to each element. When there are multiple modes, returns the smallest value.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Mode of projected values
Exceptions
std::invalid_argumentIf range is empty

Definition at line 286 of file basic_statistics.hpp.

◆ modes() [1/2]

template<typename Iterator >
auto statcpp::modes ( Iterator  first,
Iterator  last 
) -> std::vector<typename std::iterator_traits<Iterator>::value_type>

Returns all modes (returns a vector sorted in ascending order)

Returns all most frequent values in the range. When there are multiple modes, returns all of them in ascending order as a vector.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Vector of modes (ascending order)
Exceptions
std::invalid_argumentIf range is empty

Definition at line 334 of file basic_statistics.hpp.

◆ modes() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::modes ( Iterator  first,
Iterator  last,
Projection  proj 
) -> std::vector<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>>

Returns all modes of projected values using a lambda expression.

Returns all most frequent values after applying a projection function to each element. When there are multiple modes, returns all of them in ascending order as a vector.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Vector of modes of projected values (ascending order)
Exceptions
std::invalid_argumentIf range is empty

Definition at line 389 of file basic_statistics.hpp.

◆ moving_average()

template<typename Iterator >
std::vector< double > statcpp::moving_average ( Iterator  first,
Iterator  last,
std::size_t  window 
)

Simple moving average.

Calculates the simple moving average with the specified window size.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
windowWindow size
Returns
Vector of moving averages
Exceptions
std::invalid_argumentIf range is empty or window size is invalid

Definition at line 328 of file time_series.hpp.

◆ mse()

template<typename Iterator1 , typename Iterator2 >
double statcpp::mse ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2 
)

Mean Squared Error (MSE)

Calculates the mean squared error between actual and predicted values.

Template Parameters
Iterator1RandomAccessIterator type for actual values
Iterator2RandomAccessIterator type for predicted values
Parameters
first1Beginning iterator of actual values
last1End iterator of actual values
first2Beginning iterator of predicted values
Returns
MSE
Exceptions
std::invalid_argumentIf range is empty

Definition at line 237 of file time_series.hpp.

◆ multicollinearity_score()

double statcpp::multicollinearity_score ( const std::vector< std::vector< double > > &  X)
inline

Calculate multicollinearity score.

Score ranges from 0 to 1, with values closer to 1 indicating stronger multicollinearity. Calculated as Score = 1 - |det(R)|.

Parameters
XPredictor matrix (n x p)
Returns
double Multicollinearity score (0: no correlation, 1: perfect multicollinearity)
Exceptions
std::invalid_argumentIf there are fewer than 2 observations
std::invalid_argumentIf there are fewer than 2 or more than 3 predictors

Definition at line 1098 of file linear_regression.hpp.

◆ multiple_imputation_bootstrap()

multiple_imputation_result statcpp::multiple_imputation_bootstrap ( const std::vector< std::vector< double > > &  data,
std::size_t  m = 5,
unsigned int  seed = 0 
)
inline

Multiple imputation (simplified Bootstrap EM method)

Performs multiple imputation combining bootstrap sampling with stochastic imputation from normal distribution. Results are pooled based on Rubin's rules.

Parameters
dataInput data (rows: observations, columns: variables)
mNumber of imputations (default: 5)
seedRandom seed (0 for random seed)
Returns
multiple_imputation_result Multiple imputation result
Exceptions
std::invalid_argumentIf data is empty

Definition at line 646 of file missing_data.hpp.

◆ multiple_imputation_pmm()

multiple_imputation_result statcpp::multiple_imputation_pmm ( const std::vector< std::vector< double > > &  data,
std::size_t  m = 5,
unsigned int  seed = 0 
)
inline

Multiple imputation (PMM: Predictive Mean Matching)

Performs multiple imputation using Predictive Mean Matching method. Randomly selects a donor from k observations closest to the predicted value. Results are pooled based on Rubin's rules.

Parameters
dataInput data (rows: observations, columns: variables)
mNumber of imputations (default: 5)
seedRandom seed (0 for random seed)
Returns
multiple_imputation_result Multiple imputation result
Exceptions
std::invalid_argumentIf data is empty

Definition at line 480 of file missing_data.hpp.

◆ multiple_linear_regression()

multiple_regression_result statcpp::multiple_linear_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y 
)
inline

Perform multiple linear regression.

Estimates multiple regression model y = b0 + b1*x1 + ... + bp*xp using least squares method. The intercept is added automatically, so X should not contain an intercept column.

Parameters
XPredictor matrix (n x p). Each row is one observation, each column is one predictor
yResponse variable vector (n-dimensional)
Returns
multiple_regression_result Regression analysis results
Exceptions
std::invalid_argumentIf data is empty
std::invalid_argumentIf X and Y have different numbers of observations
std::invalid_argumentIf number of predictors is greater than or equal to number of observations
std::invalid_argumentIf X contains an intercept column (all 1s column)

Definition at line 523 of file linear_regression.hpp.

◆ nbinom_cdf()

double statcpp::nbinom_cdf ( std::uint64_t  k,
double  r,
double  p 
)
inline

Negative binomial distribution cumulative distribution function (CDF)

P(X <= k) = I_p(r, k+1) (using incomplete beta function)

Parameters
kUpper bound of failures
rNumber of successes required
pProbability of success
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf r <= 0 or p is outside (0, 1]

Definition at line 629 of file discrete_distributions.hpp.

◆ nbinom_pmf()

double statcpp::nbinom_pmf ( std::uint64_t  k,
double  r,
double  p 
)
inline

Negative binomial distribution probability mass function (PMF)

P(X = k) = C(k+r-1, k) * p^r * (1-p)^k X = Number of failures before r successes (support: k = 0, 1, 2, ...)

Parameters
kNumber of failures
rNumber of successes required (dispersion parameter, > 0, can be non-integer)
pProbability of success
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf r <= 0 or p is outside (0, 1]
Note
About parameterization: There are multiple parameterizations for the negative binomial distribution. This implementation uses the "number of failures" form (X = number of failures before r successes).
  • R's dnbinom(x, size, prob): size=r, prob=p (same, counts failures)
  • Python scipy.stats.nbinom(k, n, p): n=r, p=p (same, counts failures)
  • Some textbooks: "number of trials until r successes" = X + r

There is also a "mean-dispersion" parameterization:

  • Mean μ = r(1-p)/p
  • Variance σ² = r(1-p)/p² = μ + μ²/r This form is commonly used for modeling overdispersed data (GLM, etc.).

Definition at line 603 of file discrete_distributions.hpp.

◆ nbinom_quantile()

std::uint64_t statcpp::nbinom_quantile ( double  prob,
double  r,
double  p 
)
inline

Negative binomial distribution quantile function (inverse CDF)

Parameters
probCumulative probability
rNumber of successes required
pProbability of success
Returns
Smallest k such that P(X <= k) >= prob
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 651 of file discrete_distributions.hpp.

◆ nbinom_rand() [1/2]

std::uint64_t statcpp::nbinom_rand ( double  r,
double  p 
)
inline

Negative binomial distribution random number generation (using default engine)

Parameters
rNumber of successes required
pProbability of success
Returns
Generated random number

Definition at line 727 of file discrete_distributions.hpp.

◆ nbinom_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::nbinom_rand ( double  r,
double  p,
Engine &  engine 
)

Negative binomial distribution random number generation.

Generated as a Poisson-Gamma mixture.

Template Parameters
EngineRandom engine type
Parameters
rNumber of successes required
pProbability of success
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 703 of file discrete_distributions.hpp.

◆ nelson_aalen()

hazard_rate_result statcpp::nelson_aalen ( const std::vector< double > &  times,
const std::vector< bool > &  events 
)
inline

Nelson-Aalen cumulative hazard estimation.

Estimates the cumulative hazard function H(t) using the Nelson-Aalen estimator. Handles survival time data with censoring.

Note
The Nelson-Aalen estimator is a nonparametric estimator of the cumulative hazard function: H(t) = sum_{t_i <= t} d_i / n_i where d_i is the number of events at time t_i and n_i is the risk set size.

Relationship between cumulative hazard and survival function:

  • S(t) = exp(-H(t)) (approximation via exponential transformation)
  • Kaplan-Meier estimator directly estimates S(t) = prod(1 - d_i/n_i)
  • For small event probabilities, both are approximately equal

Advantages of Nelson-Aalen estimation:

  • Simpler confidence interval construction (variance estimated by sum d_i/n_i^2)
  • Consistent with Cox regression baseline hazard estimation (Breslow estimator)
Parameters
timesVector of observation times
eventsEvent occurrence flags (true = event occurred, false = censored)
Returns
Hazard rate estimation result
Exceptions
std::invalid_argumentIf times and events have different sizes or data is empty

Definition at line 337 of file survival.hpp.

◆ norm_cdf()

double statcpp::norm_cdf ( double  x)
inline

Standard normal CDF.

Computes the cumulative distribution function Phi(x) of the standard normal distribution.

Parameters
xArgument
Returns
Phi(x) = P(Z <= x) where Z ~ N(0, 1)

Definition at line 394 of file special_functions.hpp.

◆ norm_quantile()

double statcpp::norm_quantile ( double  p)
inline

Standard normal quantile function.

Computes the quantile function Phi^{-1}(p) of the standard normal distribution.

Parameters
pProbability (must be in (0, 1))
Returns
x such that Phi(x) = p
Note
Reference: https://home.online.no/~pjacklam/notes/invnorm/
Rational approximation by Acklam's algorithm

Definition at line 410 of file special_functions.hpp.

◆ normal_cdf()

double statcpp::normal_cdf ( double  x,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Normal distribution cumulative distribution function (CDF)

F(x) = Phi((x - mu) / sigma)

Parameters
xRandom variable value
muMean (default: 0.0)
sigmaStandard deviation (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 159 of file continuous_distributions.hpp.

◆ normal_pdf()

double statcpp::normal_pdf ( double  x,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Normal distribution probability density function (PDF)

f(x) = (1 / (sigma * sqrt(2 * pi))) * exp(-(x-mu)^2/(2*sigma^2))

Parameters
xRandom variable value
muMean (default: 0.0)
sigmaStandard deviation (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 139 of file continuous_distributions.hpp.

◆ normal_quantile()

double statcpp::normal_quantile ( double  p,
double  mu = 0.0,
double  sigma = 1.0 
)
inline

Normal distribution quantile function (inverse CDF, percent point function)

Returns the quantile (percentile value) corresponding to probability p. Q(p) = mu + sigma * Phi^(-1)(p)

where Phi^(-1)(p) is the inverse cumulative distribution function of the standard normal distribution (probit function). Example: Q(0.975) is approximately mu + 1.96*sigma (upper bound of 95% confidence interval)

Parameters
pProbability (0 < p < 1)
muMean (default: 0.0)
sigmaStandard deviation (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf sigma <= 0 or p is outside (0, 1)
Note
Boundary value handling: returns -infinity for p = 0, +infinity for p = 1.

Definition at line 185 of file continuous_distributions.hpp.

◆ normal_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::normal_rand ( double  mu,
double  sigma,
Engine &  engine 
)

Normal distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
muMean
sigmaStandard deviation
engineRandom engine
Returns
Random number following normal distribution
Exceptions
std::invalid_argumentIf sigma <= 0

Definition at line 209 of file continuous_distributions.hpp.

◆ normal_rand() [2/2]

double statcpp::normal_rand ( double  mu = 0.0,
double  sigma = 1.0 
)
inline

Normal distribution random number generation (using default engine)

Parameters
muMean (default: 0.0)
sigmaStandard deviation (default: 1.0)
Returns
Random number following normal distribution

Definition at line 225 of file continuous_distributions.hpp.

◆ number_needed_to_treat()

double statcpp::number_needed_to_treat ( const std::vector< std::vector< std::size_t > > &  table)
inline

Calculate Number Needed to Treat (NNT)

Calculated as the reciprocal of the risk difference. Represents the number of patients that need to be treated to prevent one outcome.

Parameters
table2x2 contingency table
Returns
Number needed to treat
Exceptions
std::invalid_argumentIf risk difference is zero

Definition at line 331 of file categorical.hpp.

◆ odds_ratio() [1/3]

odds_ratio_result statcpp::odds_ratio ( const std::vector< std::vector< std::size_t > > &  table)
inline

Calculate odds ratio from a 2x2 contingency table.

Calculates the odds ratio and its confidence interval. Odds ratio = (a * d) / (b * c)

Parameters
table2x2 contingency table in the form [[a, b], [c, d]]
  • a: Exposed and diseased
  • b: Exposed and not diseased
  • c: Not exposed and diseased
  • d: Not exposed and not diseased
Returns
Odds ratio calculation result
Exceptions
std::invalid_argumentIf table is not 2x2 or if cell count is zero
Note
Currently throws an exception when any cell count is zero. A future enhancement may add an optional Gart-Zweifel continuity correction (+0.5 to all cells) to handle zero-cell tables.

Definition at line 115 of file categorical.hpp.

◆ odds_ratio() [2/3]

double statcpp::odds_ratio ( double  a,
double  b,
double  c,
double  d 
)
inline

Odds ratio.

Calculates the odds ratio from a 2x2 contingency table.

Parameters
aCell (1,1) frequency (exposed, disease present)
bCell (1,2) frequency (exposed, disease absent)
cCell (2,1) frequency (unexposed, disease present)
dCell (2,2) frequency (unexposed, disease absent)
Returns
Odds ratio
Exceptions
std::invalid_argumentIf b or c is zero

Definition at line 381 of file effect_size.hpp.

◆ odds_ratio() [3/3]

odds_ratio_result statcpp::odds_ratio ( std::size_t  a,
std::size_t  b,
std::size_t  c,
std::size_t  d 
)
inline

Calculate odds ratio from a 2x2 contingency table (specifying cell values directly)

Parameters
aExposed and diseased
bExposed and not diseased
cNot exposed and diseased
dNot exposed and not diseased
Returns
Odds ratio calculation result
Exceptions
std::invalid_argumentIf cell count is zero

Definition at line 152 of file categorical.hpp.

◆ odds_ratios()

std::vector< double > statcpp::odds_ratios ( const glm_result model)
inline

Calculate odds ratios.

Calculates odds ratios from logistic regression model coefficients.

Parameters
modelFitted logistic regression model
Returns
Vector of odds ratios for each predictor (excluding intercept)
Exceptions
std::invalid_argumentIf model is not logistic regression

Definition at line 731 of file glm.hpp.

◆ odds_ratios_ci()

std::vector< std::pair< double, double > > statcpp::odds_ratios_ci ( const glm_result model,
double  confidence = 0.95 
)
inline

Confidence intervals for odds ratios.

Calculates confidence intervals for odds ratios from a logistic regression model.

Parameters
modelFitted logistic regression model
confidenceConfidence level (default: 0.95)
Returns
Vector of (lower, upper) pairs for each predictor's odds ratio
Exceptions
std::invalid_argumentIf model is not logistic regression or confidence level is outside (0,1)

Definition at line 754 of file glm.hpp.

◆ omega_squared() [1/2]

double statcpp::omega_squared ( const one_way_anova_result result)
inline

Calculate Omega-squared for one-way ANOVA.

A less biased effect size estimate compared to Eta-squared. Suitable for estimating population effect size.

Parameters
resultResult from one-way ANOVA
Returns
double Omega-squared value

Definition at line 899 of file anova.hpp.

◆ omega_squared() [2/2]

double statcpp::omega_squared ( double  ss_effect,
double  ss_total,
double  ms_error,
double  df_effect 
)
inline

Omega-squared.

A less biased estimate of effect size than eta-squared.

Parameters
ss_effectSum of squares for effect
ss_totalTotal sum of squares
ms_errorMean square error
df_effectDegrees of freedom for effect
Returns
Omega-squared
Exceptions
std::invalid_argumentIf ss_total is not positive

Definition at line 333 of file effect_size.hpp.

◆ one_hot_encode()

template<typename T >
std::vector< std::vector< double > > statcpp::one_hot_encode ( const std::vector< T > &  data)

One-hot encoding.

Template Parameters
TData type
Parameters
dataData vector
Returns
One-hot encoded 2-dimensional vector

Definition at line 1001 of file data_wrangling.hpp.

◆ one_way_ancova()

ancova_result statcpp::one_way_ancova ( const std::vector< std::vector< std::pair< double, double > > > &  groups)
inline

Perform one-way analysis of covariance.

Tests differences in group means while controlling for the effect of a covariate. Each observation is specified as a pair of dependent variable (y) and covariate (x).

Parameters
groupsData for each group. groups[i] is a vector of (y, x) pairs for group i
Returns
ancova_result Results of the analysis of covariance
Exceptions
std::invalid_argumentIf number of groups is less than 2
std::invalid_argumentIf an empty group exists
std::invalid_argumentIf number of observations is insufficient

Definition at line 688 of file anova.hpp.

◆ one_way_anova()

one_way_anova_result statcpp::one_way_anova ( const std::vector< std::vector< double > > &  groups)
inline

Perform one-way analysis of variance.

Tests whether there are significant differences in means among multiple groups. Uses F-test to compare between-group and within-group variation.

Parameters
groupsVector of vectors containing data for each group
Returns
one_way_anova_result Results of the analysis of variance
Exceptions
std::invalid_argumentIf number of groups is less than 2
std::invalid_argumentIf an empty group exists
std::invalid_argumentIf total number of observations is less than or equal to number of groups

Definition at line 125 of file anova.hpp.

◆ overdispersion_test()

double statcpp::overdispersion_test ( const glm_result model,
const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y 
)
inline

Overdispersion test (for Poisson regression)

Calculates the overdispersion parameter for a Poisson regression model. Values greater than 1 suggest the presence of overdispersion.

Parameters
modelFitted Poisson regression model
XPredictor matrix
yResponse variable vector
Returns
Overdispersion parameter (Pearson chi-square statistic / residual degrees of freedom)
Exceptions
std::invalid_argumentIf model is not Poisson

Definition at line 946 of file glm.hpp.

◆ pacf()

template<typename Iterator >
std::vector< double > statcpp::pacf ( Iterator  first,
Iterator  last,
std::size_t  max_lag 
)

Calculate partial autocorrelation function (PACF) (Durbin-Levinson algorithm)

Calculates PACF using the Durbin-Levinson algorithm.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
max_lagMaximum lag
Returns
Vector of partial autocorrelation coefficients
Exceptions
std::invalid_argumentIf range is empty

Definition at line 134 of file time_series.hpp.

◆ partial_eta_squared()

double statcpp::partial_eta_squared ( double  f,
double  df1,
double  df2 
)
inline

Calculate partial eta-squared from F-test.

Parameters
fF-statistic
df1Numerator degrees of freedom
df2Denominator degrees of freedom
Returns
Partial eta-squared

Definition at line 312 of file effect_size.hpp.

◆ partial_eta_squared_a()

double statcpp::partial_eta_squared_a ( const two_way_anova_result result)
inline

Calculate Partial eta-squared for factor A in two-way ANOVA.

Indicates the proportion of factor A effect relative to the sum of factor A effect and error.

Parameters
resultResult from two-way ANOVA
Returns
double Partial eta-squared value for factor A

Definition at line 845 of file anova.hpp.

◆ partial_eta_squared_b()

double statcpp::partial_eta_squared_b ( const two_way_anova_result result)
inline

Calculate Partial eta-squared for factor B in two-way ANOVA.

Indicates the proportion of factor B effect relative to the sum of factor B effect and error.

Parameters
resultResult from two-way ANOVA
Returns
double Partial eta-squared value for factor B

Definition at line 863 of file anova.hpp.

◆ partial_eta_squared_interaction()

double statcpp::partial_eta_squared_interaction ( const two_way_anova_result result)
inline

Calculate Partial eta-squared for interaction in two-way ANOVA.

Indicates the proportion of interaction effect relative to the sum of interaction effect and error.

Parameters
resultResult from two-way ANOVA
Returns
double Partial eta-squared value for interaction

Definition at line 881 of file anova.hpp.

◆ pca()

pca_result statcpp::pca ( const std::vector< std::vector< double > > &  data,
std::size_t  n_components 
)
inline

Principal Component Analysis.

Finds principal components through eigenvalue decomposition of the covariance matrix. Uses deflation method to compute multiple principal components.

Parameters
dataMatrix data (rows=observations, columns=variables)
n_componentsNumber of principal components to extract
Returns
PCA result
Exceptions
std::invalid_argumentIf data is empty or rows have different column counts
Note
This implementation uses the deflation method to extract multiple principal components. The deflation method may accumulate numerical errors when extracting many components. For high-dimensional data or when many components are needed, consider verifying results against a full eigendecomposition approach.

Definition at line 325 of file multivariate.hpp.

◆ pca_transform()

std::vector< std::vector< double > > statcpp::pca_transform ( const std::vector< std::vector< double > > &  data,
const pca_result pca 
)
inline

Project data onto principal component space.

Transforms data to principal component space using PCA results.

Parameters
dataMatrix data (rows=observations, columns=variables)
pcaPCA result
Returns
Data projected onto principal component space (n x n_components)
Exceptions
std::invalid_argumentIf data is empty, PCA components are empty, or dimensions don't match

Definition at line 385 of file multivariate.hpp.

◆ pearson_correlation() [1/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::pearson_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Pearson correlation coefficient.

Computes the Pearson product-moment correlation coefficient of two variables. r = Cov(X, Y) / (sigma_x * sigma_y) Values range from -1 to 1, where 1 indicates perfect positive correlation and -1 indicates perfect negative correlation.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Pearson correlation coefficient (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, number of elements is less than 2, or variance of either variable is zero

Definition at line 376 of file correlation_covariance.hpp.

◆ pearson_correlation() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::pearson_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  mean_x,
double  mean_y 
)

Pearson correlation coefficient with precomputed means.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
mean_xMean of the first data
mean_yMean of the second data
Returns
Pearson correlation coefficient (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, number of elements is less than 2, or variance of either variable is zero

Definition at line 432 of file correlation_covariance.hpp.

◆ pearson_correlation() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::pearson_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Pearson correlation coefficient (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Pearson correlation coefficient (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, number of elements is less than 2, or variance of either variable is zero

Definition at line 488 of file correlation_covariance.hpp.

◆ percentile() [1/2]

template<typename Iterator >
double statcpp::percentile ( Iterator  first,
Iterator  last,
double  p 
)

Return percentile.

Calculates specified percentile from sorted range.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
pPercentile as proportion 0.0-1.0 (e.g., 90th percentile -> p = 0.9)
Returns
Percentile value
Exceptions
std::invalid_argumentIf range is empty or p is out of range

Definition at line 285 of file order_statistics.hpp.

◆ percentile() [2/2]

template<typename Iterator , typename Projection >
double statcpp::percentile ( Iterator  first,
Iterator  last,
double  p,
Projection  proj 
)

Return percentile with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
pPercentile as proportion 0.0-1.0
projProjection function
Returns
Percentile value
Exceptions
std::invalid_argumentIf range is empty or p is out of range

Definition at line 310 of file order_statistics.hpp.

◆ permutation_test_correlation()

template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result statcpp::permutation_test_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
std::size_t  n_permutations = 10000,
Engine &  engine = get_random_engine() 
)

Perform permutation test for correlation.

Performs a permutation test for Pearson correlation coefficient between two variables. Generates the null distribution by shuffling one variable. The null hypothesis is "there is no correlation between the two variables (correlation is 0)". Computes two-sided p-value.

Note
P-value calculation uses the inclusive method: p = (count of permutation statistics as extreme or more extreme than observed + 1) / (n_permutations + 1) This method prevents p-values from being zero and provides more accurate estimation (Phipson & Smyth, 2010).
Template Parameters
Iterator1Iterator type for first variable
Iterator2Iterator type for second variable
EngineRandom engine type (default: default_random_engine)
Parameters
first1Beginning iterator of first variable
last1End iterator of first variable
first2Beginning iterator of second variable
last2End iterator of second variable
n_permutationsNumber of permutations (default: 10000)
engineReference to random engine
Returns
permutation_result structure containing permutation test results
Exceptions
std::invalid_argumentIf the two variables have different lengths
std::invalid_argumentIf number of data pairs is less than 3

Definition at line 625 of file resampling.hpp.

◆ permutation_test_paired()

template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result statcpp::permutation_test_paired ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
std::size_t  n_permutations = 10000,
Engine &  engine = get_random_engine() 
)

Perform paired permutation test.

Performs a permutation test for differences between two paired samples. Generates the null distribution by randomly flipping the signs of differences. The null hypothesis is "the mean of differences is zero". Computes two-sided p-value.

P-value calculation uses the inclusive method: p = (count(|T*| >= |T_obs|) + 1) / (n_permutations + 1)

Template Parameters
Iterator1Iterator type for first sample
Iterator2Iterator type for second sample
EngineRandom engine type (default: default_random_engine)
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
n_permutationsNumber of permutations (default: 10000)
engineReference to random engine
Returns
permutation_result structure containing permutation test results
Exceptions
std::invalid_argumentIf the two samples have different lengths
std::invalid_argumentIf samples are empty

Definition at line 538 of file resampling.hpp.

◆ permutation_test_two_sample()

template<typename Iterator1 , typename Iterator2 , typename Engine = default_random_engine>
permutation_result statcpp::permutation_test_two_sample ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
std::size_t  n_permutations = 10000,
Engine &  engine = get_random_engine() 
)

Perform two-sample permutation test (test of difference in means)

Performs a permutation test for the difference in means between two independent samples. The null hypothesis is "the two group means are equal". Computes two-sided p-value.

P-value calculation uses the inclusive method: p = (count(|T*| >= |T_obs|) + 1) / (n_permutations + 1) This includes the observed data itself as part of the null distribution, preventing p-values from being zero (Phipson & Smyth, 2010).

Template Parameters
Iterator1Iterator type for first sample
Iterator2Iterator type for second sample
EngineRandom engine type (default: default_random_engine)
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
n_permutationsNumber of permutations (default: 10000)
engineReference to random engine
Returns
permutation_result structure containing permutation test results
Exceptions
std::invalid_argumentIf either sample is empty

Definition at line 457 of file resampling.hpp.

◆ poisson_cdf()

double statcpp::poisson_cdf ( std::uint64_t  k,
double  lambda 
)
inline

Poisson distribution cumulative distribution function (CDF)

Calculates P(X <= k).

Parameters
kUpper bound of number of event occurrences
lambdaMean rate
Returns
Cumulative probability P(X <= k)
Exceptions
std::invalid_argumentIf lambda is negative

Definition at line 228 of file discrete_distributions.hpp.

◆ poisson_pmf()

double statcpp::poisson_pmf ( std::uint64_t  k,
double  lambda 
)
inline

Poisson distribution probability mass function (PMF)

P(X = k) = (lambda^k * e^(-lambda)) / k!

Parameters
kNumber of event occurrences
lambdaMean rate (lambda > 0)
Returns
Probability P(X = k)
Exceptions
std::invalid_argumentIf lambda is negative

Definition at line 207 of file discrete_distributions.hpp.

◆ poisson_quantile()

std::uint64_t statcpp::poisson_quantile ( double  p,
double  lambda 
)
inline

Poisson distribution quantile function.

Parameters
pProbability value
lambdaMean rate
Returns
Quantile
Exceptions
std::invalid_argumentIf lambda is negative or p is in an invalid range

Definition at line 247 of file discrete_distributions.hpp.

◆ poisson_rand() [1/2]

std::uint64_t statcpp::poisson_rand ( double  lambda)
inline

Poisson distribution random number generation (using default engine)

Parameters
lambdaMean rate
Returns
Generated random number

Definition at line 306 of file discrete_distributions.hpp.

◆ poisson_rand() [2/2]

template<typename Engine = default_random_engine>
std::uint64_t statcpp::poisson_rand ( double  lambda,
Engine &  engine 
)

Poisson distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
lambdaMean rate
engineRandom engine
Returns
Generated random number
Exceptions
std::invalid_argumentIf lambda is negative

Definition at line 291 of file discrete_distributions.hpp.

◆ poisson_regression()

glm_result statcpp::poisson_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
std::size_t  max_iter = 100,
double  tol = 1e-8 
)
inline

Poisson regression.

Fits a generalized linear model using Poisson distribution and log link function. Used for regression analysis of count data.

Parameters
XPredictor matrix (intercept is added automatically)
yResponse variable vector (non-negative count data)
max_iterMaximum number of iterations (default: 100)
tolConvergence tolerance (default: 1e-8)
Returns
GLM estimation results
Exceptions
std::invalid_argumentIf y is negative or X contains an intercept column

Definition at line 794 of file glm.hpp.

◆ population_covariance() [1/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::population_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Population covariance.

Computes the population covariance of two variables. Cov(X, Y) = E[(X - mu_x)(Y - mu_y)] = (1/n) * sum((x_i - x_bar)(y_i - y_bar))

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Population covariance
Exceptions
std::invalid_argumentIf range is empty or lengths differ

Definition at line 46 of file correlation_covariance.hpp.

◆ population_covariance() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::population_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  mean_x,
double  mean_y 
)

Population covariance with precomputed means.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
mean_xMean of the first data
mean_yMean of the second data
Returns
Population covariance
Exceptions
std::invalid_argumentIf range is empty or lengths differ

Definition at line 87 of file correlation_covariance.hpp.

◆ population_covariance() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::population_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Population covariance (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Population covariance
Exceptions
std::invalid_argumentIf range is empty or lengths differ

Definition at line 128 of file correlation_covariance.hpp.

◆ population_kurtosis() [1/4]

template<typename Iterator >
double statcpp::population_kurtosis ( Iterator  first,
Iterator  last 
)

Calculate population kurtosis (Excess Kurtosis)

Calculates the kurtosis of a population. An indicator of tail heaviness.

Formula: g2 = E[(X - mu)^4] / sigma^4 - 3 Subtracts 3 so that normal distribution kurtosis is 0 (excess kurtosis)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Population kurtosis value (positive = heavy tails, negative = light tails)
Exceptions
std::invalid_argumentIf range is empty or variance is zero
Note
The kurtosis (excess kurtosis) of a normal distribution is 0

Definition at line 375 of file shape_of_distribution.hpp.

◆ population_kurtosis() [2/4]

template<typename Iterator >
double statcpp::population_kurtosis ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate population kurtosis with precomputed mean.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Population kurtosis value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 413 of file shape_of_distribution.hpp.

◆ population_kurtosis() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_kurtosis ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate population kurtosis with projection.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Population kurtosis value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 454 of file shape_of_distribution.hpp.

◆ population_kurtosis() [4/4]

template<typename Iterator , typename Projection >
double statcpp::population_kurtosis ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate population kurtosis with projection and precomputed mean.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Population kurtosis value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 494 of file shape_of_distribution.hpp.

◆ population_skewness() [1/4]

template<typename Iterator >
double statcpp::population_skewness ( Iterator  first,
Iterator  last 
)

Calculate population skewness (Fisher's definition)

Calculates the skewness of a population. An indicator of distribution asymmetry.

Formula: g1 = E[(X - mu)^3] / sigma^3

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Population skewness value (positive = right-skewed, negative = left-skewed)
Exceptions
std::invalid_argumentIf range is empty or variance is zero
Note
The skewness of a normal distribution is 0

Definition at line 42 of file shape_of_distribution.hpp.

◆ population_skewness() [2/4]

template<typename Iterator >
double statcpp::population_skewness ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate population skewness with precomputed mean.

Use when the mean has already been calculated. Improves computational efficiency.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Population skewness value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 81 of file shape_of_distribution.hpp.

◆ population_skewness() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_skewness ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate population skewness with projection.

Uses a projection function to extract specific values from the data to calculate skewness.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Population skewness value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 123 of file shape_of_distribution.hpp.

◆ population_skewness() [4/4]

template<typename Iterator , typename Projection >
double statcpp::population_skewness ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate population skewness with projection and precomputed mean.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Population skewness value
Exceptions
std::invalid_argumentIf range is empty or variance is zero

Definition at line 162 of file shape_of_distribution.hpp.

◆ population_stddev() [1/4]

template<typename Iterator >
double statcpp::population_stddev ( Iterator  first,
Iterator  last 
)

Population standard deviation.

Computes the population standard deviation (square root of variance divided by N).

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Population standard deviation
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 588 of file dispersion_spread.hpp.

◆ population_stddev() [2/4]

template<typename Iterator >
double statcpp::population_stddev ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Population standard deviation using precomputed mean.

Computes population standard deviation when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Population standard deviation
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 606 of file dispersion_spread.hpp.

◆ population_stddev() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_stddev ( Iterator  first,
Iterator  last,
Projection  proj 
)

Population standard deviation of projected values using a lambda expression.

Computes the population standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Population standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 628 of file dispersion_spread.hpp.

◆ population_stddev() [4/4]

template<typename Iterator , typename Projection >
double statcpp::population_stddev ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Population standard deviation of projected values using precomputed mean.

Computes population standard deviation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Population standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 648 of file dispersion_spread.hpp.

◆ population_variance() [1/4]

template<typename Iterator >
double statcpp::population_variance ( Iterator  first,
Iterator  last 
)

Population variance.

Computes the population variance (divide by N).

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Population variance
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 258 of file dispersion_spread.hpp.

◆ population_variance() [2/4]

template<typename Iterator >
double statcpp::population_variance ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Population variance using precomputed mean.

Computes population variance when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Population variance
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 276 of file dispersion_spread.hpp.

◆ population_variance() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::population_variance ( Iterator  first,
Iterator  last,
Projection  proj 
)

Population variance of projected values using a lambda expression.

Computes the population variance of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Population variance of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 298 of file dispersion_spread.hpp.

◆ population_variance() [4/4]

template<typename Iterator , typename Projection >
double statcpp::population_variance ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Population variance of projected values using precomputed mean.

Computes population variance using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Population variance of projected values
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 318 of file dispersion_spread.hpp.

◆ power_analysis_t_one_sample() [1/2]

power_result statcpp::power_analysis_t_one_sample ( double  effect_size,
std::size_t  n,
double  alpha,
alternative_hypothesis  alt 
)
inline

Power analysis for one-sample t-test (enum overload, returning struct)

Parameters
effect_sizeEffect size
nSample size
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Power analysis result

Definition at line 615 of file power_analysis.hpp.

◆ power_analysis_t_one_sample() [2/2]

power_result statcpp::power_analysis_t_one_sample ( double  effect_size,
std::size_t  n,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Power analysis for one-sample t-test (calculate power)

Parameters
effect_sizeEffect size
nSample size
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Power analysis result

Definition at line 469 of file power_analysis.hpp.

◆ power_analysis_t_one_sample_n() [1/2]

power_result statcpp::power_analysis_t_one_sample_n ( double  effect_size,
double  power,
double  alpha,
alternative_hypothesis  alt 
)
inline

Power analysis for one-sample t-test, sample size (enum overload, returning struct)

Parameters
effect_sizeEffect size
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Power analysis result

Definition at line 631 of file power_analysis.hpp.

◆ power_analysis_t_one_sample_n() [2/2]

power_result statcpp::power_analysis_t_one_sample_n ( double  effect_size,
double  power = 0.80,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Power analysis for one-sample t-test (calculate sample size)

Parameters
effect_sizeEffect size
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Power analysis result

Definition at line 490 of file power_analysis.hpp.

◆ power_iteration()

std::pair< double, std::vector< double > > statcpp::power_iteration ( const std::vector< std::vector< double > > &  matrix,
std::size_t  max_iter = 1000,
double  tol = 1e-10 
)
inline

Find largest eigenvalue and eigenvector using power iteration.

Finds the largest eigenvalue and corresponding eigenvector of a matrix through iterative computation.

Parameters
matrixSymmetric matrix
max_iterMaximum number of iterations (default: 1000)
tolConvergence threshold (default: 1e-10)
Returns
Pair of (eigenvalue, eigenvector)

Definition at line 259 of file multivariate.hpp.

◆ power_prop_test() [1/2]

double statcpp::power_prop_test ( double  p1,
double  p2,
std::size_t  n,
double  alpha,
alternative_hypothesis  alt 
)
inline

Calculate power for two-sample proportion test (enum overload)

Parameters
p1Proportion of group 1
p2Proportion of group 2
nSample size per group
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Statistical power (0.0 to 1.0)

Definition at line 582 of file power_analysis.hpp.

◆ power_prop_test() [2/2]

double statcpp::power_prop_test ( double  p1,
double  p2,
std::size_t  n,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Calculate power for two-sample proportion test.

Parameters
p1Proportion of group 1
p2Proportion of group 2
nSample size per group
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Statistical power (0.0 to 1.0)
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 355 of file power_analysis.hpp.

◆ power_t_test_one_sample() [1/2]

double statcpp::power_t_test_one_sample ( double  effect_size,
std::size_t  n,
double  alpha,
alternative_hypothesis  alt 
)
inline

Calculate power for one-sample t-test (enum overload)

Parameters
effect_sizeEffect size (Cohen's d)
nSample size
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Statistical power (0.0 to 1.0)

Definition at line 515 of file power_analysis.hpp.

◆ power_t_test_one_sample() [2/2]

double statcpp::power_t_test_one_sample ( double  effect_size,
std::size_t  n,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Calculate power for one-sample t-test.

Parameters
effect_sizeEffect size (Cohen's d)
nSample size
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis: "two.sided", "greater", "less" (default: "two.sided")
Returns
Statistical power (0.0 to 1.0)
Exceptions
std::invalid_argumentIf parameters are invalid
Note
This function uses normal distribution approximation. Strictly speaking, the noncentral t-distribution should be used, but for large sample sizes (n > 30 approximately), sufficient accuracy is obtained. For small samples, power may be slightly overestimated.

Definition at line 156 of file power_analysis.hpp.

◆ power_t_test_two_sample() [1/2]

double statcpp::power_t_test_two_sample ( double  effect_size,
std::size_t  n1,
std::size_t  n2,
double  alpha,
alternative_hypothesis  alt 
)
inline

Calculate power for two-sample t-test (enum overload)

Parameters
effect_sizeEffect size (Cohen's d)
n1Sample size of group 1
n2Sample size of group 2
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Statistical power (0.0 to 1.0)

Definition at line 548 of file power_analysis.hpp.

◆ power_t_test_two_sample() [2/2]

double statcpp::power_t_test_two_sample ( double  effect_size,
std::size_t  n1,
std::size_t  n2,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Calculate power for two-sample t-test.

Parameters
effect_sizeEffect size (Cohen's d)
n1Sample size of group 1
n2Sample size of group 2
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Statistical power (0.0 to 1.0)
Exceptions
std::invalid_argumentIf parameters are invalid
Note
This function uses normal distribution approximation. Strictly speaking, the noncentral t-distribution should be used, but for large total sample sizes (n1 + n2 > 60 approximately), sufficient accuracy is obtained. For small samples, power may be slightly overestimated.

Definition at line 255 of file power_analysis.hpp.

◆ predict() [1/2]

double statcpp::predict ( const multiple_regression_result model,
const std::vector< double > &  x 
)
inline

Make prediction using multiple regression model.

Parameters
modelMultiple regression analysis results
xPredictor variable vector (do not include intercept)
Returns
double Predicted value
Exceptions
std::invalid_argumentIf x dimension doesn't match model's number of predictors

Definition at line 662 of file linear_regression.hpp.

◆ predict() [2/2]

double statcpp::predict ( const simple_regression_result model,
double  x 
)
inline

Make prediction using simple regression model.

Parameters
modelSimple regression analysis results
xPredictor variable value
Returns
double Predicted value

Definition at line 649 of file linear_regression.hpp.

◆ predict_count()

double statcpp::predict_count ( const glm_result model,
const std::vector< double > &  x 
)
inline

Expected count prediction with Poisson regression.

Uses a fitted Poisson regression model to predict expected counts for new data points.

Parameters
modelFitted GLM model (Poisson distribution)
xPredictor variable vector
Returns
Predicted expected count
Exceptions
std::invalid_argumentIf model is not Poisson or x dimension doesn't match

Definition at line 824 of file glm.hpp.

◆ predict_probability()

double statcpp::predict_probability ( const glm_result model,
const std::vector< double > &  x 
)
inline

Probability prediction with logistic regression.

Uses a fitted logistic regression model to predict probabilities for new data points.

Parameters
modelFitted GLM model (binomial distribution)
xPredictor variable vector
Returns
Predicted probability (range 0 to 1)
Exceptions
std::invalid_argumentIf model is not binomial or x dimension doesn't match

Definition at line 705 of file glm.hpp.

◆ prediction_interval_simple()

template<typename IteratorX >
prediction_interval statcpp::prediction_interval_simple ( const simple_regression_result model,
IteratorX  x_first,
IteratorX  x_last,
double  x_new,
double  confidence = 0.95 
)

Calculate prediction interval for simple regression model.

Calculates the prediction interval for a new observation. The prediction interval shows the probability that a future individual observation falls within this interval.

Template Parameters
IteratorXIterator type for predictor variable
Parameters
modelSimple regression analysis results
x_firstBeginning iterator for original predictor variable data
x_lastEnding iterator for original predictor variable data
x_newx value of the point to predict
confidenceConfidence level (default: 0.95)
Returns
prediction_interval Predicted value and prediction interval
Exceptions
std::invalid_argumentIf confidence is outside (0, 1) range

Definition at line 695 of file linear_regression.hpp.

◆ press_statistic()

template<typename IteratorX , typename IteratorY >
double statcpp::press_statistic ( IteratorX  x_first,
IteratorX  x_last,
IteratorY  y_first,
IteratorY  y_last,
const simple_regression_result model 
)

Calculate PRESS statistic.

Calculates the Prediction Sum of Squares (prediction residual sum of squares). Used for efficient computation of leave-one-out cross-validation.

Template Parameters
IteratorXIterator type for predictor variable
IteratorYIterator type for response variable
Parameters
x_firstBeginning iterator for predictor variable
x_lastEnding iterator for predictor variable
y_firstBeginning iterator for response variable
y_lastEnding iterator for response variable
modelSimple regression model
Returns
PRESS statistic
Exceptions
std::invalid_argumentIf x and y have different lengths

Definition at line 183 of file model_selection.hpp.

◆ pseudo_r_squared_mcfadden()

double statcpp::pseudo_r_squared_mcfadden ( const glm_result model)
inline

McFadden's pseudo R-squared.

Calculates McFadden's pseudo R-squared. Defined as 1 - (LL_model / LL_null).

Parameters
modelFitted GLM model
Returns
McFadden's pseudo R-squared

Definition at line 977 of file glm.hpp.

◆ pseudo_r_squared_nagelkerke()

double statcpp::pseudo_r_squared_nagelkerke ( const glm_result model,
const std::vector< double > &  y,
std::size_t  n 
)
inline

Nagelkerke's pseudo R-squared.

Calculates Nagelkerke's pseudo R-squared. Cox-Snell pseudo R-squared adjusted to have a maximum value of 1.

Uses the relationship: deviance = -2 * (LL_model - LL_saturated), so LL_null = LL_saturated - null_deviance / 2. For binomial (0/1 responses) and Poisson, the saturated model log-likelihood is computed explicitly.

Parameters
modelFitted GLM model
yResponse variable vector (needed to compute saturated LL for non-Gaussian)
nSample size
Returns
Nagelkerke's pseudo R-squared

Definition at line 999 of file glm.hpp.

◆ quartiles() [1/2]

template<typename Iterator >
quartile_result statcpp::quartiles ( Iterator  first,
Iterator  last 
)

Return quartiles.

Calculates quartiles (Q1, Q2, Q3) from sorted range.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
Returns
Quartiles
Exceptions
std::invalid_argumentIf range is empty
Note
Equivalent to R's type=7 (default) or Excel's QUARTILE.INC.

Definition at line 230 of file order_statistics.hpp.

◆ quartiles() [2/2]

template<typename Iterator , typename Projection >
quartile_result statcpp::quartiles ( Iterator  first,
Iterator  last,
Projection  proj 
)

Return quartiles with projection.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning of sorted range
lastEnd of sorted range
projProjection function
Returns
Quartiles
Exceptions
std::invalid_argumentIf range is empty

Definition at line 255 of file order_statistics.hpp.

◆ r_squared()

template<typename IteratorY , typename IteratorPred >
double statcpp::r_squared ( IteratorY  y_first,
IteratorY  y_last,
IteratorPred  pred_first,
IteratorPred  pred_last 
)

Calculate coefficient of determination from observed and predicted values.

Calculated as R^2 = 1 - SS_residual / SS_total.

Template Parameters
IteratorYIterator type for observed values
IteratorPredIterator type for predicted values
Parameters
y_firstBeginning iterator for observed values
y_lastEnding iterator for observed values
pred_firstBeginning iterator for predicted values
pred_lastEnding iterator for predicted values
Returns
double Coefficient of determination R^2
Exceptions
std::invalid_argumentIf y and predictions have different lengths
std::invalid_argumentIf there are fewer than 2 observations

Definition at line 1125 of file linear_regression.hpp.

◆ r_to_d()

double statcpp::r_to_d ( double  r)
inline

Convert correlation coefficient to Cohen's d.

Parameters
rCorrelation coefficient
Returns
Cohen's d
Exceptions
std::invalid_argumentIf |r| >= 1

Definition at line 273 of file effect_size.hpp.

◆ randomize_seed()

void statcpp::randomize_seed ( )
inline

Randomly reset the random engine seed.

Re-initializes the global random engine seed with a value obtained from a random device. Use this when unpredictable random sequences are needed.

Definition at line 56 of file random_engine.hpp.

◆ range() [1/2]

template<typename Iterator >
double statcpp::range ( Iterator  first,
Iterator  last 
)

Range (maximum - minimum)

Computes the difference between the maximum and minimum values in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Range (maximum - minimum)
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 50 of file dispersion_spread.hpp.

◆ range() [2/2]

template<typename Iterator , typename Projection >
double statcpp::range ( Iterator  first,
Iterator  last,
Projection  proj 
)

Range of projected values using a lambda expression.

Computes the range of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Range of projected values (maximum - minimum)
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 73 of file dispersion_spread.hpp.

◆ rank_transform()

std::vector< double > statcpp::rank_transform ( const std::vector< double > &  data)
inline

Rank transformation.

Uses average rank for ties

Parameters
dataData vector
Returns
Vector of ranks

Definition at line 415 of file data_wrangling.hpp.

◆ relative_error()

double statcpp::relative_error ( double  x,
double  x_ref 
)
inline

Compute the relative error between two values.

relative_error = |x - x_ref| / max(|x_ref|, eps)

Parameters
xComputed value
x_refReference value
Returns
Relative error

Definition at line 229 of file numerical_utils.hpp.

◆ relative_frequency() [1/2]

template<typename Iterator >
auto statcpp::relative_frequency ( Iterator  first,
Iterator  last 
) -> std::unordered_map<typename std::iterator_traits<Iterator>::value_type, double>

Return relative frequency for each value.

Calculates the relative frequency by dividing each value's frequency by the total count.

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator
lastEnding iterator
Returns
Map of values and their relative frequencies

Definition at line 232 of file frequency_distribution.hpp.

◆ relative_frequency() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::relative_frequency ( Iterator  first,
Iterator  last,
Projection  proj 
) -> std::unordered_map<std::invoke_result_t<Projection, typename std::iterator_traits<Iterator>::value_type>, double>

Relative frequency with projection.

Returns the relative frequency of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator
lastEnding iterator
projProjection function
Returns
Map of values and their relative frequencies

Definition at line 266 of file frequency_distribution.hpp.

◆ relative_risk() [1/2]

relative_risk_result statcpp::relative_risk ( const std::vector< std::vector< std::size_t > > &  table)
inline

Calculate relative risk (risk ratio) from a 2x2 contingency table.

Calculates the relative risk and its confidence interval. Relative risk = (a/(a+b)) / (c/(c+d))

Standard error is calculated on the log scale (Greenland-Robins method): SE(log RR) = sqrt((1-p1)/(n1*p1) + (1-p0)/(n0*p0)) = sqrt((1-p1)/a + (1-p0)/c) where p1 = a/(a+b), p0 = c/(c+d)

Parameters
table2x2 contingency table in the form [[a, b], [c, d]]
  • a: Exposed and diseased
  • b: Exposed and not diseased
  • c: Not exposed and diseased
  • d: Not exposed and not diseased
Returns
Relative risk calculation result
Exceptions
std::invalid_argumentIf table is not 2x2, if row total is zero, or if risk is zero

Definition at line 191 of file categorical.hpp.

◆ relative_risk() [2/2]

relative_risk_result statcpp::relative_risk ( std::size_t  a,
std::size_t  b,
std::size_t  c,
std::size_t  d 
)
inline

Calculate relative risk from a 2x2 contingency table (specifying cell values directly)

Parameters
aExposed and diseased
bExposed and not diseased
cNot exposed and diseased
dNot exposed and not diseased
Returns
Relative risk calculation result
Exceptions
std::invalid_argumentIf row total is zero or if risk is zero

Definition at line 239 of file categorical.hpp.

◆ ridge_regression()

regularized_regression_result statcpp::ridge_regression ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  y,
double  lambda,
bool  standardize = true,
std::size_t  max_iter = 1000,
double  tol = 1e-6 
)
inline

Perform Ridge regression (L2 regularization)

Solves Ridge regression using coordinate descent. L2 penalty shrinks coefficients and handles multicollinearity.

Parameters
XPredictor matrix (each row is one sample, no intercept column)
yResponse variable vector
lambdaRegularization parameter (>= 0)
standardizeWhether to standardize data (default: true)
max_iterMaximum number of iterations (default: 1000)
tolConvergence tolerance (default: 1e-6)
Returns
Regularized regression result
Exceptions
std::invalid_argumentIf lambda is negative, data is empty, or X and y have different sizes

Definition at line 463 of file model_selection.hpp.

◆ risk_difference() [1/2]

risk_difference_result statcpp::risk_difference ( const std::vector< std::vector< std::size_t > > &  table)
inline

Calculate risk difference from a 2x2 contingency table.

Calculates the risk difference (attributable risk) and its confidence interval. Risk difference = (a/(a+b)) - (c/(c+d))

Parameters
table2x2 contingency table in the form [[a, b], [c, d]]
Returns
Risk difference calculation result
Exceptions
std::invalid_argumentIf table is not 2x2 or if row total is zero

Definition at line 268 of file categorical.hpp.

◆ risk_difference() [2/2]

risk_difference_result statcpp::risk_difference ( std::size_t  a,
std::size_t  b,
std::size_t  c,
std::size_t  d 
)
inline

Calculate risk difference from a 2x2 contingency table (specifying cell values directly)

Parameters
aExposed and diseased
bExposed and not diseased
cNot exposed and diseased
dNot exposed and not diseased
Returns
Risk difference calculation result
Exceptions
std::invalid_argumentIf row total is zero

Definition at line 312 of file categorical.hpp.

◆ risk_ratio()

double statcpp::risk_ratio ( double  a,
double  b,
double  c,
double  d 
)
inline

Relative risk (risk ratio)

Calculates the relative risk from a 2x2 contingency table.

Parameters
aCell (1,1) frequency (exposed, disease present)
bCell (1,2) frequency (exposed, disease absent)
cCell (2,1) frequency (unexposed, disease present)
dCell (2,2) frequency (unexposed, disease absent)
Returns
Relative risk
Exceptions
std::invalid_argumentIf row total is zero or risk in group 2 is zero

Definition at line 402 of file effect_size.hpp.

◆ rmse()

template<typename Iterator1 , typename Iterator2 >
double statcpp::rmse ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2 
)

Root Mean Squared Error (RMSE)

Template Parameters
Iterator1RandomAccessIterator type for actual values
Iterator2RandomAccessIterator type for predicted values
Parameters
first1Beginning iterator of actual values
last1End iterator of actual values
first2Beginning iterator of predicted values
Returns
RMSE
Exceptions
std::invalid_argumentIf range is empty

Definition at line 266 of file time_series.hpp.

◆ rolling_max()

std::vector< double > statcpp::rolling_max ( const std::vector< double > &  data,
std::size_t  window 
)
inline

Moving maximum.

Parameters
dataData vector
windowWindow size
Returns
Vector of moving maximums

Definition at line 885 of file data_wrangling.hpp.

◆ rolling_mean()

std::vector< double > statcpp::rolling_mean ( const std::vector< double > &  data,
std::size_t  window 
)
inline

Moving average.

Parameters
dataData vector
windowWindow size
Returns
Vector of moving averages

Definition at line 788 of file data_wrangling.hpp.

◆ rolling_min()

std::vector< double > statcpp::rolling_min ( const std::vector< double > &  data,
std::size_t  window 
)
inline

Moving minimum.

Parameters
dataData vector
windowWindow size
Returns
Vector of moving minimums

Definition at line 862 of file data_wrangling.hpp.

◆ rolling_std()

std::vector< double > statcpp::rolling_std ( const std::vector< double > &  data,
std::size_t  window 
)
inline

Moving standard deviation.

Parameters
dataData vector
windowWindow size
Returns
Vector of moving standard deviations

Definition at line 833 of file data_wrangling.hpp.

◆ rolling_sum()

std::vector< double > statcpp::rolling_sum ( const std::vector< double > &  data,
std::size_t  window 
)
inline

Moving sum.

Parameters
dataData vector
windowWindow size
Returns
Vector of moving sums

Definition at line 908 of file data_wrangling.hpp.

◆ safe_divide()

double statcpp::safe_divide ( double  numerator,
double  denominator,
double  default_value = std::numeric_limits<double>::quiet_NaN() 
)
inline

Safe division with check for division by zero.

Parameters
numeratorNumerator
denominatorDenominator
default_valueValue to return if denominator is zero (default: NaN)
Returns
numerator / denominator, or default_value if denominator is zero

Definition at line 243 of file numerical_utils.hpp.

◆ sample_covariance() [1/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::sample_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Sample covariance (unbiased covariance)

Computes the sample covariance (unbiased estimator) of two variables. s_xy = (1/(n-1)) * sum((x_i - x_bar)(y_i - y_bar))

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Sample covariance
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 172 of file correlation_covariance.hpp.

◆ sample_covariance() [2/3]

template<typename Iterator1 , typename Iterator2 >
double statcpp::sample_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
double  mean_x,
double  mean_y 
)

Sample covariance with precomputed means.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
mean_xMean of the first data
mean_yMean of the second data
Returns
Sample covariance
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 216 of file correlation_covariance.hpp.

◆ sample_covariance() [3/3]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::sample_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Sample covariance (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Sample covariance
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 260 of file correlation_covariance.hpp.

◆ sample_kurtosis() [1/4]

template<typename Iterator >
double statcpp::sample_kurtosis ( Iterator  first,
Iterator  last 
)

Calculate sample kurtosis (bias-corrected version)

Calculates the bias-corrected kurtosis estimate from a sample.

Formula: G2 = ((n+1) * g2 + 6) * (n-1) / ((n-2)(n-3)) where g2 is the population kurtosis estimator (excess kurtosis)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Sample kurtosis value
Exceptions
std::invalid_argumentIf number of elements is less than 4

Definition at line 535 of file shape_of_distribution.hpp.

◆ sample_kurtosis() [2/4]

template<typename Iterator >
double statcpp::sample_kurtosis ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate sample kurtosis with precomputed mean.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Sample kurtosis value
Exceptions
std::invalid_argumentIf number of elements is less than 4

Definition at line 559 of file shape_of_distribution.hpp.

◆ sample_kurtosis() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_kurtosis ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate sample kurtosis with projection.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Sample kurtosis value
Exceptions
std::invalid_argumentIf number of elements is less than 4

Definition at line 587 of file shape_of_distribution.hpp.

◆ sample_kurtosis() [4/4]

template<typename Iterator , typename Projection >
double statcpp::sample_kurtosis ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate sample kurtosis with projection and precomputed mean.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample kurtosis value
Exceptions
std::invalid_argumentIf number of elements is less than 4

Definition at line 613 of file shape_of_distribution.hpp.

◆ sample_size_for_moe_mean()

std::size_t statcpp::sample_size_for_moe_mean ( double  margin_of_error,
double  sigma,
double  confidence_level = 0.95 
)
inline

Calculate sample size for mean estimation (known population standard deviation)

Calculates the sample size required to achieve the specified margin of error. n = (z_{alpha/2} * sigma / MoE)^2

Parameters
margin_of_errorTarget margin of error
sigmaPopulation standard deviation (known or estimated)
confidence_levelConfidence level (default: 0.95)
Returns
Required sample size
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 627 of file estimation.hpp.

◆ sample_size_for_moe_proportion()

std::size_t statcpp::sample_size_for_moe_proportion ( double  margin_of_error,
double  confidence_level = 0.95,
double  p_estimate = 0.5 
)
inline

Calculate sample size for proportion estimation.

Calculates the sample size required to achieve the specified margin of error. n = (z_{alpha/2} / MoE)^2 * p(1-p)

Parameters
margin_of_errorTarget margin of error
confidence_levelConfidence level (default: 0.95)
p_estimatePrior estimate of proportion (default: 0.5 for most conservative estimate)
Returns
Required sample size
Exceptions
std::invalid_argumentIf parameters are outside valid range

Definition at line 591 of file estimation.hpp.

◆ sample_size_prop_test() [1/2]

std::size_t statcpp::sample_size_prop_test ( double  p1,
double  p2,
double  power,
double  alpha,
alternative_hypothesis  alt 
)
inline

Calculate required sample size for two-sample proportion test (enum overload)

Parameters
p1Proportion of group 1
p2Proportion of group 2
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Required sample size per group

Definition at line 599 of file power_analysis.hpp.

◆ sample_size_prop_test() [2/2]

std::size_t statcpp::sample_size_prop_test ( double  p1,
double  p2,
double  power = 0.80,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Calculate required sample size for two-sample proportion test.

Parameters
p1Proportion of group 1
p2Proportion of group 2
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Required sample size per group
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 409 of file power_analysis.hpp.

◆ sample_size_t_test_one_sample() [1/2]

std::size_t statcpp::sample_size_t_test_one_sample ( double  effect_size,
double  power,
double  alpha,
alternative_hypothesis  alt 
)
inline

Calculate required sample size for one-sample t-test (enum overload)

Parameters
effect_sizeEffect size (Cohen's d)
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
altType of alternative hypothesis (default: two_sided)
Returns
Required sample size

Definition at line 531 of file power_analysis.hpp.

◆ sample_size_t_test_one_sample() [2/2]

std::size_t statcpp::sample_size_t_test_one_sample ( double  effect_size,
double  power = 0.80,
double  alpha = 0.05,
const std::string &  alternative = "two.sided" 
)
inline

Calculate required sample size for one-sample t-test.

Parameters
effect_sizeEffect size (Cohen's d)
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Required sample size
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 195 of file power_analysis.hpp.

◆ sample_size_t_test_two_sample() [1/2]

std::size_t statcpp::sample_size_t_test_two_sample ( double  effect_size,
double  power,
double  alpha,
double  ratio,
alternative_hypothesis  alt 
)
inline

Calculate required sample size for two-sample t-test (enum overload)

Parameters
effect_sizeEffect size (Cohen's d)
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
ratioRatio n2/n1 (default: 1.0)
altType of alternative hypothesis (default: two_sided)
Returns
Required sample size for group 1

Definition at line 565 of file power_analysis.hpp.

◆ sample_size_t_test_two_sample() [2/2]

std::size_t statcpp::sample_size_t_test_two_sample ( double  effect_size,
double  power = 0.80,
double  alpha = 0.05,
double  ratio = 1.0,
const std::string &  alternative = "two.sided" 
)
inline

Calculate required sample size for two-sample t-test (per group)

Parameters
effect_sizeEffect size (Cohen's d)
powerTarget power (default: 0.80)
alphaSignificance level (default: 0.05)
ratioRatio n2/n1 (default: 1.0 = equal sizes)
alternativeType of alternative hypothesis (default: "two.sided")
Returns
Required sample size for group 1 (group 2 size is n1 * ratio)
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 295 of file power_analysis.hpp.

◆ sample_skewness() [1/4]

template<typename Iterator >
double statcpp::sample_skewness ( Iterator  first,
Iterator  last 
)

Calculate sample skewness (bias-corrected version)

Calculates the bias-corrected skewness estimate from a sample.

Formula: G1 = sqrt(n(n-1)) / (n-2) * g1 where g1 is the population skewness estimator

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Sample skewness value
Exceptions
std::invalid_argumentIf number of elements is less than 3

Definition at line 202 of file shape_of_distribution.hpp.

◆ sample_skewness() [2/4]

template<typename Iterator >
double statcpp::sample_skewness ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate sample skewness with precomputed mean.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Sample skewness value
Exceptions
std::invalid_argumentIf number of elements is less than 3

Definition at line 225 of file shape_of_distribution.hpp.

◆ sample_skewness() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_skewness ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate sample skewness with projection.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Sample skewness value
Exceptions
std::invalid_argumentIf number of elements is less than 3

Definition at line 252 of file shape_of_distribution.hpp.

◆ sample_skewness() [4/4]

template<typename Iterator , typename Projection >
double statcpp::sample_skewness ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate sample skewness with projection and precomputed mean.

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample skewness value
Exceptions
std::invalid_argumentIf number of elements is less than 3

Definition at line 277 of file shape_of_distribution.hpp.

◆ sample_stddev() [1/4]

template<typename Iterator >
double statcpp::sample_stddev ( Iterator  first,
Iterator  last 
)

Sample standard deviation.

Computes the sample standard deviation (square root of variance divided by N-1).

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Sample standard deviation
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 669 of file dispersion_spread.hpp.

◆ sample_stddev() [2/4]

template<typename Iterator >
double statcpp::sample_stddev ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Sample standard deviation using precomputed mean.

Computes sample standard deviation when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Sample standard deviation
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 687 of file dispersion_spread.hpp.

◆ sample_stddev() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_stddev ( Iterator  first,
Iterator  last,
Projection  proj 
)

Sample standard deviation of projected values using a lambda expression.

Computes the sample standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Sample standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 709 of file dispersion_spread.hpp.

◆ sample_stddev() [4/4]

template<typename Iterator , typename Projection >
double statcpp::sample_stddev ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Sample standard deviation of projected values using precomputed mean.

Computes sample standard deviation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 729 of file dispersion_spread.hpp.

◆ sample_variance() [1/4]

template<typename Iterator >
double statcpp::sample_variance ( Iterator  first,
Iterator  last 
)

Sample variance (unbiased variance)

Computes the unbiased sample variance (divide by N-1).

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Sample variance
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 339 of file dispersion_spread.hpp.

◆ sample_variance() [2/4]

template<typename Iterator >
double statcpp::sample_variance ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Sample variance using precomputed mean.

Computes sample variance when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Sample variance
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 357 of file dispersion_spread.hpp.

◆ sample_variance() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::sample_variance ( Iterator  first,
Iterator  last,
Projection  proj 
)

Sample variance of projected values using a lambda expression.

Computes the sample variance of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Sample variance of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 379 of file dispersion_spread.hpp.

◆ sample_variance() [4/4]

template<typename Iterator , typename Projection >
double statcpp::sample_variance ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Sample variance of projected values using precomputed mean.

Computes sample variance using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample variance of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 399 of file dispersion_spread.hpp.

◆ sample_with_replacement()

template<typename T >
std::vector< T > statcpp::sample_with_replacement ( const std::vector< T > &  data,
std::size_t  n 
)

Random sampling (with replacement)

Template Parameters
TData type
Parameters
dataData vector
nSample size
Returns
Sampled data

Definition at line 625 of file data_wrangling.hpp.

◆ sample_without_replacement()

template<typename T >
std::vector< T > statcpp::sample_without_replacement ( const std::vector< T > &  data,
std::size_t  n 
)

Random sampling (without replacement)

Template Parameters
TData type
Parameters
dataData vector
nSample size
Returns
Sampled data

Definition at line 651 of file data_wrangling.hpp.

◆ scheffe_posthoc()

posthoc_result statcpp::scheffe_posthoc ( const one_way_anova_result anova_result,
double  alpha = 0.05 
)
inline

Perform Scheffe's method for multiple comparisons.

Performs multiple comparisons among all pairs of groups using Scheffe's method as a post-hoc test following one-way ANOVA. This is the most conservative method.

Scheffe's method is valid for any linear contrast, applicable not only to pairwise comparisons but also to complex contrasts. The F statistic is calculated as t^2 / (k-1) and compared to F(k-1, df_error) distribution. The p-value is computed as 1 - F_cdf(F_s, k-1, df_error).

Parameters
anova_resultResult from one-way ANOVA
alphaSignificance level (default: 0.05)
Returns
posthoc_result Post-hoc comparison results
Exceptions
std::invalid_argumentIf alpha is outside the range (0, 1)

Definition at line 591 of file anova.hpp.

◆ seasonal_diff()

template<typename Iterator >
std::vector< double > statcpp::seasonal_diff ( Iterator  first,
Iterator  last,
std::size_t  period 
)

Seasonal differencing.

Calculates the seasonal difference for time series data with seasonality.

Template Parameters
IteratorRandomAccessIterator type
Parameters
firstBeginning iterator
lastEnd iterator
periodSeasonal period
Returns
Vector of seasonal differenced series
Exceptions
std::invalid_argumentIf data is insufficient for the period

Definition at line 455 of file time_series.hpp.

◆ sensitivity_analysis_pattern_mixture()

sensitivity_analysis_result statcpp::sensitivity_analysis_pattern_mixture ( const std::vector< double > &  data,
const std::vector< double > &  delta_values 
)
inline

Sensitivity analysis using pattern mixture model.

Evaluates robustness of estimates by varying the difference (delta) between missing and observed values under MNAR (Missing Not At Random) assumption.

Basic formula of pattern mixture model:

  • E[Y] = E[Y|R=1] * P(R=1) + E[Y|R=0] * P(R=0)
  • where R=1 indicates observed, R=0 indicates missing
  • Sensitivity parameter delta: E[Y|R=0] = E[Y|R=1] + delta

Interpretation of delta:

  • delta = 0: MAR (missing follows same distribution as observed)
  • delta > 0: Missing values tend to be higher than observed
  • delta < 0: Missing values tend to be lower than observed
Note
This implementation uses a simplified assumption for variance (equal to observed variance). More rigorous analysis requires pattern-specific variance estimation.
Parameters
data1D data for analysis
delta_valuesVector of sensitivity parameter delta values
Returns
sensitivity_analysis_result Sensitivity analysis result
Exceptions
std::invalid_argumentIf data is empty or all values are missing

Definition at line 810 of file missing_data.hpp.

◆ sensitivity_analysis_selection_model()

sensitivity_analysis_result statcpp::sensitivity_analysis_selection_model ( const std::vector< double > &  data,
const std::vector< double > &  phi_values 
)
inline

Sensitivity analysis using selection model.

Evaluates robustness of estimates by varying the degree (phi) to which missingness depends on the response value. phi = 0 corresponds to MAR assumption, and phi > 0 indicates that missing values tend to be lower than observed values.

Parameters
data1D data for analysis
phi_valuesVector of sensitivity parameter phi values
Returns
sensitivity_analysis_result Sensitivity analysis result
Exceptions
std::invalid_argumentIf data is empty or all values are missing

Definition at line 888 of file missing_data.hpp.

◆ set_seed()

void statcpp::set_seed ( std::uint64_t  seed)
inline

Set the seed of the random engine.

Sets the seed of the global random engine to the specified value. Use this when reproducible random sequences are needed.

Parameters
seedSeed value to set

Definition at line 45 of file random_engine.hpp.

◆ shapiro_wilk_test()

template<typename Iterator >
test_result statcpp::shapiro_wilk_test ( Iterator  first,
Iterator  last 
)

Perform Shapiro-Wilk test.

Tests whether data follows a normal distribution. Uses Royston's algorithm for approximation. Optimized for sample sizes n <= 50, but supports up to n <= 5000.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of range
lastEnding iterator of range
Returns
test_result Test result containing W statistic, p-value, and sample size
Exceptions
std::invalid_argumentIf there are fewer than 3 elements
std::invalid_argumentIf there are more than 5000 elements
std::invalid_argumentIf variance is zero
Note
Null hypothesis: Data follows a normal distribution
W statistic closer to 1 indicates higher normality

Definition at line 144 of file nonparametric_tests.hpp.

◆ silhouette_score()

double statcpp::silhouette_score ( const std::vector< std::vector< double > > &  data,
const std::vector< std::size_t > &  labels 
)
inline

Calculate silhouette score.

Calculates the silhouette score to evaluate clustering quality.

Parameters
dataVector of data points
labelsCluster labels
Returns
Silhouette score (-1 to 1, closer to 1 is better)
Exceptions
std::invalid_argumentIf data is empty or sizes don't match
Note
Score interpretation: 0.7-1.0: strong structure, 0.5-0.7: reasonable structure, 0.25-0.5: weak structure, < 0.25: no substantial structure

Definition at line 498 of file clustering.hpp.

◆ simple_linear_regression()

template<typename IteratorX , typename IteratorY >
simple_regression_result statcpp::simple_linear_regression ( IteratorX  x_first,
IteratorX  x_last,
IteratorY  y_first,
IteratorY  y_last 
)

Perform simple linear regression.

Estimates simple regression model y = b0 + b1*x using least squares method. Calculates regression coefficients, standard errors, t-tests, F-test, and coefficient of determination.

Template Parameters
IteratorXIterator type for predictor variable
IteratorYIterator type for response variable
Parameters
x_firstBeginning iterator for predictor variable
x_lastEnding iterator for predictor variable
y_firstBeginning iterator for response variable
y_lastEnding iterator for response variable
Returns
simple_regression_result Regression analysis results
Exceptions
std::invalid_argumentIf x and y have different lengths
std::invalid_argumentIf there are fewer than 3 observations
std::invalid_argumentIf x has zero variance

Definition at line 128 of file linear_regression.hpp.

◆ skewness() [1/4]

template<typename Iterator >
double statcpp::skewness ( Iterator  first,
Iterator  last 
)

Calculate skewness (alias for sample_skewness)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
Returns
Sample skewness value

Definition at line 298 of file shape_of_distribution.hpp.

◆ skewness() [2/4]

template<typename Iterator >
double statcpp::skewness ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Calculate skewness (precomputed mean version)

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
precomputed_meanPrecomputed mean value
Returns
Sample skewness value

Definition at line 313 of file shape_of_distribution.hpp.

◆ skewness() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::skewness ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate skewness (projection version)

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
Returns
Sample skewness value

Definition at line 332 of file shape_of_distribution.hpp.

◆ skewness() [4/4]

template<typename Iterator , typename Projection >
double statcpp::skewness ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Calculate skewness (projection version, precomputed mean)

Template Parameters
IteratorInput iterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnd iterator of data range
projProjection function
precomputed_meanPrecomputed mean value
Returns
Sample skewness value

Definition at line 349 of file shape_of_distribution.hpp.

◆ sort_values()

template<typename T >
std::vector< T > statcpp::sort_values ( const std::vector< T > &  data,
bool  ascending = true 
)

Return a sorted vector (ascending)

Template Parameters
TData type
Parameters
dataData vector
ascendingtrue for ascending, false for descending
Returns
Sorted vector

Definition at line 579 of file data_wrangling.hpp.

◆ spearman_correlation() [1/2]

template<typename Iterator1 , typename Iterator2 >
double statcpp::spearman_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)

Spearman's rank correlation coefficient.

Computes Spearman's rank correlation coefficient of two variables. rho = Pearson(rank(X), rank(Y)) Applies Pearson correlation coefficient to ranked data. Can detect monotonic relationships and is robust to outliers.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
Returns
Spearman's rank correlation coefficient (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 650 of file correlation_covariance.hpp.

◆ spearman_correlation() [2/2]

template<typename Iterator1 , typename Iterator2 , typename Projection1 , typename Projection2 >
double statcpp::spearman_correlation ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
Projection1  proj1,
Projection2  proj2 
)

Spearman's rank correlation coefficient (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Spearman's rank correlation coefficient (-1 to 1)
Exceptions
std::invalid_argumentIf range is empty, lengths differ, or number of elements is less than 2

Definition at line 690 of file correlation_covariance.hpp.

◆ sqrt_transform()

std::vector< double > statcpp::sqrt_transform ( const std::vector< double > &  data)
inline

Square root transformation.

Parameters
dataData vector
Returns
Square root-transformed data (negative values become NA)

Definition at line 366 of file data_wrangling.hpp.

◆ standard_error() [1/3]

template<typename Iterator >
double statcpp::standard_error ( Iterator  first,
Iterator  last 
)

Calculate standard error of the mean.

Standard error: SE = s / sqrt(n)

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
Returns
Standard error
Exceptions
std::invalid_argumentIf there are fewer than 2 elements

Definition at line 38 of file estimation.hpp.

◆ standard_error() [2/3]

template<typename Iterator >
double statcpp::standard_error ( Iterator  first,
Iterator  last,
double  precomputed_stddev 
)

Calculate standard error of the mean (using precomputed standard deviation)

Template Parameters
IteratorIterator type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
precomputed_stddevPrecomputed standard deviation
Returns
Standard error
Exceptions
std::invalid_argumentIf the range is empty

Definition at line 81 of file estimation.hpp.

◆ standard_error() [3/3]

template<typename Iterator , typename Projection >
double statcpp::standard_error ( Iterator  first,
Iterator  last,
Projection  proj 
)

Calculate standard error of the mean (projection version)

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBeginning iterator of data range
lastEnding iterator of data range
projProjection function
Returns
Standard error
Exceptions
std::invalid_argumentIf there are fewer than 2 elements

Definition at line 60 of file estimation.hpp.

◆ standardize()

std::vector< std::vector< double > > statcpp::standardize ( const std::vector< std::vector< double > > &  data)
inline

Z-score standardization.

Standardizes each variable to mean 0 and standard deviation 1. Data is passed with rows=observations and columns=variables.

Parameters
dataMatrix data (rows=observations, columns=variables)
Returns
Standardized data
Exceptions
std::invalid_argumentIf data is empty, rows have different column counts, there are fewer than 2 observations, or any variable has zero variance

Definition at line 139 of file multivariate.hpp.

◆ stddev() [1/4]

template<typename Iterator >
double statcpp::stddev ( Iterator  first,
Iterator  last 
)

Standard deviation (alias for sample_stddev)

Computes sample standard deviation. Equivalent to sample_stddev.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Standard deviation
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 750 of file dispersion_spread.hpp.

◆ stddev() [2/4]

template<typename Iterator >
double statcpp::stddev ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Standard deviation using precomputed mean.

Computes sample standard deviation when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Standard deviation
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 768 of file dispersion_spread.hpp.

◆ stddev() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::stddev ( Iterator  first,
Iterator  last,
Projection  proj 
)

Standard deviation of projected values using a lambda expression.

Computes the sample standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 790 of file dispersion_spread.hpp.

◆ stddev() [4/4]

template<typename Iterator , typename Projection >
double statcpp::stddev ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Standard deviation of projected values using precomputed mean.

Computes sample standard deviation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Standard deviation of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 810 of file dispersion_spread.hpp.

◆ stdev() [1/4]

template<typename Iterator >
double statcpp::stdev ( Iterator  first,
Iterator  last,
double  precomputed_mean,
std::size_t  ddof 
)

Standard deviation using precomputed mean (with ddof)

Use when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
ddofDegrees of freedom correction (0 or 1)
Returns
Standard deviation
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 523 of file dispersion_spread.hpp.

◆ stdev() [2/4]

template<typename Iterator , typename Projection >
double statcpp::stdev ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean,
std::size_t  ddof 
)

Standard deviation of projected values using precomputed mean (with ddof)

Computes standard deviation using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
ddofDegrees of freedom correction (0 or 1)
Returns
Standard deviation of projected values
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 567 of file dispersion_spread.hpp.

◆ stdev() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::stdev ( Iterator  first,
Iterator  last,
Projection  proj,
std::size_t  ddof = 0 
)

Standard deviation of projected values using a lambda expression (with ddof)

Computes the standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
ddofDegrees of freedom correction (0 or 1)
Returns
Standard deviation of projected values
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 546 of file dispersion_spread.hpp.

◆ stdev() [4/4]

template<typename Iterator >
double statcpp::stdev ( Iterator  first,
Iterator  last,
std::size_t  ddof = 0 
)

Standard deviation (ddof = Delta Degrees of Freedom)

ddof = 0: Population standard deviation (square root of variance divided by N) ddof = 1: Sample standard deviation (square root of variance divided by N-1) Behaves like NumPy's np.std(a, ddof=...).

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
ddofDegrees of freedom correction (0 or 1)
Returns
Standard deviation
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 504 of file dispersion_spread.hpp.

◆ stratified_sample()

template<typename K , typename V >
std::vector< V > statcpp::stratified_sample ( const std::vector< K > &  strata,
const std::vector< V > &  data,
double  sample_ratio 
)

Stratified sampling.

Template Parameters
KStratum type
VData type
Parameters
strataVector of strata
dataData vector
sample_ratioSampling ratio
Returns
Stratified sampled data

Definition at line 682 of file data_wrangling.hpp.

◆ studentized_range_cdf()

double statcpp::studentized_range_cdf ( double  q,
double  k,
double  df 
)
inline

CDF of the studentized range distribution.

Computes P(Q <= q) where Q follows the studentized range distribution with k groups and df degrees of freedom.

Uses the Copenhaver & Holland (1988) algorithm with nested Gauss-Legendre quadrature, equivalent to R's ptukey().

Parameters
qQuantile value
kNumber of groups (must be >= 2)
dfDegrees of freedom (must be > 0)
Returns
Probability P(Q <= q)
Exceptions
std::invalid_argumentIf k < 2 or df <= 0

Definition at line 1235 of file continuous_distributions.hpp.

◆ studentized_range_quantile()

double statcpp::studentized_range_quantile ( double  p,
double  k,
double  df 
)
inline

Quantile function of the studentized range distribution.

Computes q such that P(Q <= q) = p where Q follows the studentized range distribution with k groups and df degrees of freedom.

Uses Newton-Raphson iteration with numerical differentiation (central difference).

Parameters
pProbability (must be in [0, 1])
kNumber of groups (must be >= 2)
dfDegrees of freedom (must be > 0)
Returns
Quantile value
Exceptions
std::invalid_argumentIf k < 2, df <= 0, or p is outside [0, 1]
Note
Uses Newton-Raphson iteration with tolerance eps = 1e-10 and maximum 50 iterations. If the iteration does not converge within the maximum number of iterations, the best approximation so far is returned (no exception is thrown). For interior points (0 < p < 1), the result is a finite value. Boundary values p = 0 or p = 1 may return +/-infinity as per the distribution definition. In practice, convergence is achieved for all typical input ranges.

Definition at line 1460 of file continuous_distributions.hpp.

◆ sum() [1/2]

template<typename Iterator >
auto statcpp::sum ( Iterator  first,
Iterator  last 
)

Sum.

Computes the sum of all elements in the range.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Sum value

Definition at line 46 of file basic_statistics.hpp.

◆ sum() [2/2]

template<typename Iterator , typename Projection >
auto statcpp::sum ( Iterator  first,
Iterator  last,
Projection  proj 
)

Sum of projected values using a lambda expression.

Computes the sum of the results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Sum of projected values

Definition at line 65 of file basic_statistics.hpp.

◆ t_cdf()

double statcpp::t_cdf ( double  x,
double  df 
)
inline

t-distribution cumulative distribution function (CDF)

Computed using the regularized incomplete beta function. The CDF of t-distribution is expressed as:

F(x; nu) = 1 - 0.5 * I_{nu/(nu+x^2)}(nu/2, 1/2) (for x >= 0) F(x; nu) = 0.5 * I_{nu/(nu+x^2)}(nu/2, 1/2) (for x < 0)

where I_z(a,b) is the regularized incomplete beta function and nu is degrees of freedom. This transformation enables efficient computation of t-distribution CDF via beta distribution CDF.

Parameters
xRandom variable value
dfDegrees of freedom nu
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 707 of file continuous_distributions.hpp.

◆ t_pdf()

double statcpp::t_pdf ( double  x,
double  df 
)
inline

t-distribution probability density function (PDF)

f(x) = Gamma((nu+1)/2) / (sqrt(nu*pi) * Gamma(nu/2)) * (1 + x^2/nu)^(-(nu+1)/2)

Parameters
xRandom variable value
dfDegrees of freedom
Returns
Probability density
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 680 of file continuous_distributions.hpp.

◆ t_quantile()

double statcpp::t_quantile ( double  p,
double  df 
)
inline

t-distribution quantile function (Newton-Raphson method)

Parameters
pProbability (0 < p < 1)
dfDegrees of freedom
Returns
Quantile
Exceptions
std::invalid_argumentIf df <= 0 or p is outside (0, 1)
Note
Uses Newton-Raphson iteration with tolerance eps = 1e-10 and maximum 50 iterations. If the iteration does not converge within the maximum number of iterations, the best approximation so far is returned (no exception is thrown). For interior points (0 < p < 1), the result is a finite value. Boundary values p = 0 or p = 1 may return +/-infinity as per the distribution definition. In practice, convergence is achieved for all typical input ranges.

Definition at line 739 of file continuous_distributions.hpp.

◆ t_rand() [1/2]

double statcpp::t_rand ( double  df)
inline

t-distribution random number generation (using default engine)

Parameters
dfDegrees of freedom
Returns
Random number following t-distribution

Definition at line 812 of file continuous_distributions.hpp.

◆ t_rand() [2/2]

template<typename Engine = default_random_engine>
double statcpp::t_rand ( double  df,
Engine &  engine 
)

t-distribution random number generation

Template Parameters
EngineRandom engine type
Parameters
dfDegrees of freedom
engineRandom engine
Returns
Random number following t-distribution
Exceptions
std::invalid_argumentIf df <= 0

Definition at line 797 of file continuous_distributions.hpp.

◆ t_test()

template<typename Iterator >
test_result statcpp::t_test ( Iterator  first,
Iterator  last,
double  mu0,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

One-sample t-test.

Tests whether the sample mean equals a specific value (unknown population variance).

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of sample data
lastEnd iterator of sample data
mu0Population mean under null hypothesis
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (t-statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf number of elements is less than 2 or variance is zero

Definition at line 231 of file parametric_tests.hpp.

◆ t_test_paired()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::t_test_paired ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

Paired t-test.

Tests whether the mean of differences between two paired samples equals zero.

Template Parameters
Iterator1Input iterator type for first sample
Iterator2Input iterator type for second sample
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (t-statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf sample lengths differ or are less than 2

Definition at line 415 of file parametric_tests.hpp.

◆ t_test_two_sample()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::t_test_two_sample ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

Two-sample t-test (independent samples, pooled variance)

Tests whether the means of two independent samples are equal. Assumes equal variance and uses pooled variance.

Template Parameters
Iterator1Input iterator type for first sample
Iterator2Input iterator type for second sample
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (t-statistic, p-value, degrees of freedom)
Exceptions
std::invalid_argumentIf either sample has less than 2 elements or variance is zero

Definition at line 284 of file parametric_tests.hpp.

◆ t_test_welch()

template<typename Iterator1 , typename Iterator2 >
test_result statcpp::t_test_welch ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

Two-sample t-test (Welch's method)

Tests whether the means of two independent samples are equal. Does not assume equal variance; uses Welch-Satterthwaite approximation for degrees of freedom.

Template Parameters
Iterator1Input iterator type for first sample
Iterator2Input iterator type for second sample
Parameters
first1Beginning iterator of first sample
last1End iterator of first sample
first2Beginning iterator of second sample
last2End iterator of second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (t-statistic, p-value, Welch approximation degrees of freedom)
Exceptions
std::invalid_argumentIf either sample has less than 2 elements or variance is zero

Definition at line 345 of file parametric_tests.hpp.

◆ t_to_r()

double statcpp::t_to_r ( double  t,
double  df 
)
inline

Convert t-value to correlation coefficient.

Parameters
tt-statistic
dfDegrees of freedom
Returns
Correlation coefficient

Definition at line 249 of file effect_size.hpp.

◆ test_mcar_simple()

mcar_test_result statcpp::test_mcar_simple ( const std::vector< std::vector< double > > &  data)
inline

Little's MCAR test (simplified version)

Tests whether the mean difference between complete and incomplete data is significant, determining if data is MCAR (Missing Completely At Random).

Note
This is a simplified version; the complete Little's test requires covariance estimation via EM algorithm.
Parameters
data2D data for testing (rows: observations, columns: variables)
Returns
mcar_test_result Test result (chi-square statistic, p-value, degrees of freedom, conclusion)
Exceptions
std::invalid_argumentIf data is empty

Definition at line 209 of file missing_data.hpp.

◆ tgamma()

double statcpp::tgamma ( double  x)
inline

Gamma function.

Computes the gamma function Gamma(x).

Parameters
xArgument
Returns
Gamma(x)
Exceptions
std::domain_errorIf x is a non-positive integer
Note
For small positive integers, computes factorial directly.

Definition at line 116 of file special_functions.hpp.

◆ trimmed_mean() [1/2]

template<typename Iterator >
double statcpp::trimmed_mean ( Iterator  first,
Iterator  last,
double  proportion 
)

Trimmed mean (accepts a sorted range. proportion: exclusion ratio per side, 0.0 to less than 0.5)

Computes the mean after excluding a certain proportion of data from both ends. Useful for reducing the influence of outliers.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
proportionExclusion ratio per side (0.0 to less than 0.5)
Returns
Trimmed mean
Exceptions
std::invalid_argumentIf range is empty, proportion is out of range, or all elements are excluded

Definition at line 590 of file basic_statistics.hpp.

◆ trimmed_mean() [2/2]

template<typename Iterator , typename Projection >
double statcpp::trimmed_mean ( Iterator  first,
Iterator  last,
double  proportion,
Projection  proj 
)

Trimmed mean of projected values using a lambda expression (projection results must be in sorted order)

Computes the trimmed mean of the results after applying a projection function to each element. Assumes that projection results are sorted.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
proportionExclusion ratio per side (0.0 to less than 0.5)
projProjection function
Returns
Trimmed mean of projected values
Exceptions
std::invalid_argumentIf range is empty, proportion is out of range, or all elements are excluded

Definition at line 634 of file basic_statistics.hpp.

◆ tukey_hsd()

posthoc_result statcpp::tukey_hsd ( const one_way_anova_result anova_result,
const std::vector< std::vector< double > > &  groups,
double  alpha = 0.05 
)
inline

Perform Tukey's Honestly Significant Difference (HSD) test.

Performs all pairwise comparisons among groups using the studentized range distribution (Tukey-Kramer method for unequal sample sizes).

The q statistic is computed as |mean_i - mean_j| / SE where SE = sqrt(MSE/2 * (1/n_i + 1/n_j)), and p-values are obtained from the studentized range distribution with k groups and df_error degrees of freedom.

Parameters
anova_resultResult from one-way ANOVA
groupsData for each group (currently unused; retained for API compatibility and potential future use such as input validation)
alphaSignificance level (default: 0.05)
Returns
posthoc_result Post-hoc comparison results (statistic field contains q statistic)
Exceptions
std::invalid_argumentIf alpha is outside the range (0, 1)

Definition at line 370 of file anova.hpp.

◆ two_way_anova()

two_way_anova_result statcpp::two_way_anova ( const std::vector< std::vector< std::vector< double > > > &  data)
inline

Perform two-way analysis of variance (with replication)

Tests the effects of two factors (A, B) and their interaction on the dependent variable. Assumes equal cell sizes.

Parameters
data3-dimensional data array. data[i][j] is the vector of observations for factor A=i, factor B=j
Returns
two_way_anova_result Results of the analysis of variance
Exceptions
std::invalid_argumentIf number of levels for factor A is less than 2
std::invalid_argumentIf number of levels for factor B is less than 2
std::invalid_argumentIf number of levels for factor B is inconsistent
std::invalid_argumentIf cell sizes are unequal
std::invalid_argumentIf an empty cell exists

Definition at line 215 of file anova.hpp.

◆ uniform_cdf()

double statcpp::uniform_cdf ( double  x,
double  a = 0.0,
double  b = 1.0 
)
inline

Uniform distribution cumulative distribution function (CDF)

F(x) = (x - a) / (b - a)

Parameters
xRandom variable value
aLower bound (default: 0.0)
bUpper bound (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf a >= b

Definition at line 60 of file continuous_distributions.hpp.

◆ uniform_pdf()

double statcpp::uniform_pdf ( double  x,
double  a = 0.0,
double  b = 1.0 
)
inline

Uniform distribution probability density function (PDF)

f(x) = 1 / (b - a) for a <= x <= b

Parameters
xRandom variable value
aLower bound (default: 0.0)
bUpper bound (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf a >= b

Definition at line 38 of file continuous_distributions.hpp.

◆ uniform_quantile()

double statcpp::uniform_quantile ( double  p,
double  a = 0.0,
double  b = 1.0 
)
inline

Uniform distribution quantile function (inverse CDF)

Q(p) = a + p * (b - a)

Parameters
pProbability (0 <= p <= 1)
aLower bound (default: 0.0)
bUpper bound (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf a >= b or p is outside [0, 1]

Definition at line 81 of file continuous_distributions.hpp.

◆ uniform_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::uniform_rand ( double  a,
double  b,
Engine &  engine 
)

Uniform distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
aLower bound
bUpper bound
engineRandom engine
Returns
Random number following uniform distribution
Exceptions
std::invalid_argumentIf a >= b

Definition at line 103 of file continuous_distributions.hpp.

◆ uniform_rand() [2/2]

double statcpp::uniform_rand ( double  a = 0.0,
double  b = 1.0 
)
inline

Uniform distribution random number generation (using default engine)

Parameters
aLower bound (default: 0.0)
bUpper bound (default: 1.0)
Returns
Random number following uniform distribution

Definition at line 119 of file continuous_distributions.hpp.

◆ validate_data()

validation_result statcpp::validate_data ( const std::vector< double > &  data,
bool  allow_missing = false,
bool  allow_infinite = false,
bool  allow_negative = true 
)
inline

Data validation.

Parameters
dataData vector
allow_missingAllow missing values
allow_infiniteAllow infinite values
allow_negativeAllow negative values
Returns
Validation result

Definition at line 1109 of file data_wrangling.hpp.

◆ validate_range()

bool statcpp::validate_range ( const std::vector< double > &  data,
double  min_val = -std::numeric_limits<double>::infinity(),
double  max_val = std::numeric_limits<double>::infinity() 
)
inline

Range validation.

Parameters
dataData vector
min_valMinimum value
max_valMaximum value
Returns
true if all values are within range

Definition at line 1149 of file data_wrangling.hpp.

◆ value_counts()

template<typename T >
std::map< T, std::size_t > statcpp::value_counts ( const std::vector< T > &  data)

Count duplicates.

Template Parameters
TData type
Parameters
dataData vector
Returns
Map of values and their occurrence counts

Definition at line 744 of file data_wrangling.hpp.

◆ var() [1/4]

template<typename Iterator >
double statcpp::var ( Iterator  first,
Iterator  last,
double  precomputed_mean,
std::size_t  ddof 
)

Variance using precomputed mean (with ddof)

Use when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
ddofDegrees of freedom correction (0 or 1)
Returns
Variance
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 147 of file dispersion_spread.hpp.

◆ var() [2/4]

template<typename Iterator , typename Projection >
double statcpp::var ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean,
std::size_t  ddof 
)

Variance of projected values using precomputed mean (with ddof)

Computes variance using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
ddofDegrees of freedom correction (0 or 1)
Returns
Variance of projected values
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 222 of file dispersion_spread.hpp.

◆ var() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::var ( Iterator  first,
Iterator  last,
Projection  proj,
std::size_t  ddof = 0 
)

Variance of projected values using a lambda expression (with ddof)

Computes the variance of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
ddofDegrees of freedom correction (0 or 1)
Returns
Variance of projected values
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 185 of file dispersion_spread.hpp.

◆ var() [4/4]

template<typename Iterator >
double statcpp::var ( Iterator  first,
Iterator  last,
std::size_t  ddof = 0 
)

Variance (ddof = Delta Degrees of Freedom)

ddof = 0: Population variance (divide by N) ddof = 1: Sample variance / unbiased variance (divide by N-1)

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
ddofDegrees of freedom correction (0 or 1)
Returns
Variance
Exceptions
std::invalid_argumentIf range is empty, ddof is not 0 or 1, or ddof=1 with fewer than 2 elements

Definition at line 112 of file dispersion_spread.hpp.

◆ variance() [1/4]

template<typename Iterator >
double statcpp::variance ( Iterator  first,
Iterator  last 
)

Variance (alias for sample_variance)

Computes sample variance. Equivalent to sample_variance.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Variance
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 420 of file dispersion_spread.hpp.

◆ variance() [2/4]

template<typename Iterator >
double statcpp::variance ( Iterator  first,
Iterator  last,
double  precomputed_mean 
)

Variance using precomputed mean.

Computes sample variance when the mean has been precomputed.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
precomputed_meanPrecomputed mean value
Returns
Variance
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 438 of file dispersion_spread.hpp.

◆ variance() [3/4]

template<typename Iterator , typename Projection , typename = std::enable_if_t< std::is_invocable_v<Projection, typename std::iterator_traits<Iterator>::value_type>>>
double statcpp::variance ( Iterator  first,
Iterator  last,
Projection  proj 
)

Variance of projected values using a lambda expression.

Computes the sample variance of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Variance of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 460 of file dispersion_spread.hpp.

◆ variance() [4/4]

template<typename Iterator , typename Projection >
double statcpp::variance ( Iterator  first,
Iterator  last,
Projection  proj,
double  precomputed_mean 
)

Variance of projected values using precomputed mean.

Computes sample variance using a projection function and precomputed mean.

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
precomputed_meanPrecomputed mean value
Returns
Variance of projected values
Exceptions
std::invalid_argumentIf the range is empty or has fewer than 2 elements

Definition at line 480 of file dispersion_spread.hpp.

◆ weibull_cdf()

double statcpp::weibull_cdf ( double  x,
double  shape,
double  scale = 1.0 
)
inline

Weibull distribution cumulative distribution function (CDF)

F(x) = 1 - exp(-(x/lambda)^k)

Parameters
xRandom variable value
shapeShape parameter k
scaleScale parameter lambda (default: 1.0)
Returns
Cumulative probability
Exceptions
std::invalid_argumentIf shape <= 0 or scale <= 0

Definition at line 1138 of file continuous_distributions.hpp.

◆ weibull_pdf()

double statcpp::weibull_pdf ( double  x,
double  shape,
double  scale = 1.0 
)
inline

Weibull distribution probability density function (PDF)

f(x) = (k/lambda) * (x/lambda)^(k-1) * exp(-(x/lambda)^k)

Parameters
xRandom variable value
shapeShape parameter k
scaleScale parameter lambda (default: 1.0)
Returns
Probability density
Exceptions
std::invalid_argumentIf shape <= 0 or scale <= 0

Definition at line 1103 of file continuous_distributions.hpp.

◆ weibull_quantile()

double statcpp::weibull_quantile ( double  p,
double  shape,
double  scale = 1.0 
)
inline

Weibull distribution quantile function.

Q(p) = lambda * (-ln(1 - p))^(1/k)

Parameters
pProbability (0 <= p <= 1)
shapeShape parameter k
scaleScale parameter lambda (default: 1.0)
Returns
Quantile
Exceptions
std::invalid_argumentIf shape <= 0, scale <= 0, or p is outside [0, 1]

Definition at line 1164 of file continuous_distributions.hpp.

◆ weibull_rand() [1/2]

template<typename Engine = default_random_engine>
double statcpp::weibull_rand ( double  shape,
double  scale,
Engine &  engine 
)

Weibull distribution random number generation.

Template Parameters
EngineRandom engine type
Parameters
shapeShape parameter k
scaleScale parameter lambda
engineRandom engine
Returns
Random number following Weibull distribution
Exceptions
std::invalid_argumentIf shape <= 0 or scale <= 0

Definition at line 1191 of file continuous_distributions.hpp.

◆ weibull_rand() [2/2]

double statcpp::weibull_rand ( double  shape,
double  scale = 1.0 
)
inline

Weibull distribution random number generation (using default engine)

Parameters
shapeShape parameter k
scaleScale parameter lambda (default: 1.0)
Returns
Random number following Weibull distribution

Definition at line 1210 of file continuous_distributions.hpp.

◆ weighted_covariance() [1/2]

template<typename Iterator1 , typename Iterator2 , typename WeightIterator >
double statcpp::weighted_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
WeightIterator  weight_first 
)

Weighted covariance.

Computes covariance with weights applied. Applies Bessel correction.

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
WeightIteratorIterator type for weights
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
weight_firstBegin iterator for weights
Returns
Weighted covariance
Exceptions
std::invalid_argumentIf range is empty, lengths differ, negative weight exists, or sum of weights is zero

Definition at line 925 of file correlation_covariance.hpp.

◆ weighted_covariance() [2/2]

template<typename Iterator1 , typename Iterator2 , typename WeightIterator , typename Projection1 , typename Projection2 >
double statcpp::weighted_covariance ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2,
WeightIterator  weight_first,
Projection1  proj1,
Projection2  proj2 
)

Weighted covariance (projection version)

Template Parameters
Iterator1Iterator type for the first data
Iterator2Iterator type for the second data
WeightIteratorIterator type for weights
Projection1Projection function type for the first data
Projection2Projection function type for the second data
Parameters
first1Begin iterator for the first data
last1End iterator for the first data
first2Begin iterator for the second data
last2End iterator for the second data
weight_firstBegin iterator for weights
proj1Projection function for the first data
proj2Projection function for the second data
Returns
Weighted covariance
Exceptions
std::invalid_argumentIf range is empty, lengths differ, negative weight exists, or sum of weights is zero

Definition at line 1019 of file correlation_covariance.hpp.

◆ weighted_harmonic_mean() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_harmonic_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first 
)

Weighted harmonic mean.

Computes the harmonic mean with weights applied to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
Returns
Weighted harmonic mean
Exceptions
std::invalid_argumentIf range is empty, if negative weight exists, if value is zero, or if sum of weights is zero
Deprecated:
Use weighted_harmonic_mean(first, last, weight_first, weight_last) overload for range safety

Definition at line 939 of file basic_statistics.hpp.

◆ weighted_harmonic_mean() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_harmonic_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
Projection  proj 
)

Weighted harmonic mean (projection version)

Computes the weighted harmonic mean of the results after applying a projection function to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
projProjection function
Returns
Weighted harmonic mean of projected values
Exceptions
std::invalid_argumentIf range is empty, if negative weight exists, if value is zero, or if sum of weights is zero
Deprecated:
Use weighted_harmonic_mean(first, last, weight_first, weight_last, proj) overload for range safety

Definition at line 1047 of file basic_statistics.hpp.

◆ weighted_harmonic_mean() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_harmonic_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last 
)

Weighted harmonic mean (safe range version)

Computes the harmonic mean with weights applied to each element. Validates that data and weight ranges have the same size.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
Returns
Weighted harmonic mean
Exceptions
std::invalid_argumentIf range is empty, if ranges differ in size, if negative weight exists, if value is zero, or if sum of weights is zero

Definition at line 885 of file basic_statistics.hpp.

◆ weighted_harmonic_mean() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_harmonic_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
Projection  proj 
)

Weighted harmonic mean (safe range version with projection)

Computes the weighted harmonic mean of the results after applying a projection function to each element. Validates that data and weight ranges have the same size.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
projProjection function
Returns
Weighted harmonic mean of projected values
Exceptions
std::invalid_argumentIf range is empty, if ranges differ in size, if negative weight exists, if value is zero, or if sum of weights is zero

Definition at line 991 of file basic_statistics.hpp.

◆ weighted_mean() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first 
)

Definition at line 715 of file basic_statistics.hpp.

◆ weighted_mean() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
Projection  proj 
)

Definition at line 796 of file basic_statistics.hpp.

◆ weighted_mean() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last 
)

Weighted mean.

Computes the mean with weights applied to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
Returns
Weighted mean
Exceptions
std::invalid_argumentIf range is empty, if negative weight exists, or if sum of weights is zero

Definition at line 680 of file basic_statistics.hpp.

◆ weighted_mean() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_mean ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
Projection  proj 
)

Weighted mean (projection version)

Computes the weighted mean of the results after applying a projection function to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
projProjection function
Returns
Weighted mean of projected values
Exceptions
std::invalid_argumentIf range is empty, if negative weight exists, or if sum of weights is zero

Definition at line 761 of file basic_statistics.hpp.

◆ weighted_median() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_median ( Iterator  first,
Iterator  last,
WeightIterator  weight_first 
)

Weighted median.

Calculates the weighted median.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
Returns
Weighted median
Exceptions
std::invalid_argumentIf range is empty, weight is negative, or sum of weights is zero

Definition at line 493 of file order_statistics.hpp.

◆ weighted_median() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_median ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
Projection  proj 
)

Weighted median with projection.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
projProjection function
Returns
Weighted median
Exceptions
std::invalid_argumentIf range is empty, weight is negative, or sum of weights is zero

Definition at line 651 of file order_statistics.hpp.

◆ weighted_median() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_median ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last 
)

Weighted median (safe overload)

Calculates the weighted median with range safety validation.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
weight_lastEnd of weights
Returns
Weighted median
Exceptions
std::invalid_argumentIf range is empty, sizes mismatch, weight is negative, or sum of weights is zero

Definition at line 413 of file order_statistics.hpp.

◆ weighted_median() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_median ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
Projection  proj 
)

Weighted median with projection (safe overload)

Calculates the weighted median with range safety validation.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
weight_lastEnd of weights
projProjection function
Returns
Weighted median
Exceptions
std::invalid_argumentIf range is empty, sizes mismatch, weight is negative, or sum of weights is zero

Definition at line 571 of file order_statistics.hpp.

◆ weighted_percentile() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_percentile ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
double  p 
)

Weighted percentile.

Calculates the weighted percentile.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
pPercentile as proportion 0.0-1.0
Returns
Weighted percentile value
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 814 of file order_statistics.hpp.

◆ weighted_percentile() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_percentile ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
double  p,
Projection  proj 
)

Weighted percentile with projection.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
pPercentile as proportion 0.0-1.0
projProjection function
Returns
Weighted percentile value
Exceptions
std::invalid_argumentIf parameters are invalid

Definition at line 976 of file order_statistics.hpp.

◆ weighted_percentile() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_percentile ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
double  p 
)

Weighted percentile (safe overload)

Calculates the weighted percentile with range safety validation.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
weight_lastEnd of weights
pPercentile as proportion 0.0-1.0
Returns
Weighted percentile value
Exceptions
std::invalid_argumentIf parameters are invalid or sizes mismatch

Definition at line 732 of file order_statistics.hpp.

◆ weighted_percentile() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_percentile ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
double  p,
Projection  proj 
)

Weighted percentile with projection (safe overload)

Calculates the weighted percentile with range safety validation.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBeginning of range
lastEnd of range
weight_firstBeginning of weights
weight_lastEnd of weights
pPercentile as proportion 0.0-1.0
projProjection function
Returns
Weighted percentile value
Exceptions
std::invalid_argumentIf parameters are invalid or sizes mismatch

Definition at line 894 of file order_statistics.hpp.

◆ weighted_stddev() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_stddev ( Iterator  first,
Iterator  last,
WeightIterator  weight_first 
)

Weighted standard deviation.

Deprecated:
Use weighted_stddev(first, last, weight_first, weight_last) overload for range safety

Computes the square root of weighted variance.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
Returns
Weighted standard deviation
Exceptions
std::invalid_argumentIf range is empty, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1446 of file dispersion_spread.hpp.

◆ weighted_stddev() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_stddev ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
Projection  proj 
)

Weighted standard deviation (projection version)

Deprecated:
Use weighted_stddev(first, last, weight_first, weight_last, proj) overload for range safety

Computes the weighted standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
projProjection function
Returns
Weighted standard deviation of projected values
Exceptions
std::invalid_argumentIf range is empty, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1492 of file dispersion_spread.hpp.

◆ weighted_stddev() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_stddev ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last 
)

Weighted standard deviation.

Computes the square root of weighted variance.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
Returns
Weighted standard deviation
Exceptions
std::invalid_argumentIf range is empty, data and weight ranges differ in length, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1424 of file dispersion_spread.hpp.

◆ weighted_stddev() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_stddev ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
Projection  proj 
)

Weighted standard deviation (projection version)

Computes the weighted standard deviation of results after applying a projection function to each element.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
projProjection function
Returns
Weighted standard deviation of projected values
Exceptions
std::invalid_argumentIf range is empty, data and weight ranges differ in length, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1468 of file dispersion_spread.hpp.

◆ weighted_variance() [1/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_variance ( Iterator  first,
Iterator  last,
WeightIterator  weight_first 
)

Weighted variance (reliability weights / analytic weights)

Deprecated:
Use weighted_variance(first, last, weight_first, weight_last) overload for range safety

Computes variance with weights applied to each element. Returns unbiased estimator with Bessel's correction.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
Returns
Weighted variance
Exceptions
std::invalid_argumentIf range is empty, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1206 of file dispersion_spread.hpp.

◆ weighted_variance() [2/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_variance ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
Projection  proj 
)

Weighted variance (projection version)

Deprecated:
Use weighted_variance(first, last, weight_first, weight_last, proj) overload for range safety

Computes weighted variance of results after applying a projection function to each element. Returns unbiased estimator with Bessel's correction.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
projProjection function
Returns
Weighted variance of projected values
Exceptions
std::invalid_argumentIf range is empty, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1356 of file dispersion_spread.hpp.

◆ weighted_variance() [3/4]

template<typename Iterator , typename WeightIterator >
double statcpp::weighted_variance ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last 
)

Weighted variance (reliability weights / analytic weights)

Computes variance with weights applied to each element. Returns unbiased estimator with Bessel's correction.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
Returns
Weighted variance
Exceptions
std::invalid_argumentIf range is empty, data and weight ranges differ in length, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1129 of file dispersion_spread.hpp.

◆ weighted_variance() [4/4]

template<typename Iterator , typename WeightIterator , typename Projection >
double statcpp::weighted_variance ( Iterator  first,
Iterator  last,
WeightIterator  weight_first,
WeightIterator  weight_last,
Projection  proj 
)

Weighted variance (projection version)

Computes weighted variance of results after applying a projection function to each element. Returns unbiased estimator with Bessel's correction.

Template Parameters
IteratorIterator type
WeightIteratorWeight iterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
weight_firstBegin iterator for weights
weight_lastEnd iterator for weights
projProjection function
Returns
Weighted variance of projected values
Exceptions
std::invalid_argumentIf range is empty, data and weight ranges differ in length, negative weights exist, sum of weights is zero, or insufficient effective sample size

Definition at line 1279 of file dispersion_spread.hpp.

◆ wilcoxon_signed_rank_test()

template<typename Iterator >
test_result statcpp::wilcoxon_signed_rank_test ( Iterator  first,
Iterator  last,
double  mu0 = 0.0,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

Perform Wilcoxon signed-rank test (one-sample)

Tests whether the median of data equals a specified value. A nonparametric test that does not assume normal distribution. Uses normal approximation (with continuity correction) for p-value calculation.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of range
lastEnding iterator of range
mu0Median under null hypothesis (default: 0.0)
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result containing W+ statistic (sum of ranks for positive differences), p-value, and sample size of non-zero differences
Exceptions
std::invalid_argumentIf there are fewer than 2 elements
std::invalid_argumentIf there are fewer than 2 non-zero differences
Note
Null hypothesis: Median equals mu0
Observations with zero difference from mu0 are excluded

Definition at line 559 of file nonparametric_tests.hpp.

◆ winsorize()

template<typename Iterator >
std::vector< double > statcpp::winsorize ( Iterator  first,
Iterator  last,
double  limits = 0.05 
)

Winsorization.

Replaces extreme values with specified percentile values.

Template Parameters
IteratorIterator type
Parameters
firstBeginning of range
lastEnd of range
limitsProportion to replace from each tail (e.g., 0.05 = replace top and bottom 5%)
Returns
Winsorized data
Exceptions
std::invalid_argumentIf range is empty or limits is invalid
Note
Reduces the impact of outliers while preserving the number of data points.

Definition at line 303 of file robust.hpp.

◆ z_test()

template<typename Iterator >
test_result statcpp::z_test ( Iterator  first,
Iterator  last,
double  mu0,
double  sigma,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)

One-sample z-test (known variance)

Tests whether the sample mean equals a specific value when the population variance is known.

Template Parameters
IteratorInput iterator type
Parameters
firstBeginning iterator of sample data
lastEnd iterator of sample data
mu0Population mean under null hypothesis
sigmaKnown population standard deviation
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (z-statistic, p-value, df=infinity)
Exceptions
std::invalid_argumentIf sigma is not positive or range is empty

Definition at line 72 of file parametric_tests.hpp.

◆ z_test_proportion()

test_result statcpp::z_test_proportion ( std::size_t  successes,
std::size_t  trials,
double  p0,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)
inline

One-sample proportion z-test.

Tests whether the sample proportion equals a specific population proportion.

Parameters
successesNumber of successes
trialsNumber of trials
p0Population proportion under null hypothesis
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (z-statistic, p-value, df=infinity)
Exceptions
std::invalid_argumentIf p0 is outside (0,1), trials is 0, or successes exceeds trials

Definition at line 121 of file parametric_tests.hpp.

◆ z_test_proportion_two_sample()

test_result statcpp::z_test_proportion_two_sample ( std::size_t  successes1,
std::size_t  trials1,
std::size_t  successes2,
std::size_t  trials2,
alternative_hypothesis  alt = alternative_hypothesis::two_sided 
)
inline

Two-sample proportion z-test.

Tests whether two sample proportions are equal (using pooled proportion).

Parameters
successes1Number of successes in first sample
trials1Number of trials in first sample
successes2Number of successes in second sample
trials2Number of trials in second sample
altType of alternative hypothesis (default: two-sided)
Returns
test_result Test result (z-statistic, p-value, df=infinity)
Exceptions
std::invalid_argumentIf trials is 0 or successes exceeds trials

Definition at line 169 of file parametric_tests.hpp.

Variable Documentation

◆ default_abs_tol

constexpr double statcpp::default_abs_tol = 1e-12
constexpr

Default absolute tolerance for floating-point comparisons.

Definition at line 29 of file numerical_utils.hpp.

◆ default_rel_tol

constexpr double statcpp::default_rel_tol = 1e-9
constexpr

Default relative tolerance for floating-point comparisons.

Definition at line 24 of file numerical_utils.hpp.

◆ epsilon

constexpr double statcpp::epsilon = std::numeric_limits<double>::epsilon()
constexpr

Machine epsilon for double precision.

Definition at line 19 of file numerical_utils.hpp.

◆ is_random_engine_v

template<typename T >
constexpr bool statcpp::is_random_engine_v = is_random_engine<T>::value
inlineconstexpr

Variable template version of is_random_engine.

Template Parameters
TType to check

Definition at line 131 of file random_engine.hpp.

◆ log_sqrt_2_pi

constexpr double statcpp::log_sqrt_2_pi = 0.91893853320467274178
inlineconstexpr

Natural logarithm of sqrt(2*pi)

Definition at line 39 of file special_functions.hpp.

◆ NA

constexpr double statcpp::NA = std::numeric_limits<double>::quiet_NaN()
inlineconstexpr

Constant representing NA (NaN)

Definition at line 38 of file data_wrangling.hpp.

◆ pi

constexpr double statcpp::pi = 3.14159265358979323846
inlineconstexpr

Pi constant.

Definition at line 24 of file special_functions.hpp.

◆ sqrt_2

constexpr double statcpp::sqrt_2 = 1.41421356237309504880
inlineconstexpr

Square root of 2.

Definition at line 29 of file special_functions.hpp.

◆ sqrt_2_pi

constexpr double statcpp::sqrt_2_pi = 2.50662827463100050242
inlineconstexpr

Square root of 2*pi.

Definition at line 34 of file special_functions.hpp.