Error: The 'cmdstanr' package is required to fit COSMIC models. Install it with install.packages('cmdstanr', repos = c('https://stan-dev.r-universe.dev', getOption('repos'))).

test_that("prep_cosmic_data runs on simple input", {
out <- prep_cosmic_data(d, id, idOff, y)
data.frame(idOff = c(1L, 2L), idOffOrig = c(1, 2)))
test_that("cosmic runs on tiny dataset", {
test_that("fails with fewer than 3 force types", {
test_that("officer_summary works with supplied draws", {
test_that("outlier_report filters and orders an officer summary", {
), class = c("cosmic_officer_summary", "data.frame"))
report <- outlier_report(off_summary, prob_outlier = 0.8)
test_that("outlier_report returns all officers when prob_outlier is zero", {
report <- outlier_report(off_summary, prob_outlier = 0)
test_that("outlier_report rejects fitted models directly", {
fit <- structure(list(), class = "cosmic_fit")
test_that("diagnostics flag poor convergence and HMC issues", {
rownames(summary_matrix) <- c("lambda[1]", "lambda[2]", "lp__")
test_that("diagnostic printer reports clean fits", {
expect_match(output[1], "COSMIC fit diagnostics: OK")
expect_match(output[length(output)], "No major diagnostic problems detected")
test_that("stan summary extractor handles matrix and list outputs", {
summary.fake_fit_summary <- function(object, ...) object
summary.fake_fit_summary_list <- function(object, ...) object
.stan_summary_matrix(structure(list(summary = summary_matrix), class = "fake_fit_summary_list")),
.complete_enumeration_logcl <- function(d, lambda, s) {
log_numerator <- sum(lambda[d$idOff] * s[d$y])
incident_denominators <- vapply(incident_rows, function(rows) {
counts <- table(factor(d$y[rows], levels = seq_along(s)))
assignments <- arrangements::permutations(length(s), freq = counts)
.compiled_stan_logcl <- function(model, d, lambda, s) {
on.exit(unlink(tmp, recursive = TRUE), add = TRUE)
sDelta = array(as.numeric(diff(s)[-1]), dim = n_force_types - 2L)
on.exit(Sys.setenv(PATH = old_path), add = TRUE)
c(file.path(cmdstanr::cmdstan_path(), "stan", "lib", "stan_math", "lib", "tbb"),
lp <- read.csv(output_file, comment.char = "#", check.names = FALSE)[["lp__"]]
prior_kernel <- -0.5 * sum((lambda / prior_sd_lambda)^2) -
0.5 * sum((diff(s)[-1] / prior_sd_sdiff)^2)
test_that("DP matches complete enumeration across incident shapes", {
stan_file <- system.file("stan", "cosmic.stan", package = "cosmic")
cpp_options = list(stan_threads = TRUE),
name = "three force types with two-officer incidents",
name = "four force types with repeated outcomes",
name = "five force types with wider y range",