Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé
Module « scipy.stats »

Fonction random_table - module scipy.stats

Signature de la fonction random_table

def random_table(row, col, *, seed=None) 

Description

help(scipy.stats.random_table)

Contingency tables from independent samples with fixed marginal sums.

This is the distribution of random tables with given row and column vector
sums. This distribution represents the set of random tables under the null
hypothesis that rows and columns are independent. It is used in hypothesis
tests of independence.

Because of assumed independence, the expected frequency of each table
element can be computed from the row and column sums, so that the
distribution is completely determined by these two vectors.

Methods
-------
logpmf(x)
    Log-probability of table `x` to occur in the distribution.
pmf(x)
    Probability of table `x` to occur in the distribution.
mean(row, col)
    Mean table.
rvs(row, col, size=None, method=None, random_state=None)
    Draw random tables with given row and column vector sums.

Parameters
----------
row : array_like
    Sum of table entries in each row.
col : array_like
    Sum of table entries in each column.
seed : {None, int, np.random.RandomState, np.random.Generator}, optional
    Used for drawing random variates.
    If `seed` is `None`, the `~np.random.RandomState` singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used, seeded
    with seed.
    If `seed` is already a ``RandomState`` or ``Generator`` instance,
    then that object is used.
    Default is `None`.

Notes
-----
The row and column vectors must be one-dimensional, not empty,
and each sum up to the same value. They cannot contain negative
or noninteger entries.

Random elements from the distribution are generated either with Boyett's
[1]_ or Patefield's algorithm [2]_. Boyett's algorithm has
O(N) time and space complexity, where N is the total sum of entries in the
table. Patefield's algorithm has O(K x log(N)) time complexity, where K is
the number of cells in the table and requires only a small constant work
space. By default, the `rvs` method selects the fastest algorithm based on
the input, but you can specify the algorithm with the keyword `method`.
Allowed values are "boyett" and "patefield".

.. versionadded:: 1.10.0

Examples
--------
>>> from scipy.stats import random_table

>>> row = [1, 5]
>>> col = [2, 3, 1]
>>> random_table.mean(row, col)
array([[0.33333333, 0.5       , 0.16666667],
       [1.66666667, 2.5       , 0.83333333]])

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> dist = random_table(row, col)
>>> dist.rvs(random_state=123)
array([[1, 0, 0],
       [1, 3, 1]])

References
----------
.. [1] J. Boyett, AS 144 Appl. Statist. 28 (1979) 329-332
.. [2] W.M. Patefield, AS 159 Appl. Statist. 30 (1981) 91-97


Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé