# Problems with IPTW adjusted survival analysis in stata

#### fjanisch

##### New Member
Hello, i hope you can maybe help me.

I am trying to do a IPTW survival analysis adherent to the paper of Seisen et al. I use Stata/MP 14.0

https://www.researchgate.net/profile...-Data-Base.pdf

I first did a multiple imputation and subsequently, iptw. I created a graph with a comparison of values before and after weighting with the kernel density. After that, i basically did a cox regression test. My code is below. treatement in this case is "cn":

mi set flong
mi register imputed pt pn
mi impute chained (ologit) pt pn, add (15) replace augment noisily

mi xeq: logit cn; predict ps0, pr
mi xeq: logit cn age gender histo sarcomatoid pt pn mskcc; predict ps1 , pr
mi xeq: gen ipw= cn*(ps0/ps1) + ((1-cn)*((1-ps0)/(1-ps1)))

tempvar fw
gen fw' = round((n*1000),1)
twoway (kdensity ps1 if cn==0 [fw=fw'], bw(0.02) lpattern(solid) lwidth(medthick) lcolor("0 64 115")) (kdensity ps1 if cn==1 [fw=fw'] , bw(0.02) lpattern(solid) lwidth(medthick) lcolor("220 169 31")), xtitle("Propensity Score", size (medlarge)) xlabel(0.4 0.6 0.8 1) ytitle("Kernel Density", size (medlarge)) ylabel(0 2 4 6 8 10, angle (horizontal)) legend(order (1 2) label(1 "No CN") label(2 "CN") cols (1)) legend(pos(2) ring(0)) graphregion(fcolor(white)) xtitle("propensity scores BEFORE matching") saving(before, replace)

tempvar fw
gen fw' = round((ipw*1000),1)
twoway (kdensity ps1 if cn==0 [fw=fw'], bw(0.02) lpattern(solid) lwidth(medthick) lcolor("0 64 115")) (kdensity ps1 if cn==1 [fw=fw'] , bw(0.02) lpattern(solid) lwidth(medthick) lcolor("220 169 31")), xtitle("Propensity Score", size (medlarge)) xlabel(0.4 0.6 0.8 1) ytitle("Kernel Density", size (medlarge)) ylabel(0 2 4 6 8 10, angle (horizontal)) legend(order (1 2) label(1 "No CN") label(2 "CN") cols (1)) legend(pos(2) ring(0)) graphregion(fcolor(white)) xtitle("propensity scores AFTER matching") saving(after, replace)

graph combine before.gph after.gph, ycommon

mi stset timedeath [pweight = ipw], failure (css==1)

sts test cn

Problems:

1) Unfortunately, i have no idea how to do the rest of the graphs in the paper that my supervisor insists on. I looked everywhere, but can not find them. In paarticular, i dont know how to do the iptw-adjusted hazard ratio forrest plot, and Fig. A1 to depict the balancing through weighting.

2) I tried to do the standardised differences before and after Weighting. However, it does not seem to make a lot of difference:

Before:
. stddiff gender i.smoking histo sarcomatoid i.pt i.pn i.mskcc, by (cn) abs

------------------------------------------------------------------------------
| cn=0 | cn=1 |
| Mean or N SD or (%) | Mean or N SD or (%) | Std Diff
-------------+-------------------------+-------------------------+------------
gender | .2848 .45276 | .2308 .42337 | 0.12329
| | |
smoking | | |
1 | 19 (12.0) | 15 (14.4) | 0.20418
2 | 37 (23.4) | 19 (18.3) |
3 | 7 ( 4.4) | 2 ( 1.9) |
4 | 95 (60.1) | 68 (65.4) |
| | |
histo | .1772 .38306 | .1827 .38829 | 0.01420
sarcomatoid | .01899 .13691 | .1442 .35302 | 0.46778
| | |
pt | | |
0 | 43 (33.9) | 17 (16.5) | 0.61733
1 | 31 (24.4) | 13 (12.6) |
2 | 47 (37.0) | 63 (61.2) |
3 | 6 ( 4.7) | 10 ( 9.7) |
| | |
pn | | |
0 | 64 (52.5) | 27 (27.8) | 0.91122
1 | 48 (39.3) | 27 (27.8) |
2 | 10 ( 8.2) | 43 (44.3) |
| | |
mskcc | | |
0 | 48 (30.4) | 11 (10.6) | 0.56903
1 | 89 (56.3) | 64 (61.5) |
2 | 21 (13.3) | 29 (27.9) |
------------------------------------------------------------------------------

After:

------------------------------------------------------------------------------
| cn=0 | cn=1 |
| Mean or N SD or (%) | Mean or N SD or (%) | Std Diff
-------------+-------------------------+-------------------------+------------
gender | .2848 .45141 | .2308 .42145 | 0.12375
| | |
smoking | | |
1 | 304 (12.0) | 240 (14.4) | 0.20418
2 | 592 (23.4) | 304 (18.3) |
3 | 112 ( 4.4) | 32 ( 1.9) |
4 | 1520 (60.1) | 1088 (65.4) |
| | |
histo | .1772 .38193 | .1827 .38653 | 0.01425
sarcomatoid | .01899 .13651 | .1442 .35143 | 0.46980
| | |
pt | | |
0 | 803 (32.2) | 276 (16.6) | 0.54292
1 | 573 (22.9) | 211 (12.7) |
2 | 983 (39.4) | 1016 (61.1) |
3 | 138 ( 5.5) | 160 ( 9.6) |
| | |
pn | | |
0 | 1236 (49.6) | 474 (28.6) | 0.74497
1 | 953 (38.2) | 470 (28.4) |
2 | 303 (12.2) | 713 (43.0) |
| | |
mskcc | | |
0 | 768 (30.4) | 176 (10.6) | 0.56903
1 | 1424 (56.3) | 1024 (61.5) |
2 | 336 (13.3) | 464 (27.9) |
------------------------------------------------------------------------------

Do i miss something? Do i have to do the std differently to properly assess the effect of iptw?

3) How does weighting affect the median survival exactly? SInce after iptw, sts test automatically swithes to a cox regression instead of a log rank, i was not able to calculate the statistical difference in median survival
(Code: sts test cn if r(p50), logrank) <-- "logrank" was deleted for the weighted values.

I know i have a lot of questions. I tried to read it up myself, but as a not formally trained statistician, without help i dont know where to start or where to turn to.
i hope you can help me and am already greatful for every bit of advice.

Kind regards,

Florian

#### hlsmith

##### Less is more. Stay pure. Stay poor.
I did a comparable analyses about 6 months ago. I ending up using SAS for most of it and a little R too. So you are asking how to get the fig 2 (standardized) at the end? I feel like R should have a program for it, I didn't figure it out when I did my analyses. I just reported it in a table. I feel like SAS automatically does it with causaltrt procedure, but I was not using that.

As for comparing the median, can you also fit a K-M. I feel like I fit both K-M and Survival using same weights both times.

Talk more about using kernel weights. I remember thinking about that but may have seen a paper saying why it was less desirable. But it was just a single paper. So you mean get the PS's via a GAM or something?

Interested to hear more, not a STATA user.

#### fjanisch

##### New Member
Yes, Fig. A2 of the appendix. They have the standardized differences in a table as well. In the paper, everything was done in stata, so it must be possible somehow.

Yes, interestingly, when using the sts test, which usually is used as well to compare the medians and is used for the K-M as well, it gives me the same result for weighted and unweighted values.

Well, from how i understand it, Kernel is a smoothed out version of a density estimation, such as a histogram. It uses a smoothing parameter (bandwidth). How i got it, it is easier to compare unweighted and weighted cohorts, since the values are not discrete and as such, offer a better visualization. Stata calculates the ps, and conecutively the iptw, automatically when doing a logit regression. You can then just tell it to create two kernel density graphs of the cohorts before and after weighting and then combine them. stata has an option for the graphical image.

#### ondansetron

##### TS Contributor
3) How does weighting affect the median survival exactly? SInce after iptw, sts test automatically swithes to a cox regression instead of a log rank, i was not able to calculate the statistical difference in median survival
(Code: sts test cn if r(p50), logrank) <-- "logrank" was deleted for the weighted values.
I would just like to clarify that the logrank or other options for "comparing survival between groups" via a cox regression or KM plot is not a test for median survival. The test is more general for the null hypothesis that the survival functions/distributions are equal across groups and a significant test could lead you to conclude the survival curves (overall functions) are different in some manner, but this is not a test for differences median survival.

#### hlsmith

##### Less is more. Stay pure. Stay poor.
@ondansetron - I agree that it is not a test of medians. I feel via the K-M you can get the median values and then conduct a test at them or other percentile levels. Unsure where the issue is in Stata.

@fjanisch - I totally get your reference to kernel density now. I thought you were originally saying the scores themselves came from a smoothing process, but yes comparing scores via smoothed histograms is common.

Just for curiosity, what data was missing and if you did multiple imputations was that just before the logistic process where scores were calculated? And did you run multiple logistics and pool them to get the scores?

Thanks.