# var(1) = 0 ?? Classic List Threaded 14 messages Open this post in threaded view
|

## var(1) = 0 ??

 Is there a particular reason that octave (and matlab) has var(1) = 0? I must have missed that during my math classes. M.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 > Is there a particular reason that octave (and matlab) has var(1) = 0? It is correct, the variance of a single sample is zero and not only in matlab and octave... :-) you do not only get the same if you take var(2) = var(5) = var(c) = 0, where is c a constant, etc, but also if you take a time series with constant values, for instance, var(ones(1,10)) = 0... Cheers, Ismael. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: var(1) = 0 ??

 var(1) = 0 is at least in conflict with the standard definition of the unbiased estimate, where the sum of squared deviations is scaled by n-1 (n sample size). But common sense has it that a sample of size 1 simply has *no* variance, so  the result is basically a convention; it just hurts my math feelings to see var(1) = 0. M.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 On 27 Jan 2012, at 22:40, Muhali wrote: > var(1) = 0 is at least in conflict with the standard definition of the > unbiased estimate, where the sum of squared deviations is scaled by n-1 (n > sample size). but if all elements in the sample are equal, e.g.: >> n = 100; >> samp = ones (1, n); then the mean value has that same value >> mean (samp) ans =  1 therefore all the squred deviations are 0: >> mu = mean (samp); >> any ((samp - mu).^2) ans = 0 and the "standard definition of the unbiased estimate" still returns 0: >> sum ((samp - mu).^2) / (n - 1) ans = 0 why would you expect a different result? c. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: var(1) = 0 ??

 > why would you expect a different result? this is where it is getting philosophical, or Bayesian, if you want. If you pick one number out of an unknown population, we just don't know whether there is variance in the population or not. There is no best estimate for the variance; 0 is just as good as any other. So I would very much prefer a result of NaN, but it is mostly convention as I said. At least the help text, which has (n-1) in the denominator, should be adjusted accordingly. M.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 Hello.Indeed, this is an interesting observation. I have checked this in several softwares.  Scilab and R reported an error or NA message with var(c) and FreeMat reported ans = 0. Python (scipy) also reported 0 as answer. Cheers. On Fri, Jan 27, 2012 at 19:35, Muhali wrote: > why would you expect a different result? this is where it is getting philosophical, or Bayesian, if you want. If you pick one number out of an unknown population, we just don't know whether there is variance in the population or not. There is no best estimate for the variance; 0 is just as good as any other. So I would very much prefer a result of NaN, but it is mostly convention as I said. At least the help text, which has (n-1) in the denominator, should be adjusted accordingly. M. -- View this message in context: http://octave.1599824.n4.nabble.com/var-1-0-tp4334677p4335089.html Sent from the Octave - General mailing list archive at Nabble.com. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave -- «But Gwindor answered: 'The doom lies in yourself, not in your name.'»JRR Tolkien _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: var(1) = 0 ??

 According to the manual it is possible to choose whether the denominator in the calculation of the variance is N-1 (for an unbiased estimate of some sample) or N (for the variance of some complete population) by setting a second parameter in the function to "0" or "1", respectively, with 0 as default (hence with N-1 as the default denominator). The behaviour of the function is not as expected from the manual for vector arguments of size one. The following is as expected from the manual: ```>> a = [1 2 3] a = 1 2 3 >> var(a) ans = 1 >> var(a, 0) ans = 1 >> var(a, 1) ans = 0.66667 >> ```Unless I have misunderstood the manual, the last line of the following is unexpected ```>> b =  b = 2 >> var(b) ans = 0 >> var(b, 0) ans = 0 >> var(b, 1) ans = 0 ```  I would have expected an error message rather than the last result. Presumably, the function has been coded to return the same value as that returned by Matlab. As noted above, it might be sensible if this were acknowledged in the manual. However good you think Octave is, it's much, much better.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 In reply to this post by Muhali On 28 Jan 2012, at 01:05, Muhali wrote: I think this behaviour is matlab compatible so it should not be changed, > At least the help text, which has (n-1) in the denominator, should be > adjusted accordingly. I just pushed this changeset, does it look OK to you? c. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: var(1) = 0 ??

 This post was updated on . Apologies for asking here (I'm still relatively naive in the support rather than the use of open source). I would be grateful for a link to the changeset or a link to instructions for registering (if necessary) so that I could see it. Thanks in advance. However good you think Octave is, it's much, much better.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 On 28 Jan 2012, at 15:15, pathematica wrote: > Apologies for asking here (I'm still relatively naive in the support rather > than use of open source). No need to apologize, that was just me who forgot to attach the link. > I would be grateful for a link to the changeset here it is: http://hg.savannah.gnu.org/hgweb/octave/rev/bedccd0abe39> or > a link to instructions for registering (if necessary) so that I could see > it. Thanks in advance. There is no need to register to browse the sources. c. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: var(1) = 0 ??

 Thanks for the link and the proposed change looks good to me However good you think Octave is, it's much, much better.
Open this post in threaded view
|

## Re: var(1) = 0 ??

 This post was updated on . After a little reflection, I note that the proposed inclusion reads well (alerting to behaviour based on the number of elements in the set passed to it) but, whilst the description of the change is true ("behaviour when input is a scalar"), it is not comprehensive. For example, the dialogue at the terminal shown above demonstrates "behaviour when input is a vector of order one" as well as behaviour when it is a scalar.   However good you think Octave is, it's much, much better.