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

find_formula struggles with few model objects #138

Closed
IndrajeetPatil opened this issue Sep 16, 2019 · 8 comments
Closed

find_formula struggles with few model objects #138

IndrajeetPatil opened this issue Sep 16, 2019 · 8 comments
Labels
Bug 🐛 Something isn't working

Comments

@IndrajeetPatil
Copy link
Member

# model-1
library(car) 
#> Loading required package: carData
mod <- stats::lm(
  formula = conformity ~ fcategory * partner.status,
  data = Moore,
  contrasts = list(fcategory = contr.sum, partner.status = contr.sum)
)

# random-effects
insight::find_random(car::Anova(mod, type = "III"))
#> Error in find_formula.data.frame(x): A data frame is no valid object for this function



# model-2
library(lme4)
#> Loading required package: Matrix
#> Registered S3 methods overwritten by 'lme4':
#>   method                          from
#>   cooks.distance.influence.merMod car 
#>   influence.merMod                car 
#>   dfbeta.influence.merMod         car 
#>   dfbetas.influence.merMod        car
set.seed(123)
startvec <- c(Asym = 200, xmid = 725, scal = 350)
nm1 <- lme4::nlmer(circumference ~ SSlogis(age, Asym, xmid, scal) ~ Asym | Tree,
                   Orange,
                   start = startvec
)

# random-effects
insight::find_random(nm1)
#> Error in reformulate(attr(termobj, "term.labels")[-dropx], response = if (keep.response) termobj[[2L]], : 'termlabels' must be a character vector of length at least one

Created on 2019-09-16 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       Europe/Berlin               
#>  date     2019-09-16                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                        
#>  abind         1.4-5      2016-07-21 [1] CRAN (R 3.5.0)                
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)                
#>  boot          1.3-23     2019-07-05 [1] CRAN (R 3.6.1)                
#>  callr         3.3.1      2019-07-18 [1] CRAN (R 3.6.1)                
#>  car         * 3.0-3      2019-05-27 [1] CRAN (R 3.6.0)                
#>  carData     * 3.0-2      2018-09-30 [1] CRAN (R 3.5.1)                
#>  cellranger    1.1.0      2016-07-27 [1] CRAN (R 3.5.1)                
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.1)                
#>  curl          4.1        2019-09-16 [1] CRAN (R 3.6.1)                
#>  data.table    1.12.2     2019-04-07 [1] CRAN (R 3.5.3)                
#>  desc          1.2.0      2019-04-03 [1] Github (r-lib/desc@c860e7b)   
#>  devtools      2.2.0      2019-09-07 [1] CRAN (R 3.6.1)                
#>  digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.0)                
#>  DT            0.8        2019-08-07 [1] CRAN (R 3.6.1)                
#>  ellipsis      0.2.0.1    2019-07-02 [1] CRAN (R 3.6.0)                
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                
#>  forcats       0.4.0      2019-02-17 [1] CRAN (R 3.5.2)                
#>  foreign       0.8-71     2018-07-20 [2] CRAN (R 3.6.1)                
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                
#>  haven         2.1.1      2019-07-04 [1] CRAN (R 3.6.0)                
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                
#>  hms           0.5.1      2019-08-23 [1] CRAN (R 3.6.1)                
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.1)                
#>  htmlwidgets   1.3        2018-09-30 [1] CRAN (R 3.5.1)                
#>  insight       0.5.0.9000 2019-09-16 [1] local                         
#>  knitr         1.24       2019-08-08 [1] CRAN (R 3.6.1)                
#>  lattice       0.20-38    2018-11-04 [2] CRAN (R 3.6.1)                
#>  lme4        * 1.1-21     2019-03-05 [1] CRAN (R 3.6.0)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.1)                
#>  MASS          7.3-51.4   2019-03-31 [1] CRAN (R 3.6.0)                
#>  Matrix      * 1.2-17     2019-03-22 [1] CRAN (R 3.6.0)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                
#>  minqa         1.2.4      2014-10-09 [1] CRAN (R 3.5.1)                
#>  nlme          3.1-140    2019-05-12 [2] CRAN (R 3.6.1)                
#>  nloptr        1.2.1      2018-10-03 [1] CRAN (R 3.5.1)                
#>  openxlsx      4.1.0.1    2019-05-28 [1] CRAN (R 3.6.0)                
#>  pillar        1.4.2      2019-06-29 [1] CRAN (R 3.6.0)                
#>  pkgbuild      1.0.5      2019-08-26 [1] CRAN (R 3.6.1)                
#>  pkgconfig     2.0.2      2018-08-16 [1] CRAN (R 3.5.1)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.1)                
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.1)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                
#>  Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.6.1)                
#>  readxl        1.3.1      2019-03-13 [1] CRAN (R 3.6.0)                
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                
#>  rio           0.5.16     2018-11-26 [1] CRAN (R 3.6.0)                
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.6.0)                
#>  rmarkdown     1.15       2019-08-21 [1] CRAN (R 3.6.1)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.1)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                
#>  testthat      2.2.1      2019-07-25 [1] CRAN (R 3.6.1)                
#>  tibble        2.1.3      2019-06-06 [1] CRAN (R 3.6.0)                
#>  usethis       1.5.1.9000 2019-09-12 [1] Github (r-lib/usethis@a2342b8)
#>  vctrs         0.2.0      2019-07-05 [1] CRAN (R 3.6.1)                
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.1)                
#>  xfun          0.9        2019-08-21 [1] CRAN (R 3.6.1)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.1)                
#>  zeallot       0.1.0      2018-01-28 [1] CRAN (R 3.5.1)                
#>  zip           2.0.4      2019-09-01 [1] CRAN (R 3.6.1)                
#> 
#> [1] C:/Users/inp099/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library
@IndrajeetPatil IndrajeetPatil added the Bug 🐛 Something isn't working label Sep 16, 2019
@IndrajeetPatil
Copy link
Member Author

@strengejacke Do you think this bug can be fixed before the next CRAN submission?
I want to use this function in my package but been waiting for this to be fixed.

@strengejacke
Copy link
Member

I can look at this, there is no hurry for insight to be released, I think.

@strengejacke
Copy link
Member

related to #66

@strengejacke
Copy link
Member

two things:

  1. car::Anova() returns a data frame, and I don't see how to get any information about the underlying model object.

  2. nlmer() only works with included fixed effects when the random effect term is written in classical lmer-style, i.e. circumference ~ SSlogis(age, Asym, xmid, scal) ~ x1 + x2 + (Asym | Tree).

@IndrajeetPatil
Copy link
Member Author

Thanks for fixing this so quickly!

@strengejacke
Copy link
Member

The 2nd point can be blamed to the lmee-package, because findbars() doesn't work properly here:

library(lme4)
#> Loading required package: Matrix
data("Orange")

Orange$x1 <- runif(nrow(Orange))
Orange$x2 <- rnorm(nrow(Orange))

set.seed(123)
startvec <- c(Asym = 200, xmid = 725, scal = 350)

m1 <- lme4::nlmer(
  circumference ~ SSlogis(age, Asym, xmid, scal) ~ x1 + x2 + Asym | Tree,
  Orange,
  start = startvec
)

m2 <- lme4::nlmer(
  circumference ~ SSlogis(age, Asym, xmid, scal) ~ x1 + x2 + (Asym | Tree),
  Orange,
  start = startvec
)

lme4::findbars(formula(m1))
#> [[1]]
#> x1 + x2 + Asym | Tree
lme4::findbars(formula(m2))
#> [[1]]
#> Asym | Tree

Created on 2019-10-17 by the reprex package (v0.3.0)

@IndrajeetPatil
Copy link
Member Author

Maybe we can raise an issue on lme4's GitHub repo?

@strengejacke
Copy link
Member

Yes, I did already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants