A shop planning tomorrow’s stock wants a single number for demand, a sense of how far demand can stray from that number, and a way to use the temperature forecast. For a probability model, expected value, variance and covariance answer these questions, and a conditional expectation updates the prediction once the temperature is known. This lesson defines these quantities with the assumptions they need, collects variances and covariances in a covariance matrix, and keeps quantities of a model apart from averages computed from data. The joint model of temperature and demand used throughout is constructed for illustration.
Key terms
Expected value
Definition Let be a discrete random variable with PMF . If is finite, the expected value of is
with the sum over the support. For a function , the expected value is , provided is finite. For an absolutely continuous with density , the sum becomes an integral,
provided the same integral with in place of is finite. The expected value is a property of the model. The average of observed values is the expected value of the empirical distribution, which gives each observation the weight . It is a different quantity, which can serve as an estimate of when the observations come from the population the model describes.
In plain words The expected value is a probability-weighted average of the possible values, the balance point of the distribution. It need not be a value the variable can take. When the sum or integral of absolute values is infinite, no finite expected value exists, and a finite average computed from a sample does not show that one exists.
Example A constructed joint model gives the temperature in degrees Celsius and the demand in units.
| Probability | Total | ||
|---|---|---|---|
| Total |
The margins give degrees and units, a demand that no single day has. The expected squared demand is square units. For a continuous example, let be uniform on with density . Its expected value is the area under from to , a triangle with base and height , so .
Linearity of expectation
Definition Let and be random variables on the same sample space with finite expected values, and let , and be constants. Then
The rule extends to every finite sum, , and it holds whether or not the variables are independent. For a random vector whose components have finite expected values, is the vector of those expected values, and for a constant vector linearity gives . The rule covers linear combinations only. For a nonlinear function , the value need not equal .
In plain words The mean of a sum is the sum of the means, and constant factors and shifts pass straight through. This holds even when the parts are strongly related, which makes the rule easy to apply. The spread of a sum is a different matter, and it does depend on how the parts move together.
Example If demand on each of two days has expected value units, total demand over the two days has expected value units, whether the two days are independent or closely linked. The temperature in Fahrenheit, , has expected value degrees Fahrenheit. Squaring does not pass through, since while .
Variance
Definition Let have a finite second moment , and write . The variance of is
and the standard deviation is its nonnegative square root. Expanding the square gives . For constants and , , and the standard deviation is multiplied by . For observed values with average , the variance of the empirical distribution divides by . For the usual sample variance divides by instead,
When the observations are independent and identically distributed with finite variance, the expected value of is exactly . The divisor compensates for measuring the deviations from , which is computed from the same observations, rather than from .
In plain words Variance is the expected squared distance from the mean. Squaring keeps deviations above and below the mean from canceling, and it gives the variance squared units, while the standard deviation returns to the original unit. A large variance can come from a change of units rather than from more uncertainty. The divisors and answer different questions, so a report should say which one it uses.
Example Demand in the joint model deviates from by with probability and by with probability , so
square units, and the shortcut gives again. The standard deviation is units. Temperature deviates from by or , so square degrees and degrees. Measuring demand in tenths of a unit multiplies every value by and the variance by , to . For the three observed values , and , the squared deviations from total , so the empirical variance is and the sample variance is .
Covariance and correlation
Definition For random variables and with finite second moments and means and , the covariance is
It is symmetric in and , it satisfies , and for constants and , so its value depends on the units of both variables. When both standard deviations are positive, the correlation is
It has no units, it lies in , and it equals or exactly when with probability for some constants and . If either standard deviation is , the correlation is undefined. Independent variables with finite second moments have covariance , but covariance does not imply independence.
In plain words Covariance averages the product of the two deviations from the means. It is positive when the products of same-sign deviations, weighted by probability, outweigh those of opposite-sign deviations, and negative in the reverse case. Correlation rescales the covariance to a number between and that measures linear association only, so a strong curved relation can have correlation . A correlation in data describes an association and does not by itself show that either variable causes the other.
Example In the joint model the centered products for the cells , , and are , , and . Weighting them by , , and gives , in degrees times units of demand. The shortcut agrees, since and . The correlation is
With the temperature in Fahrenheit the covariance becomes , while the correlation stays . For a dependence that covariance misses, let be , or with probability each. Then , yet is a function of , and differs from .
Covariance matrix
Definition Let be a random vector whose components have finite second moments, with mean vector . Its covariance matrix is the matrix
whose entry in row and column is , with the variances on the diagonal. It is symmetric and positive semidefinite, because for every constant vector
For data, center the columns of an design matrix by subtracting each column’s average, call the result , and let . The sample covariance matrix is an estimate of the covariance matrix of the feature vector when the rows are independent and identically distributed draws of it.
In plain words A covariance matrix lists every variance and every pairwise covariance of a set of variables in one array. Each entry carries the units of its two variables, so the entries are not interchangeable numbers. Positive semidefiniteness says that no weighted combination of the variables can have negative variance.
Example For temperature and demand, in that order,
The weights , with in units of demand per degree, give the combination , and
which a direct computation of from the table confirms. The weight is , and it gives the smallest variance of over all numbers , a fact that returns with linear regression.
Conditional expectation
Definition Let be a discrete random variable, let be a value with , and let be a discrete random variable with a finite expected value. Write . The conditional expectation of given is the expected value of this conditional distribution,
The law of total expectation says that is the sum of over the support of . If also has a finite second moment, then for every number
where is the variance of the conditional distribution. So the conditional mean is the single prediction with the smallest expected squared error given . Read as a function of , it is the prediction rule with the smallest expected squared error, which is why regression under squared loss aims at it. When is continuous, , so conditional probabilities given cannot be defined as ratios, and a more general construction is needed.
In plain words A conditional expectation is an average taken inside a group, with the probabilities rescaled to sum to within that group. Knowing the condition can shift the prediction, and the overall mean is the average of the group means weighted by the group probabilities. A conditional mean is still an average, not a promise about any single case, and other losses lead to other summaries, such as a median for absolute error.
Example Given , divide the row probabilities and by to get and , so units. Given the rescaled probabilities are and , and units. The overall mean comes back as . Predicting on cool days and on warm days gives an expected squared error of square units, less than the from predicting every day.
Check yourself
- A variable takes the value with probability and the value with probability . Find , and the standard deviation, and check the variance with .
Show the answer
The mean is . The deviations from are and , with squares and , so
The standard deviation is . As a check, , and .
- Let be equally likely to be , , or , and let . Show that . Does it follow that joint probabilities of and are products of their separate probabilities, as for independent variables?
Show the answer
By symmetry . The variable is or with probability each, so , and
So . It does not follow that they are independent. The event and is impossible, so its probability is , while . Knowing fixes the size of exactly. Zero covariance rules out only a linear association, and it does not allow multiplying marginal probabilities.
- In the joint model of this lesson, a forecaster must give one number for the demand on a day known to be at degrees, and is judged by squared error. Compare the expected squared error of predicting the overall mean with that of predicting .
Show the answer
Given , demand is with probability and with probability , so . Predicting gives the conditional variance,
Predicting gives square units. The difference equals , as the decomposition into conditional variance plus squared distance from the conditional mean predicts. Using the known temperature lowers the expected squared error, because the overall mean averages over cool days that do not apply.