prob: Calculate Probabilities from Random Draws

View source: R/draws.R

probR Documentation

Calculate Probabilities from Random Draws

Description

Convert an rvec of logical values (an rvec_lgl) into a vector of probabilities.

Usage

prob(x, na_rm = FALSE)

## S3 method for class 'rvec_lgl'
prob(x, na_rm = FALSE)

## S3 method for class 'logical'
prob(x, na_rm = FALSE)

Arguments

x

An object of class rvec_lgl.

na_rm

Whether to remove NAs before calculating summaries. Default is FALSE.

Details

prob() is essentially just draws_mean() with a different name. The proportion of draws that are TRUE is used as an estimate of the underlying probability. The different name can make the intent of the code clearer.

Value

A logical vector with the same length as x.

See Also

  • draws_mean() Means across draws. Gives the same result as prob when applied to logical rvecs.

Examples

m <- rbind(c(FALSE,  TRUE),
           c(TRUE,   TRUE),
           c(FALSE,  FALSE))
x <- rvec(m)
x
prob(x)

## logical rvec created on the fly
## through operations such as '>'
m <- rbind(c(-1,  1.3, 2),
           c(2, 0.1, -1),
           c(Inf, 0, -0.5))
y <- rvec(m)
y
prob(y > 0)
prob(y >= 0)
prob(y^2 > 0)

rvec documentation built on Aug. 8, 2025, 7:29 p.m.