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

Montserrat Rue montse.rue at cmb.udl.cat
Fri Apr 11 23:53:30 CEST 2008

```Dear Professor Therneau,

We have followed your advice and the results that we have obtained make a
lot of sense. Thanks a lot!

I would like to check if we took a correct approach to obtain the expected
number of events. Since we had the hazard function as continuous (we used
splines)  we have obtained the expected number of events for each
individual of sample 1 integrating the sample 2 hazard function, as a
cumulative hazard, in the survival time interval of the individual. This
estimation would correspond to the sum of the products that you mentioned
(time at risk) * (rate during that time).

Do you think that we have estimated correctly the expected number of events?

Thanks again!

Montse

> ----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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Montserrat Rue
Department of Basic Medical Sciences
University of Lleida (Spain)

```