tests/testthat/test-swissmetro-b25.R

test_that("b25 Swissmetro triangular mixture matches native Biogeme", {
  skip_if_not(identical(Sys.getenv("RBIOGEME_RUN_INTEGRATION"), "1"), "Set RBIOGEME_RUN_INTEGRATION=1 to run full Swissmetro equivalence tests")
  skip_if_not(rbiogeme_test_configure_python(), "Set RBIOGEME_PYTHON to a compatible native Biogeme interpreter")
  data_path <- rbiogeme_test_swissmetro_path()
  skip_if(!nzchar(data_path), "Set RBIOGEME_SWISSMETRO_DATA to the Swissmetro .dat file")
  data <- read.delim(data_path, check.names = FALSE, stringsAsFactors = FALSE)
  r_model <- r_swissmetro_mixture(data, "b25", number_of_draws = 256L)$model
  temporary_directory <- tempfile("rbiogeme-b25-")
  dir.create(temporary_directory, recursive = TRUE)
  original_directory <- getwd()
  setwd(temporary_directory)
  on.exit(setwd(original_directory), add = TRUE)
  r_fit <- estimate(r_model, model_name = "b25_triangular_mixture", control = r_model$control)
  native <- native_swissmetro_mixture(data, "b25", number_of_draws = 256L)
  expect_equal(nobs(r_fit), native$number_of_rows)
  expect_identical(r_fit$beta_names, native$results$beta_names)
  expect_equal(unname(coef(r_fit)), native$results$beta_values, tolerance = 2e-7)
  expect_equal(as.numeric(logLik(r_fit)), native$results$final_log_likelihood, tolerance = 2e-7)
})

Try the rbiogeme package in your browser

Any scripts or data that you put into this service are public.

rbiogeme documentation built on Sept. 29, 2026, 5:09 p.m.