# Proportional hazard ratio formula in R

I'm new proportional hazard ratio models and new-ish to R, so I suspect this is a basic question:

The scenario is modeling the speed of an effect through hazard ratios. People are joining an organization, and most are invited by someone else within the organization*. The speed measured is the time between when the invitation is made and the person joins the organization, called the `registration_interval`. The way that seems evident to model this in R is like so:

````analysis<-coxph(Surv(registration_interval) ~ Factor1 + Factor2 + Factor3 ...)
````

However, there's also the prospect that people are faster/slower to join the organization as the date of their invitation moves along (ex. people invited in 2012 might join faster than people joining in 2009), and this could interact with the various factors. What is a sensible way to incorporate this `date` information?

*We only have data for those that do ultimately join the organization. We consider our model as simply modeling "joiners", and not right-censoring everyone whose invitation-registration intervals are infinitely long.

Edit for clarification: We know when people are invited, so on any given date there are only a certain number of people invited who could join. If everyone were invited all at once the proper model setup would just be:

````analysis<-coxph(Surv(registration_interval) ~ date + Factor1 + Factor2 + Factor3 ...)
````

But since the `registration_interval` is determined by two dates, there is some interaction between that and `date`. The hazard function would, for example, look quite different if there is a span of time in which nobody is invited, versus a span of time in which thousands of people are invited. Perhaps this is all packaged within `Surv`, and I'll look into it.

Edit regarding putting both `date` and `registration_interval` or join time information in Surv: Nope. That appears to be a red herring.

-

## 1 Answer

If `date` is the date people are invited, I would write a model just like you suggest in your second formula:

````coxph(Surv(registration_interval) ~ date + Factor1 + Factor2 + Factor3 ...)
````

When in doubt, it is always useful to write the full model.

$$\lambda(t|X) = \lambda_0(t) \cdot \exp(\beta_{date} X_{date} + \beta_1 X_1 + \beta_2 X_2 + ...)$$

In essence, this means that for the same values of `Factor1, Factor2, ...` (the variables $X_1, X_2, ...$) the hazard (the probability of answering the invitation at a particular instant) is multiplied by a factor $\exp(\beta_{date}X_{date})$. Note that if `date` increases linearly with time, the effect on the hazard will increase or decrese exponentially, so you might want to use `log(date)`, or another function of `date` instead.

I think that if everybody was invited at the same date, you would not use this model, because $X_{date}$ would be the same for every subject and would carry no information whatsoever (it would be absorbed in $\lambda_0(t)$ and could be removed from the model).

I also think that the hazard function does not change if there is a span of time in which nobody is invited, versus a span of time in which thousands of people are invited. What changes is the values of $X_{date}$, which is a property of individuals, not of the model.

Regarding the possibilities of interactions with the other variables, you can add product terms to the model as shown below.

````coxph(Surv(registration_interval) ~ date + Factor1 + Factor2 + Factor3 +
    date:Factor1 + date:Factor2 + date:Factor3)
````

In summary, I would try following the approach that you suggest yourself.

-
default
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 5, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.954071044921875, "perplexity_flag": "middle"}