2

I am trying to do a quantile regression with the rq function of the 'quantreg' library. I have a problem because R completely crash when I add the 'weights' argument.

I added a reproducible example here:

library(quantreg)

prof  <- seq(1, 500)
n_profit <- 150

xpred <- seq(min(prof), max(prof), length = n_profit)
x = prof
h=10
tau = 0.5

y <- c(rep(NA, 60), rnorm(n = length(prof) - 60))
z <- x - xpred[1]
z2 <-z^2
wx <- dnorm(z/h)

And then, this works:

r <- rq(y ~ z + z2, tau = 0.5,  ci = FALSE)

But if I try to add the weights argument like this

r <- rq(y ~ z + z2, tau = 0.5, weights = wx,  ci = FALSE)

I have the message 'R session Aborted, R encountered a fatal error ...'

Here, R information:

  sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252                
LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C                   LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quantreg_5.35 SparseM_1.77 

loaded via a namespace (and not attached):
[1] compiler_3.5.0     Matrix_1.2-14      tools_3.5.0            
MatrixModels_0.4-1 grid_3.5.0        
[6] lattice_0.20-35   

RStudio
Version 1.1.447 – © 2009-2018 RStudio, Inc.

Note: this example works under R version 3.3.3.

Do you have any idea how to fix it?

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 1
    Could be a numeric computing issue, maybe it doesn't like the NAs. But also will all the negative y-values get logged and then be infinite? Maybe should try changing some values around. Most likely the issue is the program is stuck in an infinite loop, or the number of iterations just becomes too large for R to handle. – Tony Hellmuth May 04 '18 at 01:08
  • Thanks for your answer. I also suspect a problem with the package and R version, because this example works under R version 3.3.3 – A. Receveur May 04 '18 at 03:59

0 Answers0