Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export(show_call)
export(show_engines)
export(show_fit)
export(show_model_info)
export(stan_conf_int)
export(surv_reg)
export(svm_poly)
export(svm_rbf)
Expand Down
6 changes: 2 additions & 4 deletions R/linear_reg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,11 @@ set_pred(
res$.std_error <- apply(results, 2, sd, na.rm = TRUE)
res
},
func = c(pkg = "rstanarm", fun = "posterior_linpred"),
func = c(pkg = "parsnip", fun = "stan_conf_int"),
args =
list(
object = expr(object$fit),
newdata = expr(new_data),
transform = TRUE,
seed = expr(sample.int(10^5, 1))
newdata = expr(new_data)
)
)
)
Expand Down
26 changes: 14 additions & 12 deletions R/logistic_reg_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ set_pred(
res_1 <- res_2
res_1$lo <- 1 - res_2$hi
res_1$hi <- 1 - res_2$lo
res <- bind_cols(res_1, res_2)
lo_nms <- paste0(".pred_lower_", object$lvl)
hi_nms <- paste0(".pred_upper_", object$lvl)
colnames(res) <- c(lo_nms[1], hi_nms[1], lo_nms[2], hi_nms[2])
colnames(res_1) <- c(lo_nms[1], hi_nms[1])
colnames(res_2) <- c(lo_nms[2], hi_nms[2])
res <- bind_cols(res_1, res_2)

if (object$spec$method$pred$conf_int$extras$std_error)
res$.std_error <- results$se.fit
Expand Down Expand Up @@ -509,22 +510,22 @@ set_pred(
res_1 <- res_2
res_1$lo <- 1 - res_2$hi
res_1$hi <- 1 - res_2$lo
res <- bind_cols(res_1, res_2)
lo_nms <- paste0(".pred_lower_", object$lvl)
hi_nms <- paste0(".pred_upper_", object$lvl)
colnames(res) <- c(lo_nms[1], hi_nms[1], lo_nms[2], hi_nms[2])
colnames(res_1) <- c(lo_nms[1], hi_nms[1])
colnames(res_2) <- c(lo_nms[2], hi_nms[2])
res <- bind_cols(res_1, res_2)

if (object$spec$method$pred$conf_int$extras$std_error)
if (object$spec$method$pred$conf_int$extras$std_error) {
res$.std_error <- apply(results, 2, sd, na.rm = TRUE)
}
res
},
func = c(pkg = "rstanarm", fun = "posterior_linpred"),
func = c(pkg = "parsnip", fun = "stan_conf_int"),
args =
list(
object = quote(object$fit),
newdata = quote(new_data),
transform = TRUE,
seed = expr(sample.int(10^5, 1))
object = expr(object$fit),
newdata = expr(new_data)
)
)
)
Expand Down Expand Up @@ -554,10 +555,11 @@ set_pred(
res_1 <- res_2
res_1$lo <- 1 - res_2$hi
res_1$hi <- 1 - res_2$lo
res <- bind_cols(res_1, res_2)
lo_nms <- paste0(".pred_lower_", object$lvl)
hi_nms <- paste0(".pred_upper_", object$lvl)
colnames(res) <- c(lo_nms[1], hi_nms[1], lo_nms[2], hi_nms[2])
colnames(res_1) <- c(lo_nms[1], hi_nms[1])
colnames(res_2) <- c(lo_nms[2], hi_nms[2])
res <- bind_cols(res_1, res_2)

if (object$spec$method$pred$pred_int$extras$std_error)
res$.std_error <- apply(results, 2, sd, na.rm = TRUE)
Expand Down
24 changes: 24 additions & 0 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,28 @@ update_engine_parameters <- function(eng_args, ...) {
ret
}

# ------------------------------------------------------------------------------
# Since stan changed the function interface
#' Wrapper for stan confidence intervals
#' @param object A stan model fit
#' @param newdata A data set.
#' @export
#' @keywords internal
stan_conf_int <- function(object, newdata) {
check_installs(list(method = list(libs = "rstanarm")))
if (utils::packageVersion("rstanarm") >= "2.21.1") {
fn <- rlang::call2("posterior_epred", .ns = "rstanarm",
object = expr(object),
newdata = expr(newdata),
seed = expr(sample.int(10^5, 1)))
} else {
fn <- rlang::call2("posterior_linpred", .ns = "rstanarm",
object = expr(object),
newdata = expr(newdata),
transform = TRUE,
seed = expr(sample.int(10^5, 1)))
}
rlang::eval_tidy(fn)
}


17 changes: 17 additions & 0 deletions man/stan_conf_int.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.