1
function [s]=variancef(x,fre,orien)
3
//This function computes the variance of the values of a vector or
4
//matrix x, each of them counted with a frequency signaled by the
5
//corresponding values of the integer vector or matrix fre with the same
8
//For a vector or matrix x, s=variancef(x,fre) (or s=variancef(x,fre,'*') returns
9
//in scalar s the variance of all the entries of x, each value counted
10
//with the multiplicity indicated by the corresponding value of fre.
12
//s=variancef(x,fre,'r')(or, equivalently, s=variancef(x,fre,1)) returns in each
13
//entry of the row vector s of type 1xsize(x,'c') the variance of each
14
//column of x, each value counted with the multiplicity indicated by the
15
//corresponding value of fre.
17
//s=variancef(x,fre,'c')(or, equivalently, s=variancef(x,fre,2)) returns in each
18
//entry of the column vector s of type size(x,'c')x1 the variance of
19
//each row of x, each value counted with the multiplicity indicated by
20
//the corresponding value of fre.
22
//author: carlos klimann
26
//Fixed by ck 2001-03-28: verify if sum(fre)> 1
28
if x==[] then s=%nan, return, end
31
error('variancef requires two or three inputs.'),
33
if x==[]|fre==[]|fre==0, s=%nan;return,end
36
if sumfre <= 1 then error('Frequencies must be greater than 1'), end
37
s=(sum(((x-meanf(x,fre)).^2).*fre))/(sumfre-1),
42
if sumfre <= 1 then error('Frequencies must be greater than 1'),end
43
s=(sum(((x-meanf(x,fre)).^2).*fre))/(sumfre-1),
44
elseif orien=='r'|orien==1,
46
if or(sumfre==0) then error('Frequencies must be greater than 1'),end
47
s=(sum(((x-ones(size(x,'r'),1)*meanf(x,fre,'r')).^2).*fre))./ ..
49
elseif orien=='c'|orien==2,
51
if or(sumfre==0) then error('Frequencies must be greater than 1'),end
52
s=(sum((x-(meanf(x,fre,'c')*ones(1,size(x,'c')))).^2,'c'))./..
54
else error('3rd argument of variancef must be equal to *, c, r, 1 or 2'),