Search code examples
rsurvival

'termlabels' error in coxph() function of survival package


I am trying to analyse a reoccurring event dataset and I am struggling to fit the model.

A subset of my data:

outdat <- structure(list(yr = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), jday = c(141, 151, 156, 157, 157, 158, 164, 168,  168, 168, 168, 168, 168, 170, 171, 171, 177, 177, 177, 178, 179,   181, 182, 182, 182, 182, 182, 184, 186, 188, 188, 188, 189, 191,     197, 197, 197, 198, 198, 199, 209, 211, 217, 223, 230, 161, 187,    196, 196, 196, 197, 197, 201, 204, 204, 204, 208, 209, 211, 212,     215, 215, 219, 221, 222, 225, 229, 229, 245, 252, 256, 159, 160,    166, 172, 174, 174, 178, 178, 178, 178, 178, 179, 182, 185, 185, 186, 186, 187, 187, 187, 187, 187, 187, 188, 188, 192, 195, 195,     195, 195, 195, 196, 196, 196, 200, 200, 200, 200, 202, 203, 204,     207, 207, 207, 207, 207, 207, 207, 208, 212, 212, 226), out = c(1,   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), row.names = c(NA,     -123L), class = c("tbl_df", "tbl", "data.frame"))

The data is showing an occurrence of crop disease in a country and I am trying to first the Cox PH model. The survival package manual recommends defining the term cluster() in the formula.

cm <- coxph(Surv(time =jday, event = out ) ~ cluster(yr), data = outdat)
Error in reformulate(temp[1 - tcl]) : 
'termlabels' must be a character vector of length at least one  

If I do not define covariate as a grouping variable the model is fitted.

cm <- coxph(Surv(time =jday, event = out ) ~ yr, data = outdat)

Note that I have tried changing the class of outdat$yr to character/factor.


Solution

  • A cluster() term adjusts the standard errors of the hazards, but since it's the only term on the right hand side of the formula, you have no covariates to adjust. You need at least one covariate. And I wouldn't include the cluster term unless you had a specific reason to.

    See here for more info