Skip to content

Commit

Permalink
plot doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Oct 4, 2023
1 parent 1d312ff commit 2bb532e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ predictions <- function(model,

# if type is NULL, we backtransform if relevant
type_string <- sanitize_type(model = model, type = type, calling_function = "predictions")
if (type_string == "invlink(link)") {
if (identical(type_string, "invlink(link)")) {
if (is.null(hypothesis)) {
type_call <- "link"
} else {
Expand Down
1 change: 1 addition & 0 deletions R/sanitize_condition.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sanitize_condition <- function(model, condition, variables = NULL, modeldata = N
respname <- insight::find_response(model)

flag <- checkmate::check_true(all(names(condition) %in% c(colnames(dat), "group")))
browser()
if (!isTRUE(flag)) {
msg <- sprintf("Entries in the `condition` argument must be element of: %s",
paste(colnames(dat), collapse = ", "))
Expand Down
8 changes: 8 additions & 0 deletions book/articles/machine_learning.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ mod <- linear_reg(mode = "regression") |>
avg_comparisons(mod, newdata = bikes, type = "response")
```

We can also plot the results as usual:

```{r, warning = FALSE}
plot_predictions(mod, condition = "temp", points = .2)
```

When the engine is not supported by `marginaleffects`, we can also obtain correct results, but no uncertainy estimates. Here is a random forest model:

```{r}
forest_tidy <- rand_forest(mode = "regression") |>
set_engine("ranger") |>
fit(count ~ ., data = bikes)
avg_comparisons(forest_tidy, newdata = bikes, type = "numeric")
plot_predictions(forest_tidy, newdata = bikes, by = "temp", type = "numeric")
```

0 comments on commit 2bb532e

Please sign in to comment.