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 #357

Merged
merged 11 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
^CRAN-SUBMISSION$
\.code-workspace$
^\.lintr$
^tests/testthat/_snaps/.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: modelbased
Title: Estimation of Model-Based Predictions, Contrasts and Means
Version: 0.8.9.42
Version: 0.9.0
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down Expand Up @@ -89,4 +89,3 @@ Config/testthat/parallel: true
Roxygen: list(markdown = TRUE)
Config/Needs/check: stan-dev/cmdstanr
Config/Needs/website: easystats/easystatstemplate
Remotes: vincentarelbundock/marginaleffects
2 changes: 1 addition & 1 deletion R/estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#' # By default: selects first factor
#' estimate_contrasts(model)
#'
#' # Can also run contrasts between points of numeric
#' # Can also run contrasts between points of numeric, stratified by "Species"
#' estimate_contrasts(model, contrast = "Petal.Width", by = "Species", length = 4)
#'
#' # Or both
Expand Down
16 changes: 8 additions & 8 deletions R/estimate_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@
#' which computes a kind of "weighted average" for the values at which these
#' terms are hold constant. These predictions are a good representation of the
#' sample, because all possible values and levels of the non-focal predictors
#' are taken into account. It answers the question, "What is the predicted
#' value for an 'average' observation in *my data*?". It refers to randomly
#' picking a subject of your sample and the result you get on average. This
#' approach is the one taken by default in the `emmeans` package.
#' are considered. It answers the question, "What is the predicted value for
#' an 'average' observation in *my data*?". It refers to randomly picking a
#' subject of your sample and the result you get on average. This approach is
#' the one taken by default in the `emmeans` package.
#' - `"population"`: Non-focal predictors are marginalized over the observations
#' in the sample, where the sample is replicated multiple times to produce
#' "counterfactuals" and then takes the average of these predicted values
#' (aggregated/grouped by the focal terms). It can be considered as
#' extrapolation to a hypothetical target population. Counterfactual
#' predictions are useful, insofar as the results can also be transferred to
#' other contexts (Dickerman and Hernan, 2020). It answers the question, "What
#' is the predicted for the 'average' observation in *the broader target
#' population*?". It does not only refer to the actual data in your observed
#' sample, but also "what would be if" we had more data, or if we had data
#' from a different sample.
#' is the predicted response value for the 'average' observation in *the
#' broader target population*?". It does not only refer to the actual data in
#' your observed sample, but also "what would be if" we had more data, or if
#' we had data from a different sample.
#'
#' In other words, the distinction between marginalization types resides in whether
#' the prediction are made for:
Expand Down
18 changes: 9 additions & 9 deletions man/estimate_contrasts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions man/estimate_means.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions man/get_emmeans.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/testthat/test-attributes_estimatefun.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## TODO: skip for marginaleffects 0.24.0?

skip_if_not_installed("emmeans")
skip_if_not_installed("marginaleffects")

Expand Down Expand Up @@ -55,6 +53,7 @@ test_that("attributes_means, contrasts", {


test_that("attributes_means, slopes", {
skip_if_not_installed("marginaleffects", minimum_version = "0.24.1")
data(iris)
model <- lm(Sepal.Length ~ Species + Sepal.Width, data = iris)

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-brms.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
skip_on_cran()
skip_on_os("windows")
skip_if_not_installed("brms")
skip_if_not_installed("BH")
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
estim <- suppressMessages(estimate_contrasts(model, by = "Species=c('versicolor', 'virginica')", backend = "emmeans"))
expect_identical(dim(estim), c(1L, 9L))

estim <- suppressMessages(estimate_contrasts(model, contrast = "Species=c('versicolor', 'virginica')", backend = "marginaleffects"))

Check warning on line 25 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=25,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 134 characters.
expect_identical(dim(estim), c(1L, 9L))

# Two factors
Expand All @@ -40,7 +40,7 @@
expect_identical(dim(estim), c(3L, 10L))
estim <- suppressMessages(estimate_contrasts(model, contrast = "Species", backend = "marginaleffects"))
expect_identical(dim(estim), c(3L, 9L))
estim <- suppressMessages(estimate_contrasts(model, contrast = "Species", by = "fac='A'", backend = "marginaleffects"))

Check warning on line 43 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=43,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.
expect_identical(dim(estim), c(3L, 9L))

# One factor and one continuous
Expand Down Expand Up @@ -83,7 +83,7 @@
## FIXME: doesn't work right nw
# estim <- suppressMessages(estimate_contrasts(model, by = "all", backend = "marginaleffects"))
# expect_identical(dim(estim), c(12L, 11L))
estim <- suppressMessages(estimate_contrasts(model, contrast = c("vs", "am"), by = "gear='5'", backend = "marginaleffects"))

Check warning on line 86 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=86,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 126 characters.
expect_identical(dim(estim), c(6L, 9L))
expect_named(estim, c("Level1", "Level2", "Difference", "SE", "CI_low", "CI_high", "t", "df", "p"))
expect_equal(estim$Difference, c(-6.98333, -11.275, -18.25833, -4.29167, -11.275, -6.98333), tolerance = 1e-4)
Expand All @@ -107,11 +107,11 @@

model <- lm(Petal.Width ~ factor1 * factor2 * factor3, data = dat)

estim <- suppressMessages(estimate_contrasts(model, contrast = c("factor1", "factor2", "factor3"), by = "all", backend = "emmeans"))

Check warning on line 110 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=110,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 134 characters.
expect_identical(dim(estim), c(28L, 9L))
estim <- suppressMessages(estimate_contrasts(model, contrast = c("factor1", "factor2"), by = "factor3='F'", backend = "emmeans"))

Check warning on line 112 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=112,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
expect_identical(dim(estim), c(6L, 10L))
estim <- suppressMessages(estimate_contrasts(model, contrast = c("factor1", "factor2"), by = "factor3", backend = "emmeans"))

Check warning on line 114 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=114,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
expect_identical(dim(estim), c(12L, 10L))


Expand Down Expand Up @@ -155,6 +155,7 @@


test_that("estimate_contrasts - Bayesian", {
skip_on_cran()
skip_if_not_installed("logspline")
skip_if_not_installed("rstanarm")
skip_if_not_installed("lme4")
Expand All @@ -178,7 +179,7 @@
)
estim <- suppressMessages(estimate_contrasts(model, contrast = "all", backend = "emmeans"))
expect_identical(dim(estim), c(15L, 7L))
estim <- suppressMessages(estimate_contrasts(model, by = c("Species", "Petal.Length_factor='A'"), backend = "emmeans"))

Check warning on line 182 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=182,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.
expect_identical(dim(estim), c(3L, 8L))
estim <- estimate_contrasts(model, contrast = c("Species", "Petal.Length_factor"), backend = "marginaleffects")
expect_identical(dim(estim), c(15L, 10L))
Expand Down Expand Up @@ -234,7 +235,7 @@

estim <- suppressWarnings(suppressMessages(estimate_contrasts(model, test = "bf", backend = "emmeans")))
expect_identical(dim(estim), c(3L, 6L))
estim <- suppressWarnings(suppressMessages(estimate_contrasts(model, predict = "link", test = "bf", backend = "emmeans")))

Check warning on line 238 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=238,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
expect_identical(dim(estim), c(3L, 6L))
})

Expand All @@ -254,6 +255,7 @@


test_that("estimate_contrasts - dfs", {
skip_on_cran()
skip_if_not_installed("lme4")
skip_if_not_installed("pbkrtest")
skip_if_not_installed("lmerTest")
Expand All @@ -263,8 +265,8 @@
data$Petal.Length_factor <- ifelse(data$Petal.Length < 4.2, "A", "B")
model <- lme4::lmer(Sepal.Width ~ Species + (1 | Petal.Length_factor), data = data)

estim1 <- suppressMessages(estimate_contrasts(model, lmer.df = "satterthwaite", p_adjust = "holm", backend = "emmeans"))

Check warning on line 268 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=268,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.
estim2 <- suppressMessages(estimate_contrasts(model, lmer.df = "kenward-roger", p_adjust = "holm", backend = "emmeans"))

Check warning on line 269 in tests/testthat/test-estimate_contrasts.R

View workflow job for this annotation

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

file=tests/testthat/test-estimate_contrasts.R,line=269,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.

expect_true(all(estim1$CI_low != estim2$CI_low))
expect_equal(estim1$CI_low, c(-2.43, -2.25692, -2.89384), tolerance = 1e-4)
Expand All @@ -280,7 +282,7 @@


test_that("estimate_contrasts - marginaleffects", {
## TODO: skip for marginaleffects 0.24.0?
# ignore failing snapshot tests, should resolve with next marginaleffects version
skip_if_not_installed("Formula")
skip_if_not_installed("ggeffects")
data(coffee_data, package = "ggeffects")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-estimate_means_mixed.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
skip_on_cran()
skip_if_not_installed("emmeans")
skip_if_not_installed("marginaleffects")

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-glmmTMB.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
skip_on_cran()
skip_if_not_installed("glmmTMB")
skip_if_not_installed("emmeans")
skip_if_not_installed("marginaleffects")
Expand Down
Loading