Skip to content

Commit 7fbe78c

Browse files
Add required_pkgs() methods to all conformal interval methods (#190)
1 parent a30e1a2 commit 7fbe78c

12 files changed

+202
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: probably
22
Title: Tools for Post-Processing Predicted Values
3-
Version: 1.1.1.9000
3+
Version: 1.1.1.9001
44
Authors@R: c(
55
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre")),
66
person("Davis", "Vaughan", , "[email protected]", role = "aut"),

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ S3method(required_pkgs,cal_estimate_multinomial)
126126
S3method(required_pkgs,cal_estimate_multinomial_spline)
127127
S3method(required_pkgs,cal_estimate_none)
128128
S3method(required_pkgs,cal_object)
129+
S3method(required_pkgs,int_conformal_cv)
130+
S3method(required_pkgs,int_conformal_full)
131+
S3method(required_pkgs,int_conformal_quantile)
132+
S3method(required_pkgs,int_conformal_split)
129133
S3method(threshold_perf,data.frame)
130134
S3method(type_sum,cal_object)
131135
S3method(vec_cast,character.class_pred)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# probably (development version)
22

3+
* Add `required_pkgs()` methods to `int_conformal_cv()`, `int_conformal_full()`, `int_conformal_quantile()`, and `int_conformal_split()`. (#190)
4+
35
# probably 1.1.1
46

57
* Updated unit tests for new ggplot2 release (#180).

R/conformal_infer.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ print.int_conformal_full <- function(x, ...) {
113113
invisible(x)
114114
}
115115

116+
#' @rdname required_pkgs.int_conformal_cv
117+
#' @keywords internal
118+
#' @export
119+
required_pkgs.int_conformal_full <- function(x, infra = TRUE, ...) {
120+
model_pkgs <- required_pkgs(x$wflow, infra = infra)
121+
122+
if (infra) {
123+
model_pkgs <- c(model_pkgs, "probably")
124+
}
125+
126+
model_pkgs <- unique(model_pkgs)
127+
model_pkgs
128+
}
129+
116130
# ------------------------------------------------------------------------------
117131

118132
#' Prediction intervals from conformal methods

R/conformal_infer_cv.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ print.int_conformal_cv <- function(x, ...) {
148148
invisible(x)
149149
}
150150

151+
#' S3 methods to track which additional packages are needed for prediction
152+
#' intervals via conformal inference
153+
#' @param x a conformal interval object
154+
#' @inheritParams generics::required_pkgs
155+
#' @export
156+
required_pkgs.int_conformal_cv <- function(x, infra = TRUE, ...) {
157+
model_pkgs <- map(x$models, required_pkgs, infra = infra)
158+
model_pkgs <- unlist(model_pkgs)
159+
160+
if (infra) {
161+
model_pkgs <- c(model_pkgs, "probably")
162+
}
163+
164+
model_pkgs <- unique(model_pkgs)
165+
model_pkgs
166+
}
167+
151168
# ------------------------------------------------------------------------------
152169
# helpers
153170

R/conformal_infer_quantile.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ print.int_conformal_quantile <- function(x, ...) {
115115
invisible(x)
116116
}
117117

118+
#' @rdname required_pkgs.int_conformal_cv
119+
#' @keywords internal
120+
#' @export
121+
required_pkgs.int_conformal_quantile <- function(x, infra = TRUE, ...) {
122+
model_pkgs <- required_pkgs(x$wflow, infra = infra)
123+
124+
if (infra) {
125+
model_pkgs <- c(model_pkgs, "probably")
126+
}
127+
128+
model_pkgs <- unique(model_pkgs)
129+
model_pkgs
130+
}
131+
118132
#' @export
119133
#' @rdname predict.int_conformal_full
120134
predict.int_conformal_quantile <- function(object, new_data, ...) {

R/conformal_infer_split.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ print.int_conformal_split <- function(x, ...) {
9494
invisible(x)
9595
}
9696

97+
#' @rdname required_pkgs.int_conformal_cv
98+
#' @keywords internal
99+
#' @export
100+
required_pkgs.int_conformal_split <- function(x, infra = TRUE, ...) {
101+
model_pkgs <- required_pkgs(x$wflow, infra = infra)
102+
103+
if (infra) {
104+
model_pkgs <- c(model_pkgs, "probably")
105+
}
106+
107+
model_pkgs <- unique(model_pkgs)
108+
model_pkgs
109+
}
110+
97111
#' @export
98112
#' @rdname predict.int_conformal_full
99113
predict.int_conformal_split <- function(object, new_data, level = 0.95, ...) {

man/int_conformal_full.Rd

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/required_pkgs.int_conformal_cv.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-conformal-intervals-quantile.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,13 @@ test_that("split conformal quantile intervals", {
6363
nrow(new_int),
6464
nrow(sim_new)
6565
)
66+
67+
expect_identical(
68+
required_pkgs(lm_int),
69+
c(required_pkgs(lm_int$wflow), "probably")
70+
)
71+
expect_identical(
72+
required_pkgs(lm_int, infra = FALSE),
73+
required_pkgs(lm_int$wflow, infra = FALSE)
74+
)
6675
})

0 commit comments

Comments
 (0)