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

emmean support for monotonic effects #1134

Closed
mattansb opened this issue Apr 6, 2021 · 4 comments
Closed

emmean support for monotonic effects #1134

mattansb opened this issue Apr 6, 2021 · 4 comments
Labels
Milestone

Comments

@mattansb
Copy link

mattansb commented Apr 6, 2021

emmeans seems unable to find monotonic effects (missing from the reference grid):

library(brms)
library(emmeans)

income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 100, TRUE), 
                 levels = income_options, ordered = TRUE)
mean_ls <- c(30, 60, 70, 75)
ls <- mean_ls[income] + rnorm(100, sd = 7)
dat <- data.frame(income, ls)

fit1 <- brm(ls ~ mo(income), data = dat)


emmeans(fit1,~income)
#> Error in emmeans(fit1, ~income) : 
#>   No variable named income in the reference grid

ref_grid(fit1)
#> 'emmGrid' object with variables:
#>   1 = 1
@paul-buerkner
Copy link
Owner

Yes that is true. I am not yet sure, how we shall best handle monotonic effects in emmeans.

@mattansb
Copy link
Author

mattansb commented Apr 6, 2021

I think this would be handled best if it were in the reference grid as a "factor".

@mattansb
Copy link
Author

mattansb commented Jun 8, 2021

This issue also seems to be solved by the suggestion I made here: #907 (comment)

library(brms)
library(emmeans)

income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 100, TRUE), 
                 levels = income_options, ordered = TRUE)
mean_ls <- c(30, 60, 70, 75)
ls <- mean_ls[income] + rnorm(100, sd = 7)
dat <- data.frame(income, ls)

fit1 <- brm(ls ~ mo(income), data = dat)


emmeans(fit1,  ~ income)
#>  income      emmean lower.HPD upper.HPD
#>  below_20      30.3      27.4      33.2
#>  20_to_40      60.1      57.0      63.3
#>  40_to_100     69.4      66.3      72.6
#>  greater_100   75.2      72.7      77.8
#> 
#> Point estimate displayed: median 
#> HPD interval probability: 0.95 

@paul-buerkner
Copy link
Owner

Implemented via #1177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants