ranvar

There are other concepts named ranvar. See the entire list.

ranvar, function

def nosort process ranvar(a: number): ranvar
def nosort process ranvar(a: number, w: number): ranvar

Builds an empirical ranvar from observations a. The weighted overload uses non-negative weights w, normalized within each group.

Examples

table T = with
  [| as A, as G |]
  [| 1, "a" |]
  [| 2, "a" |]
  [| 1, "b" |]
  [| 3, "b" |]

table G[gdim] = by T.G

show table "Empirical means" with
  gdim
  mean(ranvar(T.A)) as "Mean"
  group by gdim

This outputs the following table:

gdim Mean
a 1.5
b 2
table T = with
  [| as A, as W, as G |]
  [| 1, 1.0, "a" |]
  [| 2, 2.0, "a" |]
  [| 1, 0.5, "b" |]
  [| 3, 1.5, "b" |]

table G[gdim] = by T.G

show table "Weighted means" with
  gdim
  mean(ranvar(T.A, T.W)) as "Mean"
  group by gdim

This outputs the following table:

gdim Mean
a 1.666667
b 2.5

Remarks

The aggregator returns dirac(0) on empty groups and when weights sum to zero.