StatsLibX logoStatsLibX

InferentialStats

v0.3.0

A class for performing inferential statistical analysis, including hypothesis tests, confidence intervals, normality tests, and more.

Class Overview

The InferentialStats class provides a comprehensive suite of inferential statistical tools. It accepts pandas.DataFrame, polars.DataFrame, or numpy.ndarray as input with automatic backend detection, and supports hypothesis testing, confidence intervals, normality tests, and variance tests across parametric and non-parametric methods. A backendproperty exposes the active backend. All methods return a TestResultobject with a consistent interface for inspecting statistics, p-values, and significance. v0.3.0 also fixes an ndarray handling bug in internal data conversion.

Constructor

Constructor signature
InferentialStats(data: pd.DataFrame | pl.DataFrame | np.ndarray, lang: Literal['es-ES', 'en-US'] = 'es-ES')
data : pd.DataFrame | pl.DataFrame | np.ndarray — Input data for analysis (auto-detects pandas/polars)lang : Literal['es-ES', 'en-US'] — Language for output labels (default: 'es-ES')

Methods

confidence_interval
confidence_interval(column: str, confidence: float = 0.95, statistic: Literal['mean', 'median', 'proportion'] = 'mean') -> tuple
t_test_1sample
t_test_1sample(column: str, popmean: float | None = None, popmedian: float | None = None, alternative: Literal['two-sided', 'less', 'greater'] = 'two-sided', alpha: float = 0.05) -> TestResult
t_test_2sample
t_test_2sample(column1: str, column2: str, equal_var: bool = True, alternative: Literal['two-sided', 'less', 'greater'] = 'two-sided', alpha: float = 0.05) -> TestResult
t_test_paired
t_test_paired(column1: str, column2: str, alternative: Literal['two-sided', 'less', 'greater'] = 'two-sided', alpha: float = 0.05) -> TestResult
mann_whitney_test
mann_whitney_test(column1: str, column2: str, alternative: Literal['two-sided', 'less', 'greater'] = 'two-sided', alpha: float = 0.05) -> TestResult
chi_square_test
chi_square_test(column1: str, column2: str, alpha: float = 0.05) -> TestResult
anova_oneway
anova_oneway(column: str, groups: str, alpha: float = 0.05) -> TestResult
kruskal_wallis_test
kruskal_wallis_test(column: str, groups: str, alpha: float = 0.05) -> TestResult
normality_test
normality_test(column: str, method: Literal['shapiro', 'ks', 'anderson', 'jarque_bera', 'all'] = 'shapiro', test_statistic: Literal['mean', 'median', 'mode'] = 'mean', alpha: float = 0.05) -> TestResult | dict
hypothesis_test
hypothesis_test(method: Literal['mean', 'difference_mean', 'proportion', 'variance'] = 'mean', column1: str | None = None, column2: str | None = None, pop_mean: float | None = None, pop_proportion: float | tuple = 0.5, alpha: float = 0.05, homoscedasticity: Literal['levene', 'bartlett', 'var_test'] = 'levene') -> TestResult
variance_test
variance_test(column1: str, column2: str, method: Literal['levene', 'bartlett', 'var_test'] = 'levene', center: Literal['mean', 'median', 'trimmed'] = 'median', alpha: float = 0.05) -> TestResult

TestResult

The TestResult object is returned by all hypothesis test methods. It encapsulates the test statistic, p-value, parameters, and provides a formatted output for easy interpretation.

Properties

test_nameName of the statistical test performed
statisticTest statistic value
pvalueP-value of the test (None for Anderson-Darling)
alphaSignificance level used for the test
is_significantTrue if pvalue < alpha (null hypothesis rejected)
alternativeAlternative hypothesis direction
paramsDictionary of additional test parameters (sample statistics, sample size, etc.)
homo_resultHomoscedasticity test result (if applicable)

__repr__ Formatting

The TestResult object provides a rich formatted string representation via __repr__, which includes:

Test name header with decorative border
Date and time of execution
Alternative hypothesis direction
Test statistic and p-value (or critical values)
Interpretation: reject or fail to reject H₀
Homoscedasticity test details (if applicable)
Additional parameters (sample sizes, means, etc.)
__repr__
__repr__() -> str