Skip to main content

Logistic regression with Cox PH procedures

Illustration of the Stata stcox command used for logistic regression estimation.

Results are compared to output from the logit procedure.

Background:

In SAS you can use the ties=discrete option in the model statement for moderately sized logistic regression analyses or in general for reasonable sized data sets if time is truly discrete.

The method is illustrated on sas.com for a conditional logistic regression, adding a strata statement - which in Stata compares to a strata variable specified in the strata option added to the stcox command.
Have a look at support.sas.com here.

"Extra memory is needed for certain TIES= options. Let be the maximum multiplicity of tied times.
The TIES=DISCRETE option requires extra memory (in bytes) of
4k*(p^2+4p), where k is the maximum multiplicity of tied times and p is the number of predictors/explanatory variables
Source of citation on sas.com.

The equivalent option in Stata's stcox is exactp, which however is not compatible with the vce(cluster) option. Can we mend it with the _robust command?

Stata code follows

*Demonstration
use http://www.ats.ucla.edu/stat/stata/dae/binary.dta, clear


*Benchmark estimates with the logit command


logit admit gre, or


/* Result
---------------------------------------------------------------------------
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
gre | 1.003589 .0009895 3.63 0.000 1.001651 1.00553
---------------------------------------------------------------------------
*/


logit admit gre gpa i.rank, or


/*Result
---------------------------------------------------------------------------
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
gre | 1.002267 .0010965 2.07 0.038 1.00012 1.004418
gpa | 2.234545 .7414652 2.42 0.015 1.166122 4.281877
|
rank |
2 | .5089309 .1610714 -2.13 0.033 .2736922 .9463578
3 | .2617923 .0903986 -3.88 0.000 .1330551 .5150889
4 | .2119375 .0885542 -3.71 0.000 .0934435 .4806919
---------------------------------------------------------------------------
*/


logit admit gre, or vce(cluster rank)


/*Result
(Std. Err. adjusted for 4 clusters in rank)
---------------------------------------------------------------------------
| Robust
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
gre | 1.003589 .0005782 6.22 0.000 1.002456 1.004723
---------------------------------------------------------------------------
/*


*Now similar logistic regressions with stcox


capture stset ,clear
stset time, failure(admit==1) origin(time 0)
stcox gre, exactp


/*Result
---------------------------------------------------------------------------
_t | Haz. Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
gre | 1.00358 .0009882 3.63 0.000 1.001644 1.005518
---------------------------------------------------------------------------
*/


stcox gre gpa i.rank, exactp


/*Result
---------------------------------------------------------------------------
_t | Haz. Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+-------------------------------------------------------------
gre | 1.002261 .001095 2.07 0.039 1.000117 1.00441
gpa | 2.229813 .7389021 2.42 0.016 1.164668 4.269082
|
rank |
2 | .5099792 .1611582 -2.13 0.033 .2745141 .9474148
3 | .2627833 .0906066 -3.88 0.000 .1336925 .5165218
4 | .2128309 .0888118 -3.71 0.000 .0939374 .482204
---------------------------------------------------------------------------
*/


*Note it is unwise to rearrange data and make a 'fix' for clusteret data using the stset command - due to memory limitations. A prober solution would utilize postestimation - which would also make comparison with unadjusted s.e.'s easy.

Comments

Popular posts from this blog

HackRF on Windows 8

This technical note is based on an extract from thread. I have made several changes and added recommendations. I have experienced lot of latency using GnuRadio and HackRF on Pentoo Linux, so I wanted to try out GnuRadio on Windows.



HackRF One is a transceiver, so besides SDR capabilities, it can also transmit signals, inkluding sweeping a given range, uniform and Gaussian signals. Pentoo Linux provides the most direct access to HackRF and toolboxes. Install Pentoo Linux on a separate drive, then you can use osmocom_siggen from a terminal to transmit signals such as near-field GSM bursts, which will only be detectable within a meter.









Installation of MGWin and cmake: Download and install the following packages:
- MinGW Setup (Go to the Installer directory and download setup file)
- CMake (I am using CMake 3.2.2 and I installed it in C:\CMake, this path is important in the commands we must send in the MinGW shell)
Download and extract the packages respectively in the path C:\MinGW\msys\…

Example: Beeswarm plot in R

library(foreign)

data <- read.dta("C:/Users/hellmund/Documents/MyStataDataFile.dta")

names(data)

install.packages('beeswarm')

library(beeswarm)

levels(data$group)

png(file="C:/Users/hellmund/Documents/il6.png", bg="transparent")

beeswarm(data$il6~data$group,data=data, method=c("swarm"),pch=16,pwcol=data$Gender,xlab='',ylab='il6',ylim=c(0,20))

legend('topright',legend=levels(data$Gender),title='Gender',pch=16,col=2:1)

boxplot(data$il6~data$group, data=data, add = T, names = c("","",""), col="#0000ff22")

dev.off()

Example: Business cards typeset with LaTeX

So you enjoy the quality of a professional typesetting system? You got Avery labels, a working MikTeX and the ticket package installed...
You might find some assistance from a half criminal paranoid zealot system administrator, willing to guide you through a dinosaur kingdom of TeX ... but that kind of assistance might also just leave you with nothing.

It was easy to get the layout of the labels with the option zw32010, but how about page margins? I tried to set things straight with the layouts package (\usepackage{layouts}\currentpage \pagedesign), but then there was still some unwanted white space and margins...

To make things less complicated I decided to make a single card. The solution is a hack because it needs customization (with voffset and hoffset as you see n the TeX code below) but the adjustment is more straightforward, especially if you use the boxed option with ticket.

The card was converted to png with Ghostscript and I could easily print the business cards with Averys …