prob: Probabilities for a staged event tree

View source: R/3-inference-functions.R

probR Documentation

Probabilities for a staged event tree

Description

Compute (marginal and/or conditional) probabilities of elementary events with respect to the probability encoded in a staged event tree.

Usage

prob(object, x, conditional_on = NULL, log = FALSE, na0 = TRUE)

Arguments

object

an object of class sevt with probabilities.

x

the vector or data.frame of observations.

conditional_on

named vector, the conditioning event.

log

logical, if TRUE log-probabilities are returned.

na0

logical, if NA should be converted to 0.

Details

Computes probabilities related to a vector or a data.frame of observations.

Optionally, conditional probabilities can be obtained by specifying the conditioning event in conditional_on. This can be done either with a single named vector or with a data.frame object with the same number of rows of x. In the former, the same conditioning is used for all the computed probabilities (if x has multiple rows); while with the latter different conditioning events (but on the same variables) can be specified for each row of x.

Value

the probabilities to observe each observation in x, possibly conditional on the event(s) in conditional_on.

Examples

data(Titanic)
model <- full(Titanic, lambda = 1)
samples <- expand.grid(model$tree[c(1, 4)])
pr <- prob(model, samples)
## probabilities sum up to one 
sum(pr)
## print observations with probabilities
print(cbind(samples, probability = pr))

## compute one probability
prob(model, c(Class = "1st", Survived = "Yes"))

## compute conditional probability 
prob(model, c(Survived = "Yes"), conditional_on = c(Class = "1st"))

## compute conditional probabilities with different conditioning set
prob(model, data.frame(Age = rep("Adult", 8)), 
     conditional_on = expand.grid(model$tree[2:1])) 
## the above should be the same as 
summary(model)$stages.info$Age

stagedtrees documentation built on April 29, 2022, 1:06 a.m.