inferi.variables¶
Contains the base Variable class.

class
inferi.variables.
Variable
(*values, name='')[source]¶ A Variable represents an ordered sequence of measurements. It is not the same as a Python variable  it represents variables in the statistics sense of the word.
A Variable is a container and an iterable of its values, and in many respects behaves like a
list
.Parameters:  *values – The values to go into the Variable. These will usually be numerical, but can be any type. If you provide one value, which is iterable, and which isn’t a string, the values of that iterable will become the values of the Variable.
 name (str) – The name of the Variable.
Raises:  EmptyVariableError – if no values are given.
 TypeError – if the name given isn’t a string.

values
¶ Returns the values in the Variable.
Return type: tuple

insert
(index, value)[source]¶ Inserts a value into the Variable.
Parameters:  index (int) – The index to insert at.
 value – The value to insert.

remove
(value)[source]¶ Removes a value from the Variable.
Parameters: value – The value to remove. Raises: EmptyVariableError – if you try to remove the only value.

pop
(index=1)[source]¶ Removes and returns the value at a given index  by default the last object in the Variable.
Parameters: index (int) – The index to remove at. Raises: EmptyVariableError – if you try to pop the only value. Returns: the specified value.

name
¶ Returns the name of the Variable.
Raises: TypeError – if the name set is not a string.

length
¶ The length of the Variable  the number of values it has.
Return type: int

max
¶ Returns the largest value.

min
¶ Returns the smallest value.

sum
¶ Returns the sum of the values.

mean
¶ Returns the mean of the values  their sum divided by the number of values.

median
¶ Returns the median value  the value that occurs midway through when the values are sorted. If there is an even number, the midpoint between the two median values will be returned.

frequencies
¶ Returns the frequencies of the values in the Variable.
Return type: Counter

mode
¶ Returns the mode value  the value that occurs the most often. If more than one value meets this criteria,
None
is returned.

range
¶ Returns the range of the values  the difference between the largest and smallest values.

variance
(population=False)[source]¶ Returns the variance of the values  the mean square deviation of the values from the mean. The values really have to be numerical for this to be meaningful.
You can elect to get the population variance if you wish, which uses N rather than N  1 as the denominator.
Parameters: population (bool) – If True
, the population variance will be returned (default isFalse
).Return type: float

st_dev
(population=False)[source]¶ Returns the standard deviation of the values, the square root of the
variance()
and a measure of deviation from the mean. As with that metric, you need numerical data for this to be sensible.You can elect to get the population deviation if you wish, which uses N rather than N  1 as the denominator.
Parameters: population (bool) – If True
, the population deviation will be returned (default isFalse
).Return type: float

zscore
(value, population=False)[source]¶ The zscore of a value is how many standard deviations it is from the mean.
Parameters:  value – The value who’s zscore you want to know.
 population (bool) – If
True
, the population deviation will be used (default isFalse
).

covariance_with
(variable)[source]¶ Returns the covariance between this Variable and another Variable. This is a measure of how the variance of the two series reflect each other, and is a measure of correlation.
Parameters: variable (Variable) – The other Variable. It must be the same length as this one.
Raises:  TypeError – if something other than a Variable is given.
 ValueError – if Variables of different length are given.

correlation_with
(variable)[source]¶ Returns the correlation of one Variable with another. This differs from
covariance_with()
in that it is normalised to be between 1 and 1, so the maginitude of the result is important, rather than just the sign as is the case with covariance.All the same requirements apply  the object given must be a Variable, and they must be the same length.
Parameters: variable (Variable) – The other Variable. It must be the same length as this one.