Skip to content

Commit c81f942

Browse files
authored
add argument interval for survival/quantile predictions (#615)
* add `level` to `predict_survival()` * add `interval` arg for prediction * only inherit parameter docs, not all docs * add `level` to `predict_quantile()`
1 parent 7cf4115 commit c81f942

File tree

8 files changed

+51
-136
lines changed

8 files changed

+51
-136
lines changed

NEWS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
## Other Changes
1616

17-
* When the xy interface is used and the underlying model expects to use a matrix, a better warning is issued when predictors contain non-numeric columns (including dates).
17+
* When the xy interface is used and the underlying model expects to use a matrix, a better warning is issued when predictors contain non-numeric columns (including dates).
1818

19-
* The fit time is only calculated when the `verbosity` argument of `control_parsnip()` is 2L or greater. Also, the call to `system.time()` now uses `gcFirst = FALSE`. (#611)
19+
* The fit time is only calculated when the `verbosity` argument of `control_parsnip()` is 2L or greater. Also, the call to `system.time()` now uses `gcFirst = FALSE`. (#611)
20+
21+
* Argument `interval` was added for prediction: For types "survival" and "quantile", estimates for the confidence or prediction interval can be added if available (#615).
2022

2123
# parsnip 0.1.7
2224

R/bart.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ update.bart <-
162162
}
163163

164164

165+
#' Developer functions for predictions via BART models
165166
#' @export
166167
#' @keywords internal
167168
#' @name bart-internal
168-
#' @inherit predict.model_fit
169+
#' @inheritParams predict.model_fit
169170
#' @param obj A parsnip object.
170171
#' @param ci Confidence (TRUE) or prediction interval (FALSE)
171172
#' @param level Confidence level.

R/predict.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
#' `parsnip` related options that can be passed, depending on the
2020
#' value of `type`. Possible arguments are:
2121
#' \itemize{
22-
#' \item `level`: for `type`s of "conf_int" and "pred_int" this
23-
#' is the parameter for the tail area of the intervals
22+
#' \item `interval`: for `type`s of "survival" and "quantile", should
23+
#' interval estimates be added, if available? Options are `"none"`
24+
#' and `"confidence"`.
25+
#' \item `level`: for `type`s of "conf_int", "pred_int", and "survival"
26+
#' this is the parameter for the tail area of the intervals
2427
#' (e.g. confidence level for confidence intervals).
2528
#' Default value is 0.95.
2629
#' \item `std_error`: add the standard error of fit or prediction (on
@@ -82,12 +85,10 @@
8285
#' For censored regression:
8386
#'
8487
#' * `type = "time"` produces a column `.pred_time`.
85-
#' * `type = "hazard"` results in a column `.pred_hazard`.
86-
#' * `type = "survival"` results in a list column containing tibbles with a
87-
#' `.pred_survival` column.
88-
#'
89-
#' For the last two types, the results are a nested tibble with an overall
90-
#' column called `.pred` with sub-tibbles with the above format.
88+
#' * `type = "hazard"` results in a list column `.pred` containing tibbles
89+
#' with a column `.pred_hazard`.
90+
#' * `type = "survival"` results in a list column `.pred` containing tibbles
91+
#' with a `.pred_survival` column.
9192
#'
9293
#' In the case of Spark-based models, since table columns cannot
9394
#' contain dots, the same convention is used except 1) no dots
@@ -98,6 +99,7 @@
9899
#' `predict()` function will return the same structure as above but
99100
#' filled with missing values. This does not currently work for
100101
#' multivariate models.
102+
#'
101103
#' @examples
102104
#' library(dplyr)
103105
#'
@@ -309,7 +311,7 @@ check_pred_type_dots <- function(object, type, ...) {
309311

310312
# ----------------------------------------------------------------------------
311313

312-
other_args <- c("level", "std_error", "quantile", "time", "increasing")
314+
other_args <- c("interval", "level", "std_error", "quantile", "time", "increasing")
313315
is_pred_arg <- names(the_dots) %in% other_args
314316
if (any(!is_pred_arg)) {
315317
bad_args <- names(the_dots)[!is_pred_arg]

R/predict_quantile.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#' @keywords internal
22
#' @rdname other_predict
3-
#' @param quant A vector of numbers between 0 and 1 for the quantile being
3+
#' @param quantile A vector of numbers between 0 and 1 for the quantile being
44
#' predicted.
55
#' @inheritParams predict.model_fit
66
#' @method predict_quantile model_fit
77
#' @export predict_quantile.model_fit
88
#' @export
9-
predict_quantile.model_fit <-
10-
function(object, new_data, quantile = (1:9)/10, ...) {
9+
predict_quantile.model_fit <- function(object,
10+
new_data,
11+
quantile = (1:9)/10,
12+
interval = "none",
13+
level = 0.95,
14+
...) {
1115

1216
check_spec_pred_type(object, "quantile")
1317

R/predict_survival.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @export predict_survival.model_fit
66
#' @export
77
predict_survival.model_fit <-
8-
function(object, new_data, time, ...) {
8+
function(object, new_data, time, interval = "none", level = 0.95, ...) {
99

1010
check_spec_pred_type(object, "survival")
1111

man/bart-internal.Rd

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

man/other_predict.Rd

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

man/predict.model_fit.Rd

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

0 commit comments

Comments
 (0)