Skip to content

Commit 7f05f42

Browse files
Fix bug for 4.3 where rank deficient prediction from lm model gave different column names (#987)
* add rankdeficient = "simple" for predict.lm * test for rankdeficient = "simple" for predict.lm * add news bullet
1 parent e6278b0 commit 7f05f42

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
* A few censored regression helper functions were exported: `.extract_surv_status()`, `.extract_surv_time()`, and `.time_as_binary_event()` (#973).
1010

11+
* Fixed bug where prediction on rank dificient `lm()` models produced `.pred_res` instead of `.pred`. (#985)
1112

1213
# parsnip 1.1.0
1314

R/linear_reg_data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ set_pred(
4444
list(
4545
object = expr(object$fit),
4646
newdata = expr(new_data),
47-
type = "response"
47+
type = "response",
48+
rankdeficient = "simple"
4849
)
4950
)
5051
)

tests/testthat/test_linear_reg.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,27 @@ test_that('show engine', {
318318
expect_error(show_engines("linear_re"), "No results found for model function")
319319
})
320320

321+
test_that('lm can handle rankdeficient predictions', {
322+
data <- data.frame(
323+
y = c(1,2,3,4),
324+
x1 = c(1,1,2,3),
325+
x2 = c(3,4,5,2),
326+
x3 = c(4,2,6,0),
327+
x4 = c(2,1,3,0)
328+
)
329+
data2 <- data.frame(
330+
x1 = c(3,2,1,3),
331+
x2 = c(3,2,1,4),
332+
x3 = c(3,4,5,1),
333+
x4 = c(0,0,2,3)
334+
)
335+
336+
expect_warning(
337+
preds <- linear_reg() %>%
338+
fit(y ~ ., data = data) %>%
339+
predict(new_data = data2)
340+
)
341+
342+
expect_identical(names(preds), ".pred")
343+
})
344+

0 commit comments

Comments
 (0)