# An artificial Powell example
set.seed(2345)
x <- sqrt(rnorm(100)^2)
y <- -0.5 + x +(.25 + .25*x)*rnorm(100)
plot(x,y, type="n")
s <- (y > 0)
points(x[s],y[s],cex=.9,pch=16)
points(x[!s],y[!s],cex=.9,pch=1)
yLatent <- y
y <- pmax(0,y)
yc <- rep(0,100)
for(tau in (1:4)/5){
f <- crq(Curv(y,yc) ~ x, tau = tau, method = "Pow")
xs <- sort(x)
lines(xs,pmax(0,cbind(1,xs)%*%f$coef),col="red")
abline(rq(y ~ x, tau = tau), col="blue")
abline(rq(yLatent ~ x, tau = tau), col="green")
}
legend(.15,2.5,c("Naive QR","Censored QR","Omniscient QR"),
lty=rep(1,3),col=c("blue","red","green"))
data(uis)
#estimate the Peng and Huang model using log(TIME) AFT specification
fit <- crq(Surv(log(TIME), CENSOR) ~ ND1 + ND2 + IV3 +
TREAT + FRAC + RACE + AGE * SITE, method = "Por", data = uis)
Sfit <- summary(fit,1:19/20)
PHit <- 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)),main= "Quantiles at Median Covariate Values")
plot(rearrange(pred),add=TRUE,do.points=FALSE,col.vert ="red", col.hor="red")
legend(.15,7,c("Raw","Rearranged"),lty = rep(1,2),col=c("black","red"))
Run the code above in your browser using DataLab