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

Replacement error message when using "1" or ~1 #206

Closed
TheDom42 opened this issue Jun 1, 2020 · 6 comments
Closed

Replacement error message when using "1" or ~1 #206

TheDom42 opened this issue Jun 1, 2020 · 6 comments

Comments

@TheDom42
Copy link

TheDom42 commented Jun 1, 2020

I tried to obtain the grand mean for a LMM I fitted using emmeans(..., spec = "1") the other day using an older version of the emmeans package which worked out fine.
Today I updated R and several other packages (including emmeans) due to problems with other packages.

When I tried to run the grand mean calculation on my LMM, I got an error message concerning a data.frame replacement issue.
I tried running the standard example provided in the vignette and it failed with the same error (except for the value argument reported in the error message of course).
Running it with a spec from the lm works as intended.

EDIT
I just ran the code with the old 1.4.6 binary from CRAN on R 4.0.0 - this one works. Seems to be an error introduced by version 1.4.7

library(emmeans)

pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs)
pigs.emm.s <- emmeans(pigs.lm, "1")
#> NOTE: Results may be misleading due to involvement in interactions
#> Error in `[[<-.data.frame`(`*tmp*`, ".wgt.", value = 29): replacement has 1 row, data has 0

Created on 2020-06-01 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.0 (2020-04-24)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  ** redacted for privacy reasons **         
#>  ctype    ** redacted for privacy reasons **         
#>  tz       ** redacted for privacy reasons **              
#>  date     2020-06-01                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package      * version date       lib source        
#>  assertthat     0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
#>  backports      1.1.7   2020-05-13 [1] CRAN (R 4.0.0)
#>  callr          3.4.3   2020-03-28 [1] CRAN (R 4.0.0)
#>  cli            2.0.2   2020-02-28 [1] CRAN (R 4.0.0)
#>  crayon         1.3.4   2017-09-16 [1] CRAN (R 4.0.0)
#>  desc           1.2.0   2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools       2.3.0   2020-04-10 [1] CRAN (R 4.0.0)
#>  digest         0.6.25  2020-02-23 [1] CRAN (R 4.0.0)
#>  ellipsis       0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
#>  emmeans      * 1.4.7   2020-05-25 [1] CRAN (R 4.0.0)
#>  estimability   1.3     2018-02-11 [1] CRAN (R 4.0.0)
#>  evaluate       0.14    2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi          0.4.1   2020-01-08 [1] CRAN (R 4.0.0)
#>  fs             1.4.1   2020-04-04 [1] CRAN (R 4.0.0)
#>  glue           1.4.1   2020-05-13 [1] CRAN (R 4.0.0)
#>  highr          0.8     2019-03-20 [1] CRAN (R 4.0.0)
#>  htmltools      0.4.0   2019-10-04 [1] CRAN (R 4.0.0)
#>  knitr          1.28    2020-02-06 [1] CRAN (R 4.0.0)
#>  magrittr       1.5     2014-11-22 [1] CRAN (R 4.0.0)
#>  memoise        1.1.0   2017-04-21 [1] CRAN (R 4.0.0)
#>  mvtnorm        1.1-0   2020-02-24 [1] CRAN (R 4.0.0)
#>  pkgbuild       1.0.8   2020-05-07 [1] CRAN (R 4.0.0)
#>  pkgload        1.1.0   2020-05-29 [1] CRAN (R 4.0.0)
#>  plyr           1.8.6   2020-03-03 [1] CRAN (R 4.0.0)
#>  prettyunits    1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
#>  processx       3.4.2   2020-02-09 [1] CRAN (R 4.0.0)
#>  ps             1.3.3   2020-05-08 [1] CRAN (R 4.0.0)
#>  R6             2.4.1   2019-11-12 [1] CRAN (R 4.0.0)
#>  Rcpp           1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
#>  remotes        2.1.1   2020-02-15 [1] CRAN (R 4.0.0)
#>  rlang          0.4.6   2020-05-02 [1] CRAN (R 4.0.0)
#>  rmarkdown      2.2     2020-05-31 [1] CRAN (R 4.0.0)
#>  rprojroot      1.3-2   2018-01-03 [1] CRAN (R 4.0.0)
#>  sessioninfo    1.1.1   2018-11-05 [1] CRAN (R 4.0.0)
#>  stringi        1.4.6   2020-02-17 [1] CRAN (R 4.0.0)
#>  stringr        1.4.0   2019-02-10 [1] CRAN (R 4.0.0)
#>  testthat       2.3.2   2020-03-02 [1] CRAN (R 4.0.0)
#>  usethis        1.6.1   2020-04-29 [1] CRAN (R 4.0.0)
#>  withr          2.2.0   2020-04-20 [1] CRAN (R 4.0.0)
#>  xfun           0.14    2020-05-20 [1] CRAN (R 4.0.0)
#>  xtable         1.8-4   2019-04-21 [1] CRAN (R 4.0.0)
#>  yaml           2.2.1   2020-02-01 [1] CRAN (R 4.0.0)
#> 
#> [1] ** redacted for privacy reasons **
#> [2] C:/Program Files/R/R-4.0.0/library
@bca2
Copy link

bca2 commented Jun 1, 2020

I can confirm this issue on windows and linux.
1.4.6 works.

@rvlenth
Copy link
Owner

rvlenth commented Jun 2, 2020

OK. What happened is I inserted some code that seemed to break a variation on an emtrends() issue (in issue #200). Apparently when I got that issue completely resolved, that change created this new issue.

So I can fix that by reverting to the code I had.

That said, you say:

I tried running the standard example provided in the vignette and it failed with the same error

I do not find this example in the vignettes. And the R checking process would have caught the error. So where did you find this example?

Do you think this issue is so severe that I need to ask CRAN for an emergency update before 30 days have passed? I'm reluctant to do that...

rvlenth added a commit that referenced this issue Jun 2, 2020
@rvlenth
Copy link
Owner

rvlenth commented Jun 2, 2020

Aha -- I found the bug I thought I had fixed:

> warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
> emmeans(warp.lm, "1")
 1       emmean   SE df lower.CL upper.CL
 overall   28.1 1.49 48     25.2     31.1

Results are averaged over the levels of: wool, tension 
Confidence level used: 0.95 

> # OK so far, but a by variable messes it up...
> emmeans(warp.lm, "1", by = "wool")
Error in emmeans(warp.lm, "1", by = "wool") : 
  No variable named 1 in the reference grid

And the issue in question actually wasn't number 200, it was #197. So I have my work cut out for me...

@rvlenth
Copy link
Owner

rvlenth commented Jun 2, 2020

OK, I think I have both #197 and #206 resolved now:

require(emmeans)
## Loading required package: emmeans

#206...
warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)

emmeans(warp.lm, "1")
##  1       emmean   SE df lower.CL upper.CL
##  overall   28.1 1.49 48     25.2     31.1
## 
## Results are averaged over the levels of: wool, tension 
## Confidence level used: 0.95

emmeans(warp.lm, "1", by = "wool")
## wool = A:
##  1       emmean   SE df lower.CL upper.CL
##  overall   31.0 2.11 48     26.8     35.3
## 
## wool = B:
##  1       emmean   SE df lower.CL upper.CL
##  overall   25.3 2.11 48     21.0     29.5
## 
## Results are averaged over the levels of: tension 
## Confidence level used: 0.95


#197...
model <- lm(Sepal.Length ~ poly(Petal.Length,2), data = iris)

emtrends(model, ~ 1, "Petal.Length", max.degree = 2)
## degree = linear:
##  1       Petal.Length.trend     SE  df lower.CL upper.CL
##  overall             0.4474 0.0180 147   0.4119    0.483
## 
## degree = quadratic:
##  1       Petal.Length.trend     SE  df lower.CL upper.CL
##  overall             0.0815 0.0132 147   0.0554    0.108
## 
## Confidence level used: 0.95

Created on 2020-06-01 by the reprex package (v0.3.0)

@TheDom42
Copy link
Author

TheDom42 commented Jun 2, 2020

That said, you say:

I tried running the standard example provided in the vignette and it failed with the same error

I do not find this example in the vignettes. And the R checking process would have caught the error. So where did you find this example?

Sorry, I might have misphrased that: this is not actually a "standard" example but one that I found "standard" and reproducible enough. It's the first example (in the pairwise comparisons section) found here in the vignette.
I just replaced the "source" spec.

Do you think this issue is so severe that I need to ask CRAN for an emergency update before 30 days have passed? I'm reluctant to do that...
IMHO, I don't think that this issue is so severe that it would require an emergency patch. I'm not familiar with the CRAN guidelines but too me, it seems reasonable to wait up to the next regular update. For those that are in dire need of such a functionality, they can (as you write correctly on SO) use the github version, if this one includes the patch already.

Thanks for such a swift reply and quick solution!

@rvlenth
Copy link
Owner

rvlenth commented Jul 26, 2020

I think I can close this now.

@rvlenth rvlenth closed this as completed Jul 26, 2020
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

No branches or pull requests

3 participants