Skip to content

Commit 214edd1

Browse files
Terry M Therneaucran-robot
authored andcommitted
version 3.7-0
1 parent 2e3b026 commit 214edd1

File tree

125 files changed

+16908
-1142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+16908
-1142
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Title: Survival Analysis
22
Priority: recommended
33
Package: survival
4-
Version: 3.6-4
5-
Date: 2024-04-22
4+
Version: 3.7-0
5+
Date: 2024-06-01
66
Depends: R (>= 3.5.0)
77
Imports: graphics, Matrix, methods, splines, stats, utils
88
LazyData: Yes
@@ -22,12 +22,12 @@ Description: Contains the core survival analysis routines, including
2222
License: LGPL (>= 2)
2323
URL: https://github.com/therneau/survival
2424
NeedsCompilation: yes
25-
Packaged: 2024-04-22 14:02:15 UTC; therneau
25+
Packaged: 2024-06-03 15:17:04 UTC; therneau
2626
Author: Terry M Therneau [aut, cre],
2727
Thomas Lumley [ctb, trl] (original S->R port and R maintainer until
2828
2009),
2929
Atkinson Elizabeth [ctb],
3030
Crowson Cynthia [ctb]
3131
Maintainer: Terry M Therneau <therneau.terry@mayo.edu>
3232
Repository: CRAN
33-
Date/Publication: 2024-04-24 06:50:02 UTC
33+
Date/Publication: 2024-06-05 16:30:02 UTC

MD5

Lines changed: 124 additions & 118 deletions
Large diffs are not rendered by default.

NAMESPACE

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ S3method(as.character, Surv)
6868
S3method(as.character, Surv2)
6969
S3method(as.data.frame, Surv)
7070
S3method(as.data.frame, Surv2)
71-
S3method(as.integer, Surv)
72-
S3method(as.integer, Surv2)
7371
S3method(as.logical, Surv)
7472
S3method(as.logical, Surv2)
7573
S3method(as.matrix, ratetable)
7674
S3method(as.matrix, Surv)
7775
S3method(as.matrix, Surv2)
78-
S3method(as.numeric, Surv)
79-
S3method(as.numeric, Surv2)
8076
S3method(attrassign, default)
8177
S3method(attrassign, lm)
8278
S3method(barplot, Surv)

R/Surv.R

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,23 @@ t.Surv <- function(x) t(as.matrix(x))
410410

411411
as.logical.Surv <- function(x, ...)
412412
stop("invalid operation on a survival time")
413-
as.integer.Surv <- function(x, ...) {
414-
nc <- ncol(x)
415-
x[,-nc] <- as.integer(x[,-nc])
416-
if (nc==3 && any(x[,1] >= x[,2]))
417-
stop("invalid survival time created")
418-
x
419-
}
420-
as.numeric.Surv <- function(x, ...) {
421-
nc <- ncol(x)
422-
x[,-nc] <- as.numeric(x[, -nc])
423-
x
424-
}
413+
414+
# removed 2024-06-02, make Surv act like a matrix for this op
415+
#as.integer.Surv <- function(x, ...) {
416+
# nc <- ncol(x)
417+
# x[,-nc] <- as.integer(x[,-nc])
418+
# if (nc==3 && any(x[,1] >= x[,2]))
419+
# stop("invalid survival time created")
420+
# x
421+
#}
422+
423+
# per the help file for as.numeric, this should have been as.double
424+
# so never worked anyway
425+
#as.numeric.Surv <- function(x, ...) {
426+
# nc <- ncol(x)
427+
# x[,-nc] <- as.numeric(x[, -nc])
428+
# x
429+
#}
425430

426431
mean.Surv <-function(x, ...)
427432
stop("a mean method has not been defined for Surv objects")

R/Surv2.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,6 @@ t.Surv2 <- function(x) t(as.matrix(x))
202202

203203
as.logical.Surv2 <- function(x, ...)
204204
stop("invalid operation on a survival time")
205-
as.integer.Surv2 <- function(x, ...) {
206-
x[,1] <- as.integer(x[,1])
207-
x
208-
}
209-
as.numeric.Surv2 <- function(x, ...) {
210-
x[,1] <- as.numeric(x[,1])
211-
x
212-
}
213205

214206
mean.Surv2 <-function(x, ...)
215207
stop("a mean method has not been defined for Surv2 objects")

R/concordance.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ concordancefit <- function(y, x, strata, weights, ymin=NULL, ymax=NULL,
244244
} else {
245245
sort.stop <- order(-y[,2], y[,3], risk) -1L #order by endpoint
246246
sort.start <- order(-y[,1]) -1L
247-
gfit <- .Call(Cfastkm2, y, wts, sort.stop, sort.start)
247+
gfit <- .Call(Cfastkm2, y, wts, sort.start, sort.stop)
248248
}
249249
etime <- gfit$etime
250250
}

R/coxph.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ coxph <- function(formula, data, weights, subset, na.action,
136136
istate <- model.extract(mf, "istate")
137137
}
138138
if (n==0) stop("No (non-missing) observations")
139+
if (length(id) >0) n.id <- length(unique(id))
139140

140141
type <- attr(Y, "type")
141142
multi <- FALSE
@@ -588,6 +589,7 @@ coxph <- function(formula, data, weights, subset, na.action,
588589
}
589590
fit$n <- data.n
590591
fit$nevent <- sum(Y[,ncol(Y)])
592+
if (length(id)>0) fit$n.id <- n.id
591593
fit$terms <- Terms
592594
fit$assign <- assign
593595
class(fit) <- fit$class

R/predict.coxph.R

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ predict.coxph <- function(object, newdata,
1111
type <-match.arg(type)
1212
if (type=="survival") {
1313
survival <- TRUE
14-
type <- "expected" #this is to stop lots of "or" statements
14+
type <- "expected" # survival and expecte have nearly the same code path
1515
}
1616
else survival <- FALSE
17+
if (type == "expected") reference <- "sample" # a common ref is easiest
1718

1819
n <- object$n
1920
Terms <- object$terms
@@ -162,8 +163,14 @@ predict.coxph <- function(object, newdata,
162163
pred <- se <- double(nrow(mf2))
163164
newx <- newx - rep(object$means, each=nrow(newx))
164165
newrisk <- c(exp(newx %*% object$coef) + newoffset)
166+
if (ncol(y) ==3 && survival) { #
167+
t0 <- unname(min(y[,1])) # the start of the survival curve
168+
# simpler is all(newy[,1] == t0), but
169+
# use of all.equal allows for roundoff error in newdata
170+
if (!isTRUE(all.equal(as.vector(newy[,1]), rep(t0, nrow(newy)))))
171+
stop("predicted survival must be from the start of the curve")
165172
}
166-
173+
}
167174
survtype<- ifelse(object$method=='efron', 3,2)
168175
for (i in ustrata) {
169176
indx <- which(oldstrat == i)
@@ -173,66 +180,60 @@ predict.coxph <- function(object, newdata,
173180
afit.n <- length(afit$time)
174181
if (missing(newdata)) {
175182
# In this case we need se.fit, nothing else
176-
j1 <- approx(afit$time, 1:afit.n, y[indx,1], method='constant',
177-
f=0, yleft=0, yright=afit.n)$y
183+
j1 <- findInterval(y[indx,1], afit$time)
178184
chaz <- c(0, afit$cumhaz)[j1 +1]
179185
varh <- c(0, cumsum(afit$varhaz))[j1 +1]
180186
xbar <- rbind(0, afit$xbar)[j1+1,,drop=F]
181187
if (ncol(y)==2) {
182188
dt <- (chaz * x[indx,]) - xbar
183189
se[indx] <- sqrt(varh + rowSums((dt %*% object$var) *dt)) *
184190
risk[indx]
185-
}
191+
}
186192
else {
187-
j2 <- approx(afit$time, 1:afit.n, y[indx,2], method='constant',
188-
f=0, yleft=0, yright=afit.n)$y
189-
chaz2 <- c(0, afit$cumhaz)[j2 +1]
190-
varh2 <- c(0, cumsum(afit$varhaz))[j2 +1]
191-
xbar2 <- rbind(0, afit$xbar)[j2+1,,drop=F]
193+
j2 <- findInterval(y[indx,2], afit$time)
194+
chaz2 <- c(0, afit$cumhaz)[j2 +1L]
195+
varh2 <- c(0, cumsum(afit$varhaz))[j2 +1L]
196+
xbar2 <- rbind(0, afit$xbar)[j2+ 1L,,drop=F]
192197
dt <- (chaz * x[indx,]) - xbar
193198
v1 <- varh + rowSums((dt %*% object$var) *dt)
194199
dt2 <- (chaz2 * x[indx,]) - xbar2
195200
v2 <- varh2 + rowSums((dt2 %*% object$var) *dt2)
196201
se[indx] <- sqrt(v2-v1)* risk[indx]
197-
}
198202
}
203+
}
199204

200205
else {
201206
#there is new data
202207
use.x <- TRUE
203208
indx2 <- which(newstrat == i)
204-
j1 <- approx(afit$time, 1:afit.n, newy[indx2,1],
205-
method='constant', f=0, yleft=0, yright=afit.n)$y
209+
j1 <- findInterval(newy[indx2,1], afit$time)
206210
chaz <-c(0, afit$cumhaz)[j1+1]
207211
pred[indx2] <- chaz * newrisk[indx2]
208212
if (se.fit) {
209213
varh <- c(0, cumsum(afit$varhaz))[j1+1]
210214
xbar <- rbind(0, afit$xbar)[j1+1,,drop=F]
211-
}
215+
}
212216
if (ncol(y)==2) {
213217
if (se.fit) {
214218
dt <- (chaz * newx[indx2,]) - xbar
215219
se[indx2] <- sqrt(varh + rowSums((dt %*% object$var) *dt)) *
216220
newrisk[indx2]
217-
}
218221
}
222+
}
219223
else {
220-
j2 <- approx(afit$time, 1:afit.n, newy[indx2,2],
221-
method='constant', f=0, yleft=0, yright=afit.n)$y
222-
chaz2 <- approx(-afit$time, afit$cumhaz, -newy[indx2,2],
223-
method="constant", rule=2, f=0)$y
224-
chaz2 <-c(0, afit$cumhaz)[j2+1]
224+
j2 <- findInterval(newy[indx2,2], afit$time)
225+
chaz2 <-c(0, afit$cumhaz)[j2+1L]
225226
pred[indx2] <- (chaz2 - chaz) * newrisk[indx2]
226-
227+
227228
if (se.fit) {
228-
varh2 <- c(0, cumsum(afit$varhaz))[j1+1]
229-
xbar2 <- rbind(0, afit$xbar)[j1+1,,drop=F]
229+
varh2 <- c(0, cumsum(afit$varhaz))[j2 +1L]
230+
xbar2 <- rbind(0, afit$xbar)[j2 + 1L,,drop=F]
230231
dt <- (chaz * newx[indx2,]) - xbar
231232
dt2 <- (chaz2 * newx[indx2,]) - xbar2
232233

233234
v2 <- varh2 + rowSums((dt2 %*% object$var) *dt2)
234235
v1 <- varh + rowSums((dt %*% object$var) *dt)
235-
se[indx2] <- sqrt(v2-v1)* risk[indx2]
236+
se[indx2] <- sqrt(v2-v1)* newrisk[indx2]
236237
}
237238
}
238239
}

R/print.coxph.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ print.coxph <-
7979
"\n", sep="")
8080
omit <- x$na.action
8181
cat("n=", x$n)
82+
if (!is.null(x$n.id)) cat(", unique id=", x$n.id)
8283
if (!is.null(x$nevent)) cat(", number of events=", x$nevent, "\n")
8384
else cat("\n")
8485
if (length(omit))

R/print.summary.coxph.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ print.summary.coxph <-
2020
if (length(omit))
2121
cat(" (", naprint(omit), ")\n", sep="")
2222

23-
if (nrow(x$coef)==0) { # Null model
23+
if (nrow(x$coefficients)==0) { # Null model
2424
cat (" Null model\n")
2525
return()
2626
}

0 commit comments

Comments
 (0)