ranvar

ranvar, contextual keyword

The ranvar type represents a probability distribution over integers.

r = poisson(2)

show summary "Ranvar" with
  mean(r) as "Mean"
  dispersion(r) as "Dispersion"

This outputs the following summary:

Mean Dispersion
1.999924 0.9996943

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.

ranvar, montecarlo accumulator

The accumulator returns the empirical distribution of the sampled values.

r = poisson(3)
montecarlo 1000 with
  dev = random.ranvar(r)
  sample r2 = ranvar(dev)

show summary "Empirical ranvar" with
  mean(r2) as "Mean"
  dispersion(r2) as "Dispersion"

This outputs the following summary:

Mean Dispersion
2.928 0.9975465
User Contributed Notes
0 notes + add a note