Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: graphing interactions after -stpm2-


From   "Lambert, Paul (Prof.)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: graphing interactions after -stpm2-
Date   Tue, 27 Aug 2013 17:07:03 +0100

Adam,

The syntax parsing does not appear to work properly for hrnum()/hrdenom() when there is an  interaction between a categorical and continuous covariate. I will fix this in the next update.

In the meantime, you can either create your own interaction or use the -partpred- command available from SSC. See below,

sysuse cancer.dta, clear
recode drug 1=0 2/3=1
// creating own interaction
gen drug_age = drug*age
stpm2 drug age drug_age, df(3) eform sca(h)
predict hr1 if drug==1, hrnum(drug 1 drug_age .) hrdenom(drug 0) ci
line hr1 hr1_lci hr1_uci age, sort name(g1, replace)

// using partpred
stpm2 drug##c.age, df(3) eform sca(h)
partpred hr2 if drug == 1, for(1.drug 1.drug#c.age)  ci(hr2_lci hr2_uci) eform
line hr1 hr1_lci hr1_uci age, sort name(g2, replace)

Paul


Professor Paul C Lambert
Professor of Biostatistics
Department of Health Sciences 
University of Leicester
2nd Floor, Adrian Building
University Road 
Leicester LE1 7RH
Tel: +44 (0)116 229 7265, Fax: +44 (0)116 229 7250
e-mail: [email protected] 
Homepage: http://www2.le.ac.uk/Members/pl4/ 



-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Adam Olszewski
Sent: 27 August 2013 05:07
To: [email protected]
Subject: st: graphing interactions after -stpm2-

Hello,
I was wondering if someone could advise me about how to graph an interaction effect between a categorical and continuous variable in a survival model. Specifically, I would like to fit a model with interaction and then plot the hazard ratio for the categorical variable on Y-axis against the continuous predictor on X-axis.
I would like to do it fitting a flexible parametric model using the user-written -stpm2- command (available from SSC).

I imagine the series of commands being something like:

sysuse cancer.dta
* binarize for simplicity
recode drug 1=0 2/3=1
stpm2 drug##c.age, df(3) eform sca(h)
* predict hr, (..... - this is what I cannot figure out line hr age

I tried various permutations of hrnum/hrdenom option as well as margins, but I cannot get the right result. I would imagine that predict hr, hrn(drug 1 age .) hrd(drug 0 age .) should work, but it produces a flat line. I assume I am missing something simple.
A solution for a Cox model might help too, since perhaps I could figure out the stpm2 equivalent.

Best,
Adam Olszewski
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index