2.4 Vector Functions - sum, mean, median, var, std
When we type [] as a function argument, that argument is left undefined. If the argument has a default value, then the default value will be used for that undefined argument. This principle will be illustrated in the video.
Recall, that the (unbiased) sample variance is defined as:
σ2y=1N−1∑Ni=1(yi−¯y)2
where
¯y=1N∑Ni=1yi is the sample mean and where
y1,y2,...,yN are observations (numbers) of the random variables
Y1,Y2,...,YN.
In the video, we had the following matrix:
A=[1017123113]
We view the first column as three observations of the first random variable, the second column as three observations of the second random variable and so on. For instance, the first column could be the number of fishes Kalle caught in a river, the second column could be the number of fishes Kalle caught in a lake and so on.
We wrote the MATLAB code:
var(A, [], 1) %a row vector containing the variance of each column, the weighting scheme is 0 by default, meaning we divide by number of observations (N) - 1.
The answer we got was: [27.0000 0.3333 5.3333]. Let's do the calculation manually.
So, N = 3, meaning that N-1 = 2.
And doing the calculation for the first column yields:
σ2X=13−1∑3i=1x2i=12[(10−4)2+(1−4)2+(1−4)2]=12[36+9+9]=12[54]=27
Where we used that
¯y=4.
Perform the calculations for the second and third column to verify that MATLAB returns the correct answer.