MeanAndVariance
From charlesreid1
Contents
Summary
This page covers mean and variance definitions for continuous random variables (with prescribed probability density function) and discrete random variables (with prescribed probability mass function).
Mean
Continuous Random Variables
If we have a continuous random variable with a probability density function , the mean and variance are given by:
(where the integral is over the range of x values)
Discrete Random Variable
The mean of a discrete random variable with discrete values and a probability mass function is given by the expression:
Note that by definition, the probability mass function must sum to 1:
If we assume a uniform probability for each value, then the probability mass function of component i is just:
Variance
Continuous Random Variable
The variance of a continuous random variable is given by:
Note that this can be expanded and simplified,
or just
which is equivalent to saying:
Discrete Random Variable
If we have a discrete random variable with a probability mass function, the variance is given by:
This can be simplified to:
where the last term is equal to the mean,
Updating On The Fly
Updating Discrete Mean
Let's suppose we have n data values, , and we are adding one additional data value and want to compute the effect it has on the mean. For the sake of simplicity we assume that the probability mass function is uniform, so that or . Then old mean is given by:
and the new mean is given by:
We can re-express the new mean in terms of the old mean by the following relationship:
Updating Discrete Variance
Supposing the same situation - that we have n discrete data values , and we are adding one additional data value and want to compute the effect it has on the variance. As with updating the mean, we presume a uniform mass density function for the sake of simplicity, or . Then the old variance is given by:
or,
(as before, the last term is the old mean; because the probability mass function must sum to 1, the sum of 1/n is the same as the sum of 1/n^2, so the mismatch in the two terms is not a problem). Grouping the first term as SS (sum of squares) for convenience,
Now we can write out the new expression for the variance as:
which can be written in terms of the old sum of squares term as:
Thus, if we want to start with a set of n points, and quickly evaluate the effect that adding one additional point would have (say, from a pool of possible "next choices"), we can implement the above formulas for a one-shot update.
Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: