statcpp
C++17 Header-Only Statistics Library
Loading...
Searching...
No Matches
Functions
statcpp::detail Namespace Reference

Internal helper functions. More...

Functions

template<typename Iterator >
std::vector< double > compute_ranks (Iterator first, Iterator last)
 Helper function to compute ranks.
 
template<typename Iterator , typename Projection >
std::vector< double > compute_ranks (Iterator first, Iterator last, Projection proj)
 Rank computation (projection version)
 
double link_transform (double mu, link_function link)
 Link function g(mu) -> eta.
 
double inverse_link (double eta, link_function link)
 Inverse link function g^{-1}(eta) -> mu.
 
double link_derivative (double mu, link_function link)
 Derivative of link function d(eta)/d(mu) = g'(mu)
 
double variance_function (double mu, distribution_family family)
 Variance function V(mu)
 
double deviance_residual (double y, double mu, distribution_family family)
 Calculate deviance (for a single observation)
 
std::vector< double > solve_weighted_least_squares (const std::vector< std::vector< double > > &X, const std::vector< double > &z, const std::vector< double > &w, std::vector< std::vector< double > > &XtWX_inv)
 Solve weighted least squares.
 
void validate_matrix_structure (const std::vector< std::vector< double > > &data, const char *func_name)
 Validate 2D matrix structure.
 
void validate_no_intercept_column (const std::vector< std::vector< double > > &X, const char *func_name)
 Check that X data does not contain an intercept column.
 
std::vector< std::vector< double > > transpose (const std::vector< std::vector< double > > &A)
 Calculate transpose matrix.
 
std::vector< std::vector< double > > matrix_multiply (const std::vector< std::vector< double > > &A, const std::vector< std::vector< double > > &B)
 Calculate matrix product.
 
std::vector< double > matrix_vector_multiply (const std::vector< std::vector< double > > &A, const std::vector< double > &v)
 Calculate matrix-vector product.
 
std::vector< std::vector< double > > cholesky (const std::vector< std::vector< double > > &A)
 Perform Cholesky decomposition.
 
std::vector< double > solve_cholesky (const std::vector< std::vector< double > > &L, const std::vector< double > &b)
 Solve system of equations using Cholesky decomposition.
 
std::vector< std::vector< double > > inverse_cholesky (const std::vector< std::vector< double > > &L)
 Calculate inverse matrix using Cholesky decomposition.
 
void standardize_features (const std::vector< std::vector< double > > &X, std::vector< std::vector< double > > &X_scaled, std::vector< double > &X_mean, std::vector< double > &X_std, std::size_t n, std::size_t p)
 特徴量の標準化 (平均0, 標準偏差1)
 
std::vector< double > rescale_coefficients (const std::vector< double > &beta, const std::vector< double > &X_mean, const std::vector< double > &X_std, double y_mean, std::size_t p, bool standardize)
 標準化済み係数を元のスケールに逆変換する
 
double noncentrality_parameter_t (double effect_size, double n)
 Calculate noncentrality parameter for t-distribution.
 
double noncentrality_parameter_t_two_sample (double effect_size, double n1, double n2)
 Calculate noncentrality parameter for two-sample case.
 
double critical_t_two_sided (double alpha, double df)
 Calculate critical value for two-sided t-test.
 
double critical_t_one_sided (double alpha, double df)
 Calculate critical value for one-sided t-test.
 
double critical_z_two_sided (double alpha)
 Calculate critical value for two-sided normal test.
 
double critical_z_one_sided (double alpha)
 Calculate critical value for one-sided normal test.
 
const char * alternative_to_string (alternative_hypothesis alt)
 Convert alternative_hypothesis enum to string.
 

Detailed Description

Internal helper functions.

Function Documentation

◆ alternative_to_string()

const char * statcpp::detail::alternative_to_string ( alternative_hypothesis  alt)
inline

Convert alternative_hypothesis enum to string.

Parameters
altAlternative hypothesis enum value
Returns
Corresponding string ("two.sided", "greater", or "less")

Definition at line 127 of file power_analysis.hpp.

◆ cholesky()

std::vector< std::vector< double > > statcpp::detail::cholesky ( const std::vector< std::vector< double > > &  A)
inline

Perform Cholesky decomposition.

Computes lower triangular matrix L such that L * L^T = A for positive definite symmetric matrix A.

Parameters
APositive definite symmetric matrix
Returns
std::vector<std::vector<double>> Lower triangular matrix L
Exceptions
std::runtime_errorIf matrix is not positive definite

Definition at line 419 of file linear_regression.hpp.

◆ compute_ranks() [1/2]

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

Helper function to compute ranks.

Uses average rank for ties.

Template Parameters
IteratorIterator type
Parameters
firstBegin iterator
lastEnd iterator
Returns
Vector of ranks

Definition at line 546 of file correlation_covariance.hpp.

◆ compute_ranks() [2/2]

template<typename Iterator , typename Projection >
std::vector< double > statcpp::detail::compute_ranks ( Iterator  first,
Iterator  last,
Projection  proj 
)

Rank computation (projection version)

Template Parameters
IteratorIterator type
ProjectionProjection function type
Parameters
firstBegin iterator
lastEnd iterator
projProjection function
Returns
Vector of ranks

Definition at line 596 of file correlation_covariance.hpp.

◆ critical_t_one_sided()

double statcpp::detail::critical_t_one_sided ( double  alpha,
double  df 
)
inline

Calculate critical value for one-sided t-test.

Parameters
alphaSignificance level
dfDegrees of freedom
Returns
Critical value

Definition at line 97 of file power_analysis.hpp.

◆ critical_t_two_sided()

double statcpp::detail::critical_t_two_sided ( double  alpha,
double  df 
)
inline

Calculate critical value for two-sided t-test.

Parameters
alphaSignificance level
dfDegrees of freedom
Returns
Critical value

Definition at line 86 of file power_analysis.hpp.

◆ critical_z_one_sided()

double statcpp::detail::critical_z_one_sided ( double  alpha)
inline

Calculate critical value for one-sided normal test.

Parameters
alphaSignificance level
Returns
Critical value

Definition at line 117 of file power_analysis.hpp.

◆ critical_z_two_sided()

double statcpp::detail::critical_z_two_sided ( double  alpha)
inline

Calculate critical value for two-sided normal test.

Parameters
alphaSignificance level
Returns
Critical value

Definition at line 107 of file power_analysis.hpp.

◆ deviance_residual()

double statcpp::detail::deviance_residual ( double  y,
double  mu,
distribution_family  family 
)
inline

Calculate deviance (for a single observation)

Calculates the deviance residual according to the distribution family.

Parameters
yObserved value
muExpected value
familyDistribution family
Returns
Deviance residual

Definition at line 228 of file glm.hpp.

◆ inverse_cholesky()

std::vector< std::vector< double > > statcpp::detail::inverse_cholesky ( const std::vector< std::vector< double > > &  L)
inline

Calculate inverse matrix using Cholesky decomposition.

Parameters
LLower triangular matrix from Cholesky decomposition
Returns
std::vector<std::vector<double>> Inverse of the original matrix

Definition at line 489 of file linear_regression.hpp.

◆ inverse_link()

double statcpp::detail::inverse_link ( double  eta,
link_function  link 
)
inline

Inverse link function g^{-1}(eta) -> mu.

Transforms the linear predictor eta using the inverse link function to return the expected value mu.

Parameters
etaLinear predictor
linkLink function to use
Returns
Expected value mu

Definition at line 127 of file glm.hpp.

◆ link_derivative()

double statcpp::detail::link_derivative ( double  mu,
link_function  link 
)
inline

Derivative of link function d(eta)/d(mu) = g'(mu)

Calculates the derivative of the link function with respect to the expected value mu.

Parameters
muExpected value
linkLink function to use
Returns
Derivative of the link function
Exceptions
std::runtime_errorIf mu is close to 0 for cloglog link

Definition at line 160 of file glm.hpp.

◆ link_transform()

double statcpp::detail::link_transform ( double  mu,
link_function  link 
)
inline

Link function g(mu) -> eta.

Transforms the expected value mu using the link function to return the linear predictor eta.

Parameters
muExpected value
linkLink function to use
Returns
Linear predictor eta

Definition at line 95 of file glm.hpp.

◆ matrix_multiply()

std::vector< std::vector< double > > statcpp::detail::matrix_multiply ( const std::vector< std::vector< double > > &  A,
const std::vector< std::vector< double > > &  B 
)
inline

Calculate matrix product.

Parameters
ALeft matrix (m x n)
BRight matrix (n x p)
Returns
std::vector<std::vector<double>> Product matrix (m x p)
Exceptions
std::invalid_argumentIf matrix dimensions are incompatible
std::invalid_argumentIf matrix rows are inconsistent

Definition at line 345 of file linear_regression.hpp.

◆ matrix_vector_multiply()

std::vector< double > statcpp::detail::matrix_vector_multiply ( const std::vector< std::vector< double > > &  A,
const std::vector< double > &  v 
)
inline

Calculate matrix-vector product.

Parameters
AMatrix (m x n)
vVector (n-dimensional)
Returns
std::vector<double> Result vector (m-dimensional)
Exceptions
std::invalid_argumentIf matrix and vector dimensions are incompatible

Definition at line 389 of file linear_regression.hpp.

◆ noncentrality_parameter_t()

double statcpp::detail::noncentrality_parameter_t ( double  effect_size,
double  n 
)
inline

Calculate noncentrality parameter for t-distribution.

Parameters
effect_sizeEffect size
nSample size
Returns
Noncentrality parameter

Definition at line 63 of file power_analysis.hpp.

◆ noncentrality_parameter_t_two_sample()

double statcpp::detail::noncentrality_parameter_t_two_sample ( double  effect_size,
double  n1,
double  n2 
)
inline

Calculate noncentrality parameter for two-sample case.

Parameters
effect_sizeEffect size
n1Sample size of group 1
n2Sample size of group 2
Returns
Noncentrality parameter

Definition at line 75 of file power_analysis.hpp.

◆ rescale_coefficients()

std::vector< double > statcpp::detail::rescale_coefficients ( const std::vector< double > &  beta,
const std::vector< double > &  X_mean,
const std::vector< double > &  X_std,
double  y_mean,
std::size_t  p,
bool  standardize 
)
inline

標準化済み係数を元のスケールに逆変換する

Definition at line 424 of file model_selection.hpp.

◆ solve_cholesky()

std::vector< double > statcpp::detail::solve_cholesky ( const std::vector< std::vector< double > > &  L,
const std::vector< double > &  b 
)
inline

Solve system of equations using Cholesky decomposition.

Solves A * x = b (where A = L * L^T). Efficiently finds the solution using forward and back substitution.

Parameters
LLower triangular matrix from Cholesky decomposition
bRight-hand side vector
Returns
std::vector<double> Solution vector x

Definition at line 454 of file linear_regression.hpp.

◆ solve_weighted_least_squares()

std::vector< double > statcpp::detail::solve_weighted_least_squares ( const std::vector< std::vector< double > > &  X,
const std::vector< double > &  z,
const std::vector< double > &  w,
std::vector< std::vector< double > > &  XtWX_inv 
)
inline

Solve weighted least squares.

Computes (X'WX)^{-1} X'Wz using Cholesky decomposition.

Parameters
XDesign matrix
zWorking variable vector
wWeight vector
XtWX_invOutput: inverse of (X'WX)
Returns
Weighted least squares solution (coefficient vector)
Exceptions
std::runtime_errorIf matrix is not positive definite

Definition at line 276 of file glm.hpp.

◆ standardize_features()

void statcpp::detail::standardize_features ( const std::vector< std::vector< double > > &  X,
std::vector< std::vector< double > > &  X_scaled,
std::vector< double > &  X_mean,
std::vector< double > &  X_std,
std::size_t  n,
std::size_t  p 
)
inline

特徴量の標準化 (平均0, 標準偏差1)

Definition at line 393 of file model_selection.hpp.

◆ transpose()

std::vector< std::vector< double > > statcpp::detail::transpose ( const std::vector< std::vector< double > > &  A)
inline

Calculate transpose matrix.

Parameters
AInput matrix
Returns
std::vector<std::vector<double>> Transposed matrix
Exceptions
std::invalid_argumentIf rows have different column counts

Definition at line 314 of file linear_regression.hpp.

◆ validate_matrix_structure()

void statcpp::detail::validate_matrix_structure ( const std::vector< std::vector< double > > &  data,
const char *  func_name 
)
inline

Validate 2D matrix structure.

Verifies that the matrix is not empty and all rows have the same number of columns.

Parameters
dataMatrix to validate
func_nameFunction name for error messages
Exceptions
std::invalid_argumentIf matrix is empty
std::invalid_argumentIf first row is empty
std::invalid_argumentIf rows have different column counts

Definition at line 231 of file linear_regression.hpp.

◆ validate_no_intercept_column()

void statcpp::detail::validate_no_intercept_column ( const std::vector< std::vector< double > > &  X,
const char *  func_name 
)
inline

Check that X data does not contain an intercept column.

Warns if the first column is all 1.0, as the user may have mistakenly included an intercept column. The intercept is added automatically within the function, so users don't need to include it.

Parameters
XPredictor matrix
func_nameFunction name for error messages
Exceptions
std::invalid_argumentIf the first column is all 1.0

Definition at line 276 of file linear_regression.hpp.

◆ variance_function()

double statcpp::detail::variance_function ( double  mu,
distribution_family  family 
)
inline

Variance function V(mu)

Calculates the variance function according to the distribution family.

Parameters
muExpected value
familyDistribution family
Returns
Variance function value

Definition at line 200 of file glm.hpp.