gugl58
1/30/2018 - 1:40 PM

single.cox

Calculate one single coxmodel with optional covariates

single.cox <- function(response
					   ,responsename
					   ,pheno.df
					   ,survtimename
					   ,surveventname
					   ,single.corr.formulastring=c("+SEX", "+(Alter>45)", "+Stadium", "+IPS")
					   ,single.corr.formulastring.name=c("Sex", "AgeD", "Stadium", "IPS")){
	# inst.load.packages("survival", silent=TRUE)
	# inst.load.packages("stringr", silent=TRUE)
	
	survsim <- Surv(pheno.df[[survtimename]], pheno.df[[surveventname]])
	formula.resp <- paste("response", single.corr.formulastring, sep = " ")
	formula.tmp <- paste0("survsim ~ ", formula.resp)
	
	cox.tmp <- coxph(as.formula(formula.tmp), data=pheno.df)
	# convenient naming
	cox.tmp$call <- paste0('coxph(formula=', formula.tmp, ', data=pheno.tmp)')
	cox.tmp$call <- sub("response", responsename, cox.tmp$call)
	names(cox.tmp$coefficients)[1] <- responsename 
	return(cox.tmp)
}