Difference between revisions of "ChanceDist - Custom discrete distribution"
Line 2: | Line 2: | ||
[[Category:Doc Status C]] <!-- For Lumina use, do not change --> | [[Category:Doc Status C]] <!-- For Lumina use, do not change --> | ||
− | = ChanceDist( P,A,I ) = | + | == ChanceDist(P, A, I) == |
− | Creates a discrete probability distribution. | + | 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 = | + | == When to Use == |
− | Use ChanceDist() instead of the probability table when: | + | Use [[ChanceDist]]() instead of the probability table when: |
− | * The array of outcomes | + | * 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. | * The outcomes and probabilities arrays are defined as other Variables; the Variables can be used in other parts of your model. | ||
− | As of build 4.0.0.51, ChanceDist cannot be used within [[Random]]. This enhancement may occur in future releases. | + | As of build 4.0.0.51, [[ChanceDist]] cannot be used within [[Random]]. This enhancement may occur in future releases. |
− | = Example = | + | == Example == |
− | {| | + | :<code>Index Index_b := [Red, White, Blue]</code> |
− | | Index_b | + | :<code> Variable Array_1 :=</code> |
+ | :{| class="wikitable" | ||
+ | ! colspan="3" | Index_b ▶ | ||
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
! Red !! White !! Blue | ! Red !! White !! Blue | ||
|- | |- | ||
| 0.3 || 0.2 || 0.5 | | 0.3 || 0.2 || 0.5 | ||
− | |||
|} | |} | ||
Usage: | Usage: | ||
− | + | :<code>ChanceDist(Array_q, Index_b, Index_b)</code> | |
− | = Mid Value = | + | == Mid Value == |
− | [[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»). | + | [[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»). |
− | When «A» consists of unordered numeric points, this can be confusing, since the Mid value isn't the same as the numeric median. For example, with P=1/5 and A=[9,3,1,8,7], the Mid value is 1. | + | When «A» consists of unordered numeric points, this can be confusing, since the [[Mid]] value isn't the same as the numeric median. For example, with <code>P = 1/5 and</code> <code>A = [9, 3, 1, 8, 7]</code>, the [[Mid]] value is 1. |
− | 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 | + | 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, <code>P = 1/4</code> and <code>A = [1, 2, 3, 4]</code> would return <code>Mid = 3</code> even though <code>Median = 2.5</code>. 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 | + | 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 <code>X := ChanceDist(P, A)</code>, 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 | + | 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»): |
− | : | + | :<code>ChanceDist(1/Size(I), Sort(A, I), I)</code> |
or for non-uniform P: | or for non-uniform P: | ||
− | : | + | :<code>Var order := SortIndex(A, I) Do ChanceDist(P[I = order], A[I = order], I)</code> |
− | = See Also = | + | == See Also == |
* [[ProbTable]] | * [[ProbTable]] | ||
* [[Uniform]] | * [[Uniform]] | ||
* [[Prob_ChanceDist]] | * [[Prob_ChanceDist]] |
Revision as of 00:13, 12 January 2016
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.
As of build 4.0.0.51, ChanceDist cannot be used within Random. This enhancement may occur in future releases.
Example
Index Index_b := [Red, White, Blue]
Variable Array_1 :=
Index_b ▶ Red White Blue 0.3 0.2 0.5
Usage:
ChanceDist(Array_q, Index_b, Index_b)
Mid Value
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»).
When «A» consists of unordered numeric points, this can be confusing, since the Mid value isn't the same as the numeric median. For example, with P = 1/5 and
A = [9, 3, 1, 8, 7]
, the Mid value is 1.
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)
Enable comment auto-refresher