pydiodon.bicentering

pydiodon.bicentering(A)[source]

Bicentering a matrix

Parameters
Aa n x p numpy array

the matrix to be bicentered

Returns
ma float

global mean of the matrix

ra 1D numpy array (n values)

rowise means

ca 1D numpy arrau (p values)

columnwise means

Ra 2D numpy array (n x p)

bicentered matrix

Notes

If A is a matrix, builds a matrix R of same dimension centered on rows and columns.

\(m = (1/np) \sum_{i,j} a_{ij}\)

\(r = (r_1,...,r_n)\) with \(r_i = (1/p)\sum_j a_{ij} - m\)

\(c = (c_1,...,c_p)\) with \(c_j = (1/n)\sum_i a_{ij} - m\)

such that

\(\sum_ir_i = \sum_jc_j=0\)

and

for any row i, \(\sum_j R_{ij}=0\) and for any column j, \(\sum_i R_{ij}=0\)

The matrix R can describe interactions in a additive model with two categorical variables, as in

\(a_{ij} = m + r_i + c_j + R_{ij}\)

example

>>> import pydiodon as dio
>>> import numpy as np
>>> n = 4 ; p = 3
>>> A = np.arange(n*p)
>>> A.shape=(n,p)
>>> m, r, c, R = dio.bicenter(A)

af, revised 21.02.19, 22.09.21, 22.10.13