Chapter 3: computing the mean of a distribution
Chapter 3: computing the mean of a distribution
The function meandef.m returns the mean (M) of a probability distribution, calculated using the definition of the expectation of a probability distribution [eq. (3.1)]. This function must takes the set of probabilities (p) and abscissa values (X) as inputs:
>> M=meandef(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 mean value, type:
M=meandef(p,X,1);
or the set of probabilities and a start (strt) and increment value (inc):
M=meandef(p,strt,inc,1);
The mean of a discrete variable can also be computed with the function meandef.m. 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 meandef.m:
M=meandef(p,S,1);
We can then verify that the program gives the expected value derived in the text [eq. (3.8)] by typing:
.8*20
Now, try the same thing for a continuous variable. From the definition of the exponential distribution (3.18), compute probabilities for t = 0 to t = 10 when the exponential time constant (tau) is 1 (thus allowing the probabilities to become very small in the tail).
t=0:.01:10;
p=exp(-t/1);
The meandef program assumes that the p input is the full probability distribution, and will normalize if it was not already done. We can simply type:
M=meandef([p t],1);