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: Paul Kienzle
Subject: Re: weighted var, etc. (was "var(x) and std(x)")
Date: Tue, 12 Nov 2002 13:07:46 -0500
User-agent: Mutt/1.2.5.1i

On Tue, Nov 12, 2002 at 11:46:12AM -0600, Mike Miller wrote:
> 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?

To be compatible with Matlab we would extend std and var as follows:

        var(x,1) would be the biased estimate
        var(x,w) would be the weighted estimate
        std(x,1) would be the biased estimate
        std(x,flag,dim) would be the estimate along a particular dimension

Paul Kienzle
address@hidden



-------------------------------------------------------------
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]