Coverage for /usr/lib/python3/dist-packages/scipy/stats/__init__.py: 100%
30 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1"""
2.. _statsrefmanual:
4==========================================
5Statistical functions (:mod:`scipy.stats`)
6==========================================
8.. currentmodule:: scipy.stats
10This module contains a large number of probability distributions,
11summary and frequency statistics, correlation functions and statistical
12tests, masked statistics, kernel density estimation, quasi-Monte Carlo
13functionality, and more.
15Statistics is a very large area, and there are topics that are out of scope
16for SciPy and are covered by other packages. Some of the most important ones
17are:
19- `statsmodels <https://www.statsmodels.org/stable/index.html>`__:
20 regression, linear models, time series analysis, extensions to topics
21 also covered by ``scipy.stats``.
22- `Pandas <https://pandas.pydata.org/>`__: tabular data, time series
23 functionality, interfaces to other statistical languages.
24- `PyMC <https://docs.pymc.io/>`__: Bayesian statistical
25 modeling, probabilistic machine learning.
26- `scikit-learn <https://scikit-learn.org/>`__: classification, regression,
27 model selection.
28- `Seaborn <https://seaborn.pydata.org/>`__: statistical data visualization.
29- `rpy2 <https://rpy2.github.io/>`__: Python to R bridge.
32Probability distributions
33=========================
35Each univariate distribution is an instance of a subclass of `rv_continuous`
36(`rv_discrete` for discrete distributions):
38.. autosummary::
39 :toctree: generated/
41 rv_continuous
42 rv_discrete
43 rv_histogram
45Continuous distributions
46------------------------
48.. autosummary::
49 :toctree: generated/
51 alpha -- Alpha
52 anglit -- Anglit
53 arcsine -- Arcsine
54 argus -- Argus
55 beta -- Beta
56 betaprime -- Beta Prime
57 bradford -- Bradford
58 burr -- Burr (Type III)
59 burr12 -- Burr (Type XII)
60 cauchy -- Cauchy
61 chi -- Chi
62 chi2 -- Chi-squared
63 cosine -- Cosine
64 crystalball -- Crystalball
65 dgamma -- Double Gamma
66 dweibull -- Double Weibull
67 erlang -- Erlang
68 expon -- Exponential
69 exponnorm -- Exponentially Modified Normal
70 exponweib -- Exponentiated Weibull
71 exponpow -- Exponential Power
72 f -- F (Snecdor F)
73 fatiguelife -- Fatigue Life (Birnbaum-Saunders)
74 fisk -- Fisk
75 foldcauchy -- Folded Cauchy
76 foldnorm -- Folded Normal
77 genlogistic -- Generalized Logistic
78 gennorm -- Generalized normal
79 genpareto -- Generalized Pareto
80 genexpon -- Generalized Exponential
81 genextreme -- Generalized Extreme Value
82 gausshyper -- Gauss Hypergeometric
83 gamma -- Gamma
84 gengamma -- Generalized gamma
85 genhalflogistic -- Generalized Half Logistic
86 genhyperbolic -- Generalized Hyperbolic
87 geninvgauss -- Generalized Inverse Gaussian
88 gibrat -- Gibrat
89 gompertz -- Gompertz (Truncated Gumbel)
90 gumbel_r -- Right Sided Gumbel, Log-Weibull, Fisher-Tippett, Extreme Value Type I
91 gumbel_l -- Left Sided Gumbel, etc.
92 halfcauchy -- Half Cauchy
93 halflogistic -- Half Logistic
94 halfnorm -- Half Normal
95 halfgennorm -- Generalized Half Normal
96 hypsecant -- Hyperbolic Secant
97 invgamma -- Inverse Gamma
98 invgauss -- Inverse Gaussian
99 invweibull -- Inverse Weibull
100 johnsonsb -- Johnson SB
101 johnsonsu -- Johnson SU
102 kappa4 -- Kappa 4 parameter
103 kappa3 -- Kappa 3 parameter
104 ksone -- Distribution of Kolmogorov-Smirnov one-sided test statistic
105 kstwo -- Distribution of Kolmogorov-Smirnov two-sided test statistic
106 kstwobign -- Limiting Distribution of scaled Kolmogorov-Smirnov two-sided test statistic.
107 laplace -- Laplace
108 laplace_asymmetric -- Asymmetric Laplace
109 levy -- Levy
110 levy_l
111 levy_stable
112 logistic -- Logistic
113 loggamma -- Log-Gamma
114 loglaplace -- Log-Laplace (Log Double Exponential)
115 lognorm -- Log-Normal
116 loguniform -- Log-Uniform
117 lomax -- Lomax (Pareto of the second kind)
118 maxwell -- Maxwell
119 mielke -- Mielke's Beta-Kappa
120 moyal -- Moyal
121 nakagami -- Nakagami
122 ncx2 -- Non-central chi-squared
123 ncf -- Non-central F
124 nct -- Non-central Student's T
125 norm -- Normal (Gaussian)
126 norminvgauss -- Normal Inverse Gaussian
127 pareto -- Pareto
128 pearson3 -- Pearson type III
129 powerlaw -- Power-function
130 powerlognorm -- Power log normal
131 powernorm -- Power normal
132 rdist -- R-distribution
133 rayleigh -- Rayleigh
134 rel_breitwigner -- Relativistic Breit-Wigner
135 rice -- Rice
136 recipinvgauss -- Reciprocal Inverse Gaussian
137 semicircular -- Semicircular
138 skewcauchy -- Skew Cauchy
139 skewnorm -- Skew normal
140 studentized_range -- Studentized Range
141 t -- Student's T
142 trapezoid -- Trapezoidal
143 triang -- Triangular
144 truncexpon -- Truncated Exponential
145 truncnorm -- Truncated Normal
146 truncpareto -- Truncated Pareto
147 truncweibull_min -- Truncated minimum Weibull distribution
148 tukeylambda -- Tukey-Lambda
149 uniform -- Uniform
150 vonmises -- Von-Mises (Circular)
151 vonmises_line -- Von-Mises (Line)
152 wald -- Wald
153 weibull_min -- Minimum Weibull (see Frechet)
154 weibull_max -- Maximum Weibull (see Frechet)
155 wrapcauchy -- Wrapped Cauchy
157The ``fit`` method of the univariate continuous distributions uses
158maximum likelihood estimation to fit the distribution to a data set.
159The ``fit`` method can accept regular data or *censored data*.
160Censored data is represented with instances of the `CensoredData`
161class.
163.. autosummary::
164 :toctree: generated/
166 CensoredData
169Multivariate distributions
170--------------------------
172.. autosummary::
173 :toctree: generated/
175 multivariate_normal -- Multivariate normal distribution
176 matrix_normal -- Matrix normal distribution
177 dirichlet -- Dirichlet
178 dirichlet_multinomial -- Dirichlet multinomial distribution
179 wishart -- Wishart
180 invwishart -- Inverse Wishart
181 multinomial -- Multinomial distribution
182 special_ortho_group -- SO(N) group
183 ortho_group -- O(N) group
184 unitary_group -- U(N) group
185 random_correlation -- random correlation matrices
186 multivariate_t -- Multivariate t-distribution
187 multivariate_hypergeom -- Multivariate hypergeometric distribution
188 random_table -- Distribution of random tables with given marginals
189 uniform_direction -- Uniform distribution on S(N-1)
190 vonmises_fisher -- Von Mises-Fisher distribution
192`scipy.stats.multivariate_normal` methods accept instances
193of the following class to represent the covariance.
195.. autosummary::
196 :toctree: generated/
198 Covariance -- Representation of a covariance matrix
201Discrete distributions
202----------------------
204.. autosummary::
205 :toctree: generated/
207 bernoulli -- Bernoulli
208 betabinom -- Beta-Binomial
209 binom -- Binomial
210 boltzmann -- Boltzmann (Truncated Discrete Exponential)
211 dlaplace -- Discrete Laplacian
212 geom -- Geometric
213 hypergeom -- Hypergeometric
214 logser -- Logarithmic (Log-Series, Series)
215 nbinom -- Negative Binomial
216 nchypergeom_fisher -- Fisher's Noncentral Hypergeometric
217 nchypergeom_wallenius -- Wallenius's Noncentral Hypergeometric
218 nhypergeom -- Negative Hypergeometric
219 planck -- Planck (Discrete Exponential)
220 poisson -- Poisson
221 randint -- Discrete Uniform
222 skellam -- Skellam
223 yulesimon -- Yule-Simon
224 zipf -- Zipf (Zeta)
225 zipfian -- Zipfian
228An overview of statistical functions is given below. Many of these functions
229have a similar version in `scipy.stats.mstats` which work for masked arrays.
231Summary statistics
232==================
234.. autosummary::
235 :toctree: generated/
237 describe -- Descriptive statistics
238 gmean -- Geometric mean
239 hmean -- Harmonic mean
240 pmean -- Power mean
241 kurtosis -- Fisher or Pearson kurtosis
242 mode -- Modal value
243 moment -- Central moment
244 expectile -- Expectile
245 skew -- Skewness
246 kstat --
247 kstatvar --
248 tmean -- Truncated arithmetic mean
249 tvar -- Truncated variance
250 tmin --
251 tmax --
252 tstd --
253 tsem --
254 variation -- Coefficient of variation
255 find_repeats
256 rankdata
257 tiecorrect
258 trim_mean
259 gstd -- Geometric Standard Deviation
260 iqr
261 sem
262 bayes_mvs
263 mvsdist
264 entropy
265 differential_entropy
266 median_abs_deviation
268Frequency statistics
269====================
271.. autosummary::
272 :toctree: generated/
274 cumfreq
275 percentileofscore
276 scoreatpercentile
277 relfreq
279.. autosummary::
280 :toctree: generated/
282 binned_statistic -- Compute a binned statistic for a set of data.
283 binned_statistic_2d -- Compute a 2-D binned statistic for a set of data.
284 binned_statistic_dd -- Compute a d-D binned statistic for a set of data.
286Hypothesis Tests and related functions
287======================================
288SciPy has many functions for performing hypothesis tests that return a
289test statistic and a p-value, and several of them return confidence intervals
290and/or other related information.
292The headings below are based on common uses of the functions within, but due to
293the wide variety of statistical procedures, any attempt at coarse-grained
294categorization will be imperfect. Also, note that tests within the same heading
295are not interchangeable in general (e.g. many have different distributional
296assumptions).
298One Sample Tests / Paired Sample Tests
299--------------------------------------
300One sample tests are typically used to assess whether a single sample was
301drawn from a specified distribution or a distribution with specified properties
302(e.g. zero mean).
304.. autosummary::
305 :toctree: generated/
307 ttest_1samp
308 binomtest
309 skewtest
310 kurtosistest
311 normaltest
312 jarque_bera
313 shapiro
314 anderson
315 cramervonmises
316 ks_1samp
317 goodness_of_fit
318 chisquare
319 power_divergence
321Paired sample tests are often used to assess whether two samples were drawn
322from the same distribution; they differ from the independent sample tests below
323in that each observation in one sample is treated as paired with a
324closely-related observation in the other sample (e.g. when environmental
325factors are controlled between observations within a pair but not among pairs).
326They can also be interpreted or used as one-sample tests (e.g. tests on the
327mean or median of *differences* between paired observations).
329.. autosummary::
330 :toctree: generated/
332 ttest_rel
333 wilcoxon
335Association/Correlation Tests
336-----------------------------
338These tests are often used to assess whether there is a relationship (e.g.
339linear) between paired observations in multiple samples or among the
340coordinates of multivariate observations.
342.. autosummary::
343 :toctree: generated/
345 linregress
346 pearsonr
347 spearmanr
348 pointbiserialr
349 kendalltau
350 weightedtau
351 somersd
352 siegelslopes
353 theilslopes
354 page_trend_test
355 multiscale_graphcorr
357These association tests and are to work with samples in the form of contingency
358tables. Supporting functions are available in `scipy.stats.contingency`.
360.. autosummary::
361 :toctree: generated/
363 chi2_contingency
364 fisher_exact
365 barnard_exact
366 boschloo_exact
368Independent Sample Tests
369------------------------
370Independent sample tests are typically used to assess whether multiple samples
371were independently drawn from the same distribution or different distributions
372with a shared property (e.g. equal means).
374Some tests are specifically for comparing two samples.
376.. autosummary::
377 :toctree: generated/
379 ttest_ind_from_stats
380 poisson_means_test
381 ttest_ind
382 mannwhitneyu
383 ranksums
384 brunnermunzel
385 mood
386 ansari
387 cramervonmises_2samp
388 epps_singleton_2samp
389 ks_2samp
390 kstest
392Others are generalized to multiple samples.
394.. autosummary::
395 :toctree: generated/
397 f_oneway
398 tukey_hsd
399 dunnett
400 kruskal
401 alexandergovern
402 fligner
403 levene
404 bartlett
405 median_test
406 friedmanchisquare
407 anderson_ksamp
409Resampling and Monte Carlo Methods
410----------------------------------
411The following functions can reproduce the p-value and confidence interval
412results of most of the functions above, and often produce accurate results in a
413wider variety of conditions. They can also be used to perform hypothesis tests
414and generate confidence intervals for custom statistics. This flexibility comes
415at the cost of greater computational requirements and stochastic results.
417.. autosummary::
418 :toctree: generated/
420 monte_carlo_test
421 permutation_test
422 bootstrap
424Instances of the following object can be passed into some hypothesis test
425functions to perform a resampling or Monte Carlo version of the hypothesis
426test.
428.. autosummary::
429 :toctree: generated/
431 MonteCarloMethod
432 PermutationMethod
433 BootstrapMethod
435Multiple Hypothesis Testing and Meta-Analysis
436---------------------------------------------
437These functions are for assessing the results of individual tests as a whole.
438Functions for performing specific multiple hypothesis tests (e.g. post hoc
439tests) are listed above.
441.. autosummary::
442 :toctree: generated/
444 combine_pvalues
445 false_discovery_control
447Deprecated and Legacy Functions
448-------------------------------
450.. autosummary::
451 :toctree: generated/
453 binom_test
455The following functions are related to the tests above but do not belong in the
456above categories.
458Quasi-Monte Carlo
459=================
461.. toctree::
462 :maxdepth: 4
464 stats.qmc
466Contingency Tables
467==================
469.. toctree::
470 :maxdepth: 4
472 stats.contingency
474Masked statistics functions
475===========================
477.. toctree::
479 stats.mstats
482Other statistical functionality
483===============================
485Transformations
486---------------
488.. autosummary::
489 :toctree: generated/
491 boxcox
492 boxcox_normmax
493 boxcox_llf
494 yeojohnson
495 yeojohnson_normmax
496 yeojohnson_llf
497 obrientransform
498 sigmaclip
499 trimboth
500 trim1
501 zmap
502 zscore
503 gzscore
505Statistical distances
506---------------------
508.. autosummary::
509 :toctree: generated/
511 wasserstein_distance
512 energy_distance
514Sampling
515--------
517.. toctree::
518 :maxdepth: 4
520 stats.sampling
522Random variate generation / CDF Inversion
523-----------------------------------------
525.. autosummary::
526 :toctree: generated/
528 rvs_ratio_uniforms
530Fitting / Survival Analysis
531---------------------------
533.. autosummary::
534 :toctree: generated/
536 fit
537 ecdf
538 logrank
540Directional statistical functions
541---------------------------------
543.. autosummary::
544 :toctree: generated/
546 directional_stats
547 circmean
548 circvar
549 circstd
551Sensitivity Analysis
552--------------------
554.. autosummary::
555 :toctree: generated/
557 sobol_indices
559Plot-tests
560----------
562.. autosummary::
563 :toctree: generated/
565 ppcc_max
566 ppcc_plot
567 probplot
568 boxcox_normplot
569 yeojohnson_normplot
571Univariate and multivariate kernel density estimation
572-----------------------------------------------------
574.. autosummary::
575 :toctree: generated/
577 gaussian_kde
579Warnings / Errors used in :mod:`scipy.stats`
580--------------------------------------------
582.. autosummary::
583 :toctree: generated/
585 DegenerateDataWarning
586 ConstantInputWarning
587 NearConstantInputWarning
588 FitError
590Result classes used in :mod:`scipy.stats`
591-----------------------------------------
593.. warning::
595 These classes are private, but they are included here because instances
596 of them are returned by other statistical functions. User import and
597 instantiation is not supported.
599.. toctree::
600 :maxdepth: 2
602 stats._result_classes
604"""
606from ._warnings_errors import (ConstantInputWarning, NearConstantInputWarning,
607 DegenerateDataWarning, FitError)
608from ._stats_py import *
609from ._variation import variation
610from .distributions import *
611from ._morestats import *
612from ._multicomp import *
613from ._binomtest import binomtest
614from ._binned_statistic import *
615from ._kde import gaussian_kde
616from . import mstats
617from . import qmc
618from ._multivariate import *
619from . import contingency
620from .contingency import chi2_contingency
621from ._censored_data import CensoredData # noqa
622from ._resampling import (bootstrap, monte_carlo_test, permutation_test,
623 MonteCarloMethod, PermutationMethod, BootstrapMethod)
624from ._entropy import *
625from ._hypotests import *
626from ._rvs_sampling import rvs_ratio_uniforms
627from ._page_trend_test import page_trend_test
628from ._mannwhitneyu import mannwhitneyu
629from ._fit import fit, goodness_of_fit
630from ._covariance import Covariance
631from ._sensitivity_analysis import *
632from ._survival import *
634# Deprecated namespaces, to be removed in v2.0.0
635from . import (
636 biasedurn, kde, morestats, mstats_basic, mstats_extras, mvn, statlib, stats
637)
640__all__ = [s for s in dir() if not s.startswith("_")] # Remove dunders.
642from scipy._lib._testutils import PytestTester
643test = PytestTester(__name__)
644del PytestTester