# `stats.tests.test_stats`¶

Test functions for stats module

WRITTEN BY LOUIS LUANGKESORN <lluang@yahoo.com> FOR THE STATS MODULE BASED ON WILKINSON’S STATISTICS QUIZ http://www.stanford.edu/~clint/bench/wilk.txt

Additional tests by a host of SciPy developers.

## Module Contents¶

### Classes¶

 `TestTrimmedStats`() `TestCorrPearsonr`() W.II.D. Compute a correlation matrix on all the variables. `TestFisherExact`() Some tests to show that fisher_exact() works correctly. `TestCorrSpearmanr`() W.II.D. Compute a correlation matrix on all the variables. `TestCorrSpearmanrTies`() Some tests of tie-handling by the spearmanr function. `TestFindRepeats`() `TestRegression`() `TestGMean`() `TestHMean`() `TestScoreatpercentile`() `TestItemfreq`() `TestMode`() `TestVariability`() `_numpy_version_warn_context_mgr`(self,min_numpy_version,warning_type,num_warnings) A simple context maneger class to avoid retyping the same code for `TestIQR`() `TestMoments`() Comparison numbers are found using R v.1.5.1 `TestStudentTest`() `TestPowerDivergence`() `TestDescribe`() `TestRankSums`() `TestJarqueBera`() `TestMannWhitneyU`() `HarMeanTestCase`() `TestHarMean`() `GeoMeanTestCase`() `TestGeoMean`() `TestTrim`() `TestSigamClip`() `TestFOneWay`() `TestKruskal`() `TestCombinePvalues`() `TestCdfDistanceValidation`() Test that _cdf_distance() (via wasserstein_distance()) raises ValueErrors `TestWassersteinDistance`() Tests for wasserstein_distance() output values. `TestEnergyDistance`() Tests for energy_distance() output values.

### Functions¶

 `test_spearmanr`() `test_kendalltau`() `test_kendalltau_vs_mstats_basic`() `test_kendalltau_nan_2nd_arg`() `test_weightedtau`() `test_weightedtau_vs_quadratic`() `test_theilslopes`() `test_cumfreq`() `test_relfreq`() `_check_warnings`(warn_list,expected_type,expected_len) Checks that all of the warnings from a list returned by `test_percentileofscore`() `test_chisquare_masked_arrays`() `test_power_divergence_against_cressie_read_data`() `test_friedmanchisquare`() `test_kstest`() `test_ks_2samp`() `test_ttest_rel`() `test_ttest_rel_nan_2nd_arg`() `_desc_stats`(x1,x2,axis=0) `test_ttest_ind`() `test_ttest_ind_with_uneq_var`() `test_ttest_ind_nan_2nd_arg`() `test_gh5686`() `test_ttest_1samp_new`() `test_normalitytests`() `test_skewtest_too_few_samples`() `test_kurtosistest_too_few_samples`() `test_pointbiserial`() `test_obrientransform`() `test_binomtest`() `test_binomtest2`() `test_binomtest3`()
class `TestTrimmedStats`
`test_tmean`()
`test_tvar`()
`test_tstd`()
`test_tmin`()
`test_tmax`()
`test_tsem`()
class `TestCorrPearsonr`

W.II.D. Compute a correlation matrix on all the variables.

All the correlations, except for ZERO and MISS, shoud be exactly 1. ZERO and MISS should have undefined or missing correlations with the other variables. The same should go for SPEARMAN corelations, if your program has them.

`test_pXX`()
`test_pXBIG`()
`test_pXLITTLE`()
`test_pXHUGE`()
`test_pXTINY`()
`test_pXROUND`()
`test_pBIGBIG`()
`test_pBIGLITTLE`()
`test_pBIGHUGE`()
`test_pBIGTINY`()
`test_pBIGROUND`()
`test_pLITTLELITTLE`()
`test_pLITTLEHUGE`()
`test_pLITTLETINY`()
`test_pLITTLEROUND`()
`test_pHUGEHUGE`()
`test_pHUGETINY`()
`test_pHUGEROUND`()
`test_pTINYTINY`()
`test_pTINYROUND`()
`test_pROUNDROUND`()
`test_r_exactly_pos1`()
`test_r_exactly_neg1`()
`test_basic`()
class `TestFisherExact`

Some tests to show that fisher_exact() works correctly.

Note that in SciPy 0.9.0 this was not working well for large numbers due to inaccuracy of the hypergeom distribution (see #1218). Fixed now.

Also note that R and Scipy have different argument formats for their hypergeometric distribution functions.

R: > phyper(18999, 99000, 110000, 39000, lower.tail = FALSE) [1] 1.701815e-09

`test_basic`()
`test_precise`()
`test_large_numbers`()
`test_raises`()
`test_row_or_col_zero`()
`test_less_greater`()
`test_gh3014`()
class `TestCorrSpearmanr`

W.II.D. Compute a correlation matrix on all the variables.

All the correlations, except for ZERO and MISS, shoud be exactly 1. ZERO and MISS should have undefined or missing correlations with the other variables. The same should go for SPEARMAN corelations, if your program has them.

`test_scalar`()
`test_uneven_lengths`()
`test_nan_policy`()
`test_sXX`()
`test_sXBIG`()
`test_sXLITTLE`()
`test_sXHUGE`()
`test_sXTINY`()
`test_sXROUND`()
`test_sBIGBIG`()
`test_sBIGLITTLE`()
`test_sBIGHUGE`()
`test_sBIGTINY`()
`test_sBIGROUND`()
`test_sLITTLELITTLE`()
`test_sLITTLEHUGE`()
`test_sLITTLETINY`()
`test_sLITTLEROUND`()
`test_sHUGEHUGE`()
`test_sHUGETINY`()
`test_sHUGEROUND`()
`test_sTINYTINY`()
`test_sTINYROUND`()
`test_sROUNDROUND`()
`test_spearmanr_result_attributes`()
`test_spearmanr`()
class `TestCorrSpearmanrTies`

Some tests of tie-handling by the spearmanr function.

`test_tie1`()
`test_kendalltau`()
`test_kendalltau_vs_mstats_basic`()
`test_kendalltau_nan_2nd_arg`()
`test_weightedtau`()
`test_weightedtau_vs_quadratic`()
class `TestFindRepeats`
`test_basic`()
`test_empty_result`()
class `TestRegression`
`test_linregressBIGX`()
`test_regressXX`()
`test_regressZEROX`()
`test_regress_simple`()
`test_regress_simple_onearg_rows`()
`test_regress_simple_onearg_cols`()
`test_regress_shape_error`()
`test_linregress`()
`test_regress_simple_negative_cor`()
`test_linregress_result_attributes`()
`test_regress_two_inputs`()
`test_regress_two_inputs_horizontal_line`()
`test_nist_norris`()
`test_empty_input`()
`test_nan_input`()
`test_theilslopes`()
`test_cumfreq`()
`test_relfreq`()
class `TestGMean`
`test_1D_list`()
`test_1D_array`()
`test_2D_array_default`()
`test_2D_array_dim1`()
`test_large_values`()
class `TestHMean`
`test_1D_list`()
`test_1D_array`()
`test_2D_array_default`()
`test_2D_array_dim1`()
class `TestScoreatpercentile`
`setup_method`()
`test_basic`()
`test_fraction`()
`test_lower_higher`()
`test_sequence_per`()
`test_axis`()
`test_exception`()
`test_empty`()
class `TestItemfreq`
`test_numeric_types`()
`test_object_arrays`()
`test_structured_arrays`()
class `TestMode`
`test_empty`()
`test_scalar`()
`test_basic`()
`test_axes`()
`test_strings`()
`test_mixed_objects`()
`test_objects`()
`test_mode_result_attributes`()
`test_mode_nan`()
class `TestVariability`
`test_sem`()
`test_zmap`()
`test_zmap_axis`()
`test_zmap_ddof`()
`test_zscore`()
`test_zscore_axis`()
`test_zscore_ddof`()
class `_numpy_version_warn_context_mgr`(min_numpy_version, warning_type, num_warnings)

A simple context maneger class to avoid retyping the same code for different versions of numpy when the only difference is that older versions raise warnings.

This manager does not apply for cases where the old code returns different values.

`__init__`(min_numpy_version, warning_type, num_warnings)
`__enter__`()
`__exit__`(exc_type, exc_value, traceback)
`_check_warnings`(warn_list, expected_type, expected_len)

Checks that all of the warnings from a list returned by warnings.catch_all(record=True) are of the required type and that the list contains expected number of warnings.

class `TestIQR`
`test_basic`()
`test_api`()
`test_empty`()
`test_constant`()
`test_scalarlike`()
`test_2D`()
`test_axis`()
`test_rng`()
`test_interpolation`()
`test_keepdims`()
`test_nanpolicy`()
`test_scale`()
class `TestMoments`

Comparison numbers are found using R v.1.5.1 note that length(testcase) = 4 testmathworks comes from documentation for the Statistics Toolbox for Matlab and can be found at both http://www.mathworks.com/access/helpdesk/help/toolbox/stats/kurtosis.shtml http://www.mathworks.com/access/helpdesk/help/toolbox/stats/skewness.shtml Note that both test cases came from here.

`test_moment`()
`test_moment_propagate_nan`()
`test_variation`()
`test_variation_propagate_nan`()
`test_skewness`()
`test_skewness_scalar`()
`test_skew_propagate_nan`()
`test_kurtosis`()
`test_kurtosis_array_scalar`()
`test_kurtosis_propagate_nan`()
`test_moment_accuracy`()
class `TestStudentTest`
`test_onesample`()
`test_percentileofscore`()
class `TestPowerDivergence`
`check_power_divergence`(f_obs, f_exp, ddof, axis, lambda_, expected_stat)
`test_basic`()
`test_basic_masked`()
`test_axis`()
`test_ddof_broadcasting`()
`test_empty_cases`()
`test_power_divergence_result_attributes`()
`test_chisquare_masked_arrays`()
`test_power_divergence_against_cressie_read_data`()
`test_friedmanchisquare`()
`test_kstest`()
`test_ks_2samp`()
`test_ttest_rel`()
`test_ttest_rel_nan_2nd_arg`()
`_desc_stats`(x1, x2, axis=0)
`test_ttest_ind`()
`test_ttest_ind_with_uneq_var`()
`test_ttest_ind_nan_2nd_arg`()
`test_gh5686`()
`test_ttest_1samp_new`()
class `TestDescribe`
`test_describe_scalar`()
`test_describe_numbers`()
`test_describe_result_attributes`()
`test_describe_ddof`()
`test_describe_axis_none`()
`test_describe_empty`()
`test_normalitytests`()
class `TestRankSums`
`test_ranksums_result_attributes`()
class `TestJarqueBera`
`test_jarque_bera_stats`()
`test_jarque_bera_array_like`()
`test_jarque_bera_size`()
`test_skewtest_too_few_samples`()
`test_kurtosistest_too_few_samples`()
class `TestMannWhitneyU`
`test_mannwhitneyu_one_sided`()
`test_mannwhitneyu_two_sided`()
`test_mannwhitneyu_default`()
`test_mannwhitneyu_no_correct_one_sided`()
`test_mannwhitneyu_no_correct_two_sided`()
`test_mannwhitneyu_no_correct_default`()
`test_mannwhitneyu_ones`()
`test_mannwhitneyu_result_attributes`()
`test_pointbiserial`()
`test_obrientransform`()
class `HarMeanTestCase`
`test_1dlist`()
`test_1darray`()
`test_1dma`()
`test_1dmavalue`()
`test_2dlist`()
`test_2darray`()
`test_2dma`()
`test_2daxis0`()
`test_2daxis1`()
`test_2dmatrixdaxis0`()
`test_2dmatrixaxis1`()
class `TestHarMean`
`do`(a, b, axis=None, dtype=None)
class `GeoMeanTestCase`
`test_1dlist`()
`test_1darray`()
`test_1dma`()
`test_1dmavalue`()
`test_2dlist`()
`test_2darray`()
`test_2dma`()
`test_2daxis0`()
`test_2daxis1`()
`test_2dmatrixdaxis0`()
`test_2dmatrixaxis1`()
`test_1dlist0`()
`test_1darray0`()
`test_1dma0`()
`test_1dmainf`()
class `TestGeoMean`
`do`(a, b, axis=None, dtype=None)
`test_binomtest`()
`test_binomtest2`()
`test_binomtest3`()
class `TestTrim`
`test_trim1`()
`test_trimboth`()
`test_trim_mean`()
class `TestSigamClip`
`test_sigmaclip1`()
`test_sigmaclip2`()
`test_sigmaclip3`()
`test_sigmaclip_result_attributes`()
class `TestFOneWay`
`test_trivial`()
`test_basic`()
`test_large_integer_array`()
`test_result_attributes`()
`test_nist`()
class `TestKruskal`
`test_simple`()
`test_basic`()
`test_simple_tie`()
`test_another_tie`()
`test_three_groups`()
`test_empty`()
`test_kruskal_result_attributes`()
`test_nan_policy`()
class `TestCombinePvalues`
`test_fisher`()
`test_stouffer`()
`test_stouffer2`()
`test_weighted_stouffer`()
`test_weighted_stouffer2`()
class `TestCdfDistanceValidation`

Test that _cdf_distance() (via wasserstein_distance()) raises ValueErrors for bad inputs.

`test_distinct_value_and_weight_lengths`()
`test_zero_weight`()
`test_negative_weights`()
`test_empty_distribution`()
`test_inf_weight`()
class `TestWassersteinDistance`

Tests for wasserstein_distance() output values.

`test_simple`()
`test_same_distribution`()
`test_shift`()
`test_combine_weights`()
`test_collapse`()
`test_zero_weight`()
`test_inf_values`()
class `TestEnergyDistance`

Tests for energy_distance() output values.

`test_simple`()
`test_same_distribution`()
`test_shift`()
`test_combine_weights`()
`test_zero_weight`()
`test_inf_values`()