Hello,
I primarily use Stata, however I am running extended Cox models in Stata to analyse recurrent event data, the Andersen-Gill (AG) and Prentice Williams Peterson - Total Time models (PWP-TT), and I have had to use R to retrieve the predicted event count as I am unable to get them from Stata, this is done in R using the code "type="expected" after running my model:
"mymodel2 <- cbind(mydata,predict(mymodel1,type="expected"))" .
In Stata there is the predict function which is similar, for example "predict xb" for the linear predictors (https://www.stata.com/manuals/rpredict.pdf).
The option "predict, n" for predicted event counts is not allowed with a Cox model as Stata gives the error "option n not allowed".
On this link it mentions the predicted event count is the exponential of the linear predictors for a Poisson model, however this doesn't look correct for the Cox models and it doesn't match up to what R gives. I know this is incorrect as the linear predictors and exponential of them are the same for every patient, whereas the predicted event count would vary per observation for each patient like it does in R. For example:
Therefore in R, the predicted event count for patient 1 would be the cumulative sum of these which is 0.1993888608, rounding to 0 events. In Stata this is the same for every patient as the linear predictors wouldn't expect to change per patient unless a covariate changed for example, which indicates it is not the correct output for a predicted event count from the model.
Any advice how to get the predicted event count from Stata would be greatly appreciated!
Thank you,
Victoria
I primarily use Stata, however I am running extended Cox models in Stata to analyse recurrent event data, the Andersen-Gill (AG) and Prentice Williams Peterson - Total Time models (PWP-TT), and I have had to use R to retrieve the predicted event count as I am unable to get them from Stata, this is done in R using the code "type="expected" after running my model:
"mymodel2 <- cbind(mydata,predict(mymodel1,type="expected"))" .
In Stata there is the predict function which is similar, for example "predict xb" for the linear predictors (https://www.stata.com/manuals/rpredict.pdf).
The option "predict, n" for predicted event counts is not allowed with a Cox model as Stata gives the error "option n not allowed".
On this link it mentions the predicted event count is the exponential of the linear predictors for a Poisson model, however this doesn't look correct for the Cox models and it doesn't match up to what R gives. I know this is incorrect as the linear predictors and exponential of them are the same for every patient, whereas the predicted event count would vary per observation for each patient like it does in R. For example:
| Patient ID | Event Number | R predicted Event Count | Stata's "Predicted Event Count" (exponential of the linear predictor) |
| 1 | 1 | 0.000383885 | -0.5497227 |
| 1 | 2 | 0.098652224 | -0.5497227 |
| 1 | 3 | 0.100352753 | -0.5497227 |
Therefore in R, the predicted event count for patient 1 would be the cumulative sum of these which is 0.1993888608, rounding to 0 events. In Stata this is the same for every patient as the linear predictors wouldn't expect to change per patient unless a covariate changed for example, which indicates it is not the correct output for a predicted event count from the model.
Any advice how to get the predicted event count from Stata would be greatly appreciated!
Thank you,
Victoria

Comment