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

ggforest ignores interactions and polynomial or spline terms #306

Closed
fabian-s opened this issue May 4, 2018 · 5 comments
Closed

ggforest ignores interactions and polynomial or spline terms #306

fabian-s opened this issue May 4, 2018 · 5 comments

Comments

@fabian-s
Copy link
Contributor

fabian-s commented May 4, 2018

Expected behavior

ggforest shows all estimated coefficients

Actual behavior/Steps to reproduce the problem:

library("survival")
library("survminer")

colon <- within(colon, {
  sex <- factor(sex, labels = c("female", "male"))
  differ <- factor(differ, labels = c("well", "moderate", "poor"))
  extent <- factor(extent, labels = c("submuc.", "muscle", "serosa", "contig."))
  })
model <- coxph(
  Surv(time, status) ~ sex * rx + adhere + differ + extent + node4 + poly(age, 3),
  data = colon)
ggforest(model)
## Warning messages:
## 1: In .get_data(model, data = data) :
##  The `data` argument is not provided. Data will be extracted from model fit.
## 2: Removed 5 rows containing missing values (geom_errorbar). 

image

So: neither the coefs for the interaction sex:rx nor the coefficients for the polynomials are shown.

The problem is that

terms <- attr(model$terms, "dataClasses")[-1]
and following

  • only yield variable names but should extract all terms
  • do not allow for the case that numerical variables have multiple associated coefficients (splines, poly)

> devtools::session_info()
Session info -------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.447)           
 language en                          
 collate  en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2018-05-04                  

Packages -----------------------------------------------------------
 package    * version    date       source                          
 assertthat   0.2.0      2017-04-11 CRAN (R 3.4.1)                  
 base       * 3.4.4      2018-03-16 local                           
 bindr        0.1.1      2018-03-13 CRAN (R 3.4.3)                  
 bindrcpp     0.2.2      2018-03-29 CRAN (R 3.4.4)                  
 broom        0.4.4      2018-03-29 CRAN (R 3.4.4)                  
 cmprsk       2.2-7      2014-06-17 CRAN (R 3.4.1)                  
 colorspace   1.3-2      2016-12-14 CRAN (R 3.4.3)                  
 compiler     3.4.4      2018-03-16 local                           
 data.table   1.10.4-3   2017-10-27 CRAN (R 3.4.3)                  
 datasets   * 3.4.4      2018-03-16 local                           
 devtools     1.13.5     2018-02-18 CRAN (R 3.4.3)                  
 digest       0.6.15     2018-01-28 CRAN (R 3.4.3)                  
 dplyr        0.7.4      2017-09-28 CRAN (R 3.4.3)                  
 foreign      0.8-69     2017-06-21 CRAN (R 3.4.0)                  
 ggplot2    * 2.2.1      2016-12-30 CRAN (R 3.4.4)                  
 ggpubr     * 0.1.6      2017-11-14 CRAN (R 3.4.3)                  
 glue         1.2.0      2017-10-29 CRAN (R 3.4.3)                  
 graphics   * 3.4.4      2018-03-16 local                           
 grDevices  * 3.4.4      2018-03-16 local                           
 grid         3.4.4      2018-03-16 local                           
 gridExtra    2.3        2017-09-09 CRAN (R 3.4.3)                  
 gtable       0.2.0      2016-02-26 CRAN (R 3.3.0)                  
 km.ci        0.5-2      2009-08-30 CRAN (R 3.4.1)                  
 KMsurv       0.1-5      2012-12-03 CRAN (R 3.4.1)                  
 knitr        1.20       2018-02-20 CRAN (R 3.4.3)                  
 labeling     0.3        2014-08-23 CRAN (R 3.3.0)                  
 lattice      0.20-35    2017-03-25 CRAN (R 3.3.3)                  
 lazyeval     0.2.1      2017-10-29 CRAN (R 3.4.3)                  
 magrittr   * 1.5        2014-11-22 CRAN (R 3.4.3)                  
 Matrix       1.2-14     2018-04-09 CRAN (R 3.4.4)                  
 memoise      1.1.0      2017-04-21 CRAN (R 3.4.3)                  
 methods    * 3.4.4      2018-03-16 local                           
 mnormt       1.5-5      2016-10-15 CRAN (R 3.4.1)                  
 munsell      0.4.3      2016-02-13 CRAN (R 3.3.0)                  
 nlme         3.1-137    2018-04-07 CRAN (R 3.4.4)                  
 parallel     3.4.4      2018-03-16 local                           
 pillar       1.2.2      2018-04-26 CRAN (R 3.4.4)                  
 pkgconfig    2.0.1      2017-03-21 CRAN (R 3.4.1)                  
 plyr         1.8.4      2016-06-08 CRAN (R 3.3.0)                  
 psych        1.8.3.3    2018-03-30 CRAN (R 3.4.4)                  
 purrr        0.2.4      2017-10-18 cran (@0.2.4)                   
 R6           2.2.2      2017-06-17 CRAN (R 3.4.1)                  
 Rcpp         0.12.16    2018-03-13 CRAN (R 3.4.3)                  
 reshape2     1.4.3      2017-12-11 CRAN (R 3.4.3)                  
 rlang        0.2.0.9001 2018-04-17 Github (r-lib/rlang@82b2727)    
 scales       0.5.0.9000 2018-03-28 Github (hadley/scales@d767915)  
 splines      3.4.4      2018-03-16 local                           
 stats      * 3.4.4      2018-03-16 local                           
 stringi      1.1.7      2018-03-12 CRAN (R 3.4.3)                  
 stringr      1.3.0      2018-02-19 CRAN (R 3.4.3)                  
 survival   * 2.42-3     2018-04-16 CRAN (R 3.4.4)                  
 survminer  * 0.4.2      2018-01-31 CRAN (R 3.4.3)                  
 survMisc     0.5.4      2016-11-23 CRAN (R 3.4.3)                  
 tibble       1.4.2      2018-01-22 CRAN (R 3.4.3)                  
 tidyr        0.8.0      2018-01-29 CRAN (R 3.4.3)                  
 tools        3.4.4      2018-03-16 local                           
 utils      * 3.4.4      2018-03-16 local                           
 withr        2.1.2      2018-03-28 Github (jimhester/withr@79d7b0d)
 xtable       1.8-2      2016-02-05 CRAN (R 3.3.0)                  
 yaml         2.1.18     2018-03-08 CRAN (R 3.4.3)                  
 zoo          1.8-1      2018-01-08 CRAN (R 3.4.3)            
@david-awam-jansen
Copy link

I am running into a similar issue, has this bean solved?

@DanChaltiel
Copy link
Contributor

DanChaltiel commented May 13, 2019

I'm also running into this exact issue, and made some kind of workaround.
If you want to use it without waiting for the patch, just add thos prefixes: survminer:::.get_data line 48, generics::tidy line 54 and generics::glance line 55.
Also, you could try to remove the lines 50-51 as a test, as they didn't change anything to me except increasing computing time (but may serve some purpose in very specific cases).

Here are the pull requests, sorry for the duplicate, I'm still quite github-newbie...

kassambara added a commit that referenced this issue May 20, 2019
@rickyking
Copy link

I don't think it resolved. I still can't get the interaction factors.

@kassambara
Copy link
Owner

solution to show interaction is provided at #496 #496

@mmfalco
Copy link

mmfalco commented Jun 9, 2022

this solution doesn't work if you have both numerical and categorical variables, right?

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

6 participants