amazing package, some minor issues
Closed this issue · 3 comments
This is very exciting and I can't wait to see it ready for prime time!
Running on my own data:
plot(model_object,
hazard.params = list(xvar = "time",
by = "treatment",
alpha = 0.05,
ylab = "Hazard"))
produces the error:
Error in data.frame(x, x2, x3, check.names = FALSE) :
arguments imply differing number of rows: 218665, 1
Do you know why this might be happening?
Further, is there a way to handle clustering?
And finally, in the nonproportional hazard setting where I model interaction of a variable of interest with splined time, is there a way to obtain the hazard ratio for the variable of interest at specific points in time?
Thanks
Thanks for your interest in this package. Would you be able to provide us with a reproducible example. That would greatly help debug the error.
To answer your third question about Hazard ratios in the non-PH setting, here is a reproducible example of how to extract the hazard ratios and 95% confidence intervals at specific time points:
library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
library(splines)
data("eprchd")
eprchd <- transform(eprchd,
treatment = factor(treatment, levels = c("placebo","estPro")))
fit_mason <- fitSmoothHazard(status ~ treatment*ns(time),
data = eprchd,
time = "time")
summary(fit_mason)
#>
#> Call:
#> glm(formula = formula, family = binomial, data = sampleData)
#>
#> Deviance Residuals:
#> Min 1Q Median 3Q Max
#> -0.1700 -0.1484 -0.1463 -0.1315 3.1865
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -6.1074 0.1759 -34.723 < 2e-16 ***
#> treatmentestPro 0.5971 0.2245 2.659 0.00784 **
#> ns(time) 1.0750 0.4230 2.542 0.01103 *
#> treatmentestPro:ns(time) -1.1679 0.5609 -2.082 0.03731 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 3635.4 on 32723 degrees of freedom
#> Residual deviance: 3625.8 on 32720 degrees of freedom
#> AIC: 3633.8
#>
#> Number of Fisher Scoring iterations: 7
newtime <- seq(0,7,by=0.5)
newdata <- data.frame(treatment = factor("placebo",
levels = c("placebo", "estPro")),
time = newtime)
tp <- plot(fit_mason,
type = "hr",
newdata = newdata,
var = "treatment",
increment = 1,
xvar = "time",
ci = T,
rug = T)
tp
#> treatment time log_hazard_ratio standarderror hazard_ratio lowerbound
#> 1 placebo 0.0 0.597070448 0.2245467 1.8167886 1.1699570
#> 2 placebo 0.5 0.530969392 0.1977751 1.7005800 1.1541191
#> 3 placebo 1.0 0.464868336 0.1726965 1.5918046 1.1347239
#> 4 placebo 1.5 0.398767280 0.1501619 1.4899868 1.1101058
#> 5 placebo 2.0 0.332666224 0.1314857 1.3946817 1.0778399
#> 6 placebo 2.5 0.266565169 0.1185064 1.3054727 1.0348918
#> 7 placebo 3.0 0.200464113 0.1132008 1.2219698 0.9788221
#> 8 placebo 3.5 0.134363057 0.1166210 1.1438080 0.9100917
#> 9 placebo 4.0 0.068262001 0.1280698 1.0706458 0.8329762
#> 10 placebo 4.5 0.002160945 0.1456663 1.0021633 0.7532638
#> 11 placebo 5.0 -0.063940111 0.1674839 0.9380612 0.6755673
#> 12 placebo 5.5 -0.130041166 0.1920896 0.8780593 0.6025830
#> 13 placebo 6.0 -0.196142222 0.2185437 0.8218953 0.5355398
#> 14 placebo 6.5 -0.262243278 0.2462513 0.7693238 0.4747880
#> 15 placebo 7.0 -0.328344334 0.2748334 0.7201150 0.4202070
#> upperbound
#> 1 2.821233
#> 2 2.505783
#> 3 2.233003
#> 4 1.999864
#> 5 1.804662
#> 6 1.646799
#> 7 1.525517
#> 8 1.437544
#> 9 1.376129
#> 10 1.333306
#> 11 1.302548
#> 12 1.279472
#> 13 1.261366
#> 14 1.246576
#> 15 1.234072
Created on 2021-02-02 by the reprex package (v0.3.0)
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os Pop!_OS 20.04 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_US:en
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/Toronto
#> date 2021-02-02
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.2)
#> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.2)
#> casebase * 0.9.0 2020-07-03 [1] CRAN (R 4.0.2)
#> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
#> curl 4.3 2019-12-02 [1] CRAN (R 4.0.2)
#> data.table 1.13.0 2020-07-24 [1] CRAN (R 4.0.2)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
#> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> dplyr 1.0.2 2020-08-18 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2)
#> ggplot2 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.0.2)
#> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2)
#> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> Matrix 1.2-18 2019-11-27 [4] CRAN (R 4.0.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.2)
#> mgcv 1.8-33 2020-08-27 [4] CRAN (R 4.0.2)
#> mime 0.9 2020-02-04 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
#> nlme 3.1-149 2020-08-23 [4] CRAN (R 4.0.2)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
#> processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
#> ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> rlang 0.4.9 2020-11-26 [1] CRAN (R 4.0.2)
#> rmarkdown 2.5.3 2020-10-31 [1] Github (rstudio/rmarkdown@62d9b6b)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> survival 3.2-3 2020-06-13 [1] CRAN (R 4.0.2)
#> testthat 3.0.0 2020-10-31 [1] CRAN (R 4.0.2)
#> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.2)
#> usethis 1.6.3 2020-09-17 [1] CRAN (R 4.0.2)
#> vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2)
#> VGAM 1.1-3 2020-04-28 [1] CRAN (R 4.0.2)
#> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)
#> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /home/sahir/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
I'm closing this issue, since we don't have a reproducible example.