sample
sample, keyword
The sample keyword accumulates values across iterations of a
montecarlo block.
Examples
montecarlo 1000 with
x = random.uniform(-1, 1)
y = random.uniform(-1, 1)
inCircle = x^2 + y^2 < 1
sample approxPi = avg(if inCircle then 4 else 0)
show scalar "Pi approximation" with approxPi
This outputs the following scalar:
| Pi approximation |
|---|
| 3.224 |
montecarlo 1000 with
x = if random.binomial(0.2) then 0 else random.poisson(5)
sample r = ranvar(x)
show summary "Zero-inflated ranvar" with
mean(r) as "Mean"
dispersion(r) as "Disp"
This outputs the following summary:
| Mean | Disp |
|---|---|
| 4.116 | 1.895175 |
table T = extend.range(5)
montecarlo 1000 with
T.K = random.poisson(T.N)
sample T.ApproxMean = avg(T.K)
show table "Poisson means" with
T.N
T.ApproxMean
This outputs the following table:
| N | ApproxMean |
|---|---|
| 1 | 0.986 |
| 2 | 1.974 |
| 3 | 3.053 |
| 4 | 3.976 |
| 5 | 5.106 |
Remarks
At the moment, avg() and ranvar() are the only accumulators supported by
sample.