Learn R Programming

rvec (version 0.0.8)

prob: 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 rvec_lgl prob(x, na_rm = FALSE)

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

Value

A logical vector with the same length as x.

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.

See Also

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

Examples

Run this code
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)

Run the code above in your browser using DataLab