#===> extract a p-value from coxph <===# local.coxph.test <- function(coxph.fit, pos, C=NA, d=NA, sign.digits=3){ # checking H_0: C*beta.hat = c # coxph.fit is a coxph model # pos is the position numbers of the parameters of interest # C is a q-by-p matrix # d is a q-by-1 matrix n <- length(pos) if(is.na(C)){ C <- matrix(0, n, n) for(i in 1:n) C[i,i] <- 1 } else { if(dim(C)[1] != n) stop("C has improper dimensions\n") } if(is.na(d)) d <- matrix(0, n, 1) if(dim(d)[1] != dim(C)[1]) stop("C and d do not have appropriate dimensions\n") I. <- coxph.fit$var[pos,pos] est <- matrix(as.vector(coxph.fit$coeff[pos]), dim(C)[2]) X <- as.numeric( t(C%*%est - d) %*% solve( t(C) %*% I. %*% C ) %*% (C%*%est - d) ) signif(1-pchisq(X, dim(C)[1]), sign.digits) } local.p.test <- local.coxph.test