Contains the base Variable class.
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
- *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.
- EmptyVariableError – if no values are given.
- TypeError – if the name given isn’t a string.
Returns the values in the Variable.
Adds a value to the end of the Variable.
Parameters: value – The value to add.
Inserts a value into the Variable.
- index (int) – The index to insert at.
- value – The value to insert.
Removes a value from the Variable.
Parameters: value – The value to remove. Raises: EmptyVariableError – if you try to remove the only value.
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.
Returns the name of the Variable.
Raises: TypeError – if the name set is not a string.
The length of the Variable - the number of values it has.
Returns the largest value.
Returns the smallest value.
Returns the sum of the values.
Returns the mean of the values - their sum divided by the number of values.
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.
Returns the frequencies of the values in the Variable.
Returns the mode value - the value that occurs the most often. If more than one value meets this criteria,
Returns the range of the values - the difference between the largest and smallest values.
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 is
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 is
The z-score of a value is how many standard deviations it is from the mean.
- value – The value who’s z-score you want to know.
- population (bool) – If
True, the population deviation will be used (default is
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.
variable (Variable) – The other Variable. It must be the same length as this one.
- TypeError – if something other than a Variable is given.
- ValueError – if Variables of different length are given.
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.