whas.table <- read.table('http://www.stanford.edu/class/stats262/data/whas.csv', sep=',', header=T) whas.table <- whas.table[(whas.table$yrgrp == '1975 & 1978'),] attach(whas.table) library(survival) theta.val <- seq(0, 10, 0.1) AIC.val <- 0 * theta.val myextractAIC.coxph <- function (fit, scale, k = 2, edf=NULL) { if (is.null(edf)) edf <- length(fit$coef) if (edf > 0) c(edf, -2 * fit$loglik[2] + k * edf) else c(0, -2 * fit$loglik) } for (i in 1:length(theta.val)) { whas.theta.coxph <- coxph(Surv(lenfol, (fstat == 'Dead')) ~ ridge(age, lenstay, theta=theta.val[i]) + sho + chf) print(myextractAIC.coxph(whas.theta.coxph, edf=sum(whas.theta.coxph$df))) AIC.val[i] <- myextractAIC.coxph(whas.theta.coxph, edf=sum(whas.theta.coxph$df))[2] } plot(theta.val, AIC.val)