| 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 |
Create a probability matrix with counts record
cnt_prob_mat(..., count = NULL) validate_cnt_prob_mat(x)cnt_prob_mat(..., count = NULL) validate_cnt_prob_mat(x)
... |
Named |
count |
A positive integer vector indicating the number of cases. Defaults to 1L recycled to the length of the probability vectors. |
x |
A |
a cnt_prob_mat vector
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 1Lp1 <- 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
A probability vector here is used as a vector where all entries are between 0 and 1 or are missing.
prob(x = double()) validate_prob(x) is_prob(x) as_prob(x)prob(x = double()) validate_prob(x) is_prob(x) as_prob(x)
x |
A double vector of probabilities |
a prob vector
prob(c(0.4, 2 / 3, NA_real_, 1L))prob(c(0.4, 2 / 3, NA_real_, 1L))
A collection of prob vectors which sum to 1 row-wise.
prob_mat(...) validate_prob_mat(x)prob_mat(...) validate_prob_mat(x)
... |
Named |
x |
A |
a prob vector
p1 <- prob(c(0.4, 2 / 3, NA_real_, 1L)) p2 <- 1 - p1 prob_mat(pr_one = p1, pr_two = p2)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
prob_mat_from_matrix(x, ...) ## S3 method for class 'prob_mat' as.matrix(x, ...)prob_mat_from_matrix(x, ...) ## S3 method for class 'prob_mat' as.matrix(x, ...)
x |
A prob_mat or matrix |
... |
Ignored. |
prob_mat_from_matrix() returns a prob_mat and as.matrix() returns a matrix
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)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)