rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
364 stars 32 forks source link

brms emmeans #170

Closed jtipples-dev closed 4 years ago

jtipples-dev commented 4 years ago

Hello, Thanks for your great package. I'd be grateful for your help. ( R version 3.6.2, linux 17.04)

I am getting the following message when I try to use the latest version of emmeans (1.4.4) with any brms model

"Error in parse(text = x, keep.source = FALSE)[[1L]] : subscript out of bounds"

Here is an example model library(brms) library("emmeans") library(purrr) set.seed(5) n = 10 n_condition = 5 ABC = tibble( condition = rep(c("A","B","C","D","E"), n), response = rnorm(n * 5, c(0,1,2,1,-1), 0.5) )

m = brm(response ~condition+ (1|condition), data = ABC, control = list(adapt_delta = .99), prior = c( prior(normal(0, 1), class = Intercept), prior(student_t(3, 0, 1), class = sd), prior(student_t(3, 0, 1), class = sigma) ))

runs fine

emmeans(m,~condition)

Error in parse(text = x, keep.source = FALSE)[[1L]] : subscript out of bounds

platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 6.2
year 2019
month 12
day 12
svn rev 77560
language R
version.string R version 3.6.2 (2019-12-12) nickname Dark and Stormy Night

jtipples-dev commented 4 years ago

...the "Error in parse(text = x, keep.source = FALSE)[[1L]] : subscript out of bounds" is specific to brms, emmeans works fine with rstanarm (on linux)

rvlenth commented 4 years ago

For some reason, brms seems to create an object that is supposed to be a formula but is in fact an empty list. I'm not sure where that comes from, but I made a simple patch to my internal .all.vars() function that treats anything of length 0 the same as a NULL. And now it works:

> emmeans(m,~condition)
 condition emmean lower.HPD upper.HPD
 A          0.138     -2.49      2.63
 B          0.985     -1.61      3.41
 C          1.841     -0.80      3.78
 D          0.988     -1.19      3.18
 E         -0.990     -3.67      1.43

Point estimate displayed: median 
HPD interval probability: 0.95 

I suspect this is not a new error with version 1.4.4. The patch will be incorporated in the next CRAN update, or you can install it now from github. Thanks for your report.

jtipples-dev commented 4 years ago

Thanks Russ, Jason

jgeller112 commented 4 years ago

I installed master from Git, but am still having issues.

rvlenth commented 4 years ago

Works for me:

> emmeans(m,~condition)
 condition emmean lower.HPD upper.HPD
 A          0.152     -2.93      2.33
 B          0.982     -1.53      3.51
 C          1.836     -1.19      4.09
 D          0.976     -1.74      3.44
 E         -0.987     -3.95      1.53

Point estimate displayed: median 
HPD interval probability: 0.95 

Maybe you need to exit R and restart

rvlenth commented 4 years ago

PS there is kind of a CRAN mirror on git; make sure you install it from https://github.com/rvlenth/emmeans