Package 'pr'

Title: Classes for Probabilities
Description: Provides S3 classes to represent probability vectors and matrices using 'vctrs'. Allows for creation, validation, and pretty printing of each class. Includes a special probability matrix type with counts to allow for cases with limited possible values.
Authors: Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>)
Maintainer: Christopher T. Kenny <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1
Built: 2026-05-31 06:21:13 UTC
Source: https://github.com/christopherkenny/pr

Help Index


Create a probability matrix with counts record

Description

Create a probability matrix with counts record

Usage

cnt_prob_mat(..., count = NULL)

validate_cnt_prob_mat(x)

Arguments

...

Named prob vectors or vectors coercible to prob

count

A positive integer vector indicating the number of cases. Defaults to 1L recycled to the length of the probability vectors.

x

A cnt_prob_mat for validation

Value

a cnt_prob_mat vector

Examples

p1 <- prob(c(0.4, 2 / 3, NA_real_, 1L))
p2 <- 1 - p1
cnt_prob_mat(pr_one = p1, pr_two = p2, count = c(10L, 20L, 5L, 15L))
cnt_prob_mat(pr_one = p1, pr_two = p2) # count defaults to 1L

Create a probability vector

Description

A probability vector here is used as a vector where all entries are between 0 and 1 or are missing.

Usage

prob(x = double())

validate_prob(x)

is_prob(x)

as_prob(x)

Arguments

x

A double vector of probabilities

Value

a prob vector

Examples

prob(c(0.4, 2 / 3, NA_real_, 1L))

Create a probability matrix record

Description

A collection of prob vectors which sum to 1 row-wise.

Usage

prob_mat(...)

validate_prob_mat(x)

Arguments

...

Named prob vectors or vectors coercible to prob

x

A prob_mat for validation

Value

a prob vector

Examples

p1 <- prob(c(0.4, 2 / 3, NA_real_, 1L))
p2 <- 1 - p1
prob_mat(pr_one = p1, pr_two = p2)

Convert matrix into prob_mat

Description

Convert matrix into prob_mat

Usage

prob_mat_from_matrix(x, ...)

## S3 method for class 'prob_mat'
as.matrix(x, ...)

Arguments

x

A prob_mat or matrix

...

Ignored.

Value

prob_mat_from_matrix() returns a prob_mat and as.matrix() returns a matrix

Examples

p1 <- prob(c(0.4, 2 / 3, NA_real_, 1L))
p2 <- 1 - p1
pm <- prob_mat(pr_one = p1, pr_two = p2)
m <- as.matrix(pm)
m
prob_mat_from_matrix(m)