Skip to content

Commit

Permalink
Merge branch 'main' into flint
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Dec 11, 2024
2 parents bbfcc75 + cc1f461 commit 7835eb4
Show file tree
Hide file tree
Showing 34 changed files with 201 additions and 706 deletions.
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: marginaleffects
Title: Predictions, Comparisons, Slopes, Marginal Means, and Hypothesis Tests
Version: 0.24.0.4
Authors@R:
Version: 0.24.0.6
Authors@R:
c(person(given = "Vincent",
family = "Arel-Bundock",
role = c("aut", "cre", "cph"),
Expand Down Expand Up @@ -34,9 +34,9 @@ URL: https://marginaleffects.com/
BugReports: https://github.com/vincentarelbundock/marginaleffects/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Depends:
Depends:
R (>= 3.6.0)
Imports:
Imports:
checkmate,
data.table (>= 1.16.2),
generics,
Expand All @@ -47,7 +47,7 @@ Imports:
Enhances:
knitr
LinkingTo: Rcpp, RcppEigen
Suggests:
Suggests:
AER,
Amelia,
afex,
Expand Down Expand Up @@ -123,6 +123,7 @@ Suggests:
mlr3verse,
modelbased,
modelsummary,
multcomp,
nlme,
nnet,
numDeriv,
Expand Down Expand Up @@ -185,7 +186,7 @@ Suggests:
xgboost,
testthat (>= 3.0.0),
altdoc
Collate:
Collate:
'RcppExports.R'
'backtransform.R'
'bootstrap_boot.R'
Expand All @@ -200,7 +201,6 @@ Collate:
'config.R'
'conformal.R'
'datagrid.R'
'deprecated.R'
'equivalence.R'
'get_coef.R'
'get_contrast_data.R'
Expand Down Expand Up @@ -278,6 +278,7 @@ Collate:
'methods_tidymodels.R'
'methods_tobit1.R'
'modelarchive.R'
'multcomp.R'
'myTryCatch.R'
'package.R'
'plot.R'
Expand Down
9 changes: 3 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ S3method(coef,hypotheses)
S3method(coef,marginalmeans)
S3method(coef,predictions)
S3method(coef,slopes)
S3method(df.residual,comparisons)
S3method(df.residual,predictions)
S3method(df.residual,slopes)
S3method(get_coef,afex_aov)
S3method(get_coef,betareg)
S3method(get_coef,bracl)
Expand Down Expand Up @@ -192,8 +195,6 @@ export(avg_predictions)
export(avg_slopes)
export(comparisons)
export(datagrid)
export(datagridcf)
export(deltamethod)
export(expect_margins)
export(expect_predictions)
export(expect_slopes)
Expand All @@ -206,10 +207,6 @@ export(get_vcov)
export(glance)
export(hypotheses)
export(inferences)
export(marginal_means)
export(marginaleffects)
export(marginalmeans)
export(meffects)
export(plot_comparisons)
export(plot_predictions)
export(plot_slopes)
Expand Down
55 changes: 33 additions & 22 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@

## Development

* Version 0.24.0 accidentally removed the "contrast" column from the output object in calls with only one focal predictor. This column is reinstated.
* Reinstate some attributes lost with `marginaleffects_lean` but necessary for printing.
Breaking changes:

* The default `type` is now "survival" for models of class `coxph`, `flexsurvreg`, and `coxph_weightit`.
* `p_adjust` argument deprecated because of name-matching conflict with `p` argument in quantile regression and others. The recommended workflow is now to pass the object to the `hypotheses()` function and use its `multcomp` argument.
* Removed long deprecated functions from the code base. These functions were already raising errors: `marginaleffects`, `meffects`, `marginal_means`, `deltamethod`, `datagridcf`.

New:

* New `multcomp` argument for the `hypotheses()` function.
* `hypotheses()` inherits the `conf_level` from `marginaleffects` objects when available. Otherwise, the default remains 0.95.
* More informative warning for `lme4` and `glmmTMB` models with `re.form=NULL`
* `df.residual()` methods tries to call `stats::df.residual()` on the "model" attribute. If that fails or returns `NULL`, we return `Inf`.

Bugs:

* Version 0.24.0 accidentally removed the "contrast" column from the output object in calls with only one focal predictor. This column is reinstated.
* Reinstate some attributes lost with `marginaleffects_lean` but necessary for printing.
* Encoding issue in bayesian models with `by`. Thanks to @Koalha for report #1290.
* Retain necessary attribute information to ensure that "lean" return objects still print correctly #1295.
* Retain necessary attribute information to ensure that "lean" return objects still print correctly #1295.

## 0.24.0

Breaking change:

* Rows are now sorted when using the `by` argument. This may change the order of estimates, which can affect hypothesis tests using positional indices like `b1-b2=0`.
* Rows are now sorted when using the `by` argument. This may change the order of estimates, which can affect hypothesis tests using positional indices like `b1-b2=0`.

Bugs:

Expand All @@ -24,7 +35,7 @@ Bugs:

New features:

* Users can reduce the size of `marginaleffects` objects by setting the new global option `options(marginaleffects_lean = TRUE)`. This will strip the return objects of all information about the original model and data, as well ancillary attributes. The benefit of dramatically smaller return objects comes at the cost of not being able to run some post-processing inference functions like `hypotheses()` on these lean objects. Thanks to @grantmcdermott for the suggestion and code contribution #1267.
* Users can reduce the size of `marginaleffects` objects by setting the new global option `options(marginaleffects_lean = TRUE)`. This will strip the return objects of all information about the original model and data, as well ancillary attributes. The benefit of dramatically smaller return objects comes at the cost of not being able to run some post-processing inference functions like `hypotheses()` on these lean objects. Thanks to @grantmcdermott for the suggestion and code contribution #1267.

Misc:

Expand Down Expand Up @@ -146,7 +157,7 @@ New modeling packages supported:

New:

* `wts=TRUE` tries to retrieves weights used in a weighted fit such as `lm()` with the `weights` argument or a model fitted using the `survey` package. Thanks to @ngreifer for feature request
* `wts=TRUE` tries to retrieves weights used in a weighted fit such as `lm()` with the `weights` argument or a model fitted using the `survey` package. Thanks to @ngreifer for feature request
* `print.marginaleffects()` supports `style="tinytable"`, which returns a `tinytable` object. Call `print(avg_slopes(model))` to get a nice printed table in Quarto or Rmarkdown documents, via Typst, LaTeX or HTML. Default print format can be set using: `options(marginaleffects_print_style="tinytable")`
* `hypothesis` argument accepts a function which takes a `marginaleffects` data frame and returns a transformed data frame with `term` and `estimate` columns.
* `datagrid()` gets a `response` argument (default is `FALSE`) to control if the response variable is included or excluded from the grid-building process.
Expand Down Expand Up @@ -197,7 +208,7 @@ Minor:

Bug fixes:

* Error on `hypotheses(joint = "string")` for `comparisons()` objects (no result was returned). Thanks to @BorgeJorge for report #981.
* Error on `hypotheses(joint = "string")` for `comparisons()` objects (no result was returned). Thanks to @BorgeJorge for report #981.
* Enhanced support for multi-equation Bayesian models with `brms` models. Thanks to @winterstat for report #1006.
* Parameter names with spaces could break standard errors. Thanks to @Lefty2021 for report #1005.

Expand Down Expand Up @@ -239,7 +250,7 @@ Machine learning support:
Misc:

* New vignettes:
- Inverse Probability Weighting
- Inverse Probability Weighting
- Machine Learning
- Matching
* Add support for `hypotheses()` to `inferences()`. Thanks to @Tristan-Siegfried for code contribution #908.
Expand Down Expand Up @@ -421,14 +432,14 @@ Renamed arguments (backward compatibility is preserved):

New:

* `p_adjust` argument: Adjust p-values for multiple comparisons.
* `p_adjust` argument: Adjust p-values for multiple comparisons.
* `equivalence` argument available everywhere.

Performance:

* Much faster results in `avg_*()` functions for models with only categorical predictors and many rows of data, using deduplication and weights instead of unit-level estimates.
* Faster predictions in `lm()` and `glm()` models using `RcppEigen`.
* Bayesian models with many rows. Thanks to Etienne Bacher. #694
* Bayesian models with many rows. Thanks to Etienne Bacher. #694
* Faster predictions, especially with standard errors and large datasets.

Bugs:
Expand Down Expand Up @@ -524,9 +535,9 @@ New features:

Renamed functions (backward-compatibility is maintained by keeping the old function names as aliases):

* `marginaleffects()` -> `slopes()`
* `posteriordraws()` -> `posterior_draws()`
* `marginalmeans()` -> `marginal_means()`
* `marginaleffects()` -> `slopes()`
* `posteriordraws()` -> `posterior_draws()`
* `marginalmeans()` -> `marginal_means()`
* `plot_cap()` -> `plot_predictions()`
* `plot_cme()` -> `plot_slopes()`
* `plot_cco()` -> `plot_comparisons()`
Expand Down Expand Up @@ -597,7 +608,7 @@ Bug fixes and minor improvements:

* New supported model class: `gamlss`. Thanks to Marcio Augusto Diniz.
* `marginalmeans()` accepts a `wts` argument with values: "equal", "proportional", "cells".
* `by` argument
* `by` argument
- accepts data frames for complex groupings.
- in `marginalmeans` only accepts data frames.
- accepts "group" to group by response level.
Expand All @@ -609,7 +620,7 @@ Bug fixes and minor improvements:
- new shortcuts "revpairwise", "revsequential", "revreference"
* `wts` argument is respected in `by` argument and with `*avg` shortcuts in the `transform_pre` argument.
* `tidy.predictions()` and `tidy.marginalmeans()` get a new `transform_avg` argument.
* New vignettes:
* New vignettes:
- Unit-level contrasts in logistic regressions. Thanks to @arthur-albuquerque.
- Python Numpy models in `marginaleffects`. Thanks to timpipeseek.
- Bootstrap example in standard errors vignette.
Expand All @@ -623,7 +634,7 @@ Breaking changes:

Critical bug fix:

* Contrasts with interactions were incorrect in version 0.6.0. The error should have been obvious to most analysts in most cases (weird-looking alignment). Thanks to @vmikk.
* Contrasts with interactions were incorrect in version 0.6.0. The error should have been obvious to most analysts in most cases (weird-looking alignment). Thanks to @vmikk.

New supported packages and models:

Expand Down Expand Up @@ -693,7 +704,7 @@ Breaking changes:
* `type` no longer accepts a character vector. Must be a single string.
* `conf.int` argument deprecated. Use `vcov = FALSE` instead.

New supported packages and models:
New supported packages and models:

* `mlogit`
* `mhurdle`
Expand Down Expand Up @@ -735,23 +746,23 @@ New pages on the `marginaleffects` website: https://marginaleffects.com/
Argument name changes (backward compatibility is preserved:

* Everywhere:
- `conf.level` -> `conf_level`
- `conf.level` -> `conf_level`
* `datagrid()`:
- `FUN.factor` -> `FUN_factor` (same for related arguments)
- `grid.type` -> `grid_type`

## 0.4.1

New supported packages and models:
New supported packages and models:

* `stats::loess`
* `sampleSelection::selection`
* `sampleSelection::heckit`

Misc:

* `mgcv::bam` models allow `exclude` argument.
* Gam models allow `include_smooth` argument.
* `mgcv::bam` models allow `exclude` argument.
* Gam models allow `include_smooth` argument.
* New tests
* Bug fixes

Expand Down Expand Up @@ -783,7 +794,7 @@ New supported models:

Misc:

* Support `modelbased::visualisation_matrix` in `newdata` without having to specify `x` explicitly.
* Support `modelbased::visualisation_matrix` in `newdata` without having to specify `x` explicitly.
* `tidy.predictions()` and `summary.predictions()` methods.
* Documentation improvements.
* CRAN test fixes
Expand Down
8 changes: 1 addition & 7 deletions R/ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ get_ci <- function(
draws = NULL,
vcov = TRUE,
null_hypothesis = 0,
p_adjust = NULL,
model = NULL,
...) {

Expand Down Expand Up @@ -61,8 +60,7 @@ get_ci <- function(
p_overwrite

ci_overwrite <- !"conf.low" %in% colnames(x) &&
"std.error" %in% colnames(x) &&
is.null(p_adjust)
"std.error" %in% colnames(x)

if (z_overwrite) {
x[["statistic"]] <- (x[["estimate"]] - null_hypothesis) / x[["std.error"]]
Expand All @@ -83,10 +81,6 @@ get_ci <- function(
x[["conf.low"]] <- x[["estimate"]] - critical * x[["std.error"]]
x[["conf.high"]] <- x[["estimate"]] + critical * x[["std.error"]]
}

if (!is.null(p_adjust) && "p.value" %in% colnames(x)) {
x$p.value <- stats::p.adjust(x$p.value, method = p_adjust)
}

# s-value
if ("p.value" %in% colnames(x)) {
Expand Down
6 changes: 0 additions & 6 deletions R/comparisons.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ comparisons <- function(model,
wts = FALSE,
hypothesis = NULL,
equivalence = NULL,
p_adjust = NULL,
df = Inf,
eps = NULL,
numderiv = "fdforward",
Expand Down Expand Up @@ -287,7 +286,6 @@ comparisons <- function(model,
wts = wts,
hypothesis = hypothesis,
equivalence = equivalence,
p_adjust = p_adjust,
df = df),
dots)
if ("modeldata" %in% names(dots)) {
Expand All @@ -305,7 +303,6 @@ comparisons <- function(model,
conf_level <- sanitize_conf_level(conf_level, ...)
checkmate::assert_number(eps, lower = 1e-10, null.ok = TRUE)
numderiv <- sanitize_numderiv(numderiv)
sanity_equivalence_p_adjust(equivalence, p_adjust)
model <- sanitize_model(
model = model,
newdata = newdata,
Expand Down Expand Up @@ -511,7 +508,6 @@ comparisons <- function(model,
draws = draws,
estimate = "estimate",
null_hypothesis = hypothesis_null,
p_adjust = p_adjust,
model = model)

# clean rows and columns
Expand Down Expand Up @@ -603,7 +599,6 @@ avg_comparisons <- function(model,
wts = FALSE,
hypothesis = NULL,
equivalence = NULL,
p_adjust = NULL,
df = Inf,
eps = NULL,
numderiv = "fdforward",
Expand Down Expand Up @@ -638,7 +633,6 @@ avg_comparisons <- function(model,
wts = wts,
hypothesis = hypothesis,
equivalence = equivalence,
p_adjust = p_adjust,
df = df,
eps = eps,
...)
Expand Down
Loading

0 comments on commit 7835eb4

Please sign in to comment.