christophergandrud / christophergandrud/simPH

Compatibility with tvc functionality from survival package

Open
#22 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TeX
Stars
14
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Placing this here in case somebody else runs into this. Thanks for putting this package together.

It is possible to create a time-varying covariate using the tt function in the survival package. However, it isn't clear how to use simPH to estimate the time-varying relative hazard. One can use the variable that is created in the survival object, but it is saved exactly as written with parentheses around it. For example "tt(varname)". simPH works using this as the btvc parameter in the `coxsimtvc()` function. However, within simPH, `mvnorm()` seems to change it to "tt.varname." -- it replaces parentheses with periods. Then the rest of the function fails. The workaround is simply to rename the variable in the survival output object to something without parentheses prior to running `coxsimtvc()`. Then the `coxsimtvc()` function works correctly.

```
library(simPH)
library(survival)
vs_np <-
coxph(
Surv(days_to_death, event_flag) ~
tx_2L_01 +
tt(tx_2L_01), # <-- this string also gets used as a variable name in the output object
tt = function(x, t, ...) x * log(t), #<-- this is the survival package function for tvc
data = dt)

names(vs_np$coefficients)[[2]] <- "tt_tx_2L_01" # to fix compatibility with simPH
op <- coxsimtvc(vs_soc, "tx_2L_01", "tt_tx_2L_01", Xj = 1, tfun = "log", from = 1, to = 720, by = 30)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.