{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / contingency / expected_freq

function

scipy.stats.contingency:expected_freq

source: /scipy/stats/contingency.py :93

Signature

def   expected_freq ( observed )

Summary

Compute the expected frequencies from a contingency table.

Extended Summary

Given an n-dimensional contingency table of observed frequencies, compute the expected frequencies for the table based on the marginal sums under the assumption that the groups associated with each dimension are independent.

Parameters

observed : array_like

The table of observed frequencies. (While this function can handle a 1-D array, that case is trivial. Generally observed is at least 2-D.)

Returns

expected : ndarray of float64

The expected frequencies, based on the marginal sums of the table. Same shape as observed.

Notes

Array API Standard Support

expected_freq has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ⛔                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

import numpy as np
from scipy.stats.contingency import expected_freq
observed = np.array([[10, 10, 20],[20, 20, 20]])
expected_freq(observed)

Aliases

  • scipy.stats.contingency.expected_freq