# ProbTable

A discrete probability distribution with explicit outcome probabilities. A ProbTable provides an edit-table style view of the outcome probabilities, very much like a DetermTable does. It always has a Self-index, and the variable's domain attribute specifies the list of possible outcomes. The cells of the probability table specify the outcome probabilities and should add up to 1.0 along the self-index.

A ProbTable may have other indexes as well, which are processed the same way a DetermTable would process those dimensions. Specifically, if those other table index variables select a particular discrete value, then only the selected value will be in the result (a variable/index selects a value by defining a domain attribute to list the possible values, which serves as the index value, and then providing a Definition attribute that evaluates only to values that appear in the domain. See DetermTable for more details.

## Syntax

You usually define a variable as a ProbTable by selecting "Prob Table" on the definition-type pulldown. The index selector dialog appears and allows you to specify the indexes. With this interface, a ProbTable presents a graphical user interface very much like an edit table, and you so you seldom need to view the definition in expression syntax.

However, as with any Analytica definition, you can view and edit the expression syntax, with follows precisely the same form as Table and DetermTable:

`ProbTable(I, J, K)(p111, p112, p113, ..., p11n, p121, ..., plmn)`

Here the first set of parens contain the table index identifiers, with at least one of these being Self, and the second set of parentheses contain the probabilities, with the last index listed in the first set of parens varying the fastest. Each `pijk` may be a single number or an arbitrary Analytica expression, although the results should sum to 1 along the self index.

## Conditional Distributions

A ProbTable can be used to encode a discrete conditional probability distribution, `P(C|A, B)`, often with the parents `A` and `B` being defined as ProbTables. When used in this fashion, `A`, `B` and `C (Self)` are all indexes of `C`'s probability table. The domain attributes for `A`, `B` and `C` define the possible discrete values, and the ProbTables for each define the distributions or conditional distributions for each. An influence diagram built up in this fashion is known as a discrete Bayesian network. Those familiar with Bayesian network inference algorithms should note that Analytica's built-in Monte Carlo inference algorithm does not perform diagnostic inference that is often associated with Bayesian networks.

When you use a ProbTable to encode a conditional probability distribution, `P(C|A, B)`, it is not a requirement that `A` and `B` be defined as ProbTables. The statement here is just that this is a common configuration in discrete probabilistic models that utilize ProbTables. The real requirement is that `A` and `B` have anindex value, specifying all possible atomic outcomes for those variables (specified by the domain attribute), and a definition which, when evaluated, produces values from the domain. There are many possible ways to create expressions of this form that do not involve ProbTables, potentially utilizing any of the other discrete probability distribution functions and other arbitrary expression logic. In a Sample evaluation mode, the definition should evaluate to an array containing the Run index. In either the Mid or Sample evaluation modes, `A` and `B` may contain additional indexes after evaluation, which are simply array-abstracted over.

The evaluation of a conditional probability distribution, defined using ProbTable, is really identical to the evaluation of a DetermTable. Understanding this can be very helpful conceptually. Let's look at this in a little more detail here. Suppose you have defined `C` as a ProbTable representing `P(C|A, B)`. The numbers in `C`ʼs table sum to 1 along the `C (Self)` index. When an uncertain result view for `C` is requested, `Sample(A)` and `Sample(B)` are both computed. Sample(A) returns an array of `A`-outcomes indexed by Run -- let's denote these as `A[Run = 1], A[Run = 2], ..., A[Run = sampleSize]`. Similarly for `B`. With those results, `C`ʼs ProbTable is now evaluated. For each i in Run, we look at the slice of `C`ʼs ProbTable given by `C[A = A[Run = i], B = B[Run = i]]`. Keep in mind that in this subscript notation, the `A` on the left of `=` names the index value of `A`, while the `A` appearing on the right names the evaluated sample value of `A`. This ProbTable-slice is indexed only by `C`, with elements summing to 1. The ith element of the result along Run is then sampled randomly according to these probabilities. The key point to comprehend here is how this use of the parents' sample values to select a slice of `C`ʼs ProbTable functions precisely in the same fashion as a DetermTable.

## Alternate Ways to Encode Probability Tables

You have other options for encoding probability tables in Analytica. If your probabilities are computed, other methods may be far more convenient. The cells of a ProbTable may contain simple numeric values (the probabilities), or they may contain arbitrary expressions that compute the probability for each cell. However, note that when using expressions in ProbTable cells, you need to have a separate expression in each cell, which is not always convenient. Some algorithms may compute the entire probability vector using complex analytic algorithms such as Regression and other forms of data analysis, and may divide the vector by its sum to normalize the values, etc. These algorithms determine the probability distribution using array functions -- not cell-by-cell -- and as such it is far more convenient to encode these using other discrete distribution functions. A common alternative to ProbTable is ChanceDist, which accepts an index of outcomes and the array of probabilities (which, in general, are computed). ChanceDist can also be readily used within an expression, while ProbTable needs to be positioned as the outer-most (and only) function appearing within the definition.

Using ChanceDist, you can also break your encoding into two variables -- one being a DetermTable containing the probabilities, which evaluates to the specific probabilities to be used given the parent selectors, the second variable being defined using ChanceDist to actually generate the Monte Carlo sample for the distribution. This configuration is functionally equivalent to the use of ProbTable, and still provides a graphical user interface for the table of probabilities as ProbTable does. It requires one extra node in your model, but gives you convenient access to the underlying probabilities, especially when they are computed.

## Accessing the Probabilities

When you evaluate a a variable defined as a ProbTable, you get either a random sample of outcomes (in Sample mode) or a single outcome equal to the discrete median of the distribution (in Mid mode). If, for some reason, you need to have access to the actual probabilities from the table (which may be determined after the expressions in the cells are evaluated), you cannot get these from the evaluated Mid or Sample values.

The computed probabilities can be accessed using the SubTable function, which provides special optional parameters to specify that you want these values. Set the «rawProbs» parameter of SubTable to `True` to tell it that you want the actual probabilities, as in the following example:

`SubTable(C, rawProbs: True)`

When you have other selector indexes, as you would in a discrete conditional distribution, `P(C|A, B)`, this will return the selected distribution as determined/selected by the computed values of `A` and `B`. You also have the optional of obtaining the probabilities from the table, preserving the parent indexes without performing the DetermTable-style slice to select slices along `A` and `B`. To get this full table, specify «fullDeterm» as true:

`SubTable(C, rawProbs: True, fullDeterm: True)`

If you intend to make use of the underlying probabilities often within your model, it may be more convenient to split your ProbTable into two variables -- a DetermTable followed by a ChanceDist. The result of evaluating the first variable then gives you direct access to the probabilities without the need to use SubTable.

## Examples

Several examples of ProbTable are contained in the example models installed with Analytica. Take a look at these:

• `Decision Analysis\2 Branch Party Tree.ana`
• `Decision Analysis\Nonsymmetric Decision Tree.ana`
• `Decision Analysis\Party With Forecast.ana`