In R, is there a predefined function that will give me the log hazard ratio and its standard error for a black male (as shown in the example below) given the output of coxph regression?
library(survival)
library(KMsurv)
#Kidney transplant data from Klein and Moeshberger. Massage data to make
#results look like those in book
data(kidtran)
data2 <- kidtran
data2$Gender <- "male"
data2[data2$gender==2,7] <- "female"
data2$Race <- "white"
data2[data2$race==2,8] <- "black"
data2$Gender <- as.factor(data2$Gender)
data2$Race <- as.factor(data2$Race)
data2$Race <- relevel(data2$Race,ref="white")
fit2 <- coxph(Surv(time,delta) ~ Gender * Race, data=data2)
summary(fit2)
#Relative log risk for a black male (reference white female) from
#page 252 in Klein and Moeshberger
(coef(fit2)[3] + coef(fit2)[2] + coef(fit2)[1])
sqrt(sum(diag(fit2$var)) + 2*fit2$var[2,1] + 2*fit2$var[3,1] + 2*fit2$var[3,2])
#Let's use predict
black.male <- data.frame(
Gender="male",
Race="black"
)
white.female <- data.frame(
Gender="female",
Race="white"
)
bm <- predict(fit2,newdata=black.male,se.fit=TRUE)
#bm in terms of original coefficients
coef(fit2)[3]*(1-fit2$means[3]) + coef(fit2)[2]*(1-fit2$means[2]) + coef(fit2)[1]*(1-fit2$means[1])
wf <- predict(fit2,newdata=white.female,se.fit=TRUE)
#Relative log risk and se for a black male (reference white female)
bm$fit - wf$fit
sqrt(bm$se.fit^2 + wf$se.fit^2)