File: crquis.R

package info (click to toggle)
r-cran-quantreg 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,224 kB
  • sloc: fortran: 6,741; ansic: 288; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# UIS example for the crq Peng-Hwang  method.

#estimate the Peng and Huang model using log(TIME) AFT specification
if(requireNamespace("survival", quietly = TRUE)) {
    data(uis)
    Surv <- survival::Surv
    fit <- crq(Surv(log(TIME), CENSOR) ~  ND1 + ND2 + IV3 +
               TREAT + FRAC + RACE + AGE * SITE, method = "Portnoy", data = uis)
    Sfit <- summary(fit,1:19/20)
    PHit <- survival::coxph(Surv(TIME, CENSOR) ~  ND1 + ND2 + IV3 +
               TREAT + FRAC + RACE + AGE * SITE, data = uis)
    plot(Sfit, CoxPHit = PHit)
    formula <-  ~  ND1 + ND2 + IV3 + TREAT + FRAC + RACE + AGE * SITE -1
    X <- data.frame(model.matrix(formula,data=uis))
    newd <- as.list(apply(X,2,median))
    pred <- predict(fit, newdata=newd, stepfun = TRUE)
    plot(pred,do.points=FALSE,xlab = expression(tau), ylab = expression(Q(tau)),
	    lwd = 1.5, main= "Quantiles at Median Covariate Values")
    plot(rearrange(pred),add=TRUE,do.points=FALSE,col.vert ="red", col.hor="red")
    legend(.10,10,c("Raw","Rearranged"),lty = rep(1,2),col=c("black","red"))
}