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

Issue with make.transition.probs function #37

Open
LorenzC91 opened this issue Apr 14, 2021 · 9 comments
Open

Issue with make.transition.probs function #37

LorenzC91 opened this issue Apr 14, 2021 · 9 comments

Comments

@LorenzC91
Copy link

Hi Gianluca,
many thanks for having developed this useful package.

I have some issue using the function make.transition.probs
The function only works when I input a model (created with make.surv) where the nsim value equals the t intervals.
In all other cases the error is:

Error in dimnames(x) <- dn :
length of 'dimnames' [2] not equal to array extent

Also, the output of the function is not fully clear to me.

I hope my question is not too naïve, I'm new to R

Thanks in advance for your kind answer

Lorenzo

@giabaio
Copy link
Owner

giabaio commented Apr 15, 2021

@LorenzC91 thanks for this. Can I ask for more info (and possibly a replicable example) in order to debug your problem? In any case, make.transition.probs (which is being updated in the devel version of survHE) does take as input a survHE object, i.e. the output of a call to fit.models and uses the underlying survival curves to approximate the transition probabilities (indicating the chance of moving from "Non event" to "Event" between two consecutive times --- here "Non event" and "Event" depend of course on what you're modelling, for instance pre- and post-progression or pre-progression and death).

I'm not sure I follow your point about nsim above --- perhaps if you have a coded example I can help debug.

@LorenzC91
Copy link
Author

LorenzC91 commented Apr 15, 2021

Hi Gianluca,
thanks for your prompt and kind reply.

Here is the code I used:

`library(survHE)

dataset<-data

dataset$event<-NA

dataset[dataset$censored==0, 9]<-1

dataset[dataset$censored==1, 9]<-0

fitted_curves<-fit.models(formula = Surv(time, event)~1, data = dataset,
distr = c("exponential", "weibull", "gompertz", "gamma", "loglogistic", "lognormal"))

survival_curves<-make.surv(fitted_curves, mod = 1, t=c(0:10))

make.transition.probs(survival_curves)`

Using this code gives the error I mentioned above as output.

If instead I use this:

`survival_curves<-make.surv(fitted_model, mod = 1, t=c(0:10), nsim=10)

make.transition.probs(survival_curves)`

then I have an output, even if it is a bit confusing, since I have 10 rows (which I suppose are the transition probabilities in each of the 10 time points) and 10 columns (I can immagine one column for each simulation).

You said that "make.transition.probs does take as input a survHE object, i.e. the output of a call to fit.models", but I see in the Reference manual that make.transition.probs takes as input "an object obtained as output of the call to make.surv" (pag 9).
Am I missing something?

Thanks a lot for your help and patience, I really appreciate

Have a nice evening!

@giabaio
Copy link
Owner

giabaio commented Apr 16, 2021

@LorenzC91 thanks. You're right that make.transition.probs does take a make.surv output not a fit.models one. Apologies --- it's just I'm fiddling with the function in the new version, like I said, and I got confused...

In terms of the worked example, it's not really reproducible though --- what is the data object? Is it one of the datasets included in survHE? Or your own? And why do you set event to NA? I am not even sure fit.models would actually run if you passed the event indicator as an empty variable...

@LorenzC91
Copy link
Author

Hi Gianluca,
thanks for the clarification regarding the input object.
Regarding the data object: yes, is the dataset included in survHE.
Regarding the event variable: it's not set to NA, but I set it to be 0 if the censored variable is 1 and to be 1 if the censored variable is 0 (3rd and 4th line of the code)(The same can be done using dplyr::mutate together with dplyr::case_when, if you prefer).
Regarding the reproducibility of my code:
actually if you copy and paste it in you R studio it should work. It generates the fitted model and the curves.
The only issue I have is with make.transition.probs, which gives me the error reported above.

Thanks and have a nice day!

@giabaio
Copy link
Owner

giabaio commented Apr 19, 2021

@LorenzC91: my apologies for the confusion, you caught me in a moment when I was trying to juggle too many things and I got confused myself...
So: in the current version of survHE (the one on CRAN: version 1.1.2) you need to use as input for make.transition.probs the object obtained as the output to the call to make.surv. But I have been making changes and improvements to some of the functions (including make.transition.probs!) and the devel version (which you can find here) has changed this behaviour and you need to pass the output to fit.models as input.

If you install that version (which doesn't change the core of the package, but it's updated with respect to make.transition.probs), you get the following

library(survHE)
dataset<-data
dataset$event<-NA
dataset[dataset$censored==0, 9]<-1
dataset[dataset$censored==1, 9]<-0

fitted_curves<-fit.models(formula = Surv(time, event)~1, data = dataset,
distr = c("exponential", "weibull", "gompertz", "gamma", "loglogistic", "lognormal"))

make.transition.probs(fitted_curves,nsim=2)
# A tibble: 215 x 4
   profile     t lambda_1 lambda_2
   <chr>   <dbl>    <dbl>    <dbl>
 1 =        0.03  0.00232  0.00239
 2 =        0.52  0.0373   0.0383 
 3 =        0.79  0.0207   0.0213 
 4 =        0.92  0.0100   0.0103 
 5 =        1.02  0.00772  0.00793
 6 =        1.25  0.0177   0.0182 
 7 =        1.44  0.0146   0.0150 
 8 =        1.48  0.00310  0.00318
 9 =        1.61  0.0100   0.0103 
10 =        1.64  0.00232  0.00239
# … with 205 more rows

# Or setting up the times
> make.transition.probs(fitted_curves,nsim=2,t=seq(0,10))
# A tibble: 11 x 4
   profile     t lambda_1 lambda_2
   <chr>   <dbl>    <dbl>    <dbl>
 1 =           0   0        0     
 2 =           1   0.0674   0.0681
 3 =           2   0.0674   0.0681
 4 =           3   0.0674   0.0681
 5 =           4   0.0674   0.0681
 6 =           5   0.0674   0.0681
 7 =           6   0.0674   0.0681
 8 =           7   0.0674   0.0681
 9 =           8   0.0674   0.0681
10 =           9   0.0674   0.0681
11 =          10   0.0674   0.0681

which I think is what you want (there are as many columns as simulations, in the resulting object with the various transition probabilities at each time).

@LorenzC91
Copy link
Author

LorenzC91 commented Apr 24, 2021

Hi Gianluca!
Thanks a lot for your answer.
Sorry for the delay, I'm having a super busy week and couldn't find the time to check the updated version yet.
I come back to you with a feedback as soon as I can

Have a nice weekend!

@giabaio
Copy link
Owner

giabaio commented Apr 24, 2021 via email

@LorenzC91
Copy link
Author

Hi Gianluca,
I downloaded the devel version and now the function is working properly :-)
Thanks a lot for your help and congratulations again for your work with this package

Have a nice evening!

Lorenzo

@giabaio
Copy link
Owner

giabaio commented Apr 29, 2021 via email

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

2 participants