Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: weighted time dependent Cox model


From   Steve Samuels <sjsamuels@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: weighted time dependent Cox model
Date   Mon, 20 Feb 2012 07:56:27 -0500

Ehsan thanked me privately for my original answer. 

A solution follows to the followup question. Note the reappearance in the -stset- statement of the enter() and exit() options. 

But I question the use of Cox here, for the data as presented are discrete or grouped, which would invalidate the usual Cox asymptotics, I believe. -cloglog- is a Stata option that accepts weights. See the entry for "Discrete" in the Stata Survival manual and http://www.iser.essex.ac.uk/files/teaching/stephenj/ec968/pdfs/ec968st6.pdf

Shaun Scholes: The longitudinal weights in the November discussion arose from a panel survey. Ehsan's weights are for inverse probability of treatment weighting (IPTW), a method for reducing bias in the estimate of a treatment effect.  People could shift in and out of the "treatment" group, so a new weight was needed for each time interval.


Steve
sjsamuels@gmail.com


*************CODE BEGINS*************
stset exit [pw = weight],  ///
 fail(event) enter(enter) exit(exit)

capture program drop cboot
program define cboot, rclass

stcox tx, breslow
return scalar btx = _b[tx]
return scalar hrx = exp(_b[tx])

end
set seed 249662
bootstrap r(btx) r(hrx),  ///
   reps(100) cluster(id): cboot
estat boot, all
**************CODE ENDS**************

On Feb 19, 2012, at 10:29 PM, Ehsan Karim wrote:

Just a follow up question: Is there a way in Stata to handle time
dependent weights?

For the data with time dependent weights (within same person), I am
getting the following message:

. use http://stat.ubc.ca/~e.karim/dataset2, clear
. stset exit [pweight=weight], fail(event) id(id)
weight not constant within id
r(459);

Any suggestions/references will be highly appreciated. Thanks - Ehsan


##########################################
# dataset with time dependent weights (partial)
##########################################

. list
       +------------------------------------------------+
       |    id   tx   enter   exit   event         weight |
       |------------------------------------------------|
    1. |     1    0         0         1    0   1.037136 |
    2. |     1    0         1         2    0   1.299079 |
    3. |     1    0         2         3    0   1.352642 |
    4. |     1    1         3         4    0   1.245575 |
    5. |     1    0         4         5    0   1.360458 |
    6. |     1    0         5         6    0    1.23678 |
    7. |     1    0         6         7    0   1.282709 |
    8. |     1    0         7         8    0   1.606675 |
    9. |     1    0         8         9    0   2.012462 |
   10. |     1    1         9        10    0   1.356058 |
       |------------------------------------------------|
   11. |     2    0         0         1    0   1.037136 |
   12. |     2    0         1         2    0   1.079899 |
   13. |     2    1         2         3    0   1.421035 |
   14. |     2    0         3         4    0   1.151635 |
   15. |     2    1         4         5    0   1.515432 |
   16. |     2    1         5         6    0   1.765524 |
   17. |     2    1         6         7    0   2.056888 |
   18. |     2    0         7         8    0   1.666944 |
   19. |     2    0         8         9    0   1.515404 |
   20. |     2    0         9        10    0    1.57168 |
       |------------------------------------------------|
   21. |     3    0         0         1    0    .909091 |
   22. |     3    0         1         2    0   .8264464 |
   23. |     3    0         2         3    0    .751315 |
   24. |     3    0         3         4    0   .6830137 |
   25. |     3    1         4         5    0   .8987746 |
   26. |     3    0         5         6    0   .7283852 |
   27. |     3    0         6         7    0   .7554348 |
   28. |     3    0         7         8    0   .9462299 |
   29. |     3    1         8         9    0   .6375985 |
   30. |     3    0         9        10    0    .983771 |
--more--


> Subject: Re: st: weighted time dependent Cox model
> From: sjsamuels@gmail.com
> Date: Sun, 19 Feb 2012 07:32:18 -0500
> To: statalist@hsphsun2.harvard.edu
> 
> 
> Correction: "exit() specifies the latest time under which the subject is both under observation and at risk of the failure event." (Stata 12 Survival Manual, page 486).
> 
> S.
> 
> In Stata, -enter- refers to the earliest entry time for a subject, and -exit- to the last observed time. (This is in the Manual entry for -stset-). Use this -stset- statement:
> 
> ****************************************************
> stset exit [pweight=weight], fail(event) id(id)
> ****************************************************'
> 
> Steve
> sjsamuels@gmail.com
> 
> On Feb 18, 2012, at 6:07 PM, Ehsan Karim wrote:
> 
> Dear Stata list,
> 
> I am trying to reproduce the weighted time dependent Cox model
> (Andersen–Gill format with IPTW) results in Stata that are originally
> obtained from R using same dataset, but so far getting the estimates
> different. Could anyone indicate what I could be done to fix this?
> 
> Any suggestions/references will be highly appreciated.
> 
> Thanks,
> 
> Ehsan
> 
> 
> 
> ##########################################
> # R results: coef -0.288 se 0.174
> ##########################################
> 
>> dataset = read.csv("http://stat.ubc.ca/~e.karim/dataset.csv";)
>> msmc = coxph(Surv(enter, exit, event) ~ tx + cluster(id), robust = TRUE, data = dataset, weights = weight)
>> summary(msmc)
> n= 14372, number of events= 131
> 
> coef exp(coef) se(coef) robust se z Pr(>|z|)
> tx -0.2882 0.7496 0.1745 0.1964 -1.467 0.142
> 
> exp(coef) exp(-coef) lower .95 upper .95
> tx 0.7496 1.334 0.5101 1.102
> 
> Concordance= 0.534 (se = 0.021 )
> Rsquare= 0 (max possible= 0.136 )
> Likelihood ratio test= 2.8 on 1 df, p=0.09455
> Wald test = 2.15 on 1 df, p=0.1423
> Score (logrank) test = 2.75 on 1 df, p=0.09739, Robust = 2.11 p=0.1459
> 
> ##########################################
> # Stata results: coef -.605 se .643
> ##########################################
> 
> . use http://stat.ubc.ca/~e.karim/dataset, clear
> (6 vars, 14372 obs)
> . stset exit [pweight=weight], fail(event) exit(exit) id(id) enter(enter)
> id: id
> failure event: event != 0 & event < .
> obs. time interval: (exit[_n-1], exit]
> enter on or after: time enter
> exit on or before: time exit
> weight: [pweight=weight]
> ------------------------------------------------------------------------------
> 14372 total obs.
> 12872 obs. begin on or after exit
> ------------------------------------------------------------------------------
> 1500 obs. remaining, representing
> 1500 subjects
> 17 failures in single failure-per-subject data
> 1500 total analysis time at risk, at risk from t = 0
> earliest observed entry t = 0
> last observed exit t = 1
> 
> . stcox tx, nohr robust nolog
> failure _d: event
> analysis time _t: exit
> enter on or after: time enter
> exit on or before: time exit
> id: id
> weight: [pweight=weight]
> (sum of wgt is 1.5062e+03)
> 
> Cox regression -- Breslow method for ties
> 
> No. of subjects = 1506.227846 Number of obs = 1500
> No. of failures = 17.16531456
> Time at risk = 1506.227846
> Wald chi2(1) = 0.89
> Log pseudolikelihood = -124.48415 Prob > chi2 = 0.3464
> 
> (Std. Err. adjusted for 1500 clusters in id)
> ------------------------------------------------------------------------------
> | Robust
> _t | Coef. Std. Err. z P>|z| [95% Conf. Interval]
> -------------+----------------------------------------------------------------
> tx | -.6053404 .6428669 -0.94 0.346 -1.865336 .6546555
> ------------------------------------------------------------------------------
> 
> ##########################################
> # dataset (partial)
> ##########################################
> . list
> +-------------------------------------------------------------------+
> | id tx event enter exit weight _st _d _t _t0 |
> |-------------------------------------------------------------------|
> 1. | 1 0 0 0 1 1.356058 1 0 1 0 |
> 2. | 1 0 0 1 2 1.356058 0 . . . |
> 3. | 1 0 0 2 3 1.356058 0 . . . |
> 4. | 1 1 0 3 4 1.356058 0 . . . |
> 5. | 1 0 0 4 5 1.356058 0 . . . |
> 6. | 1 0 0 5 6 1.356058 0 . . . |
> 7. | 1 0 0 6 7 1.356058 0 . . . |
> 8. | 1 0 0 7 8 1.356058 0 . . . |
> 9. | 1 0 0 8 9 1.356058 0 . . . |
> 10. | 1 1 0 9 10 1.356058 0 . . . |
> |-------------------------------------------------------------------|
> 11. | 2 0 0 0 1 1.57168 1 0 1 0 |
> 12. | 2 0 0 1 2 1.57168 0 . . . |
> 13. | 2 1 0 2 3 1.57168 0 . . . |
> 14. | 2 0 0 3 4 1.57168 0 . . . |
> 15. | 2 1 0 4 5 1.57168 0 . . . |
> 16. | 2 1 0 5 6 1.57168 0 . . . |
> 17. | 2 1 0 6 7 1.57168 0 . . . |
> 18. | 2 0 0 7 8 1.57168 0 . . . |
> 19. | 2 0 0 8 9 1.57168 0 . . . |
> 20. | 2 0 0 9 10 1.57168 0 . . . |
> |-------------------------------------------------------------------|
> 21. | 3 0 0 0 1 .983771 1 0 1 0 |
> 22. | 3 0 0 1 2 .983771 0 . . . |
> 23. | 3 0 0 2 3 .983771 0 . . . |
> 24. | 3 0 0 3 4 .983771 0 . . . |
> 25. | 3 1 0 4 5 .983771 0 . . . |
> 26. | 3 0 0 5 6 .983771 0 . . . |
> 27. | 3 0 0 6 7 .983771 0 . . . |
> 28. | 3 0 0 7 8 .983771 0 . . . |
> 29. | 3 1 0 8 9 .983771 0 . . . |
> 30. | 3 0 0 9 10 .983771 0 . . . |
> -

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index