tests/testthat/test-results.R

make_test_fit <- function() {
  structure(
    list(
      model_name = "toy",
      beta_names = c("a", "b"),
      beta_values = c(1, -2),
      standard_errors = c(0.5, 1),
      t_statistics = c(2, -2),
      p_values = c(0.0455, 0.0455),
      variance_covariance = diag(c(0.25, 1)),
      final_log_likelihood = -10,
      convergence = TRUE,
      sample_size = 20L,
      optimization_messages = list(),
      biogeme_version = "3.3.5",
      python_version = "3.14.6",
      derivatives_available = TRUE
    ),
    class = c("biogeme_fit", "biogeme_result")
  )
}

test_that("result methods expose estimates and covariance", {
  fit <- make_test_fit()
  expect_equal(coef(fit), c(a = 1, b = -2))
  expect_equal(vcov(fit), diag(c(0.25, 1)))
  expect_equal(as.numeric(logLik(fit)), -10)
  expect_equal(attr(logLik(fit), "df"), 2L)
  expect_equal(nobs(fit), 20L)
})

test_that("summary returns a conventional coefficient table", {
  fit <- make_test_fit()
  result <- summary(fit)
  expect_s3_class(result, "summary.biogeme_fit")
  expect_equal(rownames(result$coefficients), c("a", "b"))
  expect_equal(result$coefficients$Estimate, c(1, -2))
  expect_equal(result$coefficients$`Std. Error`, c(0.5, 1))
  expect_output(print(result), "Final log likelihood")
})

test_that("vcov clearly reports unavailable derivatives", {
  fit <- make_test_fit()
  fit$variance_covariance <- NULL
  expect_error(vcov(fit), "variance-covariance matrix is unavailable")
  expect_output(
    print(summary(fit)),
    "derivatives were not calculated"
  )
})

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.