predict.coxphw: Predictions for a weigthed Cox model

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/predict.coxphw.r

Description

This function obtains the effect estimates (e.g. of a nonlinear or a time-dependent effect) at specified values of a continuous covariable for a model fitted by coxphw. It prints the relative or log relative hazard. Additonally, the linear predictor lp or the risk score exp(lp) can be obtained.

Usage

1
2
3
4
 ## S3 method for class 'coxphw'
predict(object, type = c("shape", "slice.time", "slice.z", "slice.x", "lp", "risk"),
        x = NULL, newx = NA, refx = NA, z = NULL, at = NULL, exp = FALSE,
        se.fit = FALSE, pval = FALSE, digits = 4, verbose = FALSE, ...)

Arguments

object

an output object of coxphw.

type

the type of predicted value. Choices are: "lp" for the linear predictors,
"risk" for the risk scores exp(lp)
"shape" for visualizing a nonlinear effect of x,
"slice.x" for slicing an interaction of type fun(x)*z at values of x, "slice.z" for slicing an interaction of type fun(x)*z at a value of z,
"slice.time" for slicing a time-by-covariate interaction of type z + fun(time):z at values of time
See details.

x

name of the continuous or time variable (use "") for type = "shape", "slice.time", "slice.x", or "slice.z".

newx

the data values for x for which the effect estimates should be obtained (e.g., 30:70) for type = "shape", "slice.time", "slice.x", or "slice.z".

refx

the reference value for variable x for type = "shape" or "slice.z". The log relative hazard at this value will be 0. (e.g., refx= 50).

z

variable which is in interaction with x (use "") for "slice.time", "slice.x", or "slice.z".

at

if type = "slice.z" at which level ("slice") of z should the effect estimates of the x be obtained.

exp

if set to TRUE (default), the log relative hazard is given, otherwise the relative hazard is requested for type = "shape", "slice.time", "slice.x", or "slice.z".

se.fit

if set to TRUE, pointwise standard errors are produced for the predictions for type = "shape", "slice.time", "slice.x", or "slice.z".

pval

if set to TRUE add Wald-test p-values to effect estimates at values of newx for type = "shape", "slice.time", "slice.x", or "slice.z". Default is set to FALSE.

digits

number of printed digits. Default is 4.

verbose

if set to TRUE (default), results are printed.

...

further parameters.

Details

This function can be used to depict the estimated nonlinear or time-dependent effect of an object of class coxphw. It supports simple nonlinear effects as well as interaction effects of a continuous variable with a binary covariate or with time (see examples section).

If the effect estimates of a simple nonlinear effect of x without interaction is requested with type = "shape", then x (the usually continuous covariate), refx (the reference value of x) and newx (for these values of x the effect estimates are obtained) must be given.

If the effect estimates of an interaction of z with x are requested with type = "slice.x", then x (the usually continuous variable), z (the categorical variable) and newx (for these values of x the effect estimates are obtained) must be given.

If the effect estimates of an interaction of z with x for one level of z are requested with type = "slice.z"), then x (the usually continuous variable), z (the categorical variable), at (at which level of z), refx (the reference value of x), and newx (for these values of x the effect estimates are obtained) must be given.

If the effect estimates of an interaction of z with time are requested with type = "slice.time", then x (the time), z (the categorical variable) and newx (for these values of x the effect estimates are obtained) must be given.

Note that if the model formula contains time-by-covariate interactions, then the linear predictor and the risk score are obtained for the failure or censoring time of each subject.

Value

If type = "shape", "slice.time", "slice.x", or "slice.z" a list with the following components:

estimates

a matrix with estimates of (log) relative hazard and corresponding confidence limits.

se

pointwise standard errors, only if se.fit = TRUE.

p

p-value, only if pval = TRUE.

alpha

the significance level = 1 - confidence level.

exp

an indicator if log relative hazard or relative hazard was obtained.

x

name of x.

If type = "lp" or "risk", a vector.

Note

In coxphw version 4.0.0 the old plotshape function is replaced with predict.coxphw and plot.coxphw.predict.

Author(s)

Georg Heinze, Meinhard Ploner, Daniela Dunkler

References

Royston P and Altman D (1994). Regression Using Fractional Polynomials of Continuous Covariates: Parsimonious Parametric Modelling. Applied Statistics 43, 429-467.

Royston P and Sauerbrei W (2008). Multivariable Model-building. A pragmatic approach to regression analysis based on fractional polynomials for modelling continuous variables. Wiley, Chichester, UK.

See Also

coxphw, plot.coxphw.predict

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
### Example for type = "slice.time"
data("gastric")
gastric$yrs <- gastric$time / 365.25

# check proportional hazards
fitcox <- coxph(Surv(yrs, status) ~ radiation + cluster(id), data = gastric, x = TRUE,
                method = "breslow")
fitcox.ph <- cox.zph(fit = fitcox, transform = "identity")


## compare and visualize linear and log-linear time-dependent effects of radiation
fit1 <- coxphw(Surv(yrs, status) ~ yrs * radiation, data = gastric, template = "PH")
summary(fit1)

predict(fit1, type = "slice.time", x = "yrs", z = "radiation", newx = c(0.5, 1, 2),
        verbose = TRUE, exp = TRUE, pval = TRUE)


fit2 <- coxphw(Surv(yrs, status) ~ log(yrs) * radiation, data = gastric, template = "PH")
summary(fit2)

predict(fit2, type = "slice.time", x = "yrs", z = "radiation", newx = c(0.5, 1, 2),
        verbose = TRUE, exp = TRUE, pval = TRUE)


plotx <- seq(from = quantile(gastric$yrs, probs = 0.05),
             to = quantile(gastric$yrs, probs = 0.95), length = 100)
y1 <- predict(fit1, type = "slice.time", x = "yrs", z = "radiation", newx = plotx)
y2 <- predict(fit2, type = "slice.time", x = "yrs", z = "radiation", newx = plotx)

plot(x = fitcox.ph, se = FALSE, xlim = c(0, 3), las = 1, lty = 3)
abline(a = 0, b = 0, lty = 3)
lines(x = plotx, y = y1$estimates[, "coef"], col = "red", lty = 1, lwd = 2)
lines(x = plotx, y = y2$estimates[, "coef"], col = "blue", lty = 2, lwd = 2)
legend(x = 1.7, y = 1.6, title = "time-dependent effect", title.col = "black",
       legend = c("LOWESS", "linear", "log-linear"), col = c("black", "red", "blue"),
       lty = c(3, 1:2), bty = "n", lwd = 2, text.col = c("black", "red", "blue"))



### Example for type = "shape"
set.seed(512364)
n <- 200
x <- 1:n
true.func <- function(x) 2.5 * log(x) - 2
x <- round(runif(x) * 60 + 10, digits = 0)
time <- round(100000 * rexp(n= n, rate = 1) / exp(true.func(x)), digits = 1)
event <- rep(x = 1, times = n)
my.data <- data.frame(x,time,event)

fit <- coxphw(Surv(time, event) ~ log(x) + x, data = my.data, template = "AHR")

predict(fit, type = "shape", newx = c(30, 50), refx = 40, x = "x", verbose = TRUE)

plotx <- seq(from = quantile(x, probs = 0.05),
             to = quantile(x, probs = 0.95), length = 100)
plot(predict(fit, type = "shape", newx = plotx, refx = 40, x = "x"))


### Example for type = "slice.x" and "slice.z"
set.seed(75315)
n <- 200
trt <- rbinom(n = n, size = 1, prob = 0.5)
x <- 1:n
true.func <- function(x) 2.5 * log(x) - 2
x <- round(runif(n = x) * 60 + 10, digits = 0)
time <- 100 * rexp(n = n, rate = 1) / exp(true.func(x) /
                                      4 * trt - (true.func(x) / 4)^2 * (trt==0))
event <- rep(x = 1, times = n)
my.data <- data.frame(x, trt, time, event)

fun<-function(x) x^(-2)
fit <- coxphw(Surv(time, event) ~ x * trt + fun(x) * trt , data = my.data,
              template = "AHR", verbose = FALSE)

# plots the interaction of trt with x (the effect of trt dependent on the values of x)
plotx <- quantile(x, probs = 0.05):quantile(x, probs = 0.95)
plot(predict(fit, type = "slice.x", x = "x", z = "trt",
             newx = plotx, verbose = FALSE), main = "interaction of trt with x")

# plot the effect of x in subjects with trt = 0
y0 <- predict(fit, type = "slice.z", x = "x", z = "trt", at = 0, newx = plotx,
              refx = median(x), verbose = FALSE)
plot(y0, main = "effect of x in subjects with trt = 0")


# plot the effect of x in subjects with trt = 1
y1 <- predict(fit, type = "slice.z", x = "x", z = "trt", at = 1, newx = plotx,
              refx = median(x), verbose = FALSE)
plot(y1, main = "effect of x in subjects with trt = 1")


# Example for type = "slice.time"
set.seed(23917)
time <- 100 * rexp(n = n, rate = 1) / exp((true.func(x) / 10)^2 / 2000 * trt + trt)
event <- rep(x = 1, times = n)
my.data <- data.frame(x, trt, time, event)
plot.x <- seq(from = 1, to = 100, by = 1)

fun  <- function(t) { PT(t)^-2 * log(PT(t)) }
fun2 <- function(t) { PT(t)^-2 }
fitahr <- coxphw(Surv(time, event) ~ fun(time) * trt + fun2(time) * trt + x,
                 data = my.data, template = "AHR")
yahr <- predict(fitahr, type = "slice.time", x = "time", z = "trt", newx = plot.x)

fitph <- coxphw(Surv(time, event) ~ fun(time) * trt + fun2(time) * trt + x,
                data = my.data, template = "PH")
yph <- predict(fitph, type = "slice.time", x = "time", z = "trt", newx = plot.x)

plot(yahr, addci = FALSE)
lines(yph$estimates$time, yph$estimates$coef, lty = 2)
legend("bottomright", legend = c("AHR", "PH"), bty = "n", lty = 1:2,
       inset = 0.05)

Example output

Loading required package: survival
coxphw(formula = Surv(yrs, status) ~ yrs * radiation, data = gastric, 
    template = "PH")

Model fitted by unweighted estimation (PH template) 

                    coef  se(coef) exp(coef) lower 0.95 upper 0.95         z
radiation      1.2699606 0.4334889 3.5607124  1.5224762  8.3276657  2.929627
yrs:radiation -0.9652886 0.3409321 0.3808733  0.1952444  0.7429892 -2.831322
                        p
radiation     0.003393692
yrs:radiation 0.004635608

Wald Chi-square = 9.047941 on 2  df, p = 0.01084588

Covariance-Matrix:
               radiation yrs:radiation
radiation      0.1879126    -0.1241715
yrs:radiation -0.1241715     0.1162347

Generalized concordance probability:   Estimates may be biased!
              concordance prob. lower 0.95 upper 0.95
radiation                0.7807     0.6036     0.8928
yrs:radiation            0.2758     0.1634     0.4263
  yrs     HR HR lower 0.95 HR upper 0.95      p
1 0.5 2.1975        1.2096        3.9924 0.0098
2 1.0 1.3562        0.8536        2.1547 0.1971
3 2.0 0.5165        0.2381        1.1207 0.0946
coxphw(formula = Surv(yrs, status) ~ log(yrs) * radiation, data = gastric, 
    template = "PH")

Model fitted by unweighted estimation (PH template) 

                          coef  se(coef) exp(coef) lower 0.95 upper 0.95
radiation           0.03766302 0.2367992 1.0383813  0.6528193   1.651660
log(yrs):radiation -0.66924556 0.4821178 0.5120948  0.1990540   1.317437
                            z         p
radiation           0.1590504 0.8736291
log(yrs):radiation -1.3881370 0.1650953

Wald Chi-square = 1.97312 on 2  df, p = 0.372857

Covariance-Matrix:
                     radiation log(yrs):radiation
radiation          0.056073853        0.004581723
log(yrs):radiation 0.004581723        0.232437577

Generalized concordance probability:   Estimates may be biased!
                   concordance prob. lower 0.95 upper 0.95
radiation                     0.5094      0.395     0.6229
log(yrs):radiation            0.3387      0.166     0.5685
  yrs     HR HR lower 0.95 HR upper 0.95      p
1 0.5 1.6513        0.7514        3.6290 0.2119
2 1.0 1.0384        0.6528        1.6517 0.8736
3 2.0 0.6530        0.2882        1.4793 0.3070
   x    coef coef lower 0.95 coef upper 0.95
1 30 -0.7201         -0.8582         -0.5821
2 50  0.5655          0.4235          0.7075

coxphw documentation built on July 8, 2020, 6:52 p.m.