Skip to content

Commit 5ae33c5

Browse files
committed
fix linear_reg tests
Addresses some failures re: some subsetting by name and some by index
1 parent a41e1c0 commit 5ae33c5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/testthat/test_linear_reg.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ test_that('bad input', {
209209

210210
# ------------------------------------------------------------------------------
211211

212-
num_pred <- names(hpc)[1:3]
212+
num_pred <- c("input_fields", "num_pending", "iterations")
213213
hpc_bad_form <- as.formula(class ~ term)
214214
hpc_basic <- linear_reg() %>% set_engine("lm")
215215

@@ -279,43 +279,44 @@ test_that('lm execution', {
279279
})
280280

281281
test_that('lm prediction', {
282-
uni_lm <- lm(input_fields ~ compounds + iterations + num_pending, data = hpc)
282+
uni_lm <- lm(compounds ~ input_fields + num_pending + iterations, data = hpc)
283283
uni_pred <- unname(predict(uni_lm, newdata = hpc[1:5, ]))
284-
inl_lm <- lm(input_fields ~ log(compounds) + class, data = hpc)
284+
inl_lm <- lm(compounds ~ log(input_fields) + class, data = hpc)
285285
inl_pred <- unname(predict(inl_lm, newdata = hpc[1:5, ]))
286-
mv_lm <- lm(cbind(compounds, iterations) ~ ., data = hpc)
286+
mv_lm <- lm(cbind(input_fields, num_pending) ~ ., data = hpc)
287287
mv_pred <- as_tibble(predict(mv_lm, newdata = hpc[1:5, ]))
288-
names(mv_pred) <- c(".pred_compounds", ".pred_iterations")
289-
288+
names(mv_pred) <- c(".pred_input_fields", ".pred_num_pending")
290289

291290
res_xy <- fit_xy(
292291
hpc_basic,
293292
x = hpc[, num_pred],
294-
y = hpc$input_fields,
293+
y = hpc$compounds,
295294
control = ctrl
296295
)
297296

298297
expect_equal(uni_pred, predict(res_xy, hpc[1:5, num_pred])$.pred)
299298

300299
res_form <- fit(
301300
hpc_basic,
302-
input_fields ~ log(compounds) + class,
301+
compounds ~ log(input_fields) + class,
303302
data = hpc,
304303
control = ctrl
305304
)
305+
306306
expect_equal(inl_pred, predict(res_form, hpc[1:5, ])$.pred)
307307

308308
res_mv <- fit(
309309
hpc_basic,
310-
cbind(compounds, iterations) ~ .,
310+
cbind(input_fields, num_pending) ~ .,
311311
data = hpc,
312312
control = ctrl
313313
)
314+
314315
expect_equal(mv_pred, predict(res_mv, hpc[1:5,]))
315316
})
316317

317318
test_that('lm intervals', {
318-
stats_lm <- lm(input_fields ~ compounds + iterations + num_pending,
319+
stats_lm <- lm(compounds ~ input_fields + iterations + num_pending,
319320
data = hpc)
320321
confidence_lm <- predict(stats_lm, newdata = hpc[1:5, ],
321322
level = 0.93, interval = "confidence")
@@ -325,7 +326,7 @@ test_that('lm intervals', {
325326
res_xy <- fit_xy(
326327
linear_reg() %>% set_engine("lm"),
327328
x = hpc[, num_pred],
328-
y = hpc$input_fields,
329+
y = hpc$compounds,
329330
control = ctrl
330331
)
331332

0 commit comments

Comments
 (0)