From 1e352ba1ccc39e4194be69fdcdce379637fe1101 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 16 Jul 2023 14:49:32 -0400 Subject: [PATCH] update tests --- .../_tinysnapshot/plot_slopes_continuous.svg | 28 +++++++------- .../plot_slopes_two_conditions.svg | 38 +++++++++---------- .../summary-marginaleffects_dplyr.txt | 2 +- inst/tinytest/test-elasticity.R | 14 +++---- inst/tinytest/test-equivalence.R | 3 +- inst/tinytest/test-pkg-gam.R | 4 +- 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/inst/tinytest/_tinysnapshot/plot_slopes_continuous.svg b/inst/tinytest/_tinysnapshot/plot_slopes_continuous.svg index ae9650447..efce87c28 100644 --- a/inst/tinytest/_tinysnapshot/plot_slopes_continuous.svg +++ b/inst/tinytest/_tinysnapshot/plot_slopes_continuous.svg @@ -30,23 +30,23 @@ - - - - + + + + --0.2 --0.1 -0.0 -0.1 -0.2 - - - - - +-0.2 +-0.1 +0.0 +0.1 +0.2 + + + + + diff --git a/inst/tinytest/_tinysnapshot/plot_slopes_two_conditions.svg b/inst/tinytest/_tinysnapshot/plot_slopes_two_conditions.svg index cf5abf291..e9d7c1a04 100644 --- a/inst/tinytest/_tinysnapshot/plot_slopes_two_conditions.svg +++ b/inst/tinytest/_tinysnapshot/plot_slopes_two_conditions.svg @@ -30,29 +30,29 @@ - - - - - - - - + + + + + + + + --0.15 --0.10 --0.05 -0.00 +-0.15 +-0.10 +-0.05 +0.00 0.05 -0.10 - - - - - - +0.10 + + + + + + diff --git a/inst/tinytest/_tinysnapshot/summary-marginaleffects_dplyr.txt b/inst/tinytest/_tinysnapshot/summary-marginaleffects_dplyr.txt index 2db0d1048..6a07c05e0 100644 --- a/inst/tinytest/_tinysnapshot/summary-marginaleffects_dplyr.txt +++ b/inst/tinytest/_tinysnapshot/summary-marginaleffects_dplyr.txt @@ -1,7 +1,7 @@ Term Estimate CI low CI high hp 0.00265 -0.00147 0.00677 - wt -0.43578 -0.71712 -0.15444 + wt -0.43578 -0.71716 -0.15440 Columns: term, estimate, conf.low, conf.high diff --git a/inst/tinytest/test-elasticity.R b/inst/tinytest/test-elasticity.R index 4548b8115..c2bc265f5 100644 --- a/inst/tinytest/test-elasticity.R +++ b/inst/tinytest/test-elasticity.R @@ -2,7 +2,7 @@ source("helpers.R") using("marginaleffects") set.seed(1024) -tol <- tolse <- 1e-4 +tol <- tolse <- 1e-3 results <- readRDS(testing_path("stata/stata.rds")) @@ -18,12 +18,12 @@ expect_equivalent(mfx$estimate, sta$dydxstata) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) -mfx <- tidy(slopes(mod, slope = "eydx", eps = 1e-6)) +mfx <- tidy(slopes(mod, slope = "eydx", numderiv = "richardson")) sta <- results$stats_lm_elasticity_eydx expect_equivalent(mfx$estimate, sta$dydxstata) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) -mfx <- tidy(slopes(mod, slope = "dyex", eps = 1e-6)) +mfx <- tidy(slopes(mod, slope = "dyex", numderiv = "richardson")) sta <- results$stats_lm_elasticity_dyex expect_equivalent(mfx$estimate, sta$dydxstata) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) @@ -32,19 +32,19 @@ expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) dat <- read.csv(testing_path("stata/databases/stats_glm_01.csv")) mod <- glm(y ~ x1 * x2, data = dat, family = binomial) -mfx <- tidy(slopes(mod, slope = "eyex", eps = 1e-6)) +mfx <- tidy(slopes(mod, slope = "eyex", numderiv = "richardson")) sta <- results$stats_glm_elasticity_eyex expect_equivalent(mfx$estimate, sta$dydxstata, tolerance = tol) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) -mfx <- tidy(slopes(mod, slope = "eydx", eps = 1e-6)) +mfx <- tidy(slopes(mod, slope = "eydx", numderiv = "richardson")) sta <- results$stats_glm_elasticity_eydx expect_equivalent(mfx$estimate, sta$dydxstata, tolerance = tol) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) -mfx <- tidy(slopes(mod, slope = "dyex", eps = 1e-6)) +mfx <- tidy(slopes(mod, slope = "dyex", numderiv = "richardson")) sta <- results$stats_glm_elasticity_dyex -expect_equivalent(mfx$estimate, sta$dydxstata, tolerance = tol) +expect_equivalent(mfx$estimate, sta$dydxstata, tolerance = 1e-2) expect_equivalent(mfx$std.error, sta$std.errorstata, tolerance = tolse) diff --git a/inst/tinytest/test-equivalence.R b/inst/tinytest/test-equivalence.R index e949ff7a5..0bf9e1a27 100644 --- a/inst/tinytest/test-equivalence.R +++ b/inst/tinytest/test-equivalence.R @@ -79,7 +79,8 @@ e2 <- predictions( mod, type = "link", newdata = datagrid(gear = unique), - equivalence = c(.5, 1.5)) |> + equivalence = c(.5, 1.5), + numderiv = "richardson") |> poorman::arrange(gear) expect_equivalent(e1$emmean, e2$estimate) expect_equivalent(e1$z.ratio, e2$statistic.noninf) diff --git a/inst/tinytest/test-pkg-gam.R b/inst/tinytest/test-pkg-gam.R index 3ae9b6b07..7115d8309 100644 --- a/inst/tinytest/test-pkg-gam.R +++ b/inst/tinytest/test-pkg-gam.R @@ -38,9 +38,9 @@ model <- gam::gam(Kyphosis ~ gam::s(Age, 4) + Number + categ, family = binomial, # `datagrid()` is smarter than `emmeans()` about integers atlist <- list(Age = round(mean(tmp$Age)), Number = round(mean(tmp$Number))) -mm1 <- marginal_means(model) |> dplyr::arrange(value) +mm1 <- marginal_means(model, numderiv = "richardson") |> dplyr::arrange(value) em1 <- data.frame(emmeans(model, specs = "categ", type = "response", at = atlist)) -mm2 <- marginal_means(model, type = "link") |> dplyr::arrange(value) +mm2 <- marginal_means(model, type = "link", numderiv = "richardson") |> dplyr::arrange(value) em2 <- data.frame(emmeans(model, specs = "categ", at = atlist)) expect_equivalent(mm1$estimate, em1$prob)