proportion

proportion(val: ndarray[float, ...] | float, comp: ndarray[float, ...] = None, tail: int = 1, axis: int = None) ndarray[float, ...] | float[source][source]

takes a value and a comparison and returns the proportion of the comparison that is greater than the value

Parameters:
  • val (array, shape (x, ) or float,) – The difference between two groups.

  • comp (array, shape (y, ) optional) – The difference between two groups.

  • tail (int, optional) – The number of tails to use. 1 for one-tailed, 2 for two-tailed.

  • axis (int, optional) – The axis to perform the permutation test across. Also known as the observations axis

Returns:

proportion – The proportion of the comparison that is greater than the value.

Return type:

array, shape (..., time)

Examples

>>> import numpy as np
>>> rand = np.random.default_rng(seed=42)
>>> diff1 = rand.random(5)
>>> diff1
array([0.77395605, 0.43887844, 0.85859792, 0.69736803, 0.09417735])
>>> proportion(diff1)
array([0.75, 0.25, 1.  , 0.5 , 0.  ])
>>> np.sum(diff1 > diff1[:, None], axis=0) / (diff1.shape[0] - 1)
array([0.75, 0.25, 1.  , 0.5 , 0.  ])
>>> diff2 = rand.random((2, 4))
>>> diff2
array([[0.97562235, 0.7611397 , 0.78606431, 0.12811363],
       [0.45038594, 0.37079802, 0.92676499, 0.64386512]])
>>> proportion(diff2, axis=1)
array([[1.        , 0.33333333, 0.66666667, 0.        ],
       [0.33333333, 0.        , 1.        , 0.66666667]])
>>> proportion(diff2, axis=0)
array([[1., 1., 0., 0.],
       [0., 0., 1., 1.]])
>>> val = 0.5
>>> compare = np.array([0.2, 0.4, 0.5, 0.7, 0.9])
>>> proportion(compare)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
>>> val = np.full(5, 0.5)
>>> compare = np.array([[0.2, 0.4, 0.4, 0.7, 0.9],
...                     [0.1, 0.3, 0.6, 0.5, 0.9]])
>>> proportion(val, compare, axis=0)
Traceback (most recent call last):
NotImplementedError