I want to write code for calculating hazard rate using coxph for a dataset. This data has 5 variables, 2 of them are used in Surv(), and two of them are used as covariates. Now I can write the function which can simply calculate hazard rate for two covariates after input dataname. However, when I want to calculate hazard ratio using same function for 3 covariates, the program said "run out of iterations and did not converge or more coefficients maybe infinite",and the result contains all five variables as covariates (which should be three). Here is my code, can anyone correct it? Thanks!
library(KMsurv)
library(survival)
data(larynx)
larynx2 = larynx[,c(2,5,1,3,4)]
larynx2$stage = as.factor(larynx2$stage)
mod = function(dataname){
fit = coxph(Surv(dataname[,1],dataname[,2]) ~ ., data = dataname, ties = "breslow")
return(list(result = summary(fit)))
}
mod(larynx2)
Surv()
instead ofdataname[, 1]
anddataname[, 2]
? There could be something weird happening since you are using.
in the formula, using the data frame in the formula, and using thedata
argument. - Gregor Thomas