Skip to content

var, svar

Variance, Sample variance

var

Variance

var x    var[x]

Where x is a numeric list, returns its variance as a float atom. Nulls are ignored.

q)var 2 3 5 7
3.6875
q)var 2 3 5 0n 7
3.6875
q)select var price by sym from trade where date=2010.10.10,sym in`IBM`MSFT

var is an aggregate function, equivalent, where sqr:{x*x} to

{avg[sqr x]-sqr[avg x]}

svar

Sample variance

svar x    svar[x]

Where x is a numeric list, returns its sample variance as a float atom.

svar(x)=\frac{n}{n-1}var(x)
q)var 2 3 5 7
3.6875
q)svar 2 3 5 7
4.916667
q)select svar price by sym from trade where date=2010.10.10,sym in`IBM`MSFT

svar is an aggregate function, equivalent to {var[x]*count[x]%-1+count x}.


cov, scov
Mathematics
Covariance, Variance
Variance