statds package#
Submodules#
statds.homoscedasticity module#
- statds.homoscedasticity.bartlett_test(dataset: DataFrame, alpha: float = 0.05)#
Perform Bartlett’s test for homogeneity of variances. This test checks the null hypothesis that all input samples (represented as columns in the dataset) come from populations with equal variances. It is commonly used before conducting ANOVA, as equal variances are an assumption of ANOVA.
Parameters#
- datasetpandas DataFrame
A DataFrame where each column represents a different group/sample. The first column is ignored.
- alphafloat, optional
The significance level for the test, default is 0.05.
Returns#
- statistical_bartlettfloat
Bartlett’s test statistic. A higher value indicates a greater likelihood of differing variances.
- p_valuefloat
The p-value for the hypothesis test. A small p-value (typically ≤ 0.05) rejects the null hypothesis, suggesting that the variances across groups are not equal.
- cv_valuefloat
Critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic and alpha. It indicates whether the null hypothesis of equal variances can be rejected or not.
Notes#
Bartlett’s test is sensitive to departures from normality. Therefore, if the data are not normally distributed, Levene’s test is a more appropriate choice. The test statistic is compared against a chi-squared distribution to obtain the p-value. The formula for the test statistic takes into account the number of groups and the total number of samples.
- statds.homoscedasticity.levene_test(dataset: DataFrame, alpha: float = 0.05, center: str = 'mean')#
Perform the Levene test for equality of variances. This test is used to assess whether the variances of two or more groups are equal. It is an essential test before conducting ANOVA, as ANOVA assumes homogeneity of variances.
Parameters#
- datasetpandas DataFrame
A DataFrame where each column represents a different group/sample. The first column is ignored.
- alphafloat, optional
The significance level for the test, default is 0.05.
- center{‘mean’, ‘median’, ‘trimmed’}, optional
The method for calculating the center of each group. Default is ‘mean’.
Returns#
- statistic_levenefloat
The Levene test statistic. A higher value indicates a greater likelihood of differing variances.
- p_valuefloat
The p-value for the hypothesis test. A small p-value (typically ≤ 0.05) rejects the null hypothesis, suggesting that the variances across groups are not equal.
- rejected_valuefloat
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic and alpha. It indicates whether the null hypothesis of equal variances can be rejected or not.
Notes#
The Levene test is robust to non-normal distributions, making it preferable to Bartlett’s test when data are not normally distributed. The choice of ‘center’ parameter (mean, median, trimmed) can affect the test’s sensitivity to departures from normality. The test statistic is computed based on the absolute deviations from the group centers and then compared against an F-distribution to obtain the p-value.
statds.no_parametrics module#
- exception statds.no_parametrics.LibraryError(message)#
Bases:
Exception
- statds.no_parametrics.binomial(dataset: DataFrame, alpha: float = 0.05, verbose: bool = False)#
Perform the Binomial Sign Test. This non-parametric test is used to determine if there is a significant difference between the medians of two dependent samples. It serves as an alternative to the paired t-test and Wilcoxon signed-rank test, particularly useful when the data does not meet the assumptions of these tests or when the data is on an ordinal scale.
Parameters#
- datasetpandas.DataFrame
A DataFrame with exactly two columns, each representing a different condition or time point for the same subjects.
- alphafloat, optional
The significance level for the test. Default is 0.05.
- verbosebool, optional
If True, prints the detailed results table.
Returns#
- statistical_binomialfloat
The Binomial test statistic, which is the largest of the counts of positive or negative differences.
- p_valuefloat
The p-value for the hypothesis test, calculated from the binomial distribution.
- cv_valuefloat or None
The critical value for the test at the specified alpha level (not calculated in this function, hence None).
- hypothesisstr
A string stating the conclusion of the test based on the test statistic and p-value in comparison to alpha.
Note#
The Binomial Sign Test counts the number of positive and negative differences between paired observations and then tests if the observed proportion of positive (or negative) differences is significantly different from 0.5 (no difference). The test assumes that the distribution of differences is symmetric around the median and ignores pairs with no difference.
- statds.no_parametrics.bonferroni(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function performs the Bonferroni correction for multiple comparisons of algorithms or treatments. The Bonferroni correction is a method to adjust significance levels when multiple statistical tests are conducted simultaneously.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
This function is useful in statistical analysis where multiple algorithms or treatments are compared and there is a need to control the Type I error (false positive) that increases with the number of comparisons.
- statds.no_parametrics.contrast_estimation_based_on_medians(dataset: DataFrame, minimize: bool = False, verbose: bool = False)#
- statds.no_parametrics.create_dataframe_results(comparisons: list, z_statistics: list, p_values: list, alphas: list, adj_p_values: list, adj_alphas: list)#
- statds.no_parametrics.finner(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Finner correction, a statistical method for controlling the family-wise error rate in multiple comparisons. The Finner correction is an alternative to other methods like Bonferroni or Holm, and it is generally more powerful than the Bonferroni correction.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Finner method is particularly useful in scenarios involving multiple comparisons, where it provides a balance between statistical power and control over Type I errors. This makes it a valuable tool in comparative studies of algorithms or treatments across various datasets.
- statds.no_parametrics.friedman(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False, apply_correction: bool = False) object#
Perform the Friedman test, a non-parametric statistical test similar to the parametric ANOVA, but for repeated measures. The Friedman test is used to detect differences in treatments across multiple test attempts. It ranks the treatments for each block (or subject), then considers these ranks.
Parameters#
- datasetpandas.DataFrame
A DataFrame with the first column as the block or subject identifier and the remaining columns as different treatments or conditions.
- alphafloat, optional
The significance level for the test, default is 0.05.
- minimizebool, optional
Determines whether the metric of interest should be minimized or maximized. If True, the metric is to be minimized; if False, it is to be maximized. This parameter is crucial for tailoring the function’s behavior to the specific nature of the data or the goal of the analysis.
- verbosebool, optional
If True, prints the detailed results table including ranks.
- apply_correctionbool, optional
If True, apply Tie correction for the Friedman two-way analysis of variance by rank
Returns#
- rankings_with_labeldict
A dictionary with the average ranks of each treatment or condition.
- statistic_friedmanfloat
The Friedman test statistic, which is chi-squared distributed under the null hypothesis.
- p_valuefloat
The p-value for the hypothesis test.
- cv_alpha_selectedfloat or None
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic, critical value, and alpha.
Note#
The Friedman test is appropriate when data is ordinal and the assumptions of parametric tests (like ANOVA) are not met. It considers the ranks of the treatments within each block, summing these ranks, and then analyzing the sums’ distribution. The test is robust against non-normal distributions and is ideal for small sample sizes.
- statds.no_parametrics.friedman_aligned_ranks(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False)#
Perform the Friedman Aligned Ranks test, an extension of the Friedman test. This test is used when dealing with multiple treatments or conditions over different subjects or blocks, especially in cases where the assumptions of the classical Friedman test may not hold. The test aligns the data by subtracting the mean across treatments for each subject before ranking.
Parameters#
- datasetpandas.DataFrame
A DataFrame with the first column as the block or subject identifier and the remaining columns as different treatments or conditions.
- alphafloat, optional
The significance level for the test, default is 0.05.
- minimizebool, optional
Determines whether the metric of interest should be minimized or maximized. If True, the metric is to be minimized; if False, it is to be maximized. This parameter is crucial for tailoring the function’s behavior to the specific nature of the data or the goal of the analysis.
- verbosebool, optional
If True, prints the detailed results table including aligned ranks.
Returns#
- rankings_with_labeldict
A dictionary with the average ranks of each treatment or condition.
- statistic_friedmanfloat
The Friedman Aligned Ranks test statistic.
- p_valuefloat
The p-value for the hypothesis test.
- cv_alpha_selectedfloat or None
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic, critical value, and alpha.
Note#
The Friedman Aligned Ranks test modifies the standard Friedman test by aligning the data for each subject before ranking. This alignment is achieved by subtracting the average rank across treatments for each subject, making the test more robust to certain types of data irregularities, like outliers. It is appropriate for ordinal data and assumes that the groups are independent and identically distributed within each block.
- statds.no_parametrics.generate_graph_p_values(data: DataFrame, name_control, all_vs_all)#
- statds.no_parametrics.hochberg(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Hochberg step-up procedure for multiple comparisons correction. It is an alternative to the Bonferroni method and is generally more powerful, especially when there are a large number of comparisons. The Hochberg procedure controls the family-wise error rate more effectively than some other methods.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figureobject
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Hochberg procedure is particularly valuable when conducting multiple comparisons in statistical analysis, as it provides a more refined approach to controlling the Type I error rate compared to more conservative methods.
- statds.no_parametrics.holland(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function applies the Holland step-down procedure for controlling the family-wise error rate in multiple comparisons. It’s an improvement over the simple Bonferroni method and is particularly useful when dealing with a large number of comparisons, and it is generally more powerful than the Bonferroni correction.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Holland method adjusts the alpha values for each comparison based on their rank in p-value, offering a more nuanced control over Type I errors compared to the Bonferroni method. It’s particularly effective in scenarios with multiple algorithm comparisons, ensuring a more accurate interpretation of statistical results.
- statds.no_parametrics.holm(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Holm-Bonferroni method, an adjustment for multiple comparisons. It is used to control the family-wise error rate when comparing multiple algorithms or treatments. This method is more powerful than the simple Bonferroni correction, especially when the number of comparisons is large.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Holm-Bonferroni method adjusts the significance levels of each comparison based on the order of their p-values, providing a less conservative approach than the original Bonferroni correction. It’s particularly useful in scenarios with multiple comparisons to control the overall type I error rate.
- statds.no_parametrics.hommel(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Hommel correction, a statistical method for adjusting p-values when performing multiple comparisons. The Hommel correction is a more powerful alternative to the Bonferroni correction, particularly when the number of comparisons is large.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Hommel correction is particularly useful in scenarios with multiple comparisons, as it provides a balance between controlling the family-wise error rate and maintaining statistical power. This makes it an effective tool in the comparative analysis of algorithms or treatments across various datasets.
- statds.no_parametrics.iman_davenport(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False)#
Perform the Iman-Davenport test, a non-parametric statistical test that is a modification of the Friedman test. This test is used when comparing more than two treatments or conditions across multiple blocks or subjects. Unlike the Friedman test, the Iman-Davenport test converts the Friedman statistic into an F-distribution providing a better approximation in certain cases, especially when dealing with small sample sizes.
Parameters#
- datasetpandas.DataFrame
A DataFrame with the first column as the block or subject identifier and the remaining columns as different treatments or conditions.
- alphafloat, optional
The significance level for the test, default is 0.05.
- minimizebool, optional
Determines whether the metric of interest should be minimized or maximized. If True, the metric is to be minimized; if False, it is to be maximized. This parameter is crucial for tailoring the function’s behavior to the specific nature of the data or the goal of the analysis.
- verbosebool, optional
If True, prints the detailed results table including ranks.
Returns#
- rankings_with_labeldict
A dictionary with the average ranks of each treatment or condition.
- statistic_iman_davenportfloat
The Iman-Davenport test statistic, which follows an F-distribution under the null hypothesis.
- reject_valuetuple
A tuple containing the critical value for the test and the p-value (if applicable).
- hypothesisstr
A string stating the conclusion of the test based on the test statistic, critical value, and alpha.
Note#
The Iman-Davenport test is particularly useful in cases where the assumptions of the Friedman test are not fully met or when a more sensitive analysis is required. It is especially effective in small sample sizes and is robust against non-normal distributions, similar to the Friedman test. However, it provides a more accurate approximation to the F-distribution, making it preferable in certain statistical analyses.
- statds.no_parametrics.kruskal_wallis(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False)#
Perform the Kruskal-Wallis H-test for independent samples to determine whether the population medians on a dependent variable are the same across all groups or not. This non-parametric method does not assume a normal distribution of the residuals, making it a robust alternative to the one-way ANOVA.
The function includes an option to adjust for ties and provides detailed output, including the test statistic, p-value, and a critical value based on the significance level (alpha). It can also print the dataset if verbose mode is enabled.
Parameters#
- datasetpd.DataFrame
A pandas DataFrame containing the dataset to be tested. The first column should be the grouping variable, and the remaining columns should contain the data for each group.
- alphafloat, optional
Significance level used to determine the critical value for the test. Default is 0.05.
- minimizebool, optional
Determines whether the metric of interest should be minimized or maximized. If True, the metric is to be minimized; if False, it is to be maximized. This parameter is crucial for tailoring the function’s behavior to the specific nature of the data or the goal of the analysis.
- verbosebool, optional
If True, prints the dataset after melting and ranking. Useful for debugging or detailed analysis. Default is False.
Returns#
- statistic_kruskalfloat
The Kruskal-Wallis H statistic, adjusted for ties.
- p_valuefloat
The p-value for the test statistic.
- critical_valuefloat
The critical chi-square value from the chi-square distribution table based on the alpha level.
- hypothesisstr
A string stating the result of the hypothesis test based on the p-value and alpha.
Notes#
The test is applied to data that is at least ordinal (rankable).
This implementation automatically adjusts for ties in the data.
The function converts the input data into long format, ranking the data, and then computes the test statistic.
- statds.no_parametrics.li(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Li method for adjusting p-values in multiple comparisons. The Li method is particularly useful when there is a control algorithm to compare against other algorithms. It adjusts p-values based on the performance of the control algorithm relative to others.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figureobject
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Li method is effective in scenarios where a specific algorithm (the control) is of particular interest, and the comparisons are made between this control and other algorithms. It provides a nuanced way to adjust for multiple comparisons by considering the performance of the control algorithm.
- statds.no_parametrics.mannwhitneyu(dataset: DataFrame, alpha: float = 0.05, verbose: bool = False)#
Perform the Mann-Whitney U Test, also known as the Wilcoxon rank-sum test. This non-parametric test is utilized to determine whether there is a significant difference between the distributions of two independent samples. It serves as an alternative to the independent t-test, particularly when the data does not satisfy the assumptions of the t-test.
Parameters#
- datasetpandas.DataFrame
A DataFrame with exactly two columns, each representing a different independent sample.
- alphafloat, optional
The significance level for the test. Default is 0.05.
- verbosebool, optional
If True, prints the detailed results table.
Returns#
- z_valuefloat
The z-value computed from the U statistic.
- cv_alpha_selectedfloat or None
The critical value for the test at the specified alpha level (not calculated in this function, hence None).
- p_valuefloat
The p-value for the hypothesis test, calculated from the normal approximation of the U distribution.
- hypothesisstr
A string stating the conclusion of the test based on the z-value and p-value in comparison to alpha.
Note#
The Mann-Whitney U test ranks all observations from both groups together and then compares the sum of ranks in each group. It is suitable for ordinal data and is robust against non-normal distributions. The test assumes that the two groups are independent and that the observations are ordinal or continuous. The normal approximation for the p-value calculation is valid for large sample sizes.
- statds.no_parametrics.mcnemar(results_1, results_2, real_results, alpha: float = 0.05, verbose: bool = False)#
- statds.no_parametrics.multiple_sign_test(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False)#
- statds.no_parametrics.nemenyi(ranks: dict, num_cases: int, alpha: float = 0.05, verbose: bool = False)#
The Nemenyi test is a post-hoc analysis method used in statistics to compare multiple algorithms or treatments. It is often used after a Friedman test has indicated significant differences across algorithms.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- rank_valueslist
The list of rank values for each algorithm.
- critical_distancefloat
The critical distance for the Nemenyi test, which is a threshold used to determine if differences between algorithm rankings are statistically significant.
- figurematplotlib.figure.Figure
A figure representing the ranking of the algorithms and the critical distances visually, often as a CD diagram.
Note#
The Nemenyi test is non-parametric and is used when the assumptions of parametric tests (like ANOVA) are not met. It’s particularly useful in scenarios where multiple algorithms are compared across various datasets.
- statds.no_parametrics.prepare_comparisons(ranks: dict, num_algorithm: int, num_cases: int, control: str | None = None, type_rank: str = 'Friedman')#
- statds.no_parametrics.quade(dataset: DataFrame, alpha: float = 0.05, minimize: bool = False, verbose: bool = False)#
Perform the Quade test, a non-parametric statistical test used to identify significant differences between three or more matched groups. This test is particularly useful for blocked designs where treatments are applied to matched groups or blocks. The Quade test considers the relative differences between treatments within each block and ranks these differences.
Parameters#
- datasetpandas.DataFrame
A DataFrame with the first column as the block or subject identifier and the remaining columns as different treatments or conditions.
- alphafloat, optional
The significance level for the test, default is 0.05.
- minimizebool, optional
Determines whether the metric of interest should be minimized or maximized. If True, the metric is to be minimized; if False, it is to be maximized. This parameter is crucial for tailoring the function’s behavior to the specific nature of the data or the goal of the analysis.
- verbosebool, optional
If True, prints the detailed results table including ranks.
Returns#
- rankings_with_labeldict
A dictionary with the average ranks of each treatment or condition.
- statistic_quadefloat
The Quade test statistic.
- p_valuefloat
The p-value for the hypothesis test.
- cv_alpha_selectedNone
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic, critical value, and alpha.
Note#
The Quade test adjusts for differences in treatment effects within each block by incorporating the range of each block into the ranking process. This makes it more sensitive to treatment effects in the presence of block-to-block variability. It’s appropriate for ordinal data and assumes that the treatments are independent and identically distributed within each block.
- statds.no_parametrics.rom(ranks: dict, num_cases: int, alpha: float = 0.05, control: str | None = None, type_rank: str = 'Friedman', verbose: bool = False)#
This function implements the Rom method, which is a step-down procedure for adjusting p-values in the context of multiple comparisons. The Rom method is an improvement over the Bonferroni correction, providing a more powerful approach, especially when the number of comparisons is large.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- controlstr, optional
An optional string specifying a control algorithm against which others will be compared. If None, all algorithms are compared against each other.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figureobject
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
The Rom method is particularly useful in scenarios involving multiple comparisons, as it offers a more accurate control of the family-wise error rate compared to simpler methods like Bonferroni, especially in cases with a large number of algorithms or treatments being compared.
- statds.no_parametrics.shaffer(ranks: dict, num_cases: int, alpha: float = 0.05, type_rank: str = 'Friedman', verbose: bool = False)#
This function applies Shaffer’s multiple comparison procedure, which is a more refined method for adjusting p-values in the context of multiple comparisons. Shaffer’s method is an extension of the Bonferroni correction and is generally more powerful, particularly when the number of comparisons is large.
Parameters#
- ranksdict
A dictionary where keys are the names of the algorithms and values are their respective ranks. The ranks must be obtained based on multiple non-parametric tests.
- num_casesint
An integer representing the number of cases, datasets, or instances over which the rankings were calculated.
- alphafloat, optional
A float representing the significance level used in the test. It defaults to 0.05, which is a common choice in statistical testing.
- type_rankstr, optional
A string indicating the type of ranking used (e.g., “Friedman”). Defaults to “Friedman”.
- verbosebool, optional
A boolean indicating whether to print additional information (like the critical distance). Defaults to False.
Returns#
- comparison_resultspandas.DataFrame
A DataFrame with the results of the comparisons, including adjusted z-values and adjusted p-values.
- comparison_figurematplotlib.figure.Figure
A figure graphically displaying the results of the tests, typically a bar chart or scatter plot.
Note#
Shaffer’s method is particularly effective in scenarios with multiple comparisons, as it provides a more accurate control of the family-wise error rate compared to simpler methods like Bonferroni, especially when the number of algorithms or treatments being compared is large.
- statds.no_parametrics.wilconxon(dataset: DataFrame, alpha: float = 0.05, verbose: bool = False)#
Perform the Wilcoxon signed-rank test. This non-parametric test is used to compare two related samples, matched samples, or repeated measurements on a single sample to assess whether their population mean ranks differ. It is an alternative to the paired Student’s t-test when the data is not normally distributed.
Parameters#
- datasetpandas.DataFrame
A DataFrame with exactly two columns, each representing a different condition or time point for the same subjects.
- alphafloat, optional
The significance level for the test. Default is 0.05.
- verbosebool, optional
If True, prints the detailed results table.
Returns#
- w_wilcoxonfloat
The Wilcoxon test statistic, which is the smallest of the sums of the positive and negative ranks.
- p_valuefloat or None
The p-value for the hypothesis test (only for large sample sizes, otherwise None).
- cv_alpha_selectedfloat or None
The critical value for the test at the specified alpha level (only for small sample sizes, otherwise None).
- hypothesisstr
A string stating the conclusion of the test based on the test statistic, critical value, or p-value and alpha.
Note#
The Wilcoxon signed-rank test makes fewer assumptions than the t-test and is appropriate when the data are not normally distributed. It ranks the absolute differences between pairs, then compares these ranks. The test is sensitive to ties and has different procedures for small and large sample sizes. For large samples, the test statistic is approximately normally distributed, allowing the use of normal approximation for p-value calculation.
statds.normality module#
- statds.normality.d_agostino_pearson(data: array, alpha: float = 0.05)#
Perform the D’Agostino and Pearson’s omnibus test for normality. This test combines skew and kurtosis to produce an omnibus test of normality, testing the null hypothesis that a sample comes from a normally distributed population.
Parameters#
- datanumpy.array
Array of sample data. It should be a one-dimensional numpy array.
- alphafloat, optional
The significance level for test analysis. Default is 0.05.
Returns#
- statistic_dpfloat
The D’Agostino and Pearson’s test statistic.
- p_valuefloat
The p-value for the hypothesis test. A small p-value (typically ≤ 0.05) rejects the null hypothesis, indicating the data is not normally distributed.
- cv_valuefloat
Critical value for the test based on the chi-squared distribution with 2 degrees of freedom.
- hypothesisstr
A string stating the conclusion of the test based on the p-value and alpha. It indicates whether the null hypothesis can be rejected or not.
Note#
The test calculates skewness and kurtosis of the data, standardizes these values, and then calculates a test statistic that follows a chi-squared distribution with 2 degrees of freedom under the null hypothesis. The p-value is then derived from this chi-squared distribution.
- statds.normality.kolmogorov_smirnov(data: array, alpha: float = 0.05)#
Perform the Kolmogorov-Smirnov test for goodness of fit. This non-parametric test compares a sample with a reference probability distribution (in this case, the normal distribution), assessing whether the sample data follows the same distribution as the reference distribution.
Parameters#
- datanumpy.array
Array of sample data. It should be a one-dimensional numpy array.
- alphafloat, optional
The significance level for the test. Default is 0.05.
Returns#
- d_maxfloat
The maximum difference between the Empirical Cumulative Distribution Function (ECDF) of the data and the Cumulative Distribution Function (CDF) of the reference distribution (normal distribution in this case).
- p_valuefloat
The p-value for the hypothesis test. A small p-value (typically ≤ 0.05) rejects the null hypothesis, suggesting that the sample data does not follow the reference distribution.
- cv_valuefloat
Critical value for the Kolmogorov-Smirnov test. This is currently set to None.
- hypothesisstr
A string stating the conclusion of the test based on the p-value and alpha. It indicates whether the null hypothesis can be rejected or not.
Note#
The test calculates the maximum difference (d_max) between the ECDF of the sample data and the CDF of the normal distribution. The KS statistic is then derived from this difference and the sample size. The p-value is estimated from the KS statistic. This test is non-parametric and does not assume a normal distribution of the data.
- statds.normality.kurtosis(data: array, bias: bool = True)#
Calculate the kurtosis of the given data. Kurtosis is a measure of the “tailedness” of the probability distribution of a real-valued random variable. In a general sense, kurtosis quantifies whether the tails of the data distribution are heavier or lighter compared to a normal distribution.
Parameters#
- datanumpy.array
Array of sample data. It should be a one-dimensional numpy array.
- biasbool, optional
A boolean indicating whether to correct for statistical bias. If False, calculations are corrected for bias. Default is True, meaning no bias correction is applied.
Returns#
- float
The kurtosis of the data, representing the degree of kurtosis in the distribution: A value greater than 3 indicates a distribution with heavier tails and a sharper peak compared to a normal distribution. A value less than 3 indicates a distribution with lighter tails and a flatter peak compared to a normal distribution. A value close to 3, especially when bias is False, indicates a distribution similar to a normal distribution in terms of kurtosis.
Note#
The bias parameter affects the calculation of kurtosis. If bias is False, the result is adjusted for bias, making it more representative for samples from a larger population. If bias is True (default), the kurtosis is calculated without any adjustments. The adjustment for bias involves a correction factor based on the number of samples, which corrects the result for the tendency of small samples to underestimate kurtosis.
- statds.normality.kurtosis_test(b2: float, n: int)#
Perform a kurtosis test to assess the ‘tailedness’ or peakedness of the probability distribution of a dataset. This test calculates a z-score for the kurtosis and the corresponding p-value to determine the statistical significance of the kurtosis.
Parameters#
- b2float
The squared sample kurtosis.
- nint
The sample size.
Returns#
- z_b2float
The z-score for the kurtosis test. This score indicates the degree of peakedness in the distribution.
- p_valuefloat
The p-value corresponding to the z-score. A small p-value (typically ≤ 0.05) suggests that the distribution of the data has significant kurtosis, differing from a normal distribution.
Note#
The kurtosis test is used to determine if a dataset has heavier or lighter tails compared to a normal distribution. The test involves calculating the mean and variance of b2, the standardized version of b2, and then computing the standardized moment of b2. The z-score and p-value help assess whether the kurtosis of the dataset significantly deviates from that of a normal distribution, where the kurtosis is expected to be around 0.
- statds.normality.pp_plot(data: array)#
Generate a Probability-Probability (PP) plot for a given dataset. A PP plot is a graphical technique for assessing how closely a set of data follows a given distribution, typically the normal distribution. It compares the empirical cumulative distribution function (CDF) of the data to the theoretical CDF of the specified distribution.
Parameters#
- datanumpy.array
A numpy array of sample data to be analyzed.
Returns#
- matplotlib.figure.Figure
A matplotlib figure object that contains the PP plot.
Note#
In a PP plot, the y-axis shows the empirical CDF of the data, and the x-axis displays the theoretical CDF of the distribution being tested (normal distribution in this case). A 45-degree reference line is added to the plot. If the data follow the specified distribution, the plot will align closely with this line. The PP plot is useful for assessing the goodness of fit of a distribution and is particularly helpful for determining if data follow a normal distribution, which is a common assumption in various statistical tests.
- statds.normality.qq_plot(data: array)#
Generate a Quantile-Quantile (QQ) plot for a given dataset. A QQ plot is a graphical tool to help assess if a dataset follows a particular distribution, such as a normal distribution. It compares the quantiles of the data to the quantiles of a theoretical distribution.
Parameters#
- datanumpy.array
A numpy array of sample data to be analyzed.
Returns#
- matplotlib.figure.Figure
A matplotlib figure object that contains the QQ plot.
Note#
In the QQ plot, the quantiles of the data are plotted against the quantiles of a theoretical distribution (in this case, the normal distribution). If the data follow the theoretical distribution, the points on the QQ plot will approximately lie on the line y = x. Departures from this line indicate departures from the theoretical distribution. The plot helps in visually assessing normality, which is a common assumption in many statistical tests.
- statds.normality.shapiro_wilk_normality(data: array, alpha: float = 0.05)#
Performs the Shapiro-Wilk test for normality. This test assesses the null hypothesis that the data was drawn from a normal distribution.
Parameters#
- datanumpy.array
Array of sample data. It should be a one-dimensional numpy array.
- alphafloat, optional
The significance level for test analysis. Default is 0.05.
Returns#
- statistics_wfloat
The W statistic for the test, a measure of normality.
- p_valuefloat
The p-value for the hypothesis test. A small p-value (typically ≤ 0.05) rejects the null hypothesis, indicating the data is not normally distributed.
- cv_valuefloat
Critical value for the Shapiro-Wilk test. This is currently set to None.
- hypothesisstr
A string stating the conclusion of the test based on the p-value and alpha. It indicates whether the null hypothesis can be rejected or not.
- statds.normality.skewness(data: array, bias: bool = True)#
Calculate the skewness of the given data. Skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean. Positive skewness indicates a distribution with an asymmetric tail extending towards more positive values, while negative skewness indicates a distribution with an asymmetric tail extending towards more negative values.
Parameters#
- datanumpy.array
Array of sample data. It should be a one-dimensional numpy array.
- biasbool, optional
A boolean indicating whether to correct for statistical bias. If False, calculations are corrected for bias. Default is True, meaning no bias correction is applied.
Returns#
- float
The skewness of the data, indicating the degree of asymmetry in the distribution: - A value close to 0 indicates a symmetric distribution. - A positive value indicates a distribution that is skewed to the right. - A negative value indicates a distribution that is skewed to the left.
Note#
The bias parameter affects the calculation of skewness. If bias is False, the result is adjusted for bias, making it suitable for samples from a larger population. If bias is True (default), the skewness of the sample is calculated without any adjustments.
- statds.normality.skewness_test(b2, n)#
Perform a skewness test to assess the asymmetry of the probability distribution of a dataset. This test calculates a z-score for the skewness and the corresponding p-value to determine the statistical significance of the skewness.
Parameters#
- b2float
The squared sample skewness.
- nint
The sample size.
Returns#
- z_b1float
The z-score for the skewness test. A higher absolute value indicates greater skewness.
- p_valuefloat
The p-value corresponding to the z-score. A small p-value (typically ≤ 0.05) suggests that the distribution of the data is significantly skewed.
Note#
The skewness test is a hypothesis test that evaluates whether the skewness of the data differs significantly from 0, which would indicate a symmetric distribution. The test uses the sample size and the squared skewness to compute the test statistic. It’s particularly useful for determining if a distribution departs from normality, where skewness is expected to be about 0.
statds.parametrics module#
- statds.parametrics.anova_cases(dataset: DataFrame, alpha: float = 0.05)#
Perform an ANOVA (Analysis of Variance) test. This statistical test is used to compare the means of two or more groups to determine if at least one group mean is significantly different from the others. It’s commonly used when there are three or more groups.
Parameters#
- datasetpandas.DataFrame
A DataFrame where each column represents a different group/sample. The first column is ignored.
- alphafloat, optional
The significance level for the test. Default is 0.05.
Returns#
- summary_resultspandas.DataFrame
A DataFrame with a summary of each group’s mean, standard deviation, and standard error.
- anova_resultspandas.DataFrame
A DataFrame with the ANOVA results, including degrees of freedom, sum of squares, mean square, F-statistic, and rejected value for between groups and within groups.
- statistical_f_anovafloat
The F-statistic for the ANOVA test. A higher value suggests a greater difference between group means.
- p_valuefloat
The p-value for the hypothesis test (currently not calculated and set to None).
- rejected_valuefloat
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the F-statistic and alpha.
Note#
ANOVA tests the null hypothesis that all group means are equal. The test assumes that the groups are sampled from populations with normal distributions and equal variances. The F-statistic is calculated based on the ratio of variance between the groups to the variance within the groups. A significant F-statistic (p-value less than alpha) indicates that at least one group mean is significantly different.
- statds.parametrics.anova_within_cases(dataset: DataFrame, alpha: float = 0.05)#
Perform a within-subject ANOVA (Analysis of Variance). This type of ANOVA is used when the same subjects are used for each treatment (i.e., the subjects are subjected to repeated measures). This test is beneficial for analyzing the effects of different conditions or treatments on a single group of subjects.
Parameters#
- datasetpandas.DataFrame
A DataFrame where each column represents a different condition/treatment for the same subjects. The first column is typically used for subject identification and is ignored in the analysis.
- alphafloat, optional
The significance level for the test. Default is 0.05.
Returns#
- summary_resultspandas.DataFrame
A DataFrame with a summary of each group’s mean, standard deviation, and standard error.
- anova_resultspandas.DataFrame
A DataFrame with the ANOVA results, including degrees of freedom, sum of squares, mean square, F-statistic, and rejected value for different sources of variance (between conditions, between subjects, etc.).
- statistical_f_anovafloat
The F-statistic for the ANOVA test. A higher value suggests a significant differensce between conditions or treatments.
- p_valuefloat
The p-value for the hypothesis test (currently not calculated and set to None).
- rejected_valuefloat
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the F-statistic and alpha.
Note#
Within-subject ANOVA controls for potential variability among subjects, as each subject serves as their own control. This test separates the variance due to the interaction between subjects and conditions from the variance due to differences between conditions and residual variance. It assumes sphericity, which implies that the variances of the differences between all possible pairs of conditions are equal.
- statds.parametrics.t_test_paired(dataset: DataFrame, alpha: float = 0.05, verbose: bool = False)#
Perform a paired t-test. This statistical test is used to compare the means of two related groups of samples, typically before and after a specific treatment or intervention. The test assumes that the differences between pairs are normally distributed.
Parameters#
- datasetpandas.DataFrame
A DataFrame with exactly two columns, each representing a different group/sample. These groups must be related or paired in some way (e.g., measurements before and after an intervention).
- alphafloat, optional
The significance level for the test. Default is 0.05.
- verbosebool, optional
A boolean indicating whether to print detailed results. If True, prints the test statistic, rejected value, p-value, and hypothesis. Default is False.
Returns#
- statistical_tfloat
The t-test statistic. A higher absolute value indicates a greater difference between the paired groups.
- p_valuefloat
The p-value for the hypothesis test (currently not calculated and set to None).
- rejected_valuefloat
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic and alpha. It indicates whether the null hypothesis (no difference between means) can be rejected or not.
Note#
The paired t-test is appropriate for comparing two means from the same group or individual under two different conditions. The test statistic is calculated by dividing the mean difference between paired observations by the standard error of the mean difference. The test is sensitive to the normality assumption of the differences between pairs.
- statds.parametrics.t_test_unpaired(dataset: DataFrame, alpha: float = 0.05, verbose: bool = False)#
Perform an unpaired (independent) t-test. This statistical test is used to compare the means of two unrelated groups of samples to determine if there is a statistically significant difference between the two means. It’s appropriate when the two groups are independent of each other.
Parameters#
- datasetpandas.DataFrame
A DataFrame with exactly two columns, each representing a different group/sample. These groups must be independent or unpaired.
- alphafloat, optional
The significance level for the test. Default is 0.05.
- verbosebool, optional
A boolean indicating whether to print detailed results. If True, prints the test statistic, rejected value, p-value, and hypothesis. Default is False.
Returns#
- statistical_tfloat
The t-test statistic. A higher absolute value indicates a greater difference between the group means.
- p_valuefloat
The p-value for the hypothesis test (currently not calculated and set to None).
- rejected_valuefloat
The critical value for the test at the specified alpha level.
- hypothesisstr
A string stating the conclusion of the test based on the test statistic and alpha. It indicates whether the null hypothesis (no difference between means) can be rejected or not.
Note#
The unpaired t-test assumes that the two groups have equal variances and that the samples are randomly drawn. The test statistic is calculated by taking the difference between the two group means and dividing by the standard error of the mean difference. The test is sensitive to the normality assumption of the sample data.
statds.stats module#
- statds.stats.binomial_coef(n: int, k: int)#
Calculate the binomial coefficient (n choose k).
Parameters#
- nint
The total number of items.
- kint
The number of items to be chosen.
Returns#
- int
The binomial coefficient value (n choose k).
- statds.stats.get_cdf_normal(z_value)#
Calculate the cumulative distribution function (CDF) of the standard normal distribution.
Parameters#
- z_valuefloat
The z-value for which the CDF is calculated.
Returns#
- float
The CDF value for the given z-value.
- statds.stats.get_cv_f_distribution(df_numerator: int, df_denominator: int, alpha: float)#
Retrieve the critical value from an F-distribution critical values table for given degrees of freedom and alpha. This function reads an F-distribution critical values table from a CSV file, which contains critical values for different degrees of freedom for the numerator and denominator, as well as significance levels (alpha). It selects the critical value based on the provided degrees of freedom for the numerator (df_numerator), degrees of freedom for the denominator (df_denominator), and significance level (alpha).
Parameters#
- df_numeratorint
Degrees of freedom for the numerator.
- df_denominatorint
Degrees of freedom for the denominator.
- alphafloat
The significance level for which the critical value is needed.
Returns#
- float
The critical value corresponding to the input degrees of freedom and alpha.
- statds.stats.get_cv_q_distribution(k_degrees_of_freedom: int, num_alg: int, alpha: float)#
Retrieve the critical value from a Q-table for a given chi-squared distribution. This function reads a Q-table from a CSV file, which contains critical values for various degrees of freedom, numerator degrees of freedom, and numbers of algorithms. It selects the critical value based on the provided degrees of freedom (k_degrees_of_freedom), number of algorithms (num_alg), and significance level (alpha).
Parameters#
- k_degrees_of_freedomint
The degrees of freedom of the chi-squared distribution.
- num_algint
The number of algorithms.
- alphafloat
The significance level for which the critical value is needed.
Returns#
- float
The critical value corresponding to the input degrees of freedom, number of algorithms, and alpha.
- statds.stats.get_cv_t_distribution(k_degrees_of_freedom: int, alpha: float)#
Retrieve the critical value from a t-distribution critical values table for a given degrees of freedom and alpha. This function reads a t-distribution critical values table from a CSV file, which contains critical values for different degrees of freedom and significance levels (alpha). It selects the critical value based on the provided degrees of freedom (k_degrees_of_freedom) and significance level (alpha).
Parameters#
- k_degrees_of_freedomint
Degrees of freedom for the t-distribution.
- alphafloat
The significance level for which the critical value is needed.
Returns#
- float
The critical value corresponding to the input degrees of freedom and alpha.
- statds.stats.get_cv_willcoxon(num_problems: int, alpha: float)#
Retrieve the critical value from a Wilcoxon signed-rank test critical values table for a given number of samples and alpha. This function reads a Wilcoxon signed-rank test critical values table from a CSV file, which contains critical values for different numbers of samples and significance levels (alpha). It selects the critical value based on the provided number of samples (num_problems) and significance level (alpha).
Parameters#
- num_problemsint
The number of samples for which the critical value is needed.
- alphafloat
The significance level for which the critical value is needed.
Returns#
- int
The critical value corresponding to the input number of samples and alpha.
- statds.stats.get_p_value_binomial(num: int, statistical: int, probability: float = 0.5)#
Calculate the p-value of a binomial distribution.
Parameters#
- numint
The number of trials in the binomial distribution.
- statisticalint
The number of successful trials.
- probabilityfloat, optional
The probability of success in each trial. Default is 0.5.
Returns#
- float
The p-value associated with the given values.
- statds.stats.get_p_value_chi2(z_value: float, k_degrees_of_freedom: int, alpha: float)#
Calculate the p-value of a binomial distribution.
Parameters#
- z_valuefloat
The z-value for which the CDF is calculated.
- k_degrees_of_freedomint
The degrees of freedom of the chi-squared distribution.
- alphafloat
The significance level for which the critical value is needed.
Returns#
- p_valuefloat
The p-value associated with the given z-value.
- cv_to_alphafloat
The critical value corresponding to the specified alpha.
- statds.stats.get_p_value_f(value: float, df_numerator: int, df_denominator: int)#
Calculate the p-value for a given F-statistic using the F-distribution. This function is used to determine the significance of a test statistic from an ANOVA test, comparing the ratio of variances between and within groups.
Parameters#
- valuefloat
The F-statistic value for which the p-value is to be calculated.
- df_numeratorint
The degrees of freedom for the numerator, often corresponding to the number of groups minus one.
- df_denominatorint
The degrees of freedom for the denominator, usually related to the total number of observations minus the number of groups.
Returns#
- float
The p-value corresponding to the given F-statistic and degrees of freedom. This p-value indicates the probability of observing a value at least as extreme as the F-statistic under the null hypothesis.
Note#
The calculation of the p-value depends on the degrees of freedom for both the numerator and the denominator, and the F-statistic itself.
- statds.stats.get_p_value_normal(z_value)#
Calculate the p-value for a given z-value in a standard normal distribution.
Parameters#
- z_valuefloat
The z-value for which the p-value is calculated.
Returns#
- float
The p-value associated with the given z-value.
- statds.stats.get_p_value_shapier(num_samples: int, statistics_w: float)#
Retrieve the p-value from a Shapiro-Wilk test for a given number of samples and statistics.
Parameters#
- num_samplesint
The number of samples for which the critical value is needed.
- statistics_wfloat
The statistics for which the p-value is calculated.
Returns#
- float
The p-value from the Shapiro-Wilk test.
- statds.stats.get_p_value_t(z_value: float, k_degrees_of_freedom: int, inf_approx=100, steps=1000000)#
Calculate the p-value associated with a given z-value and degrees of freedom using the t-distribution. This function approximates the p-value by converting the z-value to a t-value and then integrating over the t-distribution to find the area under the curve.
Parameters#
- z_valuefloat
The z-value for which the p-value is to be calculated.
- k_degrees_of_freedomint
The degrees of freedom for the t-distribution.
- inf_approxint, optional
The upper limit for the integral approximation, default is 100.
- stepsint, optional
The number of steps to use in the numerical approximation, default is 1,000,000.
Returns#
- float
The p-value corresponding to the given z-value and degrees of freedom.
- statds.stats.get_pdf_t(z_value: float, k_degrees_of_freedom: int)#
Calculate the t value for a given z-value and degrees of freedom.
Parameters#
- z_valuefloat
The z-value for which the chi-squared value is calculated.
- k_degrees_of_freedomint
The degrees of freedom for the chi-squared calculation.
Returns#
- float
The t value.
- statds.stats.get_q_alpha_nemenyi(num_algorithm: int, alpha: float)#
Retrieve the Q_alpha value from a Nemenyi critical values table for a given number of algorithms and alpha. This function reads a Nemenyi critical values table from a CSV file, which contains critical values for different numbers of algorithms and significance levels (alpha). It selects the Q_alpha value based on the provided number of algorithms (num_algorithm) and significance level (alpha).
Parameters#
- num_algorithmint
The number of algorithms for which the Q_alpha value is needed.
- alphafloat
The significance level for which the Q_alpha value is needed.
Returns#
- float
The Q_alpha value corresponding to the input number of algorithms and alpha.
- statds.stats.get_shapiro_weights(n_weights: int)#
Retri: inteve weights a_i for any given sample size n_weights.
Parameters#
- n_weightsint
The number of samples.
Returns#
- list
Weights a_i list for the given number of samples.
- statds.stats.inverse_gaussian_cdf(value, mu: float = 1.0, lamb: float = 1.0)#
Calculate the cumulative distribution function (CDF) of the inverse Gaussian distribution.
Parameters#
- valuefloat
The value for which the CDF is calculated.
- mufloat, optional
The mean parameter of the distribution. Default is 1.0.
- lambfloat, optional
The lambda parameter of the distribution. Default is 1.0.
Returns#
- float
The CDF of the inverse Gaussian distribution for the given value.
- statds.stats.kolmogorov_p_value(d, n)#
Calcula el p-valor para el estadístico de Kolmogorov-Smirnov.
- Parameters:
d – El estadístico de Kolmogorov-Smirnov.
n – El número de observaciones.
- Returns:
El p-valor aproximado.
statds.utils module#
- exception statds.utils.LibraryError(message)#
Bases:
Exception
- statds.utils.analysis_of_experiments(dataset, experiments: dict, generate_pdf: bool = False, name_pdf: str = 'inform.pdf')#
Performs statistical analysis on experiments and optionally generates a PDF report.
Parameters#
- datasetpandas.DataFrame
The dataset containing the experimental data.
- experimentsdict
A dictionary defining the experiments and their parameters.
- generate_pdfbool, optional
Whether to generate a PDF report (default is False).
- name_pdfstr, optional
Name of the PDF file (default is ‘inform.pdf’).
- statds.utils.dataframe_to_latex(dataframe: DataFrame, caption: str | None = None, label: str | None = None)#
Converts a pandas DataFrame into LaTeX code for table creation.
Parameters#
- dataframepandas.DataFrame
The pandas DataFrame to be converted.
- captionstr, optional
The table caption in LaTeX.
- labelstr, optional
The table label in LaTeX.
Returns#
- str
LaTeX code for creating a table.
- statds.utils.generate_json(names_experiments: list, parameters_experiments: list)#
Generates a JSON structure containing experiment parameters.
Parameters#
- names_experimentslist
List of experiment names.
- parameters_experimentslist
List of dictionaries containing experiment parameters.
Returns#
- dict
A dictionary representing experiment parameters in a structured JSON format.
- statds.utils.gets_args_functions(name_function)#
Retrieves the arguments and their default values for a specified function.
Parameters#
- name_functionfunction
The function for which argument information is required.
Returns#
- dict
A dictionary containing argument names as keys and their default values as values.
- statds.utils.print_results(title_experiment, title, test_subtitle, test_result, h_post_hoc, show_table, show_graph)#
Prints the results and related information to the console.
Parameters#
- title_experimentstr
Title for the experiment section.
- titlestr
Title for the document.
- test_subtitlestr
Subtitle for the test section.
- test_resultlist
List of test results to be printed.
- h_post_hocstr
Post-hoc information or analysis to be included.
- show_tablepandas.DataFrame
A DataFrame containing the test results.
- show_graphstr
Name of the saved graph or None if no graph is available.
- statds.utils.process_alpha_experiment(parameter)#
Processes and validates experiment parameters, including alpha level and test details.
Parameters#
- parameterdict
A dictionary containing experiment parameters.
Returns#
- dict
A dictionary containing processed and validated experiment parameters.
Raises#
- LibraryError
If the provided parameters are invalid or missing.