help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: weighted var, etc. (was "var(x) and std(x)")


From: Julian DeMarchi
Subject: RE: weighted var, etc. (was "var(x) and std(x)")
Date: Tue, 12 Nov 2002 12:57:17 -0500

Yes, there's something similar in the MatLinks toolchest (wmean).  Same idea.  
A useful function.  Perhaps you'd be interested in writing these functions for 
Octave?

-----Original Message-----
From: Mike Miller [mailto:address@hidden
Sent: Tuesday, November 12, 2002 12:46 PM
To: Francesco Potorti`
Cc: Help-Octave List
Subject: weighted var, etc. (was "var(x) and std(x)")


On Tue, 12 Nov 2002, Francesco Potorti` wrote:

> If you compute the mean from the samples, this is correct.  If you know
> the mean a priori, then you should divide by n.  The code you cite
> computes the mean from the samples, so that's okay.


That's true.

A related issue (question):  Is there an Octave procedure for computing
weighted means and variances?  If we have a vector x of values and a
corresponding (same size) vector p of probabilities, the mean of x is p'*x
and the variance is p'*(x-p'*x).  If length(x)=n, and p=ones(n,1)/n, then
p'*(x-p'*x) = ((n-1)/n)*var(x).

If appropriate functions don't already exist, I would recommend the
following names: wmean, wvar, wstd and wcov.  I would recommend that they
work like this:

y=wmean(x,p)  <--where p is a matrix the same size as x
y=wmean(x,p)  <--where p is column vector with length(p)=size(x,1)
y=wmean(x)    <--where p is set to p=ones(size(x,1),1)/size(x,1)

wmean would compute weighted means of the columns of matrix x using the
weights given in matrix (or vector) p.  The same system would be used for
wvar, etc.  This approach has the nice side effect that wvar(x) provides
var(x)*(n-1)/n saving the user a few keystrokes.  wmean(x)=mean(x).

Has this already been done?

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]