@@ -251,6 +251,42 @@ test_that("compare_performance, Log_loss ranks in the right direction", {
251251})
252252
253253
254+ test_that(" compare_performance, LOOIC weights when not all models have LOOIC" , {
255+ skip_on_cran()
256+ skip_if_not_installed(" brms" )
257+ skip_if_not_installed(" loo" )
258+ skip_if_not_installed(" curl" )
259+ skip_if_offline()
260+ skip_if_not_installed(" httr2" )
261+
262+ m_brms <- insight :: download_model(" brms_1" )
263+ skip_if(is.null(m_brms ))
264+ m_brms2 <- m_brms
265+ m_lm <- lm(insight :: find_formula(m_brms )$ conditional , data = insight :: get_data(m_brms ))
266+
267+ # only one model has LOOIC, so there are no stacking weights (#738)
268+ out <- compare_performance(m_lm , m_brms , verbose = FALSE )
269+ expect_identical(out $ Name , c(" m_lm" , " m_brms" ))
270+ expect_true(is.na(out $ LOOIC [1 ]))
271+ expect_false(is.na(out $ LOOIC [2 ]))
272+ expect_identical(out $ LOOIC_wt , c(NA_real_ , NA_real_ ))
273+ # a missing weight prints as an empty cell, not as a weight of 1
274+ formatted <- format(out )
275+ expect_identical(formatted [[" LOOIC (weights)" ]][1 ], " " )
276+ expect_identical(formatted [[" AIC (weights)" ]][2 ], " " )
277+ expect_identical(formatted [[" AIC (weights)" ]][1 ], " 156.0" )
278+
279+ # stacking weights for the models that have LOOIC, NA for the others
280+ out <- compare_performance(m_lm , m_brms , m_brms2 , verbose = FALSE )
281+ expect_identical(out $ Name , c(" m_lm" , " m_brms" , " m_brms2" ))
282+ expect_true(is.na(out $ LOOIC_wt [1 ]))
283+ expect_equal(sum(out $ LOOIC_wt [2 : 3 ]), 1 , tolerance = 1e-6 )
284+
285+ out <- compare_performance(m_lm , m_brms , m_brms2 , rank = TRUE , verbose = FALSE )
286+ expect_identical(nrow(out ), 3L )
287+ })
288+
289+
254290test_that(" compare_performance, RMSE and Sigma still rank in the right direction" , {
255291 data(mtcars )
256292 l_best <- lm(mpg ~ wt + cyl + hp , data = mtcars )
0 commit comments