Chapter 3: computing the variance of a distribution
Chapter 3: computing the variance of a distribution
The function vardef.m returns the variance (V) of a probability distribution, calculated using the definition of the second moment of a probability distribution about its mean [eq. (3.2)]. This function, just as with meandef.m, takes the set of probabilities (p) and abscissa values (X) as inputs:
V=vardef(p,X);
The probability input must be a vector arranged as a column. There is the option to arrange the probability input as a matrix of column vectors. In this case, the X input can be either a single column vector - if all probability vectors use the same abscissa - or an equally-sized matrix.
To obtain a plot of the probability distribution and its calculated variance, type:
V=vardef(p,X,1);
The variance of a discrete variable can also be computed with the function vardef.m, and uses the same inputs. For example, we can construct the sampling distribution for the binomial distribution (N = 20, theta= .8):
S=0:20;
p=bpdf(S,S(end),.8);
and use these variables as inputs to vardef.m:
V=vardef(p,S,1);
We can then verify that the program gives the expected value derived in the text [eq. (3.9)] by typing:
20(1-.8)*.8