Skip to content

Commit 0ae5d36

Browse files
committed
added rlm for an engine only explanation
1 parent 1aac943 commit 0ae5d36

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

vignettes/articles/Scratch.Rmd

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,54 @@ predict(mda_fit, new_data = iris_test) %>%
283283
mutate(Species = iris_test$Species)
284284
```
285285

286+
287+
# Adding an engine to an existing model
288+
289+
The process here is _almost_ the same but more simple. You would only need to add the engine-specific aspects of the model. For example, if we wanted to fit a linear regression model using M-estimation, we could only add a new engine. The code for the `rlm` function in `MASS` is pretty similar to `lm`, so we can copy that code and change the package/function names:
290+
291+
```{r rlm}
292+
set_model_engine("linear_reg", "regression", eng = "rlm")
293+
set_dependency("linear_reg", eng = "rlm", pkg = "MASS")
294+
295+
set_fit(
296+
model = "linear_reg",
297+
eng = "rlm",
298+
mode = "regression",
299+
value = list(
300+
interface = "formula",
301+
protect = c("formula", "data", "weights"),
302+
func = c(pkg = "MASS", fun = "rlm"),
303+
defaults = list()
304+
)
305+
)
306+
307+
set_pred(
308+
model = "linear_reg",
309+
eng = "rlm",
310+
mode = "regression",
311+
type = "numeric",
312+
value = list(
313+
pre = NULL,
314+
post = NULL,
315+
func = c(fun = "predict"),
316+
args =
317+
list(
318+
object = expr(object$fit),
319+
newdata = expr(new_data),
320+
type = "response"
321+
)
322+
)
323+
)
324+
325+
# testing:
326+
linear_reg() %>%
327+
set_engine("rlm") %>%
328+
fit(mpg ~ ., data = mtcars)
329+
```
330+
331+
332+
333+
286334
# Pro-tips, what-ifs, exceptions, FAQ, and minutiae
287335

288336
There are various things that came to mind while writing this document.

0 commit comments

Comments
 (0)