2
$\begingroup$

I am trying plot the dose-response relation between A AND B in a random effect Cox model. But I met an error output. I don't know what happened. Following is the example.

n <- 1000
set.seed(731)

age <- round(50 + 12*rnorm(n), 1)
label(age) <- "Age"

sex <- factor(sample(c('Male','Female'), n, 
                     rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)

smoking <- factor(sample(c('Yes','No'), n, 
                         rep=TRUE, prob=c(.2, .75)))

h <- .02*exp(.02*(age-50)+.1*((age-50)/10)^3+.8*(sex=='Female')+2* 
(smoking=='Yes'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'

e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"

# Add missing data to smoking
smoking[sample(1:n, round(n*0.05))] <- NA

# Create a data frame since plotHR will otherwise
# have a hard time getting the names of the variables
ds <- data.frame(
  dt = dt,
  e = e,
  age=age, 
  smoking=smoking,
  sex=sex)
ds$center[1:500]<-1
ds$center[501:1000]<-2
library(splines)
library(coxme)
Srv <- Surv(dt,e)
fit.coxph<-coxme(Srv ~ bs(age, 3) + strata(center) + smoking + (1|sex), data=ds)
plotHR(fit.coxph,  plot.bty="o", xlim=c(30, 70),term = 'age')

Here I want to plot the non-linear relation between age and risk of my interested outcome. But it reported following error:

Error in prPhEstimate(model = model, ylog = ylog, cntrst = cntrst, xlim = xlim, : Could not identify the term 'age' among the following model terms: ''

$\endgroup$
  • $\begingroup$ I think you might get a better response on an R site like R-help. But first look at the summary of fit.coxph and see whether it does show a term called age. $\endgroup$ – mdewey Sep 4 '18 at 10:07