Smoothed HR for interaction term in coxph model

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Smoothed HR for interaction term in coxph model

Lynn Dunsire
Hello R-help members,

 

I have a dataset with 2 treatments and want to assess the effect of a
continous covariate on the Hazard ratio between treatment A and B.  I want a
smoothed interaction term which I have modelled below with the following
code:

 

surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=0) + factor(DICHOTOMOUS)
+  pspline(CONTINUOUS, df=0)*factor(DICHOTOMOUS), data = datanew2)

 

and consequently I would like to obtain a smoothed plot of the hazard ratio
between treatment A and B on the y-axis with the continuous covariate on the
x-axis.  As termplot ignores interaction terms, I was wondering if anyone
has seen anything like this before and can advise on the best way to do it.

 

Many thanks in advance for any help that you can offer,

 

Kind regards,

 

Lynn


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Smoothed HR for interaction term in coxph model

Andrews, Chris
Please include example data in the future.  Perhaps the following is useful.

(1) Your model is redundant.  The "*" produces both main effects and the interaction.  So I removed the main effects from your call
(2) For my simulated data, the df=0 option chose a model that resulted in a singular fit.  I selected a smoother spline (df=2).
(3) the two plots at the end show (1) the risk (exp(linear predictor)) for combinations of "CONTINUOUS" and "DICHOTOMOUS" and (2) a ratio (risk for A vs risk for B), which I think is what you wanted.

Chris

library(survival)
set.seed(20140530)
nn <- 1000
datanew2 <- data.frame(my.surv = Surv(rexp(nn)), DICHOTOMOUS=factor(rep(c("A","B"), nn/2)), CONTINUOUS=rnorm(nn))

#surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=0) + factor(DICHOTOMOUS) + pspline(CONTINUOUS, df=0) * factor(DICHOTOMOUS), data=datanew2)
#surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=0) * factor(DICHOTOMOUS), data=datanew2)
surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=2) * factor(DICHOTOMOUS), data=datanew2)
surv.fit

xseq <- seq(-3, 3, length=100)
predictions <- matrix(predict(surv.fit, newdata=expand.grid(CONTINUOUS=xseq, DICHOTOMOUS=factor(c("A","B"))), type="risk"), ncol=2)
matplot(predictions, type="l")
plot(xseq, predictions[,1]/predictions[,2], type="l", ylab="Hazard Ratio of Event (A vs B)", xlab="CONTINUOUS")


-----Original Message-----
From: Lynn Dunsire [mailto:[hidden email]]
Sent: Thursday, May 29, 2014 6:03 AM
To: [hidden email]
Subject: [R] Smoothed HR for interaction term in coxph model

Hello R-help members,

 

I have a dataset with 2 treatments and want to assess the effect of a
continous covariate on the Hazard ratio between treatment A and B.  I want a
smoothed interaction term which I have modelled below with the following
code:

 

surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=0) + factor(DICHOTOMOUS)
+  pspline(CONTINUOUS, df=0)*factor(DICHOTOMOUS), data = datanew2)

 

and consequently I would like to obtain a smoothed plot of the hazard ratio
between treatment A and B on the y-axis with the continuous covariate on the
x-axis.  As termplot ignores interaction terms, I was wondering if anyone
has seen anything like this before and can advise on the best way to do it.

 

Many thanks in advance for any help that you can offer,

 

Kind regards,

 

Lynn


        [[alternative HTML version deleted]]


**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Smoothed HR for interaction term in coxph model

Therneau, Terry M., Ph.D.
In reply to this post by Lynn Dunsire


On 05/30/2014 05:00 AM, [hidden email] wrote:

>
>
> I have a dataset with 2 treatments and want to assess the effect of a
> continous covariate on the Hazard ratio between treatment A and B.  I want a
> smoothed interaction term which I have modelled below with the following
> code:
>
>
>
> surv.fit <- coxph(my.surv ~ pspline(CONTINUOUS, df=0) + factor(DICHOTOMOUS)
> +  pspline(CONTINUOUS, df=0)*factor(DICHOTOMOUS), data = datanew2)
>
>
>
> and consequently I would like to obtain a smoothed plot of the hazard ratio
> between treatment A and B on the y-axis with the continuous covariate on the
> x-axis.  As termplot ignores interaction terms, I was wondering if anyone
> has seen anything like this before and can advise on the best way to do it.
>
>

You have 2 problems.
  1. The pspline code's maximization routine simply can't cope with two terms that both
have "df=0", i.e., asking it to find the best degrees of freedom.  You have to choose df
yourself.  (Making the code smarter has been on my TODO list for years, and will likely
remain there a while longer.)

  2. What you want to do is harder than you think.  For definiteness assume that we have
CONTINUOUS= age and DICHO= sex.  Then one wants a smooth curve of risk vs age for the
males, and a separate one for the females.
For a smoothing spline, that means two penalties, one attached to each term.
    People get sloppy about the term "interaction".  For two categorical variables what
needs to be done is clear, namely to have one coefficient for each unique combination.
Software will add the batch of coefficients for us automatically when a "*" is placed in
the formula.  For continuous variables the use of "*" in a formula adds the product of the
two terms, which is not an interaction except in very special circumstances.

   Between the two of these, an interaction times a pspline term is doomed to fail.
(Another update for the package -- I need to print an error message in this case).

  Products of coefficients will work for ns() terms and an interaction.

Terry T.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.