11# Automatically generated from the noweb directory
2- # tt <- function(x) x
32coxph <- function (formula , data , weights , subset , na.action ,
43 init , control , ties = c(" efron" , " breslow" , " exact" ),
54 singular.ok = TRUE , robust ,
@@ -9,6 +8,8 @@ coxph <- function(formula, data, weights, subset, na.action,
98 missing.ties <- missing(ties ) & missing(method ) # see later multistate sect
109 ties <- match.arg(ties )
1110 Call <- match.call()
11+ if (missing(formula )) stop(" a formula argument is required" )
12+
1213 # # We want to pass any ... args to coxph.control, but not pass things
1314 # # like "dats=mydata" where someone just made a typo. The use of ...
1415 # # is simply to allow things like "eps=1e6" with easier typing
@@ -20,14 +21,32 @@ coxph <- function(formula, data, weights, subset, na.action,
2021 stop(gettextf(" Argument %s not matched" ,
2122 names(extraArgs )[indx == 0L ]), domain = NA )
2223 }
24+
25+ # Gather any leftover arguments into a coxph.control call
26+ # If there is a control argument, force a call to coxph.control to both
27+ # fill it out with all the elements and do sanity checks
2328 if (missing(control )) control <- coxph.control(... )
29+ else if (is.list(control )) control <- do.call(coxph.control , control )
30+ else stop(" control argument must be a list" )
2431
32+ # make Surv(), strata() etc in a formula resolve to the survival namespace
33+ if (is.list(formula )) {
34+ newform <- removeDoubleColonSurv(formula [[1 ]])
35+ if (! is.null(newform )) {
36+ formula [[1 ]] <- newform $ formula
37+ if (newform $ newcall ) Call $ formula <- newform $ formula
38+ }
39+ } else {
40+ newform <- removeDoubleColonSurv(formula )
41+ if (! is.null(newform )) {
42+ formula <- newform $ formula
43+ if (newform $ newcall ) Call $ formula <- formula # save the nicer version
44+ }
45+ }
2546 # Move any cluster() term out of the formula, and make it an argument
2647 # instead. This makes everything easier. But, I can only do that with
2748 # a local copy, doing otherwise messes up future use of update() on
2849 # the model object for a user stuck in "+ cluster()" mode.
29- if (missing(formula )) stop(" a formula argument is required" )
30-
3150 ss <- " cluster"
3251 if (is.list(formula ))
3352 Terms <- if (missing(data )) terms(formula [[1 ]], specials = ss ) else
@@ -60,7 +79,6 @@ coxph <- function(formula, data, weights, subset, na.action,
6079 indx <- match(c(" formula" , " data" , " weights" , " subset" , " na.action" ,
6180 " cluster" , " id" , " istate" ),
6281 names(Call ), nomatch = 0 )
63- if (indx [1 ] == 0 ) stop(" A formula argument is required" )
6482 tform <- Call [c(1 ,indx )] # only keep the arguments we wanted
6583 tform [[1L ]] <- quote(stats :: model.frame ) # change the function called
6684
@@ -99,13 +117,6 @@ coxph <- function(formula, data, weights, subset, na.action,
99117 tform $ formula <- if (missing(data )) terms(formula , special ) else
100118 terms(formula , special , data = data )
101119
102- # Make "tt" visible for coxph formulas, without making it visible elsewhere
103- if (! is.null(attr(tform $ formula , " specials" )$ tt )) {
104- coxenv <- new.env(parent = environment(formula ))
105- assign(" tt" , function (x ) x , envir = coxenv )
106- environment(tform $ formula ) <- coxenv
107- }
108-
109120 # okay, now evaluate the formula
110121 mf <- eval(tform , parent.frame())
111122 Terms <- terms(mf )
@@ -155,9 +166,14 @@ coxph <- function(formula, data, weights, subset, na.action,
155166 stop(" multi-state models do not currently support pspline terms" )
156167 if (length(attr(Terms , " specials" )$ ridge ) > 0 )
157168 stop(" multi-state models do not currently support ridge penalties" )
158- if (! missing.ties ) method <- ties <- " breslow"
169+ if (missing.ties ) method <- ties <- " breslow"
159170 }
160171
172+ # the code was never designed for multiple fraily terms, but of course
173+ # someone tried it
174+ if (length(attr(Terms , " specials" )$ frailty ) > 1 )
175+ stop(" multiple frailty terms are not supported" )
176+
161177 if (control $ timefix ) Y <- aeqSurv(Y )
162178 if (length(attr(Terms , ' variables' )) > 2 ) { # a ~1 formula has length 2
163179 ytemp <- innerterms(formula [1 : 2 ])
@@ -191,10 +207,6 @@ coxph <- function(formula, data, weights, subset, na.action,
191207 if (! hasinteractions ) dropterms <- stemp $ terms
192208 } else istrat <- NULL
193209
194- if (hasinteractions && multi )
195- stop(" multi-state coxph does not support strata*covariate interactions" )
196-
197-
198210 timetrans <- attr(Terms , " specials" )$ tt
199211 if (missing(tt )) tt <- NULL
200212 if (length(timetrans )) {
0 commit comments