ChanceDist - Custom discrete distribution
ChanceDist(P, A, I)
Creates a discrete probability distribution. «A» is an array of outcomes, and «P» is the corresponding array of probabilities. «A» and «P» must both be indexed by «I».
When to Use
Use ChanceDist() instead of the probability table when:
- The array of outcomes «A» is multidimensional, or
- The outcomes and probabilities arrays are defined as other Variables; the Variables can be used in other parts of your model.
Index Index_b := [Red, White, Blue]
Variable Array_1 :=
Index_b ▶ Red White Blue 0.3 0.2 0.5
ChanceDist(Array_q, Index_b, Index_b)
ChanceDist is a discrete distribution, and as such it assumes that the data points in «A» are categorical (discrete). It also assumes that the ordering for the points is the ordering given in «A». Thus, the Mid value returns the middle point along the ordering given by «A» (where the position of the middle point is based on the weightings of each point in «P»).
Even when the points in «A» are ordered and numeric, Mid is not the same as the continuous median when the number of points is even. For example,
P = 1/4 and
A = [1, 2, 3, 4] would return
Mid = 3 even though
Median = 2.5. The discrete median is always a point in the domain, hence must be one of the points in «A».
In general in Analytica, Mid returns the median for a distribution. This is still the case even in cases just mentioned as long as you realize that ChanceDist returns the categorical median, which is different from the continuous median. For example, if you define
X := ChanceDist(P, A), where «A» is an index, and set the domain of «X» to be an index domain based on «A», then the statistics result view for «X» will display the categorical median which will coincide with the Mid value for «X». The index-valued domain tells Analytica that «X» is discrete with a defined element ordering given by «A».
When you are really dealing with a continuous quantity, you should be using either ProbDist or CumDist to define the distribution. If you really want to re-sample from «A», but want Mid to return the "numerically-middle" sample, then use (for uniform «P»):
ChanceDist(1/Size(I), Sort(A, I), I)
or for non-uniform P:
Var order := SortIndex(A, I) Do ChanceDist(P[I = order], A[I = order], I)