On Saturday, Kathy wrote:
> I'm trying to use Kaplan Meier statistics to plot the cumulative
> probability that an event occurred. I want a plot of the log of negative
> log of survival (y axis) versus time (x axis). I'd also like to stratify by
> an important categorical risk factor and test for significance between two
> or more cumulative probability curves. How can I create such cumulative
> probability statistics AND graphical plots in Stata?
>
Suppose s is the survival function and _t is the analysis time. Then
a plot of -ln(-ln(s)) verses ln(_t) can be done by the command
-stphplot-. Using the options -by()- or -strata()- on -stphplot- will
produce one curve per level of a categorical variable.
Since Kathy wants _t, rather than ln(_t) on the horizontal axis, she
should use the option -nolntime- to get that plot. Also to get
ln(-ln(s)), rather than -ln(-ln(s)), Kathy can use the option
-nonegative-.
This only solves part of Kathy's problem. She also wants to create
variables with the values of the functions ploted. This can be done
using -sts gen- as follows:
clear
sysuse cancer
stset st, f(di)
sts gen s=s, by (drug)
gen s1=s if drug==1
gen s2=s if drug==2
gen s3=s if drug==3
sort _t
twoway line s1 s2 s3 _t, connect(stairstep stairstep stairstep)
sts, by(drug)
gen lnlns1=ln(-ln(s1)) if drug==1
gen lnlns2=ln(-ln(s2)) if drug==2
gen lnlns3=ln(-ln(s3)) if drug==3
twoway connected lnlns1 lnlns2 lnlns3 _t
stphplot, by(drug) nolntime nonegative
Lastly, Kathy needs to test for difference between these curves. This
can be done by using -sts gen- again to get the standard errors,
creating the confidence intervals and then plotting, as follows:
sts gen sell=se(lls), by(drug)
gen sell1=sell if drug==1
gen sell2=sell if drug==2
gen sell3=sell if drug==3
gen lb1=lnlns1-invnorm(0.975)*sell1 if drug==1
gen lb2=lnlns2-invnorm(0.975)*sell2 if drug==2
gen lb3=lnlns3-invnorm(0.975)*sell3 if drug==3
gen ub1=lnlns1+invnorm(0.975)*sell1 if drug==1
gen ub2=lnlns2+invnorm(0.975)*sell2 if drug==2
gen ub3=lnlns3+invnorm(0.975)*sell3 if drug==3
twoway rarea lb1 ub1 _t, bcolor(gs12) || /*
*/ rarea lb2 ub2 _t, bcolor(gs13) || /*
*/ rarea lb3 ub3 _t, bcolor(gs14) || connected lnlns1 _t || /*
*/ connected lnlns2 _t || connected lnlns3 _t
--May
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/