2

我正在尝试使用“quantreg”库的 rq 函数进行分位数回归。我有一个问题,因为当我添加“权重”参数时,R 完全崩溃了。

我在这里添加了一个可重现的示例:

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)

然后,这有效:

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

但是如果我尝试像这样添加权重参数

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

我收到消息“R 会话中止,R 遇到致命错误...”

这里,R信息:

  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.

注意:此示例适用于 R 版本 3.3.3。

你知道如何解决它吗?

4

0 回答 0