power1d.stats

A module containing test statistic functions for simple experiment designs.

The following functions are available:

  • t_1sample_fn —— one sample t test
  • t_2sample_fn —— two sample t test
  • t_regress_fn —— linear regression
  • f_anova1_fn —— one-way ANOVA

All functions accept two-dimensional numpy arrays as the dependent variable input argument(s). The arrays must have shape (J,Q) where:

  • J —— sample size
  • Q —— continuum size

All functions return a test statistic continuum as a one-dimensional numpy array of size Q.

Slightly more efficient versions of the functions above are also available:

  • t_1sample_fn
  • t_2sample_fn
  • t_regress_fn
  • f_anova1_fn

The output from each of these functions is itself a function whose input arguments are identical to the normal versions above. However, the _fn versions store information like degrees of freedom and matrix inversion results so they needn’t be re-computed. This makes iterative simulation somewhat more efficient.

Main functions

t_1sample

power1d.stats.t_1sample(y)[source]

t statistic for a one-sample test

Arguments:

y —— (J x Q) data sample array

Outputs:

t continuum as a numpy array with shape = (Q,)

Example:

>>> import numpy as np
>>> import power1d
>>> J,Q   = 8, 101
>>> y     = np.random.randn( J, Q )
>>> t     = power1d.stats.t_1sample( y )

t_2sample

power1d.stats.t_2sample(yA, yB)[source]

t statistic for a two-sample test

Arguments:

yA —— (J x Q) data sample array

yB —— (J x Q) data sample array

Outputs:

t continuum as a numpy array with shape = (Q,)

Example:

>>> import numpy as np
>>> import power1d
>>> J,Q   = 8, 101
>>> yA    = np.random.randn( J, Q )
>>> yB    = np.random.randn( J, Q )
>>> t     = power1d.stats.t_2sample( yA, yB )

t_regress

power1d.stats.t_regress(y, x)[source]

t statistic for linear regression

Arguments:

y —— (J x Q) data sample array

x —— (J,) array of independent variable values

Outputs:

t continuum as a numpy array with shape = (Q,)

Example:

>>> import numpy as np
>>> import power1d
>>> J,Q   = 8, 101
>>> y     = np.random.randn( J, Q )
>>> x     = np.random.randn( J )
>>> t     = power1d.stats.t_regress( y, x )

f_anova1

power1d.stats.f_anova1(*yy)[source]

F statistic for a one-way ANOVA

Arguments:

yy —— an arbitrary number of (J x Q) data sample arrays

Outputs:

f continuum as a numpy array with shape = (Q,)

Example:

>>> import numpy as np
>>> import power1d
>>> Q     = 8, 101
>>> yA    = np.random.randn( 8, Q )
>>> yB    = np.random.randn( 5, Q )
>>> yC    = np.random.randn( 12, Q )
>>> f     = power1d.stats.f_anova1( yA, yB, yC )

Efficient functions

t_1sample_fn

power1d.stats.t_1sample_fn(J)[source]

t statistic for a one-sample test

Arguments:

J —— sample size

Outputs:

A function for computing the t statistic.

Example:

>>> import numpy as np
>>> import power1d
>>> J,Q   = 8, 101
>>> y     = np.random.randn( J, Q )
>>> fn    = power1d.stats.t_1sample_fn( J )
>>> t     = fn( y )

t_2sample_fn

power1d.stats.t_2sample_fn(JA, JB)[source]

t statistic for a two-sample test

Arguments:

JA —— sample size for group A

JB —— sample size for group B

Outputs:

A function for computing the t statistic.

Example:

>>> import numpy as np
>>> import power1d
>>> JA,JB = 8, 10
>>> Q     = 101
>>> yA    = np.random.randn( J, Q )
>>> yB    = np.random.randn( J, Q )
>>> fn    = power1d.stats.t_2sample_fn( JA, JB )
>>> t     = fn( yA, yB )

t_regress_fn

power1d.stats.t_regress_fn(x)[source]

t statistic for linear regression

Arguments:

x —— (J,) array of independent variable values

Outputs:

A function for computing the t statistic.

Example:

>>> import numpy as np
>>> import power1d
>>> J,Q   = 8, 101
>>> y     = np.random.randn( J, Q )
>>> x     = np.random.randn( J )
>>> fn    = power1d.stats.t_regress_fn( x )
>>> t     = fn( y )

f_anova1_fn

power1d.stats.f_anova1_fn(*JJ)[source]

F statistic for a one-way ANOVA

Arguments:

JJ —— an arbitrary number sample sizes

Outputs:

A function for computing the f statistic.

Example:

>>> import numpy as np
>>> import power1d
>>> JA    = 8
>>> JB    = 12
>>> JC    = 9
>>> Q     = 101
>>> yA    = np.random.randn( JA, Q )
>>> yB    = np.random.randn( JB, Q )
>>> yC    = np.random.randn( JC, Q )
>>> fn    = power1d.stats.f_anova1_fn( JA, JB, JC )
>>> f     = fn( yA, yB, yC )