tests/testthat/test-cleveland_heart.R

test_that("Bayesian binomial-logit regression-OpenCL", {
  skip_if_no_opencl()
    # Skip on CRAN to avoid long runtime / external data fetch
  skip_on_cran()
  
  ## Bundled cleaned UCI Cleveland data (see ?Cleveland); avoid fetching the
  ## raw UCI URL in tests — archive paths often move or block non-browser clients.
  df <- Cleveland
  
  # Prior setup
  ps <- Prior_Setup(hd ~ age + sex + cp + trestbps + chol +
                      fbs + restecg + thalach + exang + oldpeak + slope + ca + thal,
                    family = binomial(logit),
                    data = df)
  
  mu <- ps$mu
  sigma <- ps$Sigma
  
  # Fit Bayesian GLM with parallel + OpenCL
  glmb_hd <- glmb(
    hd ~ age + sex + cp + trestbps + chol +
      fbs + restecg + thalach + exang + oldpeak + slope + ca + thal,
    family  = binomial(link = "logit"),
    pfamily = dNormal(mu = mu, Sigma = sigma),
    data    = df,
    n       = 10000,
    Gridtype = 2,
    use_parallel = TRUE,
    use_opencl   = TRUE
    ,verbose      = FALSE
  )
  
  # Test condition: average number of candidates per acceptance < 6
  avg_candidates <- mean(glmb_hd$iters)
  expect_true(avg_candidates < 6)
  

  
})

Try the glmbayes package in your browser

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

glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.