从R的多个分位数的分位数回归中访问p值

时间:2016-11-27 06:35:32

标签: r quantreg

我想访问具有多个分位数的分位数回归的p值。

; We still have num in ECX, because int 0x80 doesn't clobber any regs (except for eax with the return value).
    test byte [ecx + eax - 1], 1
    jnz  odd

fit2 <- rq(speed ~ vsby_avg + snwd_avg, tau=c(.05, 0.95), data = test_data) fit2_summ <- summary(fit2) 给出以下结果

str(fit2_summ)

我无法使用List of 2 $ :List of 6 ..$ call : language rq(formula = speed ~ vsby_avg + snwd_avg, tau = c(0.05, 0.95), data = test_data) ..$ terms :Classes 'terms', 'formula' language speed ~ vsby_avg + snwd_avg .. .. ..- attr(*, "variables")= language list(speed, vsby_avg, snwd_avg) ..$ coefficients: num [1:3, 1:4] 57.63195 0.13474 -0.00337 0.1919 0.01212 ... 访问第50和第95个分位数的p值,因为汇总模型存在于2个分位数而不是单个分位数,在这种情况下,上述命令将起作用。

1 个答案:

答案 0 :(得分:2)

你应该指定一个计算se的方法:

# using mtcars
library(quantreg)
fit <- rq(mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)

fit.smy <- summary(fit, se = 'boot')
# > fit.smy
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.05
#
# Coefficients:
#             Value    Std. Error t value  Pr(>|t|)
# (Intercept) 29.02978  1.85711   15.63170  0.00000
# cyl         -1.43979  0.55214   -2.60766  0.01426
# disp        -0.01546  0.00773   -1.99955  0.05499
#
# Call: rq(formula = mpg ~ cyl + disp, tau = c(0.05, 0.95), data = mtcars)
#
# tau: [1] 0.95
#
# Coefficients:
#             Value    Std. Error t value  Pr(>|t|)
# (Intercept) 51.82250  6.18594    8.37747  0.00000
# cyl         -4.70281  1.84648   -2.54691  0.01644
# disp         0.01250  0.02616    0.47785  0.63634

访问P.values

# fit.smy is a list, its length is the same as tau;
lapply(fit.smy, function(x){
    x$coefficients[,4]
})
# [[1]]
#  (Intercept)          cyl         disp 
# 3.996803e-14 2.205166e-02 5.699536e-02 
# 
# [[2]]
#  (Intercept)          cyl         disp 
# 3.263261e-08 4.381427e-02 6.903882e-01