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]

Re: st: Main effect for time-varying covariate


From   Phil Clayton <[email protected]>
To   [email protected]
Subject   Re: st: Main effect for time-varying covariate
Date   Sat, 31 Aug 2013 13:25:07 +1000

Here's an example. No doubt it could be improved. Much of the code is borrowed from stphtest.ado.

Phil

-------- program crphplot --------
program define crphplot, rclass
	version 11
	syntax varname(fv), *
	
	capture assert e(cmd)=="stcrreg"
	if _rc {
		di as error "crphplot can only be used after stcrreg"
		error 498
	}
	
	* convert factor variable notation
	_ms_extract_varlist `varlist'
	local varlist "`r(varlist)'"
	
	* calculate schoenfeld-like residuals
	tempname b
	mat `b' = e(b)
	local dim = colsof(`b')
	forval i = 1/`dim' {
		tempvar sch`i'
		local schvars `schvars' `sch`i''
	}
	qui predict double `schvars' if e(sample), schoenfeld
	local n : word count `schvars'

	* subtitle will use variable label if it exists
	local varlab: variable label `varlist'
	if "`varlab'"!="" local subtitle subtitle("`varlab'")
	
	* lowess plot of the relevant variable vs time
	forvalues i=1/`n' {
		local lbl: variable label `sch`i''
		local lbl=substr("`lbl'", 23, .)
		if "`lbl'"=="`varlist'" ///
			lowess `sch`i'' _t, mean noweight ///
			title("Test of proportional subhazards assumption") ///
			xtitle(Time) `subtitle' `options'
	}
end
-------- end program --------

-------- example analysis --------
webuse hypoxia, clear
stset dftime, failure(failtype==1)
stcrreg ifp tumsize pelnode, compete(failtype==2)
crphplot ifp
-------- end example --------


On 31/08/2013, at 11:30 AM, Phil Clayton <[email protected]> wrote:

> It wouldn't be hard to program a wrapper for generating and plotting the Schoenfeld-like residuals. That's essentially what -estat phtest, plot()- does (take a look at -viewsource stphtest.ado-)


*
*   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