probDiscreteVariable: Probability distribution of discrete variables

View source: R/DiscreteLearning.R

probDiscreteVariableR Documentation

Probability distribution of discrete variables

Description

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

Usage

probDiscreteVariable(x)

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.

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.

See Also

discreteVariablesStates

Examples

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



MoTBFs documentation built on Oct. 6, 2026, 1:06 a.m.