Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bug fixes

Minor changes
* Fixed a lot of linting issues across the package.
* Increased test coverage across the package.

# report 0.6.1

Expand Down
55 changes: 55 additions & 0 deletions tests/testthat/test-coverage-MixMod.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Coverage tests for report.MixMod functions

skip_if_not_installed("GLMMadaptive")

test_that("report.MixMod coverage test", {
set.seed(999)
# Create longitudinal data suitable for GLMMadaptive
n_subjects <- 8
n_timepoints <- 4

data_mixmod <- data.frame(
id = rep(1:n_subjects, each = n_timepoints),
time = rep(c(0, 1, 2, 3), n_subjects),
x = rnorm(n_subjects * n_timepoints)
)

# Create binary outcome appropriate for GLMMadaptive
data_mixmod$y <- rbinom(
nrow(data_mixmod), 1,
plogis(-1 + 0.5 * data_mixmod$time + 0.3 * data_mixmod$x)
)

# Create GLMMadaptive mixed model
suppressWarnings({
model <- GLMMadaptive::mixed_model(
fixed = y ~ time + x,
random = ~ 1 | id,
data = data_mixmod,
family = binomial()
)
})

# Test report.MixMod (which is aliased to report.lm)
r <- suppressWarnings(report(model, data = data_mixmod))
expect_s3_class(r, "report")
expect_type(summary(r), "character")
expect_s3_class(as.data.frame(r), c("report_table", "data.frame"))

# Test report_random.MixMod specifically
rr <- report_random(model)
expect_s3_class(rr, c("report_random", "character"))
expect_true(grepl("random effect", rr, fixed = TRUE))

# Test other MixMod-specific functions for coverage
rt <- report_table(model)
expect_s3_class(rt, c("report_table", "data.frame"))

# Test report_performance for MixMod
rp <- suppressWarnings(report_performance(model))
expect_s3_class(rp, c("report_performance", "character"))

# Test report_effectsize for MixMod
re <- suppressWarnings(report_effectsize(model))
expect_s3_class(re, "report_effectsize")
})
76 changes: 76 additions & 0 deletions tests/testthat/test-coverage-brmsfit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Coverage tests for report.brmsfit functions
# These are minimal tests to ensure coverage of functions that might be skipped in CI

skip_if_not_installed("brms")

test_that("report.brmsfit coverage test", {
# Create a very simple brms model for testing
# Use minimal iterations and very simple data to make it fast
skip_if_not_installed("rstanarm") # often needed for brms

set.seed(42)
# Use a tiny dataset to make model fitting very fast
tiny_data <- data.frame(
y = rnorm(10, mean = 2),
x = rnorm(10)
)

# Create minimal brms model with very few iterations
suppressMessages(suppressWarnings({
model <- brms::brm(
y ~ x,
data = tiny_data,
refresh = 0,
iter = 100, # Very small number for speed
chains = 1, # Single chain for speed
seed = 42,
silent = 2 # Suppress output
)
}))

# Test the main report function (coverage for report.brmsfit)
r <- suppressWarnings(report(model, verbose = FALSE))
expect_s3_class(r, "report")
expect_type(summary(r), "character")
expect_s3_class(as.data.frame(r), "data.frame")

# Test report_effectsize.brmsfit coverage
r_eff <- suppressWarnings(report_effectsize(model))
expect_s3_class(r_eff, "report_effectsize")

# Test report_priors.brmsfit coverage - this might return empty for default priors
r_priors <- suppressWarnings(report_priors(model))
expect_type(r_priors, "character")
})

test_that("report_priors.brmsfit with explicit priors coverage", {
skip_if_not_installed("brms")
skip_if_not_installed("rstanarm")

set.seed(123)
tiny_data <- data.frame(
y = rnorm(8, mean = 1),
x = rnorm(8)
)

# Create model with explicit priors to test prior reporting
suppressMessages(suppressWarnings({
model_with_priors <- brms::brm(
y ~ x,
data = tiny_data,
prior = c(
brms::prior(normal(0, 1), class = Intercept),
brms::prior(normal(0, 0.5), class = b)
),
refresh = 0,
iter = 50, # Even fewer iterations
chains = 1,
seed = 123,
silent = 2
)
}))

# Test report_priors with actual priors
r_priors <- suppressWarnings(report_priors(model_with_priors))
expect_type(r_priors, "character")
})
64 changes: 64 additions & 0 deletions tests/testthat/test-coverage-compare-loo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Coverage tests for report.compare.loo function

skip_if_not_installed("brms")
skip_if_not_installed("loo")

test_that("report.compare.loo coverage test", {
skip_if_not_installed("rstanarm")

set.seed(456)
# Create minimal dataset
tiny_data <- data.frame(
y = rnorm(12, mean = 3),
x1 = rnorm(12),
x2 = rnorm(12)
)

# Create two very simple models for comparison
suppressMessages(suppressWarnings({
m1 <- brms::brm(
y ~ x1,
data = tiny_data,
refresh = 0,
iter = 50,
chains = 1,
seed = 456,
silent = 2
)

m2 <- brms::brm(
y ~ x1 + x2,
data = tiny_data,
refresh = 0,
iter = 50,
chains = 1,
seed = 456,
silent = 2
)
}))

# Add LOO criterion (this is what creates compare.loo objects)
suppressWarnings({
m1 <- brms::add_criterion(m1, "loo")
m2 <- brms::add_criterion(m2, "loo")
})

# Create model comparison object
comparison <- suppressWarnings(brms::loo_compare(
m1, m2,
model_names = c("model1", "model2")
))

# Test report.compare.loo function
r <- report(comparison)
expect_s3_class(r, c("report_text", "character"))
expect_gt(nchar(r), 0)
expect_true(grepl("ELPD", r, fixed = TRUE))

# Test with different parameters
r2 <- report(comparison, include_IC = FALSE)
expect_s3_class(r2, c("report_text", "character"))

r3 <- report(comparison, include_ENP = TRUE)
expect_s3_class(r3, c("report_text", "character"))
})
47 changes: 47 additions & 0 deletions tests/testthat/test-coverage-glmmTMB.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Coverage tests for report.glmmTMB functions

skip_if_not_installed("glmmTMB")

test_that("report.glmmTMB coverage test", {
set.seed(789)
# Create simple test data
test_data <- data.frame(
y = rpois(20, lambda = 1.5),
x = rnorm(20),
group = factor(rep(1:4, 5))
)

# Create minimal glmmTMB model
suppressWarnings({
model <- glmmTMB::glmmTMB(
y ~ x + (1 | group),
data = test_data,
family = poisson()
)
})

# Test report.glmmTMB (which is aliased to report.lm)
r <- report(model)
expect_s3_class(r, "report")
expect_type(summary(r), "character")
expect_s3_class(as.data.frame(r), c("report_table", "data.frame"))

# Test report_random.glmmTMB specifically
rr <- report_random(model)
expect_s3_class(rr, c("report_random", "character"))
expect_true(grepl("random effect", rr, fixed = TRUE))
expect_true(grepl("group", rr, fixed = TRUE))

# Test other glmmTMB-specific functions for coverage
rt <- report_table(model)
expect_s3_class(rt, c("report_table", "data.frame"))
expect_true("Parameter" %in% names(rt))

# Test report_performance for glmmTMB
rp <- report_performance(model)
expect_s3_class(rp, c("report_performance", "character"))

# Test report_effectsize for glmmTMB
re <- suppressWarnings(report_effectsize(model))
expect_s3_class(re, "report_effectsize")
})
Loading