sahirbhatnagar/casebase

competing risk object returned by fitSmoothHazard loses vglm class

Closed this issue · 1 comments

The competing risk object returned by fitSmoothHazard loses vglm class. This isn't consistent with singleEventCB objects, which maintain the glm and lm class. For some unkniown reason though, it maintains the plot method for objects of class vglm.

devtools::load_all("~/git_repositories/casebase/")
#> Loading casebase
#> See example usage at http://sahirbhatnagar.com/casebase/
library(VGAM)
#> Loading required package: stats4
#> Loading required package: splines
#> 
#> Attaching package: 'VGAM'
#> The following object is masked from 'package:casebase':
#> 
#>     s
pacman::p_load(rstpm2) # for brcancer data

# singleEventCB -----------------------------------------------------------

data("brcancer")
brcancer <- transform(brcancer, recyear=rectime / 365.24)
brcancer <- transform(brcancer, hormon=factor(hormon))
singleRisk <- fitSmoothHazard(censrec ~ hormon*bs(recyear, df = 5),
                          data = brcancer,
                          time = "recyear")
class(singleRisk)
#> [1] "singleEventCB" "glm"           "lm"
par(mfrow=c(2,2))
plot(singleRisk)

# compRisk ----------------------------------------------------------------

data("bmtcrr")
compRisk <- fitSmoothHazard(Status ~ ftime + Sex + D + Phase + Source + Age, 
                          data = bmtcrr, 
                          ratio = 100,
                          time = "ftime")
class(compRisk)
#> [1] "CompRisk"
#> attr(,"package")
#> [1] "casebase"
plot(compRisk)

# VGLM has vglm class and a plot method -----------------------------------

pneumo <- transform(pneumo, let = log(exposure.time))
fit <- vglm(cbind(normal, mild, severe) ~ let, multinomial, data = pneumo)
class(fit)
#> [1] "vglm"
#> attr(,"package")
#> [1] "VGAM"
plot(fit)

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

Right, that's not a bug, it's a feature. The class CompRisk is an S4 class that inherits from vglm. I wrote it this way because we needed a few extra slots that vglm doesn't have. The class definition is given here: https://github.com/sahirbhatnagar/casebase/blob/master/R/methods.R#L387-L400

Does it cause any problems anywhere? I would need to brush up on my S4 classes, but I think it should be fine.