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-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.