vincentarelbundock / marginaleffects

R package to compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.) for over 100 classes of statistical and ML models. Conduct linear and non-linear hypothesis tests, or equivalence tests. Calculate uncertainty estimates using the delta method, bootstrapping, or simulation-based inference
https://marginaleffects.com
Other
462 stars 48 forks source link

revdep issues with new _insight_ version #179

Closed strengejacke closed 2 years ago

strengejacke commented 2 years ago

Hi Vincent, can you check the issues related to marginaleffects and see whether it's something you have to or I can address?

https://win-builder.r-project.org/incoming_pretest/insight_0.15.0_20220103_142800/reverseDependencies/summary.txt

strengejacke commented 2 years ago

Examples:

Package: marginaleffects
Check: examples
New result: ERROR
  Running examples in ‘marginaleffects-Ex.R’ failed
  The error most likely occurred in:

  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: tidy.marginaleffects
  > ### Title: Tidy a 'marginaleffects' object
  > ### Aliases: tidy.marginaleffects
  > 
  > ### ** Examples
  > 
  > mod <- lm(mpg ~ hp * wt + factor(gear), data = mtcars)
  > mfx <- marginaleffects(mod)
  Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
    factor factor(gear) has new levels 3.0001, 4.0001, 5.0001
  Calls: marginaleffects ... <Anonymous> -> predict.lm -> model.frame -> model.frame.default
  Execution halted
vincentarelbundock commented 2 years ago

Thanks @strengejacke Don't worry about it; I will handle this.

vincentarelbundock commented 2 years ago

handle it on the marginaleffects side. Nothing needs to change in insight.

strengejacke commented 2 years ago

Vignettes

Package: marginaleffects
Check: re-building of vignette outputs
New result: WARNING
  Error(s) in re-building vignettes:

---- re-building ‘contrasts.Rmd’ using rmarkdown
  Quitting from lines 46-48 (contrasts.Rmd) 
  Error: processing vignette ‘contrasts.Rmd’ failed with diagnostics:
  factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001

  --- re-building ‘predictions.Rmd’ using rmarkdown
  Quitting from lines 36-41 (predictions.Rmd) 
  Error: processing vignette ‘predictions.Rmd’ failed with diagnostics:
  factor factor(cyl) has new level 6.1875
  --- failed re-building ‘predictions.Rmd’
strengejacke commented 2 years ago

Tests

(sorry, a bit longer)

Package: marginaleffects
Check: tests
New result: ERROR
    Running ‘spelling.R’ [0s/0s]
    Running ‘testthat.R’ [162s/82s]
  Running the tests in ‘tests/testthat.R’ failed.
  Complete output:
    > library(testthat)
    > library(marginaleffects)
    > library(margins)
    > 
    > test_check("marginaleffects")
    Starting 2 test processes
    ══ Skipped tests ═══════════════════════════════════════════════════════════════
    • On CRAN (6)
    • https://github.com/easystats/insight/issues/441 (1)
    • unsupported data argument in get_predicted.lrm (1)
    • works interactively (5)

    ══ Failed tests ════════════════════════════════════════════════════════════════
    ── Error (test-contrast.R:5:5): simple contrasts: no validity check ────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. ├─generics::tidy(marginaleffects(mod))
      2. └─marginaleffects::marginaleffects(mod)
      3.   └─marginaleffects:::get_dydx_and_se(...)
      4.     └─marginaleffects:::get_dydx(...)
      5.       └─marginaleffects:::dydx_fun(...)
      6.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      7.         └─numDeriv:::grad.default(...)
      8.           └─marginaleffects:::func(x + eps, ...)
      9.             ├─marginaleffects::get_predict(...)
     10.             └─marginaleffects:::get_predict.default(...)
     11.               ├─stats::predict(model, newdata = newdata, type = type)
     12.               └─stats::predict.lm(model, newdata = newdata, type = type)
     13.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                 └─stats::model.frame.default(...)
    ── Error (test-contrast.R:29:5): bug be dead: all levels appear ────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(...)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.lm(model, newdata = newdata, type = type)
     12.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     13.                 └─stats::model.frame.default(...)
    ── Error (test-counterfactual.R:12:5): marginal effects does not overwrite counterfactual rowid ──
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(...)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.glm(model, newdata = newdata, type = type)
     12.                 └─stats::predict.lm(...)
     13.                   ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                   └─stats::model.frame.default(...)
    ── Error (test-factor.R:6:5): factor before fitting or in formula is the same ──
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(mod1)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.lm(model, newdata = newdata, type = type)
     12.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     13.                 └─stats::model.frame.default(...)
    ── Error (test-missing.R:10:5): original data with NAs do not pose problems in glm and lm. ──
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(gear) has new levels 3.0001, 4.0001, 5.0001
    Backtrace:
         â–ˆ
      1. ├─testthat::expect_s3_class(tidy(marginaleffects(mod1)), "data.frame")
      2. │ └─testthat::quasi_label(enquo(object), arg = "object")
      3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
      4. ├─generics::tidy(marginaleffects(mod1))
      5. └─marginaleffects::marginaleffects(mod1)
      6.   └─marginaleffects:::get_dydx_and_se(...)
      7.     └─marginaleffects:::get_dydx(...)
      8.       └─marginaleffects:::dydx_fun(...)
      9.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
     10.         └─numDeriv:::grad.default(...)
     11.           └─marginaleffects:::func(x + eps, ...)
     12.             ├─marginaleffects::get_predict(...)
     13.             └─marginaleffects:::get_predict.default(...)
     14.               ├─stats::predict(model, newdata = newdata, type = type)
     15.               └─stats::predict.lm(model, newdata = newdata, type = type)
     16.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     17.                 └─stats::model.frame.default(...)
    ── Error (test-missing.R:16:5): newdata with NAs do not pose problems in lm. ───
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(gear) has new level 3.62962962962963
    Backtrace:
        â–ˆ
     1. └─marginaleffects::marginaleffects(...)
     2.   ├─marginaleffects::get_predict(...)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-pkg-MASS.R:23:5): glm.nb: marginaleffects: vs. margins ──────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(model)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.glm(model, newdata = newdata, type = type)
     12.                 └─stats::predict.lm(...)
     13.                   ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                   └─stats::model.frame.default(...)
    ── Error (test-pkg-MASS.R:32:5): glm.nb: marginaleffects: vs. Stata ────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. ├─base::merge(tidy(marginaleffects(model)), stata)
      2. ├─generics::tidy(marginaleffects(model))
      3. └─marginaleffects::marginaleffects(model)
      4.   └─marginaleffects:::get_dydx_and_se(...)
      5.     └─marginaleffects:::get_dydx(...)
      6.       └─marginaleffects:::dydx_fun(...)
      7.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      8.         └─numDeriv:::grad.default(...)
      9.           └─marginaleffects:::func(x + eps, ...)
     10.             ├─marginaleffects::get_predict(...)
     11.             └─marginaleffects:::get_predict.default(...)
     12.               ├─stats::predict(model, newdata = newdata, type = type)
     13.               └─stats::predict.glm(model, newdata = newdata, type = type)
     14.                 └─stats::predict.lm(...)
     15.                   ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     16.                   └─stats::model.frame.default(...)
    ── Error (test-pkg-MASS.R:56:5): polr: predictions: no validity ────────────────
    Error in `model.frame.default(Terms, newdata, na.action = function(x) x, 
        xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, type = "probs")
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.polr(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─MASS:::predict.polr(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(...)
     7.       └─stats::model.frame.default(...)
    ── Error (test-pkg-MASS.R:62:5): glm.nb: predictions: no validity ──────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(model)
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.glm(model, newdata = newdata, type = type)
     6.       └─stats::predict.lm(...)
     7.         ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     8.         └─stats::model.frame.default(...)
    ── Error (test-pkg-betareg.R:21:5): marginaleffects: vs. Stata ─────────────────
    Error in `model.frame.default(delete.response(object$terms[[tnam]]), newdata, 
        na.action = na.action, xlev = object$levels[[tnam]])`: factor factor(batch) has new levels 1.0001, 2.0001, 3.0001, 4.0001, 5.0001, 6.0001, 7.0001, 8.0001, 9.0001, 10.0001
    Backtrace:
         â–ˆ
      1. ├─base::merge(tidy(marginaleffects(mod)), stata)
      2. ├─generics::tidy(marginaleffects(mod))
      3. └─marginaleffects::marginaleffects(mod)
      4.   └─marginaleffects:::get_dydx_and_se(...)
      5.     └─marginaleffects:::get_dydx(...)
      6.       └─marginaleffects:::dydx_fun(...)
      7.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      8.         └─numDeriv:::grad.default(...)
      9.           └─marginaleffects:::func(x + eps, ...)
     10.             ├─marginaleffects::get_predict(...)
     11.             └─marginaleffects:::get_predict.default(...)
     12.               ├─stats::predict(model, newdata = newdata, type = type)
     13.               └─betareg:::predict.betareg(model, newdata = newdata, type = type)
     14.                 ├─stats::model.frame(...)
     15.                 └─stats::model.frame.default(...)
    ── Error (test-pkg-estimatr.R:22:5): lm_robust vs. stata ───────────────────────
    Error in `model.frame.default(rhs_terms, newdata, na.action = na.action, 
        xlev = object[["xlevels"]])`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. ├─generics::tidy(marginaleffects(model))
      2. └─marginaleffects::marginaleffects(model)
      3.   └─marginaleffects:::get_dydx_and_se(...)
      4.     └─marginaleffects:::get_dydx(...)
      5.       └─marginaleffects:::dydx_fun(...)
      6.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      7.         └─numDeriv:::grad.default(...)
      8.           └─marginaleffects:::func(x + eps, ...)
      9.             ├─marginaleffects::get_predict(...)
     10.             └─marginaleffects:::get_predict.default(...)
     11.               ├─stats::predict(model, newdata = newdata, type = type)
     12.               └─estimatr:::predict.lm_robust(model, newdata = newdata, type = type)
     13.                 └─estimatr:::get_X(object, newdata, na.action)
     14.                   ├─stats::model.frame(...)
     15.                   └─stats::model.frame.default(...)
    ── Failure (test-pkg-nnet.R:34:5): multinom vs. Stata ──────────────────────────
    mfx$estimate (`actual`) not equal to mfx$dydxstata (`expected`).

        actual     | expected      
    [1] -0.0327854 - NA         [1]
    [2] -0.0180934 - NA         [2]
    [3] NA         - -0.1471264 [3]
    [4] NA         - -0.1644309 [4]
    [5] 0.1538632  - 0.1538624  [5]
    [6] 0.1570683  - 0.1570671  [6]
    [7] 0.0260527  - 0.0260506  [7]
    [8] 0.0254591  - 0.0254577  [8]
    ── Failure (test-pkg-pscl.R:53:5): marginaleffects: zeroinfl: no validity ──────
    Class: predictions. Rows: 1. Columns: 8. type_col: TRUE. predicted_col: TRUE, se_col: TRUE
    ── Failure (test-pkg-pscl.R:54:5): marginaleffects: zeroinfl: no validity ──────
    Class: predictions. Rows: 6. Columns: 11. type_col: TRUE. predicted_col: TRUE, se_col: TRUE
    ── Error (test-pkg-quantreg.R:6:5): marginaleffects: rq: Stata ─────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects:::expect_marginaleffects(model)
      2.   └─marginaleffects::marginaleffects(object, type = type) testthat/helper-marginaleffects.R:13:2
      3.     └─marginaleffects:::get_dydx_and_se(...)
      4.       └─marginaleffects:::get_dydx(...)
      5.         └─marginaleffects:::dydx_fun(...)
      6.           ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      7.           └─numDeriv:::grad.default(...)
      8.             └─marginaleffects:::func(x + eps, ...)
      9.               ├─marginaleffects::get_predict(...)
     10.               └─marginaleffects:::get_predict.default(...)
     11.                 ├─stats::predict(model, newdata = newdata, type = type)
     12.                 └─quantreg::predict.rq(model, newdata = newdata, type = type)
     13.                   ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                   └─stats::model.frame.default(...)
    ── Failure (test-pkg-quantreg.R:16:5): predictions: rq: no validity ────────────
    Class: predictions. Rows: 32. Columns: 5. type_col: TRUE. predicted_col: TRUE, se_col: FALSE
    ── Error (test-predictions.R:10:5): insight > 0.14.1 allows us to support `type` ──
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
         â–ˆ
      1. ├─testthat::expect_warning(...)
      2. │ └─testthat:::expect_condition_matching(...)
      3. │   └─testthat:::quasi_capture(...)
      4. │     ├─testthat:::.capture(...)
      5. │     │ └─base::withCallingHandlers(...)
      6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
      7. └─marginaleffects::predictions(mod, type = "response")
      8.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
      9.   └─marginaleffects:::get_predict.default(...)
     10.     ├─stats::predict(model, newdata = newdata, type = type)
     11.     └─stats::predict.lm(model, newdata = newdata, type = type)
     12.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     13.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:29:9): conf.level argument changes width of interval ──
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, newdata = nd, conf.level = L)
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:56:5): `variables` arg: logical ───────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, variables = "am")
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:61:5): `variables` arg: numeric ───────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, variables = "wt")
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:73:5): `variables` arg: logical + numeric ─────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, variables = c("am", "wt"))
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:110:5): `typical`: all logical ────────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(...)
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-predictions.R:116:5): `typical`: missing logical ────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new level 6.1875
    Backtrace:
        â–ˆ
     1. └─marginaleffects::predictions(mod, newdata = typical(am = TRUE))
     2.   ├─marginaleffects::get_predict(model, newdata = newdata, type = predt)
     3.   └─marginaleffects:::get_predict.default(...)
     4.     ├─stats::predict(model, newdata = newdata, type = type)
     5.     └─stats::predict.lm(model, newdata = newdata, type = type)
     6.       ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     7.       └─stats::model.frame.default(...)
    ── Error (test-summary.R:7:5): simple summary output ───────────────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(mod)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.lm(model, newdata = newdata, type = type)
     12.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     13.                 └─stats::model.frame.default(...)
    ── Error (test-summary.R:15:5): summary conf.level ─────────────────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(mod)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.lm(model, newdata = newdata, type = type)
     12.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     13.                 └─stats::model.frame.default(...)
    ── Error (test-tidy.R:23:5): bug: emmeans contrast rename in binomial ──────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(cyl) has new levels 4.0001, 6.0001, 8.0001
    Backtrace:
         â–ˆ
      1. └─marginaleffects::marginaleffects(x)
      2.   └─marginaleffects:::get_dydx_and_se(...)
      3.     └─marginaleffects:::get_dydx(...)
      4.       └─marginaleffects:::dydx_fun(...)
      5.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      6.         └─numDeriv:::grad.default(...)
      7.           └─marginaleffects:::func(x + eps, ...)
      8.             ├─marginaleffects::get_predict(...)
      9.             └─marginaleffects:::get_predict.default(...)
     10.               ├─stats::predict(model, newdata = newdata, type = type)
     11.               └─stats::predict.glm(model, newdata = newdata, type = type)
     12.                 └─stats::predict.lm(...)
     13.                   ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                   └─stats::model.frame.default(...)
    ── Error (test-tidy.R:44:5): tidy: with and without contrasts ──────────────────
    Error in `model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels)`: factor factor(gear) has new levels 3.0001, 4.0001, 5.0001
    Backtrace:
         â–ˆ
      1. ├─generics::tidy(marginaleffects(model))
      2. └─marginaleffects::marginaleffects(model)
      3.   └─marginaleffects:::get_dydx_and_se(...)
      4.     └─marginaleffects:::get_dydx(...)
      5.       └─marginaleffects:::dydx_fun(...)
      6.         ├─numDeriv::grad(func = inner, x = fitfram[[variable]], method = numDeriv_method)
      7.         └─numDeriv:::grad.default(...)
      8.           └─marginaleffects:::func(x + eps, ...)
      9.             ├─marginaleffects::get_predict(...)
     10.             └─marginaleffects:::get_predict.default(...)
     11.               ├─stats::predict(model, newdata = newdata, type = type)
     12.               └─stats::predict.lm(model, newdata = newdata, type = type)
     13.                 ├─stats::model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels)
     14.                 └─stats::model.frame.default(...)
    ── Failure (test-typical.R:29:5): errors and warnings ──────────────────────────
    `typical(model = mod, cyl = "2")` did not throw the expected error.
    Backtrace:
        â–ˆ
     1. └─testthat::expect_error(typical(model = mod, cyl = "2"), regexp = "must be one of the factor levels")
     2.   └─testthat:::expect_condition_matching(...)

    [ FAIL 29 | WARN 1 | SKIP 13 | PASS 294 ]
    Error: Test failures
    Execution halted
strengejacke commented 2 years ago

I think this is due to https://github.com/easystats/insight/issues/469.

vincentarelbundock commented 2 years ago

I think this is due to easystats/insight#469.

Correct.

I have already updated marginaleffects on Github and tested it against the Github version of insight. It's only a matter of releasing the new version of marginaleffects, which I plan to do shortly after insight hits CRAN.

Thanks a lot for checking in about this potential issue. I really appreciate it.

strengejacke commented 2 years ago

Are there any urgent or nice-to-have issues related to insight::get_predicted() that we might resolve before submitting a new CRAN version, or can it wait until the next release (after this planned release) of insight?

vincentarelbundock commented 2 years ago

The only two issues that I hoped to address eventually are:

Neither seems particularly urgent.