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

Fix issues with forthcoming {marginaleffects} #363

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

strengejacke
Copy link
Member

@strengejacke strengejacke commented Jan 22, 2025

data(iris)
model <- lm(Sepal.Width ~ Species, data = iris)
modelbased::estimate_contrasts(model, backend = "marginaleffects", comparison = "pairwise")
#> We selected `contrast=c("Species")`.
#> Error: Assertion failed. One of the following must apply:
#>  * checkmate::check_character(hypothesis): Must comply to pattern '='
#>  * checkmate::check_numeric(hypothesis): Must be of type 'numeric', not
#>  * 'character'
#>  * checkmate::check_formula(hypothesis): Must be a formula, not
#>  * character
#>  * checkmate::check_matrix(hypothesis): Must be of type 'matrix', not
#>  * 'character'
#>  * checkmate::check_function(hypothesis): Must be a function, not
#>  * 'character'
#>  * checkmate::check_null(hypothesis): Must be NULL
marginaleffects::avg_predictions(model, by = "Species", hypothesis = "pairwise")
#> Error: Assertion failed. One of the following must apply:
#>  * checkmate::check_character(hypothesis): Must comply to pattern '='
#>  * checkmate::check_numeric(hypothesis): Must be of type 'numeric', not
#>  * 'character'
#>  * checkmate::check_formula(hypothesis): Must be a formula, not
#>  * character
#>  * checkmate::check_matrix(hypothesis): Must be of type 'matrix', not
#>  * 'character'
#>  * checkmate::check_function(hypothesis): Must be a function, not
#>  * 'character'
#>  * checkmate::check_null(hypothesis): Must be NULL

modelbased::estimate_contrasts(model, backend = "marginaleffects", comparison = ~pairwise)
#> We selected `contrast=c("Species")`.
#> Marginal Contrasts Analysis
#> 
#> hypothesis             | Difference |   SE |         95% CI | t(147) |      p
#> -----------------------------------------------------------------------------
#> versicolor - setosa    |      -0.66 | 0.07 | [-0.79, -0.52] |  -9.69 | < .001
#> virginica - setosa     |      -0.45 | 0.07 | [-0.59, -0.32] |  -6.68 | < .001
#> setosa - versicolor    |       0.66 | 0.07 | [ 0.52,  0.79] |   9.69 | < .001
#> virginica - versicolor |       0.20 | 0.07 | [ 0.07,  0.34] |   3.00 |  0.003
#> setosa - virginica     |       0.45 | 0.07 | [ 0.32,  0.59] |   6.68 | < .001
#> versicolor - virginica |      -0.20 | 0.07 | [-0.34, -0.07] |  -3.00 |  0.003
#> 
#> Variable predicted: Sepal.Width
#> Predictors contrasted: Species
#> p-values are uncorrected.
marginaleffects::avg_predictions(model, by = "Species", hypothesis = ~pairwise)
#> 
#>              Hypothesis Estimate Std. Error     z Pr(>|z|)    S   2.5 %  97.5 %
#>  versicolor - setosa      -0.658     0.0679 -9.69  < 0.001 71.3 -0.7912 -0.5248
#>  virginica - setosa       -0.454     0.0679 -6.68  < 0.001 35.3 -0.5872 -0.3208
#>  setosa - versicolor       0.658     0.0679  9.69  < 0.001 71.3  0.5248  0.7912
#>  virginica - versicolor    0.204     0.0679  3.00  0.00268  8.5  0.0708  0.3372
#>  setosa - virginica        0.454     0.0679  6.68  < 0.001 35.3  0.3208  0.5872
#>  versicolor - virginica   -0.204     0.0679 -3.00  0.00268  8.5 -0.3372 -0.0708
#> 
#> Type:  response

Created on 2025-01-23 with reprex v2.1.1

@strengejacke strengejacke changed the title Just for testing purposes, if latest changes in marginaleffects work Fix issues with forthcoming {marginaleffects} Jan 23, 2025
@strengejacke
Copy link
Member Author

Seems to work now, let's wait for the checks:

data(iris)
model <- lm(Sepal.Width ~ Species, data = iris)
modelbased::estimate_contrasts(model, backend = "marginaleffects", comparison = "pairwise")
#> We selected `contrast=c("Species")`.
#> Marginal Contrasts Analysis
#> 
#> hypothesis             | Difference |   SE |         95% CI | t(147) |      p
#> -----------------------------------------------------------------------------
#> versicolor - setosa    |      -0.66 | 0.07 | [-0.79, -0.52] |  -9.69 | < .001
#> virginica - setosa     |      -0.45 | 0.07 | [-0.59, -0.32] |  -6.68 | < .001
#> setosa - versicolor    |       0.66 | 0.07 | [ 0.52,  0.79] |   9.69 | < .001
#> virginica - versicolor |       0.20 | 0.07 | [ 0.07,  0.34] |   3.00 |  0.003
#> setosa - virginica     |       0.45 | 0.07 | [ 0.32,  0.59] |   6.68 | < .001
#> versicolor - virginica |      -0.20 | 0.07 | [-0.34, -0.07] |  -3.00 |  0.003
#> 
#> Variable predicted: Sepal.Width
#> Predictors contrasted: Species
#> p-values are uncorrected.
modelbased::estimate_contrasts(model, backend = "marginaleffects", comparison = ~pairwise)
#> We selected `contrast=c("Species")`.
#> Marginal Contrasts Analysis
#> 
#> hypothesis             | Difference |   SE |         95% CI | t(147) |      p
#> -----------------------------------------------------------------------------
#> versicolor - setosa    |      -0.66 | 0.07 | [-0.79, -0.52] |  -9.69 | < .001
#> virginica - setosa     |      -0.45 | 0.07 | [-0.59, -0.32] |  -6.68 | < .001
#> setosa - versicolor    |       0.66 | 0.07 | [ 0.52,  0.79] |   9.69 | < .001
#> virginica - versicolor |       0.20 | 0.07 | [ 0.07,  0.34] |   3.00 |  0.003
#> setosa - virginica     |       0.45 | 0.07 | [ 0.32,  0.59] |   6.68 | < .001
#> versicolor - virginica |      -0.20 | 0.07 | [-0.34, -0.07] |  -3.00 |  0.003
#> 
#> Variable predicted: Sepal.Width
#> Predictors contrasted: Species
#> p-values are uncorrected.

Created on 2025-01-23 with reprex v2.1.1

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.

1 participant