# Goulib.stats module¶

very basic statistics functions

`Goulib.stats.``mean_var`(data)[source]

mean and variance by stable algorithm :param :return: float (mean, variance) of data uses a stable algo by Knuth

`Goulib.stats.``mean`(data)[source]
Returns: mean of data
`Goulib.stats.``avg`(data)
Returns: mean of data
`Goulib.stats.``variance`(data)[source]
Returns: variance of data, faster (?) if mean is already available
`Goulib.stats.``var`(data)
Returns: variance of data, faster (?) if mean is already available
`Goulib.stats.``stddev`(data)[source]
Returns: standard deviation of data
`Goulib.stats.``confidence_interval`(data, conf=0.95)[source]
Returns: (low,high) bounds of 95% confidence interval of data
`Goulib.stats.``median`(data, is_sorted=False)[source]
Returns: median of data
`Goulib.stats.``mode`(data, is_sorted=False)[source]
Returns: mode (most frequent value) of data
`Goulib.stats.``kurtosis`(data)[source]
`Goulib.stats.``covariance`(data1, data2)[source]
`Goulib.stats.``stats`(l)[source]
Returns: min,max,sum,sum2,avg,var of a list
class `Goulib.stats.``Stats`(data=[], mean=None, var=None)[source]

Bases: `object`

an object that computes mean, variance and modes of data that is appended to it as in a list (but actual values are not stored)

`__init__`(data=[], mean=None, var=None)[source]

Initialize self. See help(type(self)) for accurate signature.

`__repr__`()[source]

Return repr(self).

`append`(x)[source]

`extend`(data)[source]
`remove`(data)[source]

remove data from Stats :param data: value or iterable of values

`sum`
`sum1`
`sum2`
`mean`
`avg`
`average`
`mu`
`variance`
`var`
`stddev`
`sigma`
`__add__`(other)[source]
`__sub__`(other)[source]
`__mul__`(other)[source]
`__neg__`()[source]
`__pow__`(n)[source]
`covariance`(other)[source]
`__class__`

alias of `builtins.type`

`__delattr__`

Implement delattr(self, name).

`__dir__`()

Default dir() implementation.

`__eq__`

Return self==value.

`__format__`()

Default object formatter.

`__ge__`

Return self>=value.

`__getattribute__`

Return getattr(self, name).

`__gt__`

Return self>value.

`__hash__`

Return hash(self).

`__init_subclass__`()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

`__le__`

Return self<=value.

`__lt__`

Return self<value.

`__ne__`

Return self!=value.

`__new__`()

Create and return a new object. See help(type) for accurate signature.

`__reduce__`()

Helper for pickle.

`__reduce_ex__`()

Helper for pickle.

`__setattr__`

Implement setattr(self, name, value).

`__sizeof__`()

Size of object in memory, in bytes.

`__str__`

Return str(self).

class `Goulib.stats.``Discrete`(data)[source]

discrete probability density function

Parameters: data – can be:
• list of equiprobable values (uniform distribution)
• dict of x:p values:probability pairs
`__init__`(data)[source]
Parameters: data – can be:
• list of equiprobable values (uniform distribution)
• dict of x:p values:probability pairs
`__call__`(x)[source]

Call self as a function.

`__add__`(other)
`__class__`

alias of `builtins.type`

`__delattr__`

Implement delattr(self, name).

`__dir__`()

Default dir() implementation.

`__eq__`

Return self==value.

`__format__`()

Default object formatter.

`__ge__`

Return self>=value.

`__getattribute__`

Return getattr(self, name).

`__gt__`

Return self>value.

`__hash__`

Return hash(self).

`__init_subclass__`()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

`__le__`

Return self<=value.

`__lt__`

Return self<value.

`__mul__`(other)
`__ne__`

Return self!=value.

`__neg__`()
`__new__`()

Create and return a new object. See help(type) for accurate signature.

`__pow__`(n)
`__reduce__`()

Helper for pickle.

`__reduce_ex__`()

Helper for pickle.

`__repr__`()

Return repr(self).

`__setattr__`

Implement setattr(self, name, value).

`__sizeof__`()

Size of object in memory, in bytes.

`__str__`

Return str(self).

`__sub__`(other)
`append`(x)

`average`
`avg`
`covariance`(other)
`extend`(data)
`mean`
`mu`
`remove`(data)

remove data from Stats :param data: value or iterable of values

`sigma`
`stddev`
`sum`
`sum1`
`sum2`
`var`
`variance`
class `Goulib.stats.``PDF`(pdf, data=[])[source]

probability density function

`__init__`(pdf, data=[])[source]
Parameters: f – function or operator, Expr to copy construct, or formula string
`__call__`(x=None, **kwargs)[source]

evaluate the Expr at x OR compose self(x())

`__add__`(right)
`__and__`(right)
`__class__`

alias of `builtins.type`

`__delattr__`

Implement delattr(self, name).

`__dir__`()

Default dir() implementation.

`__div__`(right)
`__eq__`(other)

Return self==value.

`__float__`()
`__format__`()

Default object formatter.

`__ge__`(other)

Return self>=value.

`__getattribute__`

Return getattr(self, name).

`__gt__`(other)

Return self>value.

`__hash__` = None
`__init_subclass__`()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

`__invert__`()
`__le__`(other)

Return self<=value.

`__lshift__`(dx)
`__lt__`(other)

Return self<value.

`__mul__`(right)
`__ne__`(other)

Return self!=value.

`__neg__`()
`__new__`()

Create and return a new object. See help(type) for accurate signature.

`__or__`(right)
`__pow__`(right)
`__reduce__`()

Helper for pickle.

`__reduce_ex__`()

Helper for pickle.

`__repr__`()

Return repr(self).

`__rmul__`(right)
`__rshift__`(dx)
`__setattr__`

Implement setattr(self, name, value).

`__sizeof__`()

Size of object in memory, in bytes.

`__str__`()

Return str(self).

`__sub__`(right)
`__truediv__`(right)
`__xor__`(right)
`append`(x)

`applx`(f, var='x')

function composition f o self = self(f(x))

`apply`(f, right=None)

function composition self o f = f(self(x))

`average`
`avg`
`complexity`()

measures the complexity of Expr :return: int, sum of the precedence of used ops

`covariance`(other)
`extend`(data)
`html`(**kwargs)
`isNum`
`isconstant`
Returns: True if Expr evaluates to a constant number or bool
`latex`()
Returns: string LaTex formula
`mean`
`mu`
`plot`(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

`png`(**kwargs)
`points`(xmin=-1, xmax=1, step=0.1)
Returns: x,y lists of float : points for a line plot
`remove`(data)

remove data from Stats :param data: value or iterable of values

`render`(fmt='svg', **kwargs)
`save`(filename, **kwargs)
`sigma`
`stddev`
`sum`
`sum1`
`sum2`
`svg`(**kwargs)
`var`
`variance`
`Goulib.stats.``normal_pdf`(x, mu, sigma)[source]

Return the probability density function at x

class `Goulib.stats.``Normal`(data=[], mean=0, var=1)[source]

represents a normal distributed variable the base class (list) optionally contains data

if data is specified, it it used to fit a normal law

`__init__`(data=[], mean=0, var=1)[source]

if data is specified, it it used to fit a normal law

`__str__`()[source]

Return str(self).

`latex`()[source]
Returns: string LaTex formula
`linear`(a, b=0)[source]
Returns: a*self+b
`__mul__`(a)[source]
`__div__`(a)[source]
`__truediv__`(a)
`__add__`(other)[source]
`__radd__`(other)[source]
`__neg__`()[source]
`__sub__`(other)[source]
`__rsub__`(other)[source]
`covariance`(other)[source]
`cov`(other)
`pearson`(other)[source]
`correlation`(other)
`corr`(other)
`__and__`(right)
`__call__`(x=None, **kwargs)

evaluate the Expr at x OR compose self(x())

`__class__`

alias of `builtins.type`

`__delattr__`

Implement delattr(self, name).

`__dir__`()

Default dir() implementation.

`__eq__`(other)

Return self==value.

`__float__`()
`__format__`()

Default object formatter.

`__ge__`(other)

Return self>=value.

`__getattribute__`

Return getattr(self, name).

`__gt__`(other)

Return self>value.

`__hash__` = None
`__init_subclass__`()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

`__invert__`()
`__le__`(other)

Return self<=value.

`__lshift__`(dx)
`__lt__`(other)

Return self<value.

`__ne__`(other)

Return self!=value.

`__new__`()

Create and return a new object. See help(type) for accurate signature.

`__or__`(right)
`__pow__`(right)
`__reduce__`()

Helper for pickle.

`__reduce_ex__`()

Helper for pickle.

`__repr__`()

Return repr(self).

`__rmul__`(right)
`__rshift__`(dx)
`__setattr__`

Implement setattr(self, name, value).

`__sizeof__`()

Size of object in memory, in bytes.

`__xor__`(right)
`append`(x)

`applx`(f, var='x')

function composition f o self = self(f(x))

`apply`(f, right=None)

function composition self o f = f(self(x))

`average`
`avg`
`complexity`()

measures the complexity of Expr :return: int, sum of the precedence of used ops

`extend`(data)
`html`(**kwargs)
`isNum`
`isconstant`
Returns: True if Expr evaluates to a constant number or bool
`mean`
`mu`
`plot`(**kwargs)

renders on IPython Notebook (alias to make usage more straightforward)

`png`(**kwargs)
`points`(xmin=-1, xmax=1, step=0.1)
Returns: x,y lists of float : points for a line plot
`remove`(data)

remove data from Stats :param data: value or iterable of values

`render`(fmt='svg', **kwargs)
`save`(filename, **kwargs)
`sigma`
`stddev`
`sum`
`sum1`
`sum2`
`svg`(**kwargs)
`var`
`variance`
`Goulib.stats.``linear_regression`(x, y, conf=None)[source]
Parameters: x,y – iterable data conf – float confidence level [0..1]. If None, confidence intervals are not returned b0,b1,b2, (b0

Return the linear regression parameters and their <prob> confidence intervals.

ex: >>> linear_regression([.1,.2,.3],[10,11,11.5],0.95)