Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare CRAN submission #691

Merged
merged 6 commits into from
Jan 17, 2025
Merged

Prepare CRAN submission #691

merged 6 commits into from
Jan 17, 2025

Conversation

strengejacke
Copy link
Member

@strengejacke strengejacke commented Jan 13, 2025

No description provided.

@DominiqueMakowski
Copy link
Member

should I submit?

@strengejacke
Copy link
Member Author

Let me try to fix failing tests first. Might be because we do no longer import marginaleffects from GitHub (no Remotes field), so we might skip some tests

@strengejacke
Copy link
Member Author

strengejacke commented Jan 16, 2025

@mattansb Do you know what's going on here, why this test suddenly fails?

    data("mtcars")
    mtcars$cyl <- factor(mtcars$cyl)
    mod <- rstanarm::stan_glm(mpg ~ cyl + hp * am, data = mtcars, refresh = 0)

    mfx <- marginaleffects::avg_slopes(mod, by = "am")
    mfx_samps <- as.data.frame(t(attr(mfx, "posterior_draws")))

    res <- hdi(mfx, ci = c(0.8, 0.9))
    expect_identical(
      as.data.frame(res[1:3]),
      data.frame(
        term = c(
          "am", "am", "am", "am", "cyl", "cyl",
          "cyl", "cyl", "cyl", "cyl", "cyl", "cyl",
          "hp", "hp", "hp", "hp"
        ),
        contrast = c(
          "1 - 0", "1 - 0", "1 - 0", "1 - 0",
          "6 - 4", "6 - 4", "8 - 4", "8 - 4",
          "6 - 4", "6 - 4", "8 - 4", "8 - 4",
          "dY/dX", "dY/dX", "dY/dX", "dY/dX"
        ),
        am = c(
          0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,
          1, 1
        ), stringsAsFactors = FALSE
      )
    )

Failing tests:


══ Failed tests ════════════════════════════════════════════════════════════════
── Failure ('test-marginaleffects.R:36:5'): marginaleffects descrive_posterior ──
as.data.frame(res[1:3]) (`actual`) not identical to data.frame(...) (`expected`).

`names(actual)`:   "term" "contrast" "CI"
`names(expected)`: "term" "contrast" "am"

`actual$CI` is a double vector (0.8, 0.9, 0.8, 0.9, 0.8, ...)
`expected$CI` is absent

`actual$am` is absent
`expected$am` is a double vector (0, 0, 1, 1, 0, ...)
── Failure ('test-marginaleffects.R:93:5'): marginaleffects bayesfactors ───────
all(c("term", "contrast", "am") %in% colnames(outsi)) is not TRUE

`actual`:   FALSE
`expected`: TRUE 

Output hdi()
image

Output marginaleffects
image

The am column is obviously missing?

@mattansb
Copy link
Member

Something is wrong - the am column should appear, as it does in insight::get_datagrid()

data("mtcars")
mtcars$cyl <- factor(mtcars$cyl)
mod <- rstanarm::stan_glm(mpg ~ cyl + hp * am, data = mtcars, refresh = 0)

mfx <- marginaleffects::avg_slopes(mod, by = "am")

insight::get_datagrid(mfx)
#>   term contrast am
#> 1   am    1 - 0  0
#> 2   am    1 - 0  1
#> 3  cyl    6 - 4  0
#> 4  cyl    8 - 4  0
#> 5  cyl    6 - 4  1
#> 6  cyl    8 - 4  1
#> 7   hp    dY/dX  0
#> 8   hp    dY/dX  1

When I run it, I do get all columns:

bayestestR::hdi(mfx, ci = c(0.8, 0.9))
#> Highest Density Interval
#> 
#> term | contrast |   am |        80% HDI |        90% HDI
#> --------------------------------------------------------
#> am   |    1 - 0 | 0.00 | [ 2.51,  6.27] | [ 1.93,  6.77]
#> am   |    1 - 0 | 1.00 | [ 2.63,  6.10] | [ 1.97,  6.40]
#> cyl  |    6 - 4 | 0.00 | [-5.95, -1.89] | [-6.55, -1.21]
#> cyl  |    8 - 4 | 0.00 | [-7.33,  0.00] | [-8.13,  1.29]
#> cyl  |    6 - 4 | 1.00 | [-5.95, -1.89] | [-6.55, -1.21]
#> cyl  |    8 - 4 | 1.00 | [-7.33,  0.00] | [-8.13,  1.29]
#> hp   |    dY/dX | 0.00 | [-0.08, -0.02] | [-0.08, -0.01]
#> hp   |    dY/dX | 1.00 | [-0.06, -0.02] | [-0.07, -0.02]

@mattansb
Copy link
Member

Something is wrong here - the tested code you posted does not match the output or the failed test...

@strengejacke
Copy link
Member Author

Are you using the dev-version of {marginaleffects}?

@strengejacke
Copy link
Member Author

Ok, this works only with the dev version of marginaleffects, not the CRAN version. I updated the test to skip if package version is 0.24.0 or lower. If checks pass, we can submit @DominiqueMakowski

@mattansb
Copy link
Member

Ah, I see. I thought this was already on CRAN. Oops.

@strengejacke
Copy link
Member Author

@DominiqueMakowski please submit.

@strengejacke
Copy link
Member Author

Remember to pull the latest changes from here ;-)
Btw, we inherit some of the docs from insight, which is not always focused on Bayesian models. You may want to change the docs for the component argument (add own description), instead of inheriting from insight.

@DominiqueMakowski
Copy link
Member

submitted

@DominiqueMakowski
Copy link
Member

on its way to CRAN.

@strengejacke strengejacke merged commit fb746e3 into main Jan 17, 2025
17 of 22 checks passed
@strengejacke strengejacke deleted the rc_0_15_1 branch January 17, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants