Learn R Programming

MoTBFs (version 2.0)

probDiscreteVariable: Probability distribution of discrete variables

Description

Compute the probabilities of a discrete variable from a data set using Laplace correction.

Usage

probDiscreteVariable(x)

Value

A list of 2 elements:

coeff

a named vector that contains the probabilities.

sizeDataLeaf

a vector containing the number of records in each leaf of the discrete tree.

Arguments

x

a "factor" containing the records of the discrete variable.

Details

Laplace correction is used to avoid the zero probability problem, with \(\alpha = 1\) as smoothing factor. Therefore, the probability for each state, \(\theta_i\), is computed as $$\theta_i = \frac{x_i + 1}{N + K}$$ for \(i = 0, 1, \ldots, K\), where \(x_i\) is the number of records of state \(i\), \(N\) is the total number of records, and \(K\) is the total number of states.

See Also

discreteVariablesStates

Examples

Run this code
## Simulate discrete variable
x <- factor(sample(c('yes', 'no', 'maybe'), 500, replace = TRUE), 
  levels = c('yes', 'no', 'maybe'))
 
## Compute probabilities
p <- probDiscreteVariable(x)
p


Run the code above in your browser using DataLab