# udpateRidge.R # # Fitting cox model using ridge regression with factor-level covariates # - Using chipmanj/survival github library(devtools) cat("\nInstalling survival from chipmanj/survival github\n\n") devtools::install_github("chipmanj/survival") library(survival) # Lung dataset cat("\nUsing lung dataset.\n") cat("\nSetting ph.ecog and inst to factor variables.\n") cat("\nKeeping age as numeric.\n") # table(lung$ph.ecog) # table(lung$ph.karno) # table(lung$inst) lung$ph.ecog <- as.factor(lung$ph.ecog) lung$inst <- as.factor(lung$inst) update0 <- survival::coxph(Surv(time,status)~age + ph.ecog + inst, data = lung) update1 <- survival::coxph(Surv(time,status)~age + ridge(ph.ecog,inst,theta=0), data = lung) update2 <- survival::coxph(Surv(time,status)~age + ridge(ph.ecog,inst,theta=100), data = lung) cat("\n\n---\n\nModel 0: Cox model adjusting for factor and non-factor covariates.\n No ridge regression.\n\n") update0 cat("\n\n--\n\nModel 1: Cox model adjusting for factor and non-factor covariates.\n Ridge applied but with theta = 0 (should match Model 0).\n") update1 cat("\n\n--\n\nModel 2: Cox model adjusting for factor and non-factor covariates.\n Ridge applied with theta = 100 (just for a frame of reference).\n\n") update2