# [R] How to estimate a hazard ratio using an external hazard function

Terry Therneau therneau at mayo.edu
Thu Apr 10 15:09:34 CEST 2008

```----included message ----
Hi,

I would like to compare the hazard functions of two samples using the
Cox proportional hazards model. For sample 1 I have individual time-to-
event data. For sample 2 I don't have individual data, but grouped
data that allows to obtain a hazard function.

I am wondering if there is an R function that allows to obtain a
hazard ratio of the two hazard funtions (under the proportionality
assumption) taking into account the censoring of the data?

I am aware of survexp and survdiff functions, but I am not sure if
that is the best way to do what I need.

Any help will be highly appreciated.

--- End inclusion ------------

The functions for population expected survival are designed for just this
problem, i.e., those that use the US death rate tables.  Under the assumption
that the second (grouped data set) has a much larger sample size than the first
(sample) data:
For each subject in sample 1, compute the expected number of events for that
subject, using the rates found in sample 2 = (time at risk) * (rate during that
time).  For population rate tables this turns out to be a sum: the external
rates are a function of age so one gets ......+ (# days at age 55)*(rate for 55
year olds) + (# days at age 56)*(rate for 56 year olds) + ....  Call the result
"expected", a vector with one element per subject.

Now fit a Poisson model with offset(log(expected)) as one of the predictors.
This is a proportional hazards model, with the usual Cox baseline hazard
lambda_0 replaced by the known hazard function from sample 2.

Terry Therneau

```