Skip to content

Commit 18e1ee1

Browse files
committed
improved residual grabbing
1 parent 1d427b7 commit 18e1ee1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

R/layer_residual_quantiles.R

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ slather.layer_residual_quantiles <-
6161
if (is.null(object$probs)) return(components)
6262

6363
s <- ifelse(object$symmetrize, -1, NA)
64-
r <- the_fit$fit$residuals
64+
r <- grab_residuals(the_fit, components)
6565
q <- quantile(c(r, s * r), probs = object$probs, na.rm = TRUE)
6666

6767
estimate <- components$predictions$.pred
6868
dstn <- dist_quantiles(map(estimate, "+", q), object$probs)
6969
components$predictions$.quantiles <- dstn
7070
components
7171
}
72+
73+
grab_residuals <- function(the_fit, components) {
74+
if (the_fit$spec$mode != "regression")
75+
rlang::abort("For meaningful residuals, the predictor should be a regression model.")
76+
77+
yhat <- predict(the_fit, new_data = components$mold$predictors)
78+
c(components$mold$outcomes - yhat)[[1]]
79+
}

0 commit comments

Comments
 (0)