Skip to content

Commit

Permalink
scoping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Dec 24, 2024
1 parent 119c4a2 commit b69b18c
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions tests/testthat/test-r2_mcfadden.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,43 @@ test_that("r2_mcfadden", {
)
})

skip_if_not_installed("withr")

test_that("r2_mcfadden, glmmTMB-beta-binomial", {
skip_if_not_installed("glmmTMB")
set.seed(101)
dd <- data.frame(x = rnorm(200))
dd$y <- glmmTMB::simulate_new(
~ 1 + x,
newdata = dd,
newparams = list(beta = c(0,1), betadisp = -1),
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)[[1]]
dd$success <- round(runif(nrow(dd), 0, dd$y))
withr::with_environment(
new.env(),
{

Check warning on line 34 in tests/testthat/test-r2_mcfadden.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-r2_mcfadden.R,line=34,col=3,[unnecessary_nesting_linter] Reduce the nesting of this statement by removing the braces {}.
test_that("r2_mcfadden, glmmTMB-beta-binomial", {
skip_if_not_installed("glmmTMB")
set.seed(101)
dd <- data.frame(x = rnorm(200))
dd$y <- glmmTMB::simulate_new(
~ 1 + x,
newdata = dd,
newparams = list(beta = c(0,1), betadisp = -1),

Check warning on line 42 in tests/testthat/test-r2_mcfadden.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-r2_mcfadden.R,line=42,col=37,[commas_linter] Put a space after a comma.
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)[[1]]
dd$success <- round(runif(nrow(dd), 0, dd$y))

m <- glmmTMB::glmmTMB(
y/10 ~ 1 + x,
data = dd,
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)
out1 <- r2(m)
out2 <- r2_mcfadden(m)
expect_equal(out1$R2, out2$R2, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out1$R2, 0.06892733, tolerance = 1e-4, ignore_attr = TRUE)
m <- glmmTMB::glmmTMB(
y/10 ~ 1 + x,

Check warning on line 49 in tests/testthat/test-r2_mcfadden.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-r2_mcfadden.R,line=49,col=10,[infix_spaces_linter] Put spaces around all infix operators.
data = dd,
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)
out1 <- r2(m)
out2 <- r2_mcfadden(m)
expect_equal(out1$R2, out2$R2, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(out1$R2, 0.06892733, tolerance = 1e-4, ignore_attr = TRUE)

m <- glmmTMB::glmmTMB(
cbind(y, success) ~ 1 + x,
data = dd,
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)
expect_warning(r2(m), regex = "calculate accurate")
expect_warning(r2_mcfadden(m), regex = "calculate accurate")
})
m <- glmmTMB::glmmTMB(
cbind(y, success) ~ 1 + x,
data = dd,
weights = rep(10, nrow(dd)),
family = glmmTMB::betabinomial()
)
expect_warning(r2(m), regex = "calculate accurate")
expect_warning(r2_mcfadden(m), regex = "calculate accurate")
})
}
)

0 comments on commit b69b18c

Please sign in to comment.