Closed rsund closed 1 year ago
Hi and sorry for the huge delay
The problem comes from the fact that survPen has no way to know that the variable 'fucut2' actually represents time
For the integration part to work in the likelihood computation, everytime you want to specify a function of time you have to make the 't1' variable (so here 'fu') appear explicitly inside the formula
Using the following formula should work (in your first attempt the bug comes from the fact that the follow-up exceeds 5 years)
f.pwcst <- ~cut(fu,breaks=c(seq(0,5,by=0.5),8),include.lowest=TRUE)
Have a great day !
First, thank you for very useful and nice piece of software that provides a lot of new tools for working with hazard.based models. In one of my applications I, however, encountered a problem that I was not able to solve by myself.
To provide you a reproducible example, I tried to replicate the problem with the data generated in your own vignette. So, here is first the code borrowed directly from the vignette to create the data and estimate the models presented in the vignette (I was working with R 4.1.1 and survPen 1.5.2 in a Windows 10 environment):
All those models are working just fine. In the case of my application, I though that it would be nice to check how the constant and piecewise constant hazard (as demonstrated in the beginning of the vignette with datCancer data) would look like, but I got very suspicious results. I was also able to repeat the problem with the data generated above.
In the following, the constant hazard model appears to provide quite reasonable estimates, but piecewise constant model "extends" the scale (although it seems to capture something from the shape of true hazard).
Here is the code I used to create variables, estimate models and to draw figures of the estimated hazards. I had problems to use the code in the first part of the vignette to create a variable for piecewise constants (didn't work in the model), so I created required variable(s) separately with dplyr functions.
As can be seen from the figures, the estimates from the piecewise constant model are much larger or smaller than the true hazard or the estimates from the other models for most parts. That is not what I expected as probably those estimates should be approximately "in the middle" of true hazard for each piece. Increasing the n.legendre -parameter did not help.
Despite of that, the hazard ratio is not too far from the true value as can be seen from the following code and figures:
I understand that survPen has not been created to primarily estimate piecewise constant models, but as those were demonstrated in the vignette and as those may sometimes be useful for various purposes, it would be nice to know what is going wrong here. I also acknowledge that the problem could be in the way I defined the model or used it to create predictions, but if that is the case, some guidance would be highly appreciated.