← Back
Editing: contingency.cpython-311.pyc
� d�c�7 � � � d Z ddlmZ ddlZddlZddlmZ ddlm Z ddl mZ ddlm Z dd lmZ g d �Zd� Zd� Z ed g d�g � � Zdd�Zdd�ZdS )ax Contingency table functions (:mod:`scipy.stats.contingency`) ============================================================ Functions for creating and analyzing contingency tables. .. currentmodule:: scipy.stats.contingency .. autosummary:: :toctree: generated/ chi2_contingency relative_risk odds_ratio crosstab association expected_freq margins � )�reduceN� )�power_divergence)� relative_risk)�crosstab)� odds_ratio)�_make_tuple_bunch)�margins� expected_freq�chi2_contingencyr �associationr r c �� �� g }t t | j � � � � }|D ]C�t j t j | �fd�|D � � � � }|� |� � �D|S )a Return a list of the marginal sums of the array `a`. Parameters ---------- a : ndarray The array for which to compute the marginal sums. Returns ------- margsums : list of ndarrays A list of length `a.ndim`. `margsums[k]` is the result of summing `a` over all axes except `k`; it has the same number of dimensions as `a`, but the length of each axis except axis `k` will be 1. Examples -------- >>> import numpy as np >>> from scipy.stats.contingency import margins >>> a = np.arange(12).reshape(2, 6) >>> a array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11]]) >>> m0, m1 = margins(a) >>> m0 array([[15], [51]]) >>> m1 array([[ 6, 8, 10, 12, 14, 16]]) >>> b = np.arange(24).reshape(2,3,4) >>> m0, m1, m2 = margins(b) >>> m0 array([[[ 66]], [[210]]]) >>> m1 array([[[ 60], [ 92], [124]]]) >>> m2 array([[[60, 66, 72, 78]]]) c � �� g | ] }|�k �|��S � r )�.0�j�ks ��9/usr/lib/python3/dist-packages/scipy/stats/contingency.py� <listcomp>zmargins.<locals>.<listcomp>U s �� �-J�-J�-J�A�1��6�6�a�6�6�6� )�list�range�ndim�np�apply_over_axes�sum�append)�a�margsums�ranged�margr s @r r r &