Skip to content

Commit

Permalink
some minor edits (lintrs)
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 4, 2024
1 parent 05bd759 commit eda3b15
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
18 changes: 9 additions & 9 deletions R/estimate_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ estimate_density.emmGrid <- function(x,
)

# This doesn't use .append_datagrid because we get a non-grid output
grid <- insight::get_datagrid(x)
grid$Parameter <- unique(out$Parameter)
out <- datawizard::data_join(grid, out, by = "Parameter")
dgrid <- insight::get_datagrid(x)
dgrid$Parameter <- unique(out$Parameter)
out <- datawizard::data_join(dgrid, out, by = "Parameter")
out$Parameter <- NULL
class(out) <- .set_density_class(out)
out
Expand All @@ -398,15 +398,15 @@ estimate_density.slopes <- function(x,
xdf <- .get_marginaleffects_draws(x)

out <- estimate_density(xdf,
method = method, precision = precision,
extend = extend, extend_scale = extend_scale,
bw = bw, ...
method = method, precision = precision,
extend = extend, extend_scale = extend_scale,
bw = bw, ...
)

# This doesn't use .append_datagrid because we get a non-grid output
grid <- insight::get_datagrid(x)
grid$Parameter <- unique(out$Parameter)
out <- datawizard::data_join(grid, out, by = "Parameter")
dgrid <- insight::get_datagrid(x)
dgrid$Parameter <- unique(out$Parameter)
out <- datawizard::data_join(dgrid, out, by = "Parameter")
out$Parameter <- NULL
class(out) <- .set_density_class(out)
out
Expand Down
12 changes: 8 additions & 4 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ format.bayesfactor_models <- function(x,
BFE$log_BF <- as.numeric(x, log = log)
BFE$BF <- insight::format_bf(abs(BFE$log_BF), name = NULL, exact = exact, ...)

if (any((sgn <- sign(BFE$log_BF) < 0)[!is.na(BFE$log_BF)])) {
sgn <- sign(BFE$log_BF)
if (any((sgn < 0)[!is.na(BFE$log_BF)])) {
BFE$BF[sgn] <- paste0("-", BFE$BF[sgn])
}

Expand Down Expand Up @@ -170,7 +171,8 @@ format.bayesfactor_inclusion <- function(x,
BFE$log_BF <- as.numeric(x, log = log)
BFE$BF <- insight::format_bf(abs(BFE$log_BF), name = NULL, exact = exact, ...)

if (any((sgn <- sign(BFE$log_BF) < 0)[!is.na(BFE$log_BF)])) {
sgn <- sign(BFE$log_BF)
if (any((sgn < 0)[!is.na(BFE$log_BF)])) {
BFE$BF[sgn] <- paste0("-", BFE$BF[sgn])
}

Expand Down Expand Up @@ -221,7 +223,8 @@ format.bayesfactor_restricted <- function(x,
BFE$log_BF <- as.numeric(x, log = log)
BFE$BF <- insight::format_bf(abs(BFE$log_BF), name = NULL, exact = exact, ...)

if (any((sgn <- sign(BFE$log_BF) < 0)[!is.na(BFE$log_BF)])) {
sgn <- sign(BFE$log_BF)
if (any((sgn < 0)[!is.na(BFE$log_BF)])) {
BFE$BF[sgn] <- paste0("-", BFE$BF[sgn])
}
BFE$log_BF <- NULL
Expand Down Expand Up @@ -267,7 +270,8 @@ format.bayesfactor_parameters <- function(x,

x$BF_override <- insight::format_bf(abs(x$log_BF), name = NULL, exact = exact, ...)

if (any((sgn <- sign(x$log_BF) < 0)[!is.na(x$log_BF)])) {
sgn <- sign(x$log_BF)
if (any((sgn < 0)[!is.na(x$log_BF)])) {
x$BF_override[sgn] <- paste0("-", x$BF_override[sgn])
}
x$log_BF <- NULL
Expand Down
26 changes: 13 additions & 13 deletions tests/testthat/test-emmGrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,65 +49,65 @@ test_that("emmGrid point_estimate", {
test_that("emmGrid ci", {
xci <- ci(all_, ci = 0.9)
expect_identical(colnames(xci)[1:2], c("group", "contrast"))
expect_equal(length(xci$CI_low), 3)
expect_equal(length(xci$CI_high), 3)
expect_length(xci$CI_low, 3)
expect_length(xci$CI_high, 3)
})

test_that("emmGrid eti", {
xeti <- eti(all_, ci = 0.9)
expect_identical(colnames(xeti)[1:2], c("group", "contrast"))
expect_equal(length(xeti$CI_low), 3)
expect_equal(length(xeti$CI_high), 3)
expect_length(xeti$CI_low, 3)
expect_length(xeti$CI_high, 3)
})

test_that("emmGrid equivalence_test", {
xeqtest <- equivalence_test(all_, ci = 0.9, range = c(-0.1, 0.1))
expect_identical(colnames(xeqtest)[1:2], c("group", "contrast"))
expect_equal(length(xeqtest$ROPE_Percentage), 3)
expect_equal(length(xeqtest$ROPE_Equivalence), 3)
expect_length(xeqtest$ROPE_Percentage, 3)
expect_length(xeqtest$ROPE_Equivalence, 3)
})

test_that("emmGrid estimate_density", {
xestden <- estimate_density(c_, method = "logspline", precision = 5)
expect_identical(colnames(xestden)[1], "contrast")
expect_equal(length(xestden$x), 5)
expect_length(xestden$x, 5)
})

test_that("emmGrid map_estimate", {
xmapest <- map_estimate(all_, method = "kernel")
expect_identical(colnames(xmapest)[1:2], c("group", "contrast"))
expect_equal(length(xmapest$MAP_Estimate), 3)
expect_length(xmapest$MAP_Estimate, 3)
})


test_that("emmGrid p_direction", {
xpd <- p_direction(all_, method = "direct")
expect_identical(colnames(xpd)[1:2], c("group", "contrast"))
expect_equal(length(xpd$pd), 3)
expect_length(xpd$pd, 3)
})

test_that("emmGrid p_map", {
xpmap <- p_map(all_, precision = 2^9)
expect_identical(colnames(xpmap)[1:2], c("group", "contrast"))
expect_equal(length(xpmap$p_MAP), 3)
expect_length(xpmap$p_MAP, 3)
})

test_that("emmGrid p_rope", {
xprope <- p_rope(all_, range = c(-0.1, 0.1))
expect_identical(colnames(xprope)[1:2], c("group", "contrast"))
expect_equal(length(xprope$p_ROPE), 3)
expect_length(xprope$p_ROPE, 3)
})

test_that("emmGrid p_significance", {
xsig <- p_significance(all_, threshold = c(-0.1, 0.1))
expect_identical(colnames(xsig)[1:2], c("group", "contrast"))
expect_equal(length(xsig$ps), 3)
expect_length(xsig$ps, 3)
})

test_that("emmGrid rope", {
xrope <- rope(all_, range = "default", ci = 0.9)
expect_identical(colnames(xrope)[1:2], c("group", "contrast"))
expect_equal(length(xrope$ROPE_Percentage), 3)
expect_length(xrope$ROPE_Percentage, 3)
})


Expand Down

0 comments on commit eda3b15

Please sign in to comment.