简体   繁体   中英

Censored quantile regression in R: getting specific quantiles

I've generated the following data in R:

library(quantreg)
library(survival)

set.seed(789)
N <- 2000
u <- runif(N)
x1 <- rbinom(N,1,.5)
x2 <- rbinom(N,1,.5)
x1x2<-x1*x2
lambda <- 1 + 1.5*x1 + 1.5*x2 + .5*x1x2
k <- 2
y <- lambda*((-log(1-u))^(1/k));max(y)
c <- runif(N,max=15)
event = as.numeric(y<=c)
mean(event);table(event)
cens <- 1-event
table(cens)mean(cens)
time <-as.matrix(ifelse(event==1,y,c))

St<-Surv(time,event,type="right")

To which I've fit the following censored quantile regression model:

q2 <- crq(St~x1 + x2 + x1x2,tau=.9,method="Portnoy")
summary(q2)

As one can see, I'm interested in the 0.9th quantile. But summary(q2) returns the 20th to 80th percentiles (by 20). How can I get only the 0.9th quantile (aka the 90th percentile)?? My problem is that, even though I request the 90th percentile in crq (ie, "tau=0.9"), the summary function keeps returning the same set of (unwanted) percentiles (20th, 40th, 60th, 80th).

Entering...

?summary.crq

Results in...

## S3 method for class 'crq'
summary(object, taus = 1:4/5, alpha = .05, se="boot", covariance=TRUE,  ...)

So you should just be able to specify tau.

summary(q2, tau = 1:9/10)

tau: [1] 0.9

Coefficients:
            Value    Lower Bd Upper Bd Std Error T Value  Pr(>|t|)
(Intercept)  1.55424  1.44255  1.66594  0.05699  27.27311  0.00000
x1           2.23893  2.03412  2.44375  0.10450  21.42528  0.00000
x2           2.15514  1.97319  2.33710  0.09284  23.21441  0.00000
x1x2         0.74453  0.35153  1.13753  0.20051   3.71309  0.00020

Specifying a single value for tau results in an error.

An example of quantile:

quantile(dataframe$columnname, na.rm=TRUE)

In this case, you want to have quantile(dataframe$columnname,probs=(0.009, 0.2, 0.8))

0.009 gives you the 0.9th quantile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM